Browse Source

增加项目结束时间和项目预算同时变更的功能

ljb 9 months ago
parent
commit
df98118c20
1 changed files with 86 additions and 30 deletions
  1. 86 30
      src/views/project-manage/components/change-form.vue

+ 86 - 30
src/views/project-manage/components/change-form.vue

@@ -58,6 +58,7 @@
               placeholder="请选择日期"
               style="width: 100%"
               :disabled="disabled"
+              @change="handleEndDateChange"
             ></el-date-picker>
             <!-- 项目负责人 -->
             <avue-select
@@ -98,6 +99,33 @@
           </td>
         </tr>
         
+        <!-- 变更结束时间,同时增加预算变更 -->
+        <tr v-if="formData.zdmc === 'xmjssj'"><td colspan="4" align="center" style="height: 46px; font-weight: 600;">预算变更</td></tr>
+        <tr v-if="formData.zdmc === 'xmjssj'">
+          <td class="doc-label">变更前</td>
+          <td class="doc-input" style="padding: 0;">
+            <div style="height: 31px; line-height: 31px; border-bottom: 1px solid #000;">总计:{{ selProject.xmysze }}万元</div>
+            <div class="year-list">
+              <div class="year-list-item" v-for="item of oldXmyszemxList" :key="item.year">
+                <div class="year">{{ item.year }}</div>
+                <div class="year-input"> {{ item.amount }} </div>
+              </div>
+            </div>
+          </td>
+          <td class="doc-label">变更后</td>
+          <td class="doc-input" style="padding: 0;">
+            <div class="year-list">
+              <div style="height: 31px; line-height: 31px; border-bottom: 1px solid #000;">总计:{{ newXmysTotal }}万元</div>
+              <div class="year-list-item" v-for="item of newXmyszemxList" :key="item.year">
+                <div class="year">{{ item.year }}</div>
+                <div class="year-input">
+                  <input v-model="item.amount" type="number" style="padding: 0 6px;" :disabled="disabled" />
+                </div>
+              </div>
+            </div>
+          </td>
+        </tr>
+
         <tr>
           <td class="doc-label">变更原因说明</td>
           <td class="doc-input" colspan="3">
@@ -203,13 +231,11 @@ export default {
     "formData.zdmc"(newVal) {
       if (newVal == 'xmfzr') {
         this.getTechnicanRosterListFunc(moment(this.selProject.xmkssj).format('yyyyMM'));
-      } else if (newVal == 'xmyszemx') {
-        this.oldXmyszemxList = JSON.parse(this.selProject.xmyszemx);
-        this.newXmyszemxList = JSON.parse(this.selProject.xmyszemx);
-        // JSON.parse(data.xmyszemx).forEach(item => {
-        //   this.formData[item.year.toString()] = item.amount;
-        // });
       }
+      // else if (newVal == 'xmyszemx' || newVal == 'xmjssj') {
+      //   this.oldXmyszemxList = JSON.parse(this.selProject.xmyszemx);
+      //   this.newXmyszemxList = JSON.parse(this.selProject.xmyszemx);
+      // }
     },
   },
   computed: {
@@ -217,9 +243,6 @@ export default {
     currProjectYear() {
       return this.selProject.xmkssj ? moment(this.selProject.xmkssj).format('YYYY') : '';
     },
-    yearList() {
-      return this.selProject && this.selProject.xmyszemx ? JSON.parse(this.selProject.xmyszemx) : [];
-    },
     // 获取变更前的值
     getChangeBeforeVal() {
       if (this.formData.zdmc === 'xmfzr') {
@@ -252,6 +275,17 @@ export default {
     };
   },
   methods: {
+    handleEndDateChange(e) {
+      let startYear = moment(this.selProject.xmkssj).format('YYYY');
+      let endYear = moment(e).format('YYYY');
+      
+      let newYearList = [];
+      for (let i=startYear; i<=endYear; i++) {
+        let _obj = this.oldXmyszemxList.find(item => item.year == i);
+        newYearList.push({ year: i, amount: _obj ? _obj.amount : '' });
+      }
+      this.newXmyszemxList = newYearList;
+    },
     /**
      * 获取人员花名册
      */
@@ -271,11 +305,10 @@ export default {
         });
       });
     },
