浏览代码

Merge branch 'dev' of http://192.168.1.41:3000/maixinrong/Calculation into dev

MaiXinRong 1 周之前
父节点
当前提交
146807658e

+ 4 - 4
app/controller/material_controller.js

@@ -1093,12 +1093,12 @@ module.exports = app => {
                 const mbList = await this._getMaterialBillsData(ctx);
                 const material_month = this.ctx.material.months ? this.ctx.material.months.split(',') : [];
                 switch (data.type) {
-                    case 'add':
+                    case 'adds':
                         // 判断是否已存在该月份
-                        if (ctx.app._.indexOf(material_month, data.updateData.yearmonth) !== -1) {
-                            throw '调差期已创建过本月的信息价,请刷新页面重新获取';
+                        if (ctx.app._.intersection(data.updateData.yearmonths, material_month).length !== 0) {
+                            throw '调差期已创建过所选月区间所有的信息价,请重新选月份';
                         }
-                        const tp = await ctx.service.materialMonth.add(data.updateData, monthList, mbList);
+                        const tp = await ctx.service.materialMonth.adds(data.updateData, monthList, mbList);
                         const materialBillsData = await this._getMaterialBillsData(ctx);
                         const monthsList = await this._getMaterialMonthsData(ctx, materialBillsData);
                         responseData.data = {

+ 42 - 9
app/public/js/material.js

@@ -1883,18 +1883,51 @@ $(document).ready(() => {
         // 创建月信息价
         $('#make-month').click(function() {
             const yearmonth = $('#months').val();
-            const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
-            if (result === null) {
+            const yearmonths = [];
+            if (yearmonth === '') {
                 toastr.error('请选择正确的信息价月份');
                 return false;
+            } else if (_.indexOf(yearmonth, '~') !== -1) {
+                const yearmonthArr = yearmonth.split('~');
+                // 对比两个年月,找出中间值年月push
+                const startYearMonth = yearmonthArr[0].trim();
+                const endYearMonth = yearmonthArr[1].trim();
+                const startYear = parseInt(startYearMonth.split('-')[0]);
+                const startMonth = parseInt(startYearMonth.split('-')[1]);
+                const endYear = parseInt(endYearMonth.split('-')[0]);
+                const endMonth = parseInt(endYearMonth.split('-')[1]);
+                if (startYear > endYear || (startYear === endYear && startMonth > endMonth)) {
+                    toastr.error('请选择正确的信息价月份');
+                    return false;
+                }
+                for (let i = startYear; i <= endYear; i++) {
+                    for (let j = (i === startYear ? startMonth : 1); j <= (i === endYear ? endMonth : 12); j++) {
+                        const monthStr = j < 10 ? `0${j}` : j;
+                        const yearmonthStr = `${i}-${monthStr}`;
+                        if (_.indexOf(yearmonths, yearmonthStr) === -1 && months.indexOf(yearmonthStr) === -1) {
+                            yearmonths.push(yearmonthStr);
+                        }
+                    }
+                }
+                if (yearmonths.length === 0) {
+                    toastr.error('调差期已创建过所选月区间所有的信息价');
+                    return false;
+                }
+            } else {
+                const result = yearmonth.match(/^(\d{1,4})(-|\/)(\d{1,2})$/);
+                if (result === null) {
+                    toastr.error('请选择正确的信息价月份');
+                    return false;
+                }
+                if (months.indexOf(yearmonth) !== -1) {
+                    toastr.error('调差期已创建过本月的信息价');
+                    return false;
+                }
+                yearmonths.push(yearmonth);
             }
-            //判断是否已存在当前月份
-            if (months.indexOf(yearmonth) !== -1) {
-                toastr.error('调差期已创建过本月的信息价');
-                return false;
-            }
-            postData(window.location.pathname + '/month/save', { type: 'add', updateData: { yearmonth: yearmonth } }, function (data) {
-                months.push(yearmonth);
+            console.log(yearmonths);
+            postData(window.location.pathname + '/month/save', { type: 'adds', updateData: { yearmonths } }, function (data) {
+                months.push(...yearmonths);
                 months.sort();
                 monthsList = data.monthsList;
                 monthFunGather.monthsListSet();

+ 10 - 0
app/public/js/measure_stage.js

@@ -222,4 +222,14 @@ function checkTableWidth() {
 
 $(function () {
     checkTableWidth();
+    const stagePeriod = $('#stage-period').datepicker({
+    }).data('datepicker');
+    const stageYearmonth = $('#stage-yearmonth').datepicker({
+        onSelect: function (formattedDate, date, inst) {
+            if (!date) return;
+            $('#stage-period').val(`${formattedDate}-01`);
+            stagePeriod.clear();;
+            stagePeriod.selectDate(new Date(date.getFullYear(), date.getMonth(), 1));
+        }
+    }).data('datepicker');
 });

+ 14 - 12
app/service/material_month.js

@@ -37,31 +37,33 @@ module.exports = app => {
          * 添加月信息价 并更新 工料平均单价、本期单价,调差金额等
          * @return {void}
          */
-        async add(data, monthList, mbList) {
+        async adds(data, monthList, mbList) {
             if (!this.ctx.tender || !this.ctx.material) {
                 throw '数据错误';
             }
             const transaction = await this.db.beginTransaction();
             try {
                 const material_month = this.ctx.material.months ? this.ctx.material.months.split(',') : [];
-                material_month.push(data.yearmonth);
+                material_month.push(...data.yearmonths);
                 material_month.sort();
                 if (mbList.length !== 0) {
                     const insertArray = [];
                     const updateArray = [];
                     for (const mb of mbList) {
-                        const one_month = {
-                            tid: this.ctx.tender.id,
-                            mid: this.ctx.material.id,
-                            mb_id: mb.id,
-                            msg_tp: monthList.length !== 0 ? null : mb.msg_tp,
-                            yearmonth: data.yearmonth,
-                        };
-                        insertArray.push(one_month);
+                        for (const ym of data.yearmonths) {
+                            const one_month = {
+                                tid: this.ctx.tender.id,
+                                mid: this.ctx.material.id,
+                                mb_id: mb.id,
+                                msg_tp: monthList.length !== 0 ? null : mb.msg_tp,
+                                yearmonth: ym,
+                            };
+                            insertArray.push(one_month);
+                        }
                         if (monthList.length !== 0) {
                             const mb_msg_tp_sum = this._.sumBy(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp');
-                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), one_month.msg_tp), [null, '', 0]);
-                            const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, one_month.msg_tp), month_num), this.ctx.material.decimal.up);
+                            const month_num = material_month.length - this.ctx.helper.arrayCount(this._.concat(this._.map(this._.filter(monthList, { mb_id: mb.id }), 'msg_tp'), insertArray[0].msg_tp), [null, '', 0]);
+                            const new_msg_tp = this.ctx.helper.round(this.ctx.helper.div(this.ctx.helper.add(mb_msg_tp_sum, insertArray[0].msg_tp), month_num), this.ctx.material.decimal.up);
                             const [newmsg_spread, newm_spread] = await this.ctx.service.materialBills.getSpread(mb, new_msg_tp);
                             const newTp = this.ctx.helper.round(this.ctx.helper.mul(mb.quantity, newm_spread), this.ctx.material.decimal.tp);
                             updateArray.push({

+ 1 - 1
app/view/material/info_modal.ejs

@@ -49,7 +49,7 @@
             <div class="modal-body">
                 <div class="form-group">
                     <label>信息价月份</label>
-                    <input class="datepicker-here form-control" id="months" placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text" data-auto-close="true">
+                    <input id="months" readonly class="datepicker-here form-control" placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-range="true" data-multiple-dates-separator=" ~ " data-language="zh" type="text">
                 </div>
                 <!--首次创建-->
                 <div class="alert alert-primary">创建月信息价后,「本期信息价」 「单价」列将无法自行填写,而是从「月信息价」中获取,如果有多个「月信息价」,将取平均值。</div>

+ 2 - 2
app/view/measure/stage_modal.ejs

@@ -30,11 +30,11 @@
                 </div>
                 <div class="form-group">
                     <label>计量年月<b class="text-danger">*</b></label>
-                    <input class="datepicker-here form-control form-control-sm" autocomplete="off" readonly placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text" name="date" autocomplete="off">
+                    <input class="datepicker-here form-control form-control-sm" id="stage-yearmonth" autocomplete="off" readonly placeholder="点击选择年月" data-view="months" data-min-view="months" data-date-format="yyyy-MM" data-language="zh" type="text" name="date" autocomplete="off">
                 </div>
                 <div class="form-group">
                     <label>开始-截止日期<b class="text-danger">*</b></label>
-                    <input class="datepicker-here form-control form-control-sm" autocomplete="off" readonly placeholder="点击选择时间" data-range="true" data-multiple-dates-separator=" ~ " data-language="zh" type="text" name="period" autocomplete="off">
+                    <input class="datepicker-here form-control form-control-sm" id="stage-period" autocomplete="off" readonly placeholder="点击选择时间" data-range="true" data-multiple-dates-separator=" ~ " data-language="zh" type="text" name="period" autocomplete="off">
                 </div>
             </div>
             <div class="modal-footer">