Browse Source

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 4 năm trước cách đây
mục cha
commit
eee74ee08c

+ 5 - 1
app/controller/schedule_controller.js

@@ -87,7 +87,8 @@ module.exports = app => {
                 // const convert = new billsPosConvert(ctx);
                 // convert.loadData(ledgerData, posData, []);
                 // const result = await convert.convert();
-                ctx.body = { err: 0, msg: '', data: ledgerData };
+                const scheduleLedgerMonthData = await ctx.service.scheduleLedgerMonth.getAllDataByCondition({ tid: ctx.tender.id });
+                ctx.body = { err: 0, msg: '', data: { bills: ledgerData, slm: scheduleLedgerMonthData } };
             } catch (err) {
                 this.log(err);
                 ctx.body = { err: 1, msg: err.toString(), data: [] };
@@ -135,6 +136,9 @@ module.exports = app => {
                     case 'delmonth':
                         responseData.data = await ctx.service.scheduleMonth.del(data.postData);
                         break;
+                    case 'ledger_edit':
+                        responseData.data = await ctx.service.scheduleLedgerMonth.save(data.postData);
+                        break;
                     default: throw '参数有误';
                 }
                 ctx.body = responseData;

+ 1 - 1
app/public/js/change_information.js

@@ -221,7 +221,7 @@ $(document).ready(() => {
     const xmjSpreadSetting = {
         cols: [
             {title: '项目节编号', colSpan: '1', rowSpan: '2', field: 'xmj_code', hAlign: 0, width: 80},
-            {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
+            // {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 120},
             {title: '细目', colSpan: '1', rowSpan: '2', field: 'xmj_jldy', hAlign: 0, width: 100},
             {title: '单位工程', colSpan: '1', rowSpan: '2', field: 'xmj_dwgc', hAlign: 0, width: 100},
             {title: '分部工程', colSpan: '1', rowSpan: '2', field: 'xmj_fbgc', hAlign: 0, width: 100},

+ 2 - 2
app/public/js/schedule_ledger.js

@@ -67,8 +67,8 @@ $(function () {
                 node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
             }
         });
-        data = addIsSelect(data);
-        baseLedgerTree.loadDatas(data);
+        const datas = addIsSelect(data.bills);
+        baseLedgerTree.loadDatas(datas);
         treeCalc.calculateAll(baseLedgerTree);
         for (const d of baseLedgerTree.nodes) {
             if (!d.b_code)

+ 11 - 7
app/public/js/schedule_plan.js

@@ -110,7 +110,7 @@ $(function () {
                 node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);
             }
         });
-        baseLedgerTree.loadDatas(data);
+        baseLedgerTree.loadDatas(data.bills);
         treeCalc.calculateAll(baseLedgerTree);
         for (const d of baseLedgerTree.nodes) {
             if (!d.b_code) {
@@ -200,8 +200,6 @@ $(function () {
                 // 判断输入位数,提示
                 if (mode === 'tp') {
                     const reg = new RegExp('^([-]?)\\d+(\\.\\d{0,'+ parseInt(tenderInfo.decimal.tp) +'})?$');
-                    console.log(reg);
-                    console.log(reg.test(validText));
                     if (validText !== null && (!reg.test(validText))) {
                         toastr.error('输入金额小数位数不能大于' + tenderInfo.decimal.tp + '位');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -209,7 +207,6 @@ $(function () {
                     }
                     plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), tenderInfo.decimal.up) : 0;
                     plan_tp = validText;
-                    select[yearmonth + '_gcl'] = plan_gcl;
                 } else {
                     const reg = new RegExp('^([-]?)\\d+(\\.\\d{0,'+ parseInt(tenderInfo.decimal.up) +'})?$');
                     if (validText !== null && (!reg.test(validText))) {
@@ -219,7 +216,6 @@ $(function () {
                     }
                     plan_gcl = validText;
                     plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), tenderInfo.decimal.tp) : 0;
-                    select[yearmonth + '_tp'] = plan_tp;
                 }
                 select[col.field] = validText;
                 const updateData = {
@@ -229,9 +225,17 @@ $(function () {
                     plan_tp,
                 };
                 console.log(updateData);
-                // postData(window.location.pathname + '/save', {type: 'mode', postData: updateData}, function (result) {
+                postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {
+                    if (mode === 'tp') {
+                        select[yearmonth + '_gcl'] = plan_gcl;
+                    } else {
+                        select[yearmonth + '_tp'] = plan_tp;
+                    }
+                    SpreadJsObj.reLoadRowData(info.sheet, info.row);
+                },function () {
+                    select[col.field] = orgValue;
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
-                // })
+                })
             }
         },
         deletePress: function (sheet) {

+ 31 - 2
app/public/js/shenpi.js

@@ -1063,7 +1063,36 @@ function setAllChildrenCanEdit(ledgerInfo, flag) {
         }
     }
 }
-
+// 编号排序,多重判断
+function sortByCode(a, b) {
+    let code1 = a.code.split('-');
+    let code2 = b.code.split('-');
+    let code1length = code1.length;
+    let code2length = code2.length;
+    for (let i = 0; i < code1length; i ++) {
+        if (i+1 <= code2length) {
+            if (code1[i] != code2[i]) {
+                if (!/^\d+$/.test(code1[i])) {
+                    return code1[i].charCodeAt() - code2[i].charCodeAt();
+                } else {
+                    return parseInt(code1[i]) - parseInt(code2[i]);
+                }
+            } else if (i+1 == code1length && code1[i] == code2[i]) {
+                if (code1length == code2length) {
+                    return 0;
+                } else {
+                    return code1length - code2length;
+                }
+            }
+        } else {
+            if (i+1 >= code1length) {
+                return 1;
+            } else {
+                return -1;
+            }
+        }
+    }
+}
 function setLeftTable(ledgerList, coolist, uid, title) {
     $('#stage_audit').text(title);
     const showCooList = _.filter(coolist, { 'user_id': parseInt(uid) });
@@ -1084,7 +1113,7 @@ function setLeftTable(ledgerList, coolist, uid, title) {
     }
 
     let html = '';
-    for (const sc of showCooList) {
+    for (const sc of showCooList.sort(sortByCode)) {
         const pichtml = sc.sign_path ? `<img src="/${sc.sign_path}" width="60"><input type="file" data-id="${sc.id}" class="upload-img-file" style="display: none;"><a href="javascript: void(0);" class="d-inline-flex upload-img">更改</a>`
             : `<img src="" style="display: none" width="60"><input type="file" data-id="${sc.id}" class="upload-img-file" style="display: none;"><a href="javascript: void(0);" class="btn btn-outline-primary btn-sm upload-img">上传签名</a>`;
         html += `<tr>` +

+ 34 - 0
app/service/schedule_ledger_month.js

@@ -6,6 +6,40 @@ module.exports = app => {
             super(ctx);
             this.tableName = 'schedule_ledger_month';
         }
+
+        async save(data) {
+            // 判断是添加,删除,还是修改
+            const transaction = await this.db.beginTransaction();
+            try {
+                const info = await this.getDataByCondition({ tid: this.ctx.tender.id, lid: data.lid, yearmonth: data.yearmonth });
+                if (info) {
+                    if (data.plan_gcl === null && data.plan_tp === null) {
+                        await transaction.delete(this.tableName, { id: info.id });
+                    } else {
+                        const updateData = {
+                            id: info.id,
+                            plan_gcl: data.plan_gcl,
+                            plan_tp: data.plan_tp,
+                        };
+                        await transaction.update(this.tableName, updateData);
+                    }
+                } else {
+                    const insertData = {
+                        tid: this.ctx.tender.id,
+                        lid: data.lid,
+                        yearmonth: data.yearmonth,
+                        plan_gcl: data.plan_gcl,
+                        plan_tp: data.plan_tp,
+                    };
+                    await transaction.insert(this.tableName, insertData);
+                }
+                await transaction.commit();
+                return true;
+            } catch (err) {
+                await transaction.rollback();
+                throw err;
+            }
+        }
     }
     return ScheduleLedgerMonth;
 };