gaosp
2024-01-18 c55d9376565a78ce31a5b8d78dad89df16c2628e
src/container/ledger/Manage-add-update.vue
@@ -1,6 +1,7 @@
<template>
   <div>
      <el-dialog :title="!dataForm.id ? '新建' : '编辑'" @close="cancel" :close-on-click-modal="false" width="80%" :visible.sync="addVisible">
      <el-dialog :title="!dataForm.id ? '新建' : '编辑'" @close="cancel" :close-on-click-modal="false" width="80%"
         :visible.sync="addVisible">
         <!-- 添加内容-->
         <el-form :model="dataForm" label-width="100px" ref="dataForm">
            <el-row :gutter="20">
@@ -196,13 +197,15 @@
               </el-col>
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="设备原值(元)" prop="originalValue">
                     <el-input v-model="dataForm.originalValue" :change="checkAmount('originalValue')" placeholder="设备原值" clearable></el-input>
                     <el-input v-model="dataForm.originalValue" :change="checkAmount('originalValue')"
                        placeholder="设备原值" clearable></el-input>
                  </el-form-item>
               </el-col>
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="设备净现值(元)" prop="presentValue">
                     <el-input v-model="dataForm.presentValue" :change="checkAmount('presentValue')"  placeholder="设备净现值" clearable></el-input>
                     <el-input v-model="dataForm.presentValue" :change="checkAmount('presentValue')"
                        placeholder="设备净现值" clearable></el-input>
                  </el-form-item>
               </el-col>
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
@@ -307,42 +310,41 @@
      // this.init(this.row)
   },
   methods: {
      checkAmount (key) {
      checkAmount(key) {
         let checkPlan = '' + this.dataForm[key]
            checkPlan = checkPlan
         checkPlan = checkPlan
            .replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
            .replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
            .replace(/^\./g, '') // 保证第一个为数字而不是.
            .replace('.', '$#$')
            .replace(/\./g, '')
            .replace('$#$', '.')
            if (checkPlan.indexOf('.') < 0 && checkPlan !== '') {
         if (checkPlan.indexOf('.') < 0 && checkPlan !== '') {
            // 以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
            checkPlan = parseFloat(checkPlan) + ''
            } else if (checkPlan.indexOf('.') >= 0) {
         } else if (checkPlan.indexOf('.') >= 0) {
            checkPlan = checkPlan
            .replace(/^()*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
            }
            this.dataForm[key] = checkPlan
               .replace(/^()*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
         }
         this.dataForm[key] = checkPlan
      },
      init(row) {
         debugger
         if (this.$refs['dataForm']) {
            this.$refs['dataForm'].resetFields()
         }
@@ -350,11 +352,11 @@
            Object.keys(row).forEach(key => {
               this.dataForm[key] = row[key]
            })
         } else {
         } else {
            Object.keys(row).forEach(key => {
               this.dataForm[key] = ''
            })
          }
         }
      },
      /* 查询使用部门*/
      cancel() {
@@ -374,47 +376,43 @@
         }
      },
      /* 提交*/
      async dataFormSubmit() {
         let valid = await new Promise(resolve => {
            this.$refs.dataForm.validate((valid) => {
               if (valid) {
                  resolve(true)
      dataFormSubmit() {
         debugger
         this.$refs.dataForm.validate((valid) => {
            console.log(valid)
            if (valid) {
               if (!this.dataForm.id) { // 新增
                  accountCreate(this.dataForm).then(res => {
                     this.$message({
                        message: '新增成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                           this.$emit('confirm')
                           this.visible = false
                        }
                     })
                  })
               } else {
                  resolve(false)
                  this.$message({
                     type: 'error',
                     message: '验证失败'
                  accountUpdate(this.dataForm).then(res => {
                     this.$message({
                        message: '修改成功',
                        type: 'success',
                        duration: 1500,
                        onClose: () => {
                           this.$emit('confirm')
                           this.visible = false
                        }
                     })
                  })
               }
            })
            } else {
               this.$message({
                  type: 'error',
                  message: '验证失败'
               })
            }
         })
         if (!valid) return
         // return
         if (!this.dataForm.id) { // 新增
            accountCreate(this.dataForm).then(res => {
               this.$message({
                  message: '新增成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                     this.$emit('confirm')
                     this.visible = false
                  }
               })
            })
         } else {
            accountUpdate(this.dataForm).then(res => {
               this.$message({
                  message: '修改成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                     this.$emit('confirm')
                     this.visible = false
                  }
               })
            })
         }
      }
   }
}
@@ -426,6 +424,11 @@
   .el-select,
   .el-input {
      width: 100%;
   }
   .el-input__inner {
      color: #000;
   }
}
@@ -458,5 +461,4 @@
   width: 178px;
   height: 178px;
   display: block;
}
</style>
}</style>