Przeglądaj źródła

甲供材料,右键插入

MaiXinRong 1 miesiąc temu
rodzic
commit
f4307e118d
2 zmienionych plików z 61 dodań i 0 usunięć
  1. 26 0
      app/public/js/se_jgcl.js
  2. 35 0
      app/service/stage_jgcl.js

+ 26 - 0
app/public/js/se_jgcl.js

@@ -245,6 +245,18 @@ $(document).ready(() => {
                     });
                 }
             },
+            insertJgcl: function(sheet) {
+                if (!sheet.zh_setting || !sheet.zh_data) return;
+
+                const node = SpreadJsObj.getSelectObject(sheet);
+                postData(window.location.pathname + '/update', {insert: { select: node.id, count: 1 }}, function (result) {
+                    jgclObj.loadUpdateData(result);
+                    SpreadJsObj.reLoadSheetData(jgclSheet);
+                    refreshSum();
+                }, function () {
+                    SpreadJsObj.reLoadSheetData(jgclSheet);
+                });
+            },
             editEnded: function (e, info) {
                 if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
 
@@ -426,6 +438,20 @@ $(document).ready(() => {
                     }
                 },
                 sprDel: '------------',
+                insert: {
+                    name: '插入',
+                    icon: 'fa-plus',
+                    callback: function (key, opt) {
+                        jgclOprObj.insertJgcl(jgclSheet);
+                    },
+                    disabled: function (key, opt) {
+                        const node = SpreadJsObj.getSelectObject(jgclSheet);
+                        return !node;
+                    },
+                    visible: function (key, opt) {
+                        return !readOnly;
+                    }
+                },
                 upMove: {
                     name: '上移',
                     icon: 'fa-arrow-up',

+ 35 - 0
app/service/stage_jgcl.js

@@ -111,6 +111,40 @@ module.exports = app => {
             });
         }
 
+        async _insertDatas(data, result) {
+            const select = await this.getDataById(data.select);
+            if (!select) throw '选中的甲供材料不存在';
+
+            const insertData = [];
+            for (let i = 0; i < data.count; i++) {
+                insertData.push({
+                    uuid: this.uuid.v4(),
+                    add_sid: this.ctx.stage.id,
+                    add_uid: this.ctx.session.sessionUser.accountId,
+                    tid: this.ctx.tender.id,
+                    sid: this.ctx.stage.id,
+                    name: '',
+                    order: select.order + i,
+                });
+            }
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.query('Update ?? SET `order` = `order` + ? WHERE sid = ? and `order` >= ?', [this.tableName, data.count, this.ctx.stage.id, select.order]);
+                await transaction.insert(this.tableName, insertData);
+                await transaction.commit();
+            } catch(err) {
+                this.ctx.log(err);
+                await transaction.rollback();
+                throw '插入甲供材料错误';
+            }
+
+            result.add = await this.getAllDataByCondition({
+                where: { sid: this.ctx.stage.id, uuid: this.ctx.helper._.map(insertData, 'uuid') }
+            });
+            result.update = await this.db.query('SELECT * FROM ?? where sid = ? and `order` >= ?', [this.tableName, this.ctx.stage.id, select.order + data.count]);
+        }
+
         async _delDatas (data) {
             const datas = data instanceof Array ? data : [data];
             const orgDatas = await this.getAllDataByCondition({where: {sid: this.ctx.stage.id, id: this.ctx.helper._.map(datas, 'id')} });
@@ -187,6 +221,7 @@ module.exports = app => {
                 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;