From 5b9a1d6cb3a7d59c8f2de83c495bba1a069b2723 Mon Sep 17 00:00:00 2001 From: gaosp <gaosp> Date: 星期五, 19 一月 2024 00:23:15 +0800 Subject: [PATCH] update --- src/container/ledger/Manage-add-update.vue | 162 ++++++++++++++++++++++++++++++++++------------------- 1 files changed, 104 insertions(+), 58 deletions(-) diff --git a/src/container/ledger/Manage-add-update.vue b/src/container/ledger/Manage-add-update.vue index 450d177..1f4031f 100644 --- a/src/container/ledger/Manage-add-update.vue +++ b/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> -- Gitblit v1.9.3