|  | @@ -378,11 +378,54 @@ $(document).ready(() => {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      SpreadJsObj.initSpreadSettingEvents(changeSpreadSetting, changeCol);
 | 
	
		
			
				|  |  |      SpreadJsObj.initSheet(changeSpreadSheet, changeSpreadSetting);
 | 
	
		
			
				|  |  | -    changeSpreadObj.setAuditValue();
 | 
	
		
			
				|  |  | -    SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
 | 
	
		
			
				|  |  | -    console.log(changeList);
 | 
	
		
			
				|  |  | -    changeSpreadObj.makeSjsFooter();
 | 
	
		
			
				|  |  | -    changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
 | 
	
		
			
				|  |  | +    const preUrl = window.location.pathname.split('/').slice(0, 4).join('/');
 | 
	
		
			
				|  |  | +    let changeListData;
 | 
	
		
			
				|  |  | +    let gclGatherData;
 | 
	
		
			
				|  |  | +    postData(preUrl + '/defaultBills', {}, function (result) {
 | 
	
		
			
				|  |  | +        gclGatherModel.loadLedgerData(result.bills);
 | 
	
		
			
				|  |  | +        gclGatherModel.loadPosData(result.pos);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        gclGatherData = gclGatherModel.gatherGclData();
 | 
	
		
			
				|  |  | +        gclGatherData = _.filter(gclGatherData, function (item) {
 | 
	
		
			
				|  |  | +            return item.leafXmjs && item.leafXmjs.length !== 0;
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        for (const ggd in gclGatherData) {
 | 
	
		
			
				|  |  | +            if (gclGatherData[ggd].leafXmjs && gclGatherData[ggd].leafXmjs.length === 0) {
 | 
	
		
			
				|  |  | +                gclGatherData.splice(ggd, 1);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            gclGatherData[ggd].code = gclGatherData[ggd].b_code;
 | 
	
		
			
				|  |  | +            let hadcid = 0;
 | 
	
		
			
				|  |  | +            for (const xmj of gclGatherData[ggd].leafXmjs) {
 | 
	
		
			
				|  |  | +                const changeLedger = _.find(changeLedgerList, { id: xmj.gcl_id });
 | 
	
		
			
				|  |  | +                const changePos = _.find(changePosList, { id: xmj.mx_id, lid: xmj.gcl_id });
 | 
	
		
			
				|  |  | +                if (changeLedger || changePos) {
 | 
	
		
			
				|  |  | +                    xmj.cid = 1;
 | 
	
		
			
				|  |  | +                    xmj.ccid = changeLedger ? changeLedger.ccid : changePos.ccid;
 | 
	
		
			
				|  |  | +                    hadcid = 1;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            if (hadcid !== 0) gclGatherData[ggd].cid = 1;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        console.log(gclGatherData);
 | 
	
		
			
				|  |  | +        // 数组去重
 | 
	
		
			
				|  |  | +        const dealBillList = result.dealBills;
 | 
	
		
			
				|  |  | +        for (const db of gclGatherData) {
 | 
	
		
			
				|  |  | +            const exist_index = dealBillList.findIndex(function (item) {
 | 
	
		
			
				|  |  | +                return item.code === db.code && item.name === db.name && item.unit === db.unit && item.unit_price === db.unit_price;
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            if (exist_index !== -1) {
 | 
	
		
			
				|  |  | +                dealBillList.splice(exist_index, 1);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        changeListData = gclGatherData.concat(dealBillList).sort(sortByCode);
 | 
	
		
			
				|  |  | +        checkAndChange(changeListData);
 | 
	
		
			
				|  |  | +        changeSpreadObj.setAuditValue();
 | 
	
		
			
				|  |  | +        SpreadJsObj.loadSheetData(changeSpreadSheet, SpreadJsObj.DataType.Data, changeList);
 | 
	
		
			
				|  |  | +        console.log(changeList);
 | 
	
		
			
				|  |  | +        changeSpreadObj.makeSjsFooter();
 | 
	
		
			
				|  |  | +        changeSpreadObj.resetXmjSpread(SpreadJsObj.getSelectObject(changeSpreadSheet));
 | 
	
		
			
				|  |  | +    });
 | 
	
		
			
				|  |  |      const userIndex = aidList.indexOf(parseInt(accountId));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      changeSpread.bind(spreadNS.Events.EditEnded, changeSpreadObj.editEnded);
 | 
	
	
		
			
				|  | @@ -496,3 +539,167 @@ function auditCheck(i) {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |      return true;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  | +function checkAndChange(changeListData) {
 | 
	
		
			
				|  |  | +    // 根据已添加的清单显示
 | 
	
		
			
				|  |  | +    if (changeList.length > 0 && changeList[0]) {
 | 
	
		
			
				|  |  | +        const removeList = [];
 | 
	
		
			
				|  |  | +        const updateList = [];
 | 
	
		
			
				|  |  | +        const updateGclIdList = [];
 | 
	
		
			
				|  |  | +        for (const [index,clinfo] of changeList.entries()) {
 | 
	
		
			
				|  |  | +            if (clinfo.lid != 0) {
 | 
	
		
			
				|  |  | +                let listinfo = changeListData.find(function (item) {
 | 
	
		
			
				|  |  | +                    return (item.id !== undefined && item.id == clinfo.lid) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && item.leafXmjs[0].gcl_id == clinfo.lid);
 | 
	
		
			
				|  |  | +                });
 | 
	
		
			
				|  |  | +                if (listinfo === undefined || (clinfo.lid && clinfo.gcl_id && clinfo.lid !== clinfo.gcl_id)) {
 | 
	
		
			
				|  |  | +                    // 有可能这部分台账发生变化,此时要更新清单lid信息,防止数据丢失
 | 
	
		
			
				|  |  | +                    const newlistinfo = changeListData.find(function (item) {
 | 
	
		
			
				|  |  | +                        return (item.id !== undefined && item.id == clinfo.gcl_id) || (item.id === undefined && item.leafXmjs !== undefined && item.leafXmjs.length !== 0 && _.find(item.leafXmjs, {gcl_id: clinfo.gcl_id }));
 | 
	
		
			
				|  |  | +                    });
 | 
	
		
			
				|  |  | +                    if ((listinfo === undefined && newlistinfo) || (listinfo && newlistinfo && !isObjEqual(listinfo, newlistinfo))) {
 | 
	
		
			
				|  |  | +                        listinfo = newlistinfo;
 | 
	
		
			
				|  |  | +                        updateList.push({id: clinfo.id, lid: newlistinfo.leafXmjs[0].gcl_id});
 | 
	
		
			
				|  |  | +                        // 更新lid
 | 
	
		
			
				|  |  | +                        changeList[index].lid = newlistinfo.leafXmjs[0].gcl_id;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                if (listinfo === undefined) {
 | 
	
		
			
				|  |  | +                    // 针对旧数据获取清单信息
 | 
	
		
			
				|  |  | +                    listinfo = changeListData[clinfo.lid - 1];
 | 
	
		
			
				|  |  | +                    if (listinfo === undefined) {
 | 
	
		
			
				|  |  | +                        toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
 | 
	
		
			
				|  |  | +                        if (changeStatus !== auditConst.status.revise) {
 | 
	
		
			
				|  |  | +                            removeList.push(clinfo);
 | 
	
		
			
				|  |  | +                        } else {
 | 
	
		
			
				|  |  | +                            updateList.push(makeWhiteList(clinfo));
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        continue;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                const info = makePushBwmx(clinfo, listinfo, removeList, updateList);
 | 
	
		
			
				|  |  | +                if (info && _.findIndex(changeLedgerList, { id: clinfo.gcl_id }) !== -1) {
 | 
	
		
			
				|  |  | +                    // 可能因为升降级关系:细目,分部分项等会发生变化,更新清单
 | 
	
		
			
				|  |  | +                    const updateInfo = {};
 | 
	
		
			
				|  |  | +                    if (info.code !== clinfo.xmj_code) {
 | 
	
		
			
				|  |  | +                        updateInfo.xmj_code = info.code;
 | 
	
		
			
				|  |  | +                        changeList[index].xmj_code = info.code;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (info.jldy !== clinfo.xmj_jldy) {
 | 
	
		
			
				|  |  | +                        updateInfo.xmj_jldy = info.jldy;
 | 
	
		
			
				|  |  | +                        changeList[index].xmj_jldy = info.jldy;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (info.dwgc !== clinfo.xmj_dwgc) {
 | 
	
		
			
				|  |  | +                        updateInfo.xmj_dwgc = info.dwgc;
 | 
	
		
			
				|  |  | +                        changeList[index].xmj_dwgc = info.dwgc;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (info.fbgc !== clinfo.xmj_fbgc) {
 | 
	
		
			
				|  |  | +                        updateInfo.xmj_fbgc = info.fbgc;
 | 
	
		
			
				|  |  | +                        changeList[index].xmj_fbgc = info.fbgc;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (info.fxgc !== clinfo.xmj_fxgc) {
 | 
	
		
			
				|  |  | +                        updateInfo.xmj_fxgc = info.fxgc;
 | 
	
		
			
				|  |  | +                        changeList[index].xmj_fxgc = info.fxgc;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    if (!_.isEmpty(updateInfo) && _.indexOf(updateGclIdList, clinfo.gcl_id) === -1) {
 | 
	
		
			
				|  |  | +                        updateGclIdList.push(clinfo.gcl_id);
 | 
	
		
			
				|  |  | +                        // updateInfo.gcl_id = info.id;
 | 
	
		
			
				|  |  | +                        updateList.push({ row: updateInfo, where: { tid: tenderId, gcl_id: clinfo.gcl_id } });
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(updateList.length > 0) {
 | 
	
		
			
				|  |  | +            console.log(updateList);
 | 
	
		
			
				|  |  | +            postData(window.location.pathname + '/save', { type:'update_list', updateData: updateList }, function (result) {
 | 
	
		
			
				|  |  | +            }, function () {
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if(removeList.length > 0) {
 | 
	
		
			
				|  |  | +            _.pullAll(changeList, removeList);
 | 
	
		
			
				|  |  | +            postData(window.location.pathname + '/save', { type:'remove_list', updateData: removeList }, function (result) {
 | 
	
		
			
				|  |  | +            }, function () {
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +function makePushBwmx(clinfo, listinfo, removeList, updateList) {
 | 
	
		
			
				|  |  | +    let info = '';
 | 
	
		
			
				|  |  | +    const checkKey = ['name', 'code', 'unit', 'unit_price'];
 | 
	
		
			
				|  |  | +    const checkLeafKey = ['oamount', 'bwmx', 'code', 'dwgc', 'fbgc', 'fxgc', 'jldy'];
 | 
	
		
			
				|  |  | +    if (listinfo.leafXmjs !== undefined) {
 | 
	
		
			
				|  |  | +        const leafInfo = listinfo.leafXmjs.find(function (item) {
 | 
	
		
			
				|  |  | +            // const flag = (item.bwmx === undefined || item.bwmx === clinfo.bwmx || item.jldy === clinfo.bwmx) && item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id)) && (item.quantity !== null ? item.quantity === parseFloat(clinfo.oamount) : 0 === parseFloat(clinfo.oamount));
 | 
	
		
			
				|  |  | +            const flag = item.gcl_id === clinfo.gcl_id && (!clinfo.mx_id || (item.mx_id && clinfo.mx_id && item.mx_id === clinfo.mx_id));
 | 
	
		
			
				|  |  | +            if (flag && item.code === clinfo.xmj_code) {
 | 
	
		
			
				|  |  | +                return flag && item.code === clinfo.xmj_code;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return flag;
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +        if (leafInfo) {
 | 
	
		
			
				|  |  | +            const oneUpdate = { id: clinfo.id };
 | 
	
		
			
				|  |  | +            let needUpdate = false;
 | 
	
		
			
				|  |  | +            // 判断要不要更新名称,单位,原数量,单价
 | 
	
		
			
				|  |  | +            checkKey.forEach(function (key) {
 | 
	
		
			
				|  |  | +                if (listinfo[key] !== clinfo[key]) {
 | 
	
		
			
				|  |  | +                    oneUpdate[key] = listinfo[key];
 | 
	
		
			
				|  |  | +                    clinfo[key] = listinfo[key];
 | 
	
		
			
				|  |  | +                    if (key === 'unit') {
 | 
	
		
			
				|  |  | +                        const oamount = ZhCalc.round(clinfo.oamount, findDecimal(listinfo[key]));
 | 
	
		
			
				|  |  | +                        if (oamount !== clinfo.oamount) {
 | 
	
		
			
				|  |  | +                            oneUpdate.oamount = oamount;
 | 
	
		
			
				|  |  | +                            clinfo.oamount = oamount;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        const camount = ZhCalc.round(clinfo.camount, findDecimal(listinfo[key]));
 | 
	
		
			
				|  |  | +                        if (camount !== clinfo.camount) {
 | 
	
		
			
				|  |  | +                            oneUpdate.camount = camount;
 | 
	
		
			
				|  |  | +                            clinfo.camount = camount;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    // else if (key === 'unit_price') {
 | 
	
		
			
				|  |  | +                    //     // 可能要更新总金额了
 | 
	
		
			
				|  |  | +                    //     oneUpdate[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
 | 
	
		
			
				|  |  | +                    //     clinfo[key] = ZhCalc.round(listinfo[key], unitPriceUnit);
 | 
	
		
			
				|  |  | +                    // }
 | 
	
		
			
				|  |  | +                    needUpdate = true;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            checkLeafKey.forEach(function (key) {
 | 
	
		
			
				|  |  | +                // 只有数量是对比leafInfo,其它对比listinfo,且有些值需要重新计算
 | 
	
		
			
				|  |  | +                if (key === 'oamount') {
 | 
	
		
			
				|  |  | +                    if (leafInfo.quantity !== clinfo[key]) {
 | 
	
		
			
				|  |  | +                        oneUpdate[key] = leafInfo.quantity;
 | 
	
		
			
				|  |  | +                        clinfo[key] = leafInfo.quantity;
 | 
	
		
			
				|  |  | +                        needUpdate = true;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else if (key === 'bwmx') {
 | 
	
		
			
				|  |  | +                    if (leafInfo[key] !== undefined && leafInfo[key] !== clinfo[key]) {
 | 
	
		
			
				|  |  | +                        oneUpdate[key] = leafInfo[key];
 | 
	
		
			
				|  |  | +                        clinfo[key] = leafInfo[key];
 | 
	
		
			
				|  |  | +                        needUpdate = true;
 | 
	
		
			
				|  |  | +                    } else if (leafInfo[key] === undefined && leafInfo.jldy !== clinfo[key]) {
 | 
	
		
			
				|  |  | +                        oneUpdate[key] = leafInfo.jldy;
 | 
	
		
			
				|  |  | +                        clinfo[key] = leafInfo.jldy;
 | 
	
		
			
				|  |  | +                        needUpdate = true;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  | +                    if (leafInfo[key] !== clinfo['xmj_' + key]) {
 | 
	
		
			
				|  |  | +                        oneUpdate['xmj_' + key] = leafInfo[key];
 | 
	
		
			
				|  |  | +                        clinfo['xmj_' + key] = leafInfo[key];
 | 
	
		
			
				|  |  | +                        needUpdate = true;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +            if (needUpdate) {
 | 
	
		
			
				|  |  | +                updateList.push(oneUpdate);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            toastr.warning('台账清单列表已不存在'+ clinfo.code +',已更新变更清单列表');
 | 
	
		
			
				|  |  | +            if (changeStatus !== auditConst.status.revise) {
 | 
	
		
			
				|  |  | +                removeList.push(clinfo);
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  | +                updateList.push(makeWhiteList(clinfo));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |