scorpio 2 gadi atpakaļ
vecāks
revīzija
af86e5471d
1 mainītis faili ar 62 papildinājumiem un 77 dzēšanām
  1. 62 77
      src/views/home/component/params/params3.vue

+ 62 - 77
src/views/home/component/params/params3.vue

@@ -25,7 +25,7 @@
                     form.month_plan_complete_amount[index] ? form.month_plan_complete_amount[index].year : ''
                   }}年度计划投资(万元)</span>
                 <div class='disable-input' @change='change(item)'>
-                  {{ form.month_complete_amount[index] ? form.month_complete_amount[index].sum : '' }}
+                  {{ form.month_plan_complete_amount[index] ? form.month_plan_complete_amount[index].sum : '2' }}
                 </div>
               </div>
               <div style='width: 20px'></div>
@@ -34,9 +34,9 @@
                     form.month_plan_complete_amount[index] ? form.month_plan_complete_amount[index].year : ''
                   }}年度累计投资(万元)</span>
                 <div class='disable-input' @change='change(item)'>
-                  {{ form.month_complete_amount[index] ? form.month_complete_amount[index].sum : '' }}
+                  {{ form.month_complete_amount[index] ? form.month_complete_amount[index].sum : '2' }}
                 </div>
-                <div class='btnSub pointer' @click='showMonth(form.month_plan_complete_amount[index].year ,1,index)'>月填报
+                <div class='btnSub pointer' @click='showMonth(form.month_complete_amount[index].year ,1,index)'>月填报
                 </div>
               </div>
             </div>
@@ -75,7 +75,8 @@
       </el-form>
     </div>
 
-    <el-dialog v-model='show' :title='current ? current.year + "年度" + current.index : ""' width='1260px'>
+    <el-dialog v-model='show' :title='current ? current.year + "年度" + current.index : ""' width='1260px'
+               @close='update(false)'>
       <div class='flex flex-center flex-align-start'>
         <div>
           <div class='padding-top'></div>
@@ -95,8 +96,8 @@
           </div>
 
           <div class='mr-5  flex flex-center'>
-            <div v-for='item in current.months' :key='item.name'>
-              <input class='input' v-model="item.data" @change='changeMonth(item,2)'>
+            <div v-for='(item,index) in current.months' :key='item.name'>
+              <input class='input' v-model="item.data" @change='changeMonth(item,2,index)'>
             </div>
           </div>
         </div>
