Forráskód Böngészése

Merge branch 'master' of http://192.168.1.41:3000/maixinrong/Calculation

TonyKang 5 éve
szülő
commit
7f801f52a7

+ 1 - 1
app/controller/deal_bills_controller.js

@@ -104,7 +104,7 @@ module.exports = app => {
                 try {
                     let fileName;
                     if (file === '签约清单导入格式.xls') {
-                        fileName = this.app.baseDir + '/app/public/deal_bills/template.xls';
+                        fileName = this.app.baseDir + '/app/public/deal_bills/签约清单导入格式.xls';
                         ctx.body = await fs.readFileSync(fileName);
                     } else if (file === '签约清单.xlsx') {
                         const create_time = Date.parse(new Date()) / 1000;

+ 22 - 1
app/controller/stage_extra_controller.js

@@ -145,6 +145,20 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async loadOther (ctx) {
+            try {
+                const data = await ctx.service.stageOther.getStageData(ctx.stage.id);
+                const preData = await ctx.service.stageOther.getPreStageData(ctx.stage.order);
+                for (const d of data) {
+                    const pd = this.ctx.helper._.find(preData, {uuid: d.uuid});
+                    if (pd) {
+                        d.pre_tp = pd.tp;
+                    }
+                }
+                ctx.body = {err: 0, msg: '', data: data};
+            } catch (error) {
+                ctx.helper.log(error);
+                ctx.body = this.ajaxErrorBody(error, '获取甲供材料数据失败,请刷新');
+            }
 
         }
 
@@ -154,7 +168,14 @@ module.exports = app => {
          * @returns {Promise<void>}
          */
         async updateOther (ctx) {
-
+            try {
+                const data = JSON.parse(ctx.request.body.data);
+                const result = await ctx.service.stageOther.updateDatas(data);
+                ctx.body = { err: 0, msg: '', data: result };
+            } catch (error) {
+                ctx.helper.log(error);
+                ctx.body = this.ajaxErrorBody(error, '提交甲供材料数据失败,请重试');
+            }
         }
     }
 

BIN
app/public/deal_bills/签约清单导入格式.xls


BIN
app/public/files/template/ledger/导入分项清单EXCEL格式.xls


BIN
app/public/files/template/ledger/导入工程量清单EXCEL格式.xls


+ 2 - 2
app/public/js/se_bonus.js

@@ -11,11 +11,11 @@
 const isPre = function (data) {
     return data.sid !== stageId;
 };
-const spreadSetting = { 
+const spreadSetting = {
     cols: [
         {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 235, formatter: '@', readOnly: isPre, },
         {title: '金额', colSpan: '1', rowSpan: '1', field: 'tp', hAlign: 2, width: 100, type: 'Number', readOnly: isPre, },
-        {title: '时间', colSpan: '1', rowSpan: '1', field: 'real_time', hAlign: 1, width: 150, formatter: '@', readOnly: isPre, },
+        {title: '时间', colSpan: '1', rowSpan: '1', field: 'real_time', hAlign: 1, width: 150, formatter: 'yyyy-MM-dd', /*cellType: 'datepicker', */readOnly: isPre, },
         {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 150, formatter: '@', readOnly: isPre, },
         {title: '依据材料证明', colSpan: '1', rowSpan: '1', field: 'proof', hAlign: 0, width: 180, formatter: '@', readOnly: isPre, },
         {

+ 59 - 1
app/public/js/spreadjs_rela/spreadjs_zh.js

@@ -539,6 +539,13 @@ const SpreadJsObj = {
             }
             sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType[cellKey]);
         }
+        if (colSetting.cellType === 'datepicker') {
+            if (!sheet.extendCellType.datepicker) {
+                sheet.extendCellType.datepicker = this.CellType.getDatePickerCellType();
+                SpreadJsObj._addActivePaintEvents(sheet, sheet.extendCellType.datepicker);
+            }
+            sheet.getRange(-1, col, -1, 1).cellType(sheet.extendCellType.datepicker);
+        }
         if (colSetting.formatter) {
             sheet.getRange(-1, col, -1, 1).formatter(colSetting.formatter);
         }
@@ -1025,7 +1032,7 @@ const SpreadJsObj = {
             };
 
             let TreeNodeCellType = function (){};
-            TreeNodeCellType.prototype = new spreadNS.CellTypes.Text();
+            TreeNodeCellType.prototype = new spreadNS.CellTypes.Base();
             const proto = TreeNodeCellType.prototype;
 
             /**
@@ -1940,6 +1947,57 @@ const SpreadJsObj = {
             combo.itemHeight(10).editorValueType(spreadNS.CellTypes.EditorValueType.value).items(items);
             return combo;
         },
+        /**
+         * 获取 日期选择 CellType
+         * @returns {DatePickerCellType}
+         */
+        getDatePickerCellType: function () {
+            let datepicker;
+            const DatePickerCellType = function () {};
+            DatePickerCellType.prototype = new spreadNS.CellTypes.Text();
+            const proto = DatePickerCellType.prototype;
+            proto.createEditorElement = function (context) {
+                return document.createElement("input");
+            };
+            proto.activateEditor = function (editorContext, cellStyle, cellRect, context) {
+                const self = this;
+                if (editorContext) {
+                    const $editor = $(editorContext);
+                    spreadNS.CellTypes.Base.prototype.activateEditor.apply(this, arguments);
+                    $editor.css("position", "absolute");
+                    datepicker = $editor.datepicker({
+                        language: 'zh',
+                        dateFormat: 'yyy-MM-DD',
+                        autoClose: true,
+                        onSelect: function (formattedDate, date, inst) {
+                            this.value = date;
+                        }
+                    }).data('datepicker');
+                    datepicker.show();
+                }
+            };
+            proto.deactivateEditor = function (editorContext, context) {
+                datepicker.hide();
+                datepicker.destroy();
+                spreadNS.CellTypes.Base.prototype.deactivateEditor.apply(this, arguments);
+            };
+            proto.setEditorValue = function (editor, value, context) {
+                if (datepicker) {
+                    datepicker.selectDate(value);
+                }
+            };
+            proto.getEditorValue = function (editor, context) {
+                return datepicker ? datepicker.focused : null;
+            };
+            proto.updateEditor = function (editorContext, cellStyle, cellRect, context) {
+                if (editorContext) {
+                    const $editor = $(editorContext);
+                    $editor.css("width", cellRect.width + 1);
+                    $editor.css("height", cellRect.height + 3);
+                }
+            };
+            return new DatePickerCellType();
+        }
     },
 
     Formatter: {

+ 1 - 0
app/service/stage_bonus.js

@@ -94,6 +94,7 @@ module.exports = app => {
                 if (d.memo) nd.memo = d.memo;
                 if (d.order) nd.order = d.order;
                 uDatas.push(nd);
+                console.log(nd);
             }
             if (uDatas.length > 0) {
                 await this.db.updateRows(this.tableName, uDatas);

+ 168 - 0
app/service/stage_other.js

@@ -0,0 +1,168 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+module.exports = app => {
+    class StageOther extends app.BaseService {
+        /**
+         * 构造函数
+         *
+         * @param {Object} ctx - egg全局变量
+         * @return {void}
+         */
+        constructor(ctx) {
+            super(ctx);
+            this.tableName = 'stage_other';
+        }
+
+        async getStageData(sid) {
+            const data = await this.getAllDataByCondition({where: { sid: sid }});
+            return data;
+        }
+
+        async getPreStageData(sorder) {
+            const sql = 'SELECT c.uuid, Sum(c.tp) as arrive_tp From ' + this.tableName +
+                '  WHERE s.`sorder` < ? And s.`tid` = ?' +
+                '  GROUP By uuid';
+            const sqlParam = [sorder, this.ctx.tender.id];
+            const data = await this.db.query(sql, sqlParam);
+            return data;
+        }
+
+        async getEndStageData(sorder) {
+            const sql = 'SELECT c.uuid, Sum(c.tp) as tp ' + this.tableName +
+                '  WHERE s.`order` <= ? And s.`tid` = ?' +
+                '  GROUP By uuid';
+            const sqlParam = [sorder, this.ctx.tender.id];
+            const data = await this.db.query(sql, sqlParam);
+            return data;
+        }
+
+        async _addDatas(data) {
+            const datas = data instanceof Array ? data : [data];
+            const insertData = [];
+            for (const d of datas) {
+                if (!d.name || !d.order) throw '新增其他数据,提交的数据错误';
+                const nd = {
+                    uuid: this.uuid.v4(),
+                    add_sid: this.ctx.stage.id,
+                    add_uid: this.ctx.session.sessionUser.accountId,
+                    sid: this.ctx.stage.id,
+                    sorder: this.ctx.stage.order,
+                    tid: this.ctx.tender.id,
+                    create_time: new Date(),
+                };
+                nd.name = d.name;
+                nd.order = d.order;
+                if (d.real_time) nd.real_time = d.real_time;
+                if (d.memo) nd.memo = d.memo;
+                insertData.push(nd);
+            }
+            await this.db.insert(this.tableName, insertData);
+            return await this.getAllDataByCondition({
+                where: { sid: this.ctx.stage.id, uuid: this.ctx.helper._.map(insertData, 'uuid') }
+            });
+        }
+
+        async _delDatas (data) {
+            const datas = data instanceof Array ? data : [data];
+            const orgDatas = await this.getAllDataByCondition({sid: this.ctx.stage.id, id: this.ctx.helper._.map(datas, 'id')});
+            for (const od of orgDatas) {
+                if (od.pre_used) throw '往期已经计量,不可删除';
+            }
+            await this.db.delete(this.tableName, {id: datas});
+            return datas;
+        }
+
+        async _updateDatas (data) {
+            const datas = data instanceof Array ? data : [data];
+            const orgDatas = await this.getAllDataByCondition({sid: this.ctx.stage.id, id: this.ctx.helper._.map(datas, 'id')});
+
+            const uDatas = [];
+            for (const d of datas) {
+                const od = this.ctx.helper._.find(orgDatas, {id: d.id});
+                if (!od) continue;
+
+                const nd = {id: od.id};
+                if (d.name) nd.name = d.name;
+                if (d.order) nd.order = d.order;
+                if (d.tp) nd.tp = this.ctx.helper.round(d.tp, this.ctx.tender.info.decimal.tp);
+                if (d.real_time) nd.real_time = d.real_time;
+                if (d.memo) nd.memo = d.memo;
+                uDatas.push(nd);
+            }
+            if (uDatas.length > 0) {
+                await this.db.updateRows(this.tableName, uDatas);
+                return uDatas;
+            } else {
+                return [];
+            }
+        }
+
+        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);
+                }
+                return result;
+            } catch (err) {
+                if (err) result.err = err;
+                return result;
+            }
+        }
+
+        async updateHistory(stage, transaction) {
+            const datas = await this.getStageData(stage.id);
+            if (datas.length === 0) return;
+
+            const filter = {stimes: this.ctx.stage.curTimes, sorder: this.ctx.stage.curOrder};
+            const updateDatas = [];
+            for (const d of datas) {
+                const history = d.shistory && d.shistory !== '' ? JSON.parse(d.shistory) : [];
+                const his = this.ctx.helper._.find(datas, filter);
+                if (his) {
+                    his.tp = d.tp;
+                } else {
+                    history.push({ stimes: this.ctx.stage.curTimes, sorder: this.ctx.stage.curOrder, tp: d.tp });
+                }
+                updateDatas.push({ id: d.id, shistory: JSON.stringify(history) });
+            }
+            await transaction.updateRows(this.tableName, updateDatas);
+        }
+
+        async addInitialStageData(stage, preStage, transaction) {
+            if (!stage || !preStage) {
+                throw '标段数据有误';
+            }
+            const preDatas = await this.getStageData(preStage.id);
+            if (preDatas.length > 0) {
+                for (const pd of preDatas) {
+                    delete pd.id;
+                    pd.pre_used = pd.pre_used || !this.ctx.helper.checkZero(pd.tp);
+                    delete pd.tp;
+                    pd.sid = stage.id;
+                }
+                const result = await transaction.insert(this.tableName, preDatas);
+                return result.affectedRows === preDatas.length;
+            } else {
+                return true;
+            }
+
+        }
+    }
+
+    return StageOther;
+};

+ 2 - 0
config/web.js

@@ -381,6 +381,8 @@ const JsFiles = {
                 files: [
                     "/public/js/spreadjs/sheets/v11/gc.spread.sheets.all.11.2.2.min.js",
                     "/public/js/decimal.min.js",
+                    "/public/js/datepicker/datepicker.min.js",
+                    "/public/js/datepicker/datepicker.zh.js",
                 ],
                 mergeFiles: [
                     "/public/js/sub_menu.js",