Browse Source

永久材料、安全生产、临时占地,插入

MaiXinRong 1 month ago
parent
commit
cb8e3f1e2d

+ 28 - 6
app/public/js/se_safe_prod.js

@@ -228,6 +228,18 @@ $(document).ready(() => {
                     });
                 }
             },
+            insert: 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) {
+                    seSafeObj.loadUpdateData(result);
+                    SpreadJsObj.reLoadSheetData(sheet);
+                    refreshSum();
+                }, function () {
+                    SpreadJsObj.reLoadSheetData(sheet);
+                });
+            },
             editEnded: function (e, info) {
                 if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
 
@@ -394,18 +406,28 @@ $(document).ready(() => {
                         seSafeOprObj.delete(safeSheet);
                     },
                     disabled: function (key, opt) {
-                        const sels = safeSheet.getSelections();
-                        if (!sels || !sels[0]) return true;
-
-                        const row = sels[0].row;
-                        const node = seSafeObj.data[row];
-                        return node === undefined || node === null;
+                        const node = SpreadJsObj.getSelectObject(safeSheet);
+                        return !node;
                     },
                     visible: function (key, opt) {
                         return !readOnly;
                     }
                 },
                 sprDel: '------------',
+                insert: {
+                    name: '插入',
+                    icon: 'fa-plus',
+                    callback: function (key, opt) {
+                        seSafeOprObj.insert(safeSheet);
+                    },
+                    disabled: function (key, opt) {
+                        const node = SpreadJsObj.getSelectObject(safeSheet);
+                        return !node;
+                    },
+                    visible: function (key, opt) {
+                        return !readOnly;
+                    }
+                },
                 upMove: {
                     name: '上移',
                     icon: 'fa-arrow-up',

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

@@ -218,6 +218,18 @@ $(document).ready(() => {
                     });
                 }
             },
+            insert: 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) {
+                    seTempObj.loadUpdateData(result);
+                    SpreadJsObj.reLoadSheetData(sheet);
+                    refreshSum();
+                }, function () {
+                    SpreadJsObj.reLoadSheetData(sheet);
+                });
+            },
             editEnded: function (e, info) {
                 if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
 
@@ -395,6 +407,20 @@ $(document).ready(() => {
                     }
                 },
                 sprDel: '------------',
+                insert: {
+                    name: '插入',
+                    icon: 'fa-plus',
+                    callback: function (key, opt) {
+                        seTempOprObj.insert(tempSheet);
+                    },
+                    disabled: function (key, opt) {
+                        const node = SpreadJsObj.getSelectObject(tempSheet);
+                        return !node;
+                    },
+                    visible: function (key, opt) {
+                        return !readOnly;
+                    }
+                },
                 upMove: {
                     name: '上移',
                     icon: 'fa-arrow-up',

+ 25 - 0
app/public/js/se_yjcl.js

@@ -209,6 +209,17 @@ $(document).ready(() => {
                     });
                 }
             },
+            insert: 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) {
+                    yjclObj.loadUpdateData(result);
+                    SpreadJsObj.reLoadSheetData(sheet);
+                }, function () {
+                    SpreadJsObj.reLoadSheetData(sheet);
+                });
+            },
             editEnded: function (e, info) {
                 if (!info.sheet.zh_setting || !info.sheet.zh_data) return;
 
@@ -398,6 +409,20 @@ $(document).ready(() => {
                     }
                 },
                 sprDel: '------------',
+                insert: {
+                    name: '插入',
+                    icon: 'fa-plus',
+                    callback: function (key, opt) {
+                        yjclOprObj.insert(yjclSheet);
+                    },
+                    disabled: function (key, opt) {
+                        const node = SpreadJsObj.getSelectObject(yjclSheet);
+                        return !node;
+                    },
+                    visible: function (key, opt) {
+                        return !readOnly;
+                    }
+                },
                 upMove: {
                     name: '上移',
                     icon: 'fa-arrow-up',

+ 1 - 1
app/service/stage_other.js

@@ -107,7 +107,7 @@ module.exports = app => {
                     sid: this.ctx.stage.id,
                     sorder: this.ctx.stage.order,
                     name: '',
-                    order: select.sorder + i,
+                    order: select.order + i,
                 });
             }
 

+ 37 - 0
app/service/stage_safe_prod.js

@@ -100,6 +100,42 @@ 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,
+                    add_time: new Date(),
+                    tid: this.ctx.tender.id,
+                    sid: this.ctx.stage.id,
+                    sorder: this.ctx.stage.order,
+                    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')} });
@@ -170,6 +206,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) {
                 throw err;

+ 37 - 0
app/service/stage_temp_land.js

@@ -96,6 +96,42 @@ 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,
+                    add_time: new Date(),
+                    tid: this.ctx.tender.id,
+                    sid: this.ctx.stage.id,
+                    sorder: this.ctx.stage.order,
+                    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')} });
@@ -161,6 +197,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) {
                 throw err;

+ 36 - 0
app/service/stage_yjcl.js

@@ -91,6 +91,41 @@ 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,
+                    sorder: this.ctx.stage.order,
+                    name: '',
+                    m_order: select.m_order + i,
+                });
+            }
+
+            const transaction = await this.db.beginTransaction();
+            try {
+                await transaction.query('Update ?? SET `m_order` = `m_order` + ? WHERE sid = ? and `m_order` >= ?', [this.tableName, data.count, this.ctx.stage.id, select.m_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 `m_order` >= ?', [this.tableName, this.ctx.stage.id, select.m_order + data.count]);
+        }
+
         async _delDatas(data) {
             const datas = data instanceof Array ? data : [data];
             const orgDatas = await this.getAllDataByCondition({
@@ -172,6 +207,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;