Selaa lähdekoodia

手动抄表提交

luogang 11 kuukautta sitten
vanhempi
commit
f5adc551bd
1 muutettua tiedostoa jossa 44 lisäystä ja 27 poistoa
  1. 44 27
      ems-ui/src/views/devmgr/meterRead/index.vue

+ 44 - 27
ems-ui/src/views/devmgr/meterRead/index.vue

@@ -51,27 +51,23 @@
           @pagination="getList" />
         <el-dialog :title="fillTitle" :visible.sync="fillFormOpen" width="500px" append-to-body>
           <el-form ref="fillForm" :model="fillForm" label-width="150px">
-            <el-form-item label="抄表月份">
-              <el-input readonly :value="fillForm.currentMonth" />
+            <el-form-item label="抄表日期">
+              <el-input :value="fillForm.currentMonth" />
             </el-form-item>
             <el-form-item label="上次抄表日期">
-              <el-input readonly :value="fillForm.lastTime" />
+              <el-input disabled :value="fillForm.lastTime" />
             </el-form-item>
             <el-form-item label="上次抄表示数">
-              <el-input readonly :value="fillForm.lastReading" />
+              <el-input disabled :value="fillForm.lastReading" />
             </el-form-item>
-            <el-form-item required :rules="[{required:true,message:'请选择本次抄表时间'}]" label="本次抄表时间" prop="meterTime">
-              <el-date-picker style="width:100%" value-format="yyyy-MM-dd" v-model="fillForm.meterTime" type="date" placeholder="选择日期">
-              </el-date-picker>
-            </el-form-item>
-            <el-form-item required :rules="[{required:true,message:'请输入当前抄表示数'}]" label="本次抄表示数" prop="meterReading">
+            <el-form-item required :rules="[{required:true,message:'请输入本次抄表示数'}]" label="本次抄表示数" prop="meterReading">
               <el-input v-model="fillForm.meterReading" oninput="value=value.replace(/[^\d]/g,'')" placeholder="请输入本次抄表示数" />
             </el-form-item>
-            <el-form-item label="倍率" prop="magnification">
-              <el-input readonly v-model="fillForm.magnification" />
+            <el-form-item label="综合倍率" prop="magnification">
+              <el-input v-model="fillForm.magnification" />
             </el-form-item>
-            <el-form-item label="增量">
-              <el-input readonly :value="increase" />
+            <el-form-item :label="`参考增量(${activeTab==='first'?'度':'吨'})`">
+              <el-input :value="increase" />
             </el-form-item>
 
           </el-form>
@@ -154,18 +150,18 @@ export default {
       },
       fillTitle: '',
       fillForm: {
+        id:'',
         currentMonth: '',
         deviceCode: '',
         areaCode: '',
-        year: '',
-        meterMonth: '',
         lastTime: '',
         lastReading: '',
         meterTime: '',
         meterReading: '',
         increase: '',
         magnification: 1
-      }
+      },
+      ifAdd: true // 判断 新增还是修改
     }
   },
   computed: {
@@ -264,31 +260,52 @@ export default {
       this.fillTitle = row.objName
       this.fillFormOpen = true
       const nowDay = new Date()
-      this.fillForm.year = nowDay.getFullYear()
-      this.fillForm.meterMonth = dateFormat(nowDay, 'yyyyMM')
-      this.fillForm.currentMonth = dateFormat(nowDay, 'yyyy年MM月')
+      this.fillForm.currentMonth = dateFormat(nowDay, 'yyyy年MM月dd日')
       this.fillForm.deviceCode = row.deviceCode
       this.fillForm.areaCode = row.areaCode
+      this.fillForm.magnification = row.magnification
+      this.ifAdd = true
       // 获取上次填报记录
       await getLastRecord(row.areaCode, row.deviceCode).then(({ data }) => {
         if (data) {
-          this.fillForm.lastTime = data.meterTime
-          this.fillForm.lastReading = data.meterReading
+          if (data.meterMonth === dateFormat(nowDay, 'yyyyMM')) {
+            this.ifAdd = false
+            this.fillForm.id = data.id
+            this.fillForm.lastTime = data.lastTime
+            this.fillForm.lastReading = data.lastReading
+            this.fillForm.meterReading = data.meterReading
+          } else {
+            this.fillForm.lastTime = data.meterTime
+            this.fillForm.lastReading = data.meterReading
+          }
         }
       })
-      // 获取设备倍率
-      getDevice(row.id).then(response => {
-        this.fillForm.magnification = response.data.magnification || 1
-      })
     },
     submitFillForm() {
       this.$refs['fillForm'].validate(valid => {
         if (valid) {
           this.fillForm.increase = this.increase
-          addMeterReading(this.fillForm)
+          if (this.ifAdd) {
+            addMeterReading(this.fillForm).then(({ code, msg }) => {
+              if (code === 200) {
+                this.$modal.msgSuccess('填报成功')
+                this.fillFormOpen = false
+              } else {
+                this.$modal.msgError(msg)
+              }
+            })
+          } else {
+            updateMeterReading(this.fillForm).then(({ code, msg }) => {
+              if (code === 200) {
+                this.$modal.msgSuccess('填报成功')
+                this.fillFormOpen = false
+              } else {
+                this.$modal.msgError(msg)
+              }
+            })
+          }
         }
       })
-      this.fillFormOpen = false
     },
     fillCancel() {
       this.fillFormOpen = false