@@ -145,72 +146,55 @@ export default {
     }
   },
   methods: {
+    /**
+     *
+     * @param type 1计划投资  2 纳统投资
+     */
     addYear (type) {
       this.disabled = false
       if (type === 1) {
-        let lastYear = new Date().getFullYear()
-        if (this.list1.length > 0) {
-          const tmp = this.list1.map(sub => sub.year)
-          const max = Math.max.apply(null, tmp)
-          lastYear = max + 1
-        }
-        const months = []
-        for (let i = 1; i <= 12; i++) {
-          months.push({ name: i, value: '' })
-        }
-        const item = {
-          type: 1,
-          year: lastYear,
-          code: lastYear + '_plan_complete_amount',
-          code2: lastYear + '_total_complete_amount',
-          value: '',
-          value1: '',
-          planMonths: months,
-          months
-        }
-        this.list1.push(item)
+        this.form.month_complete_amount.splice(0, 0, this.nextYear(Number.parseInt(this.form.month_complete_amount[0].year)))
+        this.form.month_plan_complete_amount.splice(0, 0, this.nextYear(Number.parseInt(this.form.month_plan_complete_amount[0].year)))
+        this.completeCount = this.completeCount + 1
+      } else if (type === 2) {
+        this.form.month_investment_amount.splice(0, 0, this.nextYear(Number.parseInt(this.form.month_investment_amount[0].year)))
+        this.form.month_plan_investment.splice(0, 0, this.nextYear(Number.parseInt(this.form.month_plan_investment[0].year)))
+        this.investmentCount = this.investmentCount + 1
       }
-      if (type === 2) {
-        let lastYear = new Date().getFullYear()
-        if (this.list2.length > 0) {
-          const tmp = this.list2.map(sub => sub.year)
-          const max = Math.max.apply(null, tmp)
-          lastYear = max + 1
-        }
-        const months = []
-        for (let i = 1; i <= 12; i++) {
-          months.push({ name: i, value: '' })
-        }
-        const item = {
-          type: 2,
-          year: lastYear,
-          code: lastYear + '_plan_investment_amount',
-          code2: lastYear + '_total_investment_amount',
-          value: '',
-          value1: '',
-          planMonths: months,
-          months
-        }
-        this.list2.push(item)
+    },
+    nextYear (year) {
+      const tmp2 = {}
+      tmp2.year = (year + 1).toString()
+      tmp2.sum = ''
+      tmp2.monthlyData = []
+      for (let i = 1; i <= 12; i++) {
+        const item2 = { year: tmp2.year, data: '', month: i.toString() }
+        tmp2.monthlyData.push(item2)
       }
+      return tmp2
     },
     init (res) {
-      console.log('fuck' + new Date().getTime())
       this.investmentCount = Math.max(res.month_plan_investment.length, res.month_investment_amount.length)
-      // const dd = res.month_plan_investment.filter((sub) => {
-      //   return res.month_investment_amount.findIndex(ele => sub.year === ele.year) === -1
-      // }).map(sub => { // data -》 ''
-      //   sub.monthlyData.map(ele => {
-      //     ele.data = ''
-      //     return ele
-      //   })
-      // })
-      // // 复制差集
-      // if (res.month_plan_investment.length === this.completeCount) {
-      //   res.month_investment_amount.push(dd)
-      // } else {
-      //   res.month_plan_investment.push(dd)
-      // }
+      // 求出差集
+      const dd = res.month_plan_investment.filter((sub) => {
+        return res.month_investment_amount.findIndex(ele => sub.year !== ele.year) !== -1
+      }).map(sub => { // data -》 ''
+        sub.monthlyData.map(ele => {
+          ele.data = ele.data ? ele.data : ''
+          return ele
+        })
+        return sub
+      })
+      // 复制差集
+      if (res.month_plan_investment.length === this.completeCount) {
+        dd.forEach(sub => {
+          res.month_investment_amount.push(sub)
+        })
+      } else {
+        dd.forEach(sub => {
+          res.month_plan_investment.push(sub)
+        })
+      }
 
       this.completeCount = Math.max(res.month_complete_amount.length, res.month_plan_complete_amount.length)
       // 求出差集
@@ -226,11 +210,15 @@ export default {
       // 复制差集
       if (res.month_complete_amount.length === this.completeCount) {
         d.forEach(sub => {
-          res.month_plan_complete_amount.push(sub)
+          if (res.month_plan_complete_amount.findIndex(ele => ele.year === sub.year) === -1) {
+            res.month_plan_complete_amount.push(sub)
+          }
         })
       } else {
         d.forEach(sub => {
-          res.month_complete_amount.push(sub)
+          if (res.month_complete_amount.findIndex(ele => ele.year === sub.year) === -1) {
+            res.month_complete_amount.push(sub)
+          }
         })
       }
       this.form = res
@@ -272,13 +260,13 @@ export default {
       for (let i = 1; i <= 12; i++) {
         const index = this.current.months.findIndex(sub => sub.month === i.toString())
         if (index === -1 && this.current.months.length < 12) {
-          const item = { month: i.toString(), data: '', year: '' }
-          this.current.months.push(item)
+          const ele = { month: i.toString(), data: '', year: '' }
+          this.current.months.push(ele)
         }
         const planIndex = this.current.planMonths.findIndex(sub => sub.month === i.toString())
         if (planIndex === -1 && this.current.planMonths.length < 12) {
-          const item = { month: i.toString(), data: '', year: '' }
-          this.current.planMonths.push(item)
+          const sub = { month: i.toString(), data: '', year: '' }
+          this.current.planMonths.push(sub)
         }
       }
       this.show = !this.show
@@ -291,26 +279,23 @@ export default {
      */
     changeMonth (res, type, index) {
       setTimeout(() => {
+        console.log(res)
         if (this.current.editType === 1) {
           if (type === 1) {
             this.form.month_plan_complete_amount[this.current.index].monthlyData[index] = res
-            this.form.month_plan_complete_amount[this.current.index].sum = this.getSum(this.form.month_plan_complete_amount[this.current.index].monthlyData)
           } else {
             this.form.month_complete_amount[this.current.index].monthlyData[index] = res
-            this.form.month_complete_amount[this.current.index].sum = this.getSum(this.form.month_complete_amount[this.current.index].monthlyData)
           }
         } else if (this.current.editType === 2) {
+          console.log(this.current)
           if (type === 1) {
             this.form.month_plan_investment[this.current.index].monthlyData[index] = res
-            this.form.month_plan_investment[this.current.index].sum = this.getSum(this.form.month_plan_investment[this.current.index].monthlyData)
           } else {
             this.form.month_investment_amount[this.current.index].monthlyData[index] = res
-            this.form.month_investment_amount[this.current.index].sum = this.getSum(this.form.month_investment_amount[this.current.index].monthlyData)
           }
         }
-        console.log(this.form)
-        // this.update(false)
-      }, 500)
+        console.log(this.form.month_plan_complete_amount)
+      }, 1000)
     },
     getSum (list) {
       let sum = 0