Browse Source

签约清单,计算并显示金额列

MaiXinRong 6 years ago
parent
commit
016a5f4241
1 changed files with 14 additions and 1 deletions
  1. 14 1
      app/public/js/ledger.js

+ 14 - 1
app/public/js/ledger.js

@@ -637,6 +637,8 @@ $(document).ready(function() {
                     }
                 } else if (!position) {
                     toast('新增部位请先输入名称', 'warning');
+                    info.cancel = true;
+                    return;
                 } else {
                     data.updateType = 'update';
                     data.updateData = {id: position.id};
@@ -873,6 +875,7 @@ $(document).ready(function() {
                             {title: '单位', field: 'unit', width: 50, formatter: '@', readOnly: true},
                             {title: '单价', field: 'unit_price', width: 50, readOnly: true},
                             {title: '数量', field: 'quantity', width: 50, readOnly: true},
+                            {title: '金额', field: 'total_price', width: 50, readOnly: true},
                         ],
                         emptyRows: 0,
                         headRows: 1,
@@ -964,6 +967,8 @@ $(document).ready(function() {
                 const formData = new FormData();
                 formData.append('file', file.files[0]);
                 postDataWithFile(self.url+'/upload-excel', formData, function (data) {
+                    self.data = data;
+                    self.calculateData();
                     SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
                     $('#upload-deal').modal('hide');
                 }, function () {
@@ -974,10 +979,18 @@ $(document).ready(function() {
         loadData () {
             const self = this;
             postData(this.url+'/get-data', {}, function (data) {
-                this.data = data;
+                self.data = data;
+                self.calculateData();
                 SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
             });
         }
+        calculateData () {
+            if (this.data) {
+                for (const d of this.data) {
+                    d.total_price = _.multiply(d.quantity, d.unit_price);
+                }
+            }
+        }
     }
     class BatchInsertBillsPosObj {
         constructor (obj) {