123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- /**
- * Created by Mai on 2017/7/25.
- */
- var VolumePrice = {
- createNew: function (project) {
- let tools = {
- owner: project
- };
- class volumePrice {
- constructor () {
- this.datas = [];
- let maxID = 0;
- this.getNewID = function () {
- return maxID += 1;
- };
- this.maxID = function (ID) {
- if (arguments.length === 0) {
- return maxID;
- } else {
- maxID = Math.max(ID, maxID);
- }
- };
- tools.owner.registerModule(ModuleNames.volume_price, this);
- };
- getProject () {
- return tools.owner;
- };
- getSourceType () {
- return ModuleNames.volume_price;
- };
- loadData (datas) {
- this.datas = datas;
- };
- setMaxID (ID) {
- this.maxID(ID);
- }
- getTempVolumePrice (newID, billsID, serialNo) {
- var newData = {'ID': newID, 'serialNo': serialNo, projectID: tools.owner.ID()};
- newData[project.masterField.volumePrice] = billsID;
- return newData;
- };
- getBillsSortVolumePrice (billsID) {
- var arr = this.datas.filter(function (data) {
- return data[tools.owner.masterField.volumePrice] === billsID;
- });
- arr.sort(function (x, y) {
- return x.serialNo - y.serialNo;
- });
- return arr;
- };
- getInsertVolumePriceData (billsID, pre) {
- let bv = this.getBillsSortVolumePrice(billsID);
- let updateData = [];
- if (pre) {
- let preIndex = bv.indexOf(pre), i;
- updateData.push({updateType: 'ut_create', updateData: this.getTempVolumePrice(this.maxID() + 1, billsID, preIndex < bv.length - 1 ? bv[preIndex + 1].serialNo : bv[preIndex].serialNo + 1)});
- for (i = preIndex + 1; i < bv.length; i++) {
- updateData.push({updateType: 'ut_update', updateData: this.getTempVolumePrice(bv[i].ID, billsID, i < bv.length - 1 ? bv[i+1].serialNo : bv[i].serialNo + 1)});
- }
- } else {
- updateData.push({updateType: 'ut_create', updateData: this.getTempVolumePrice(this.maxID() + 1, billsID, bv.length > 0 ? bv[bv.length - 1].serialNo + 1 : 1)});
- }
- return updateData;
- };
- insertVolumePrice (billsID, pre) {
- tools.owner.pushNow('insertVolumePrice', [this.getSourceType()], [this.getInsertVolumePriceData(billsID, pre)]);
- let bv = this.getBillsSortVolumePrice(billsID), newVP = null;
- if (pre) {
- let preIndex = bv.indexOf(pre);
- newVP = this.getTempVolumePrice(this.getNewID(), billsID, preIndex < bv.length - 1 ? bv[preIndex + 1].serialNo : bv[preIndex].serialNo + 1);
- this.datas.push(newVP);
- for (let i = preIndex + 1; i < bv.length; i++) {
- bv[i].serialNo = i < bv.length - 1 ? bv [i + 1].serialNo : bv[i].serialNo + 1;
- }
- } else {
- newVP = this.getTempVolumePrice(this.getNewID(), billsID, bv.length > 0 ? bv[bv.length - 1].serialNo + 1 : 1);
- this.datas.push(newVP);
- }
- return newVP;
- }
- }
- return new volumePrice();
- }
- }
|