gaosp
2024-01-19 5b9a1d6cb3a7d59c8f2de83c495bba1a069b2723
src/container/ledger/Manage-add-update.vue
@@ -1,14 +1,15 @@
<template>
   <div>
      <el-dialog :title="!dataForm.id ? '新建' : '编辑'" :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">
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
               <!-- <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="机床名" prop="machineName">
                     <el-input placeholder="机床名称" clearable></el-input>
                  </el-form-item>
               </el-col>
               </el-col> -->
               <!-- 
          <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
            <el-form-item label="机床ip" prop="machineIp">
@@ -173,16 +174,16 @@
                  </el-form-item>
               </el-col>
               <!--
          <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
            <el-form-item label="班次" prop="classes">
              <el-select v-model="dataForm.classes" placeholder="---请选择---">
                <el-option value="一班">一班</el-option>
                <el-option value="二班">二班</el-option>
                <el-option value="三班">三班</el-option>
              </el-select>
            </el-form-item>
          </el-col>
        -->
               <el-col :xs="24":sm="6":md="6":lg="6":xl="6">
                  <el-form-item label="班次" prop="classes">
                  <el-select v-model="dataForm.classes" placeholder="---请选择---">
                     <el-option value="一班">一班</el-option>
                     <el-option value="二班">二班</el-option>
                     <el-option value="三班">三班</el-option>
                  </el-select>
                  </el-form-item>
               </el-col>
               -->
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="生产厂家" prop="manufacturer">
                     <el-input v-model="dataForm.manufacturer" placeholder="生产厂家" clearable></el-input>
@@ -191,26 +192,25 @@
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="投产日期" prop="productionDate">
                     <el-date-picker format="yyyy-MM-dd" value-format="yyyy-MM-dd" v-model="dataForm.productionDate"
                        type="date" clearable placeholder="选择日期" clearable></el-date-picker>
                        type="date" clearable placeholder="选择日期"></el-date-picker>
                  </el-form-item>
               </el-col>
               <el-col :xs="24" :sm="6" :md="6" :lg="6" :xl="6">
                  <el-form-item label="设备原值(元)" prop="originalValue"
                     :rules="{ type: 'number', message: '设备原值必须为数字值',trigger: 'change' }">
                     <el-input v-model.number="dataForm.originalValue" placeholder="设备原值" clearable></el-input>
                  <el-form-item label="设备原值(元)" prop="originalValue">
                     <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" :rules="[
                     { type: 'number', message: '设备重量需为数字值' }
                  ]">
                     <el-input v-model.number="dataForm.presentValue" placeholder="设备净现值" clearable></el-input>
                  <el-form-item label="设备净现值(元)" prop="presentValue">
                     <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">
                  <el-form-item label="设备重量(千克)" prop="weight" :rules="[
                     { type: 'number', message: '设备重量需为数字值' }
                     { type: 'number', message: '设备重量需为数字' }
                  ]">
                     <el-input v-model.number="dataForm.weight" placeholder="设备重量" clearable></el-input>
                  </el-form-item>
@@ -307,16 +307,56 @@
      }
   },
   created() {
      this.init(this.row)
      // this.init(this.row)
   },
   methods: {
      checkAmount(key) {
         let checkPlan = '' + this.dataForm[key]
         checkPlan = checkPlan
            .replace(/[^\d.]/g, '') // 清除“数字”和“.”以外的字符
            .replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
            .replace(/^\./g, '') // 保证第一个为数字而不是.
            .replace('.', '$#$')
            .replace(/\./g, '')
            .replace('$#$', '.')
         if (checkPlan.indexOf('.') < 0 && checkPlan !== '') {
            // 以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额
            checkPlan = parseFloat(checkPlan) + ''
         } else if (checkPlan.indexOf('.') >= 0) {
            checkPlan = checkPlan
               .replace(/^()*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数
         }
         this.dataForm[key] = checkPlan
      },
      init(row) {
         if (this.$refs['dataForm']) {
            // this.$refs['dataForm'].resetFields()
            this.$refs['dataForm'].resetFields()
         }
         if (row !== undefined) {
         } else { this.dataForm.id = '' }
         if (Object.keys(row).length > 0) {
            Object.keys(row).forEach(key => {
               this.dataForm[key] = row[key]
            })
         } else {
            Object.keys(row).forEach(key => {
               this.dataForm[key] = ''
            })
         }
      },
      /* 查询使用部门*/
      cancel() {
@@ -337,40 +377,42 @@
      },
      /* 提交*/
      dataFormSubmit() {
         debugger
         this.$refs.dataForm.validate((valid) => {
            console.log(valid)
            if (valid) {
               alert('submit!');
               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
                        }
                     })
                  })
               }
            } else {
               console.log('error submit!!');
               return false;
               this.$message({
                  type: 'error',
                  message: '验证失败'
               })
            }
         })
         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
                  }
               })
            })
         }
      }
   }
}
@@ -382,6 +424,11 @@
   .el-select,
   .el-input {
      width: 100%;
   }
   .el-input__inner {
      color: #000;
   }
}
@@ -414,5 +461,4 @@
   width: 178px;
   height: 178px;
   display: block;
}
</style>
}</style>