-    formatProjectStatus() {
-
-    },
     handleProjectChange(data) {
       this.selProject = data;
+      this.oldXmyszemxList = JSON.parse(data.xmyszemx);
+      this.newXmyszemxList = JSON.parse(data.xmyszemx);
     },
     validForm() {
       let errorText = '';
@@ -289,7 +322,7 @@ export default {
         errorText = '请选择变更生效时间';
       }
 
-      if (this.formData.zdmc == 'xmyszemx') {
+      if ('xmyszemx,xmjssj'.indexOf(this.formData.zdmc) > -1) {
         for (let i=0; i<this.newXmyszemxList.length; i++) {
           let _item = this.newXmyszemxList[i];
           if (_item.amount === null || _item.amount === undefined || _item.amount === '') {
@@ -297,6 +330,9 @@ export default {
             break;
           }
         }
+        if (this.formData.zdmc === 'xmjssj' && !this.formData.bghdz) {
+          errorText = '变更后的值不能为空!';
+        }
       } else {
         if (!this.formData.bghdz || (this.formData.bghdz instanceof Array && !this.formData.bghdz.length)) {
           errorText = '变更后的值不能为空!';
@@ -305,8 +341,24 @@ export default {
       
       return errorText;
     },
-    handleResetBtn() {
-      this.formData = {};
+    /**
+     * 获取提交的参数
+     * @param changeType 变更类型
+     */
+    getFormData(changeType) {
+      const params = {
+        ...this.formData,
+        bgqdz: this.selProject[changeType],
+        attachment: JSON.stringify(this.formData.attachment),
+        xmId: this.currProjectId,
+        zdmc: changeType.toUpperCase()
+      };
+      if (changeType === 'xmyszemx') {
+        params.bghdz = JSON.stringify(this.newXmyszemxList);
+      } else if (changeType === 'xmsqdwid') {
+        params.bghdz = params.bghdz[params.bghdz.length - 1];
+      }
+      return params;
     },
     handleSaveBtn() {
       let errorText = this.validForm();
@@ -315,30 +367,34 @@ export default {
         return;
       }
 
-      const params = {
-        ...this.formData,
-        bgqdz: this.selProject[this.formData.zdmc],
-        attachment: JSON.stringify(this.formData.attachment),
-        xmId: this.currProjectId,
-        zdmc: this.formData.zdmc.toUpperCase()
-      };
+      if (this.formData.zdmc === 'xmjssj' && JSON.stringify(this.newXmyszemxList) != JSON.stringify(this.oldXmyszemxList)) {
+        this.$confirm('检测到预算发生变化,点击确定,将同时发起一个预算变更,确认要操作吗?', '提示').then(() => {
+          const params1 = this.getFormData(this.formData.zdmc);
+          const params2 = this.getFormData('xmyszemx');
+          params2.bgqdz = JSON.stringify(this.oldXmyszemxList);
 
-      if (this.formData.zdmc === 'xmyszemx') {
-        params.bghdz = JSON.stringify(this.newXmyszemxList);
-      } else if (this.formData.zdmc === 'xmsqdwid') {
-        params.bghdz = params.bghdz[params.bghdz.length - 1];
+          Promise.all([this.saveData(params1), this.saveData(params2)]).then(([res1, res2]) => {
+            if (res1.data.success) {
+              this.$message.success("保存成功!");
+              this.$emit("success");
+            }
+          });
+        });
+        return;
       }
 
-      this.saveData(params);
-    },
-    saveData(params) {
-      save(params).then(({ data }) => {
+      const params = this.getFormData(this.formData.zdmc);
+
+      this.saveData(params).then(({ data }) => {
         if (data.code == 200) {
           this.$message.success("保存成功!");
           this.$emit("success");
         }
       });
     },
+    saveData(params) {
+      return save(params)
+    },
     handleDownFile(file) {
       window.open(file.value);
     },