Browse Source

签约清单,导入相关

MaiXinRong 6 years ago
parent
commit
f90a588e1f

+ 3 - 3
app/public/js/ledger.js

@@ -383,7 +383,7 @@ $(document).ready(function() {
                 if (datas.length > 0) {
                     info.sheet.zh_tree.update('/tender/' + getTenderId() + '/ledger/update', datas, function (result) {
                         if (result.update) {
-                            result.update.concat(filterNodes);
+                            result.update = result.update.concat(filterNodes);
                         }
                         treeOperationObj.refreshTree(info.sheet, result);
                     }, function () {
@@ -1130,7 +1130,7 @@ $(document).ready(function() {
                 formData.append('file', file.files[0]);
                 postDataWithFile(self.url+'/upload-excel', formData, function (data) {
                     self.data = data;
-                    self.calculateData();
+                    //self.calculateData();
                     SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
                     $('#upload-deal').modal('hide');
                 }, function () {
@@ -1142,7 +1142,7 @@ $(document).ready(function() {
             const self = this;
             postData(this.url+'/get-data', {}, function (data) {
                 self.data = data;
-                self.calculateData();
+                //self.calculateData();
                 SpreadJsObj.loadSheetData(self.spread.getActiveSheet(), 'data', data);
             });
         }

+ 6 - 4
app/service/deal_bills.js

@@ -116,13 +116,14 @@ module.exports = app => {
                         if (value.indexOf('数量') >= 0) iQty = iCol;
                         if (value.indexOf('金额') >= 0 || value.indexOf('合价') >= 0) iTp = iCol;
                     }
-                    bCheckCol = (iCode >= 0 && iName >= 0 && iUnit >= 0 && iUp >= 0 && iQty >= 0);
+                    bCheckCol = (iCode >= 0 && iName >= 0 && iUnit >= 0 && iUp >= 0 && iQty >= 0 && iTp >= 0);
                     if (!bCheckCol) {
                         iCode = -1;
                         iName = -1;
                         iUnit = -1;
                         iUp = -1;
                         iQty = -1;
+                        iTp = -1;
                     }
                 } else if (this.ctx.helper.validBillsCode(row[iCode])) {
                     const data = {
@@ -131,10 +132,11 @@ module.exports = app => {
                         code: row[iCode],
                         name: row[iName],
                         unit: row[iUnit],
-                        unit_price: this._.toNumber(row[iUp]),
-                        quantity: this._.toNumber(row[iQty]),
+                        unit_price: (row[iUp] === undefined || row[iUp] === null) ? 0 : this._.toNumber(row[iUp]),
+                        quantity: (row[iQty] === undefined || row[iQty] === null) ? 0 : this._.toNumber(row[iQty]),
+                        total_price: (row[iTp] === undefined || row[iTp] === null) ? 0 : this._.toNumber(row[iTp]),
                     };
-                    if (this._.isNaN(data.unit_price) || this._.isNaN(data.quantity)) {
+                    if (this._.isNaN(data.unit_price) || this._.isNaN(data.quantity) || this._.isNaN(data.total_price)) {
                         throw '导入的Excel的数据类型有误,请检查第' + (iRow + 1) + '行';
                     }
                     bills.push(data);

+ 1 - 1
config/config.test.js

@@ -47,7 +47,7 @@ module.exports = appInfo => {
         app: true,
     };
     // 是否压缩替换前端js
-    config.min = false;
+    config.min = true;
 
     config.logger = {
         consoleLevel: 'WARN',

+ 34 - 0
test/app/service/deal_bills.test.js

@@ -139,4 +139,38 @@ describe('test/app/service/deal_bills.test.js', () => {
         const bills = yield ctx.service.dealBills.getAllDataByCondition({where: {tender_id: ctx.tender.id}});
         assert(bills.length === 98);
     });
+    // 导入 存在数量单价为空的数据
+    it('test import Excel data by js-xlsx', function* () {
+        const ctx = app.mockContext(mockData);
+        const file = app.baseDir  + '/test/app/test_file/deal-bills-emptyCalcField.xls';
+
+        const wb = xlsx.readFile(file);
+        const name = wb.SheetNames[0];
+        const sheetData = {
+            rows: xlsx.utils.sheet_to_json(wb.Sheets[name], {header: 1}),
+            merge: wb.Sheets[name]["!merges"],
+        };
+        const result = yield ctx.service.dealBills.importDataJsXlsx(sheetData, ctx.tender.id);
+        assert(result);
+
+        const bills = yield ctx.service.dealBills.getAllDataByCondition({where: {tender_id: ctx.tender.id}});
+        assert(bills.length === 4);
+
+        assert(bills[0].code === '101-1');
+        assert(bills[0].unit_price === 20000);
+        assert(bills[0].quantity === 1);
+        assert(bills[0].total_price === 1000);
+        assert(bills[1].code === '101-2');
+        assert(bills[1].unit_price === 1200);
+        assert(!bills[1].quantity || bills[0].quantity === 1);
+        assert(bills[1].total_price === 200);
+        assert(bills[2].code === '101-3');
+        assert(!bills[2].unit_price || bills[0].unit_price === 0);
+        assert(bills[2].quantity === 2);
+        assert(bills[2].total_price === 4000);
+        assert(bills[3].code === '101-4');
+        assert(bills[3].unit_price === 2000);
+        assert(bills[3].quantity === 3);
+        assert(!bills[3].total_price || bills[0].total_price === 0);
+    });
 });

BIN
test/app/test_file/deal-upload-test.xls