Przeglądaj źródła

签约清单,插入

MaiXinRong 2 tygodni temu
rodzic
commit
e56b085a58
2 zmienionych plików z 56 dodań i 10 usunięć
  1. 24 1
      app/public/js/ledger.js
  2. 32 9
      app/service/deal_bills.js

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

@@ -3158,7 +3158,6 @@ $(document).ready(function() {
             this.sheet = this.spread.getActiveSheet();
             SpreadJsObj.initSheet(this.spread.getActiveSheet(), this.spreadSetting);
 
-
             this.OprObj = {
                 /**
                  * 删除按钮响应事件
@@ -3225,6 +3224,19 @@ $(document).ready(function() {
                         });
                     }
                 },
+                insert: function (sheet) {
+                    if (!sheet.zh_setting || sheet.zh_setting.readOnly) return;
+
+                    const select = SpreadJsObj.getSelectObject(sheet);
+                    const data = { insert: { select_id: select ? select.id: null, count: 1 } };
+
+                    postData(self.url + '/update', data, function (result) {
+                        self.loadUpdateData(result);
+                        SpreadJsObj.reLoadSheetData(sheet);
+                    }, function () {
+                        SpreadJsObj.reLoadSheetData(sheet);
+                    });
+                },
                 editEnded: function (e, info) {
                     if (!info.sheet.zh_setting || !info.sheet.zh_data || info.sheet.zh_setting.readOnly) return;
 
@@ -3406,6 +3418,16 @@ $(document).ready(function() {
                                 SpreadJsObj.refreshSheetReadOnly(self.sheet);
                             },
                         },
+                        add: {
+                            name: '插入',
+                            icon: 'fa-plus',
+                            visible: function (key, opt) {
+                                return !self.sheet.zh_setting.readOnly;
+                            },
+                            callback: function (key, opt) {
+                                self.OprObj.insert(self.sheet);
+                            },
+                        },
                         del: {
                             name: '删除',
                             icon: 'fa-times',
@@ -3554,6 +3576,7 @@ $(document).ready(function() {
                     return updateData.del.indexOf(d.id) >= 0;
                 });
             }
+            this.data.sort((x, y) => { return x.order - y.order; });
         }
     }
     class BatchInsertBillsPosObj {

+ 32 - 9
app/service/deal_bills.js

@@ -234,6 +234,34 @@ module.exports = app => {
             return insertData;
         }
 
+        async _insertDatas(data, result) {
+            const select = await this.getDataById(data.select_id);
+            if (!select) throw '选择的签约清单不存在,请刷新页面后重试';
+
+            const insertData = [];
+            for (let i = 0; i < data.count; i++) {
+                insertData.push({
+                    id: this.uuid.v4(),
+                    tender_id: this.ctx.tender.id,
+                    order: select.order + i,
+                });
+            }
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.query('Update ?? SET `order` = `order` + ? WHERE tender_id = ? and `order` >= ?', [this.tableName, data.count, this.ctx.tender.id, select.order]);
+                await transaction.insert(this.tableName, insertData);
+                await transaction.commit();
+            } catch(err) {
+                this.ctx.log(err);
+                await transaction.rollback();
+                throw '插入数据错误';
+            }
+
+            result.add = insertData;
+            result.update = await this.db.query('SELECT * FROM ?? where tender_id = ? and `order` >= ?', [this.tableName, this.ctx.tender.id, select.order + data.count]);
+        }
+
         async _delDatas (data) {
             await this.db.delete(this.tableName, {id: data});
             return data;
@@ -278,15 +306,10 @@ module.exports = app => {
         async updateDatas(data) {
             const result = {add: [], del: [], update: []};
             try {
-                if (data.add) {
-                    result.add = await this._addDatas(data.add);
-                }
-                if (data.update) {
-                    result.update = await this._updateDatas(data.update);
-                }
-                if (data.del) {
-                    result.del = await this._delDatas(data.del);
-                }
+                if (data.add) result.add = await this._addDatas(data.add);
+                if (data.update) result.update = await this._updateDatas(data.update);
+                if (data.del) result.del = await this._delDatas(data.del);
+                if (data.insert) await this._insertDatas(data.insert, result);
                 return result;
             } catch (err) {
                 if (err) result.err = err;