From 514f26b3ad9a236a3934fba13dde40f4e7e9886b Mon Sep 17 00:00:00 2001 From: liuyuan <582976274@qq.com> Date: Thu, 2 Jan 2025 14:09:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E5=88=97=E8=A1=A8=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AD=97=E6=AE=B5abroadPrice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/modules/book/book-add-or-update.vue | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/views/modules/book/book-add-or-update.vue b/src/views/modules/book/book-add-or-update.vue index 7eaf647..917b490 100644 --- a/src/views/modules/book/book-add-or-update.vue +++ b/src/views/modules/book/book-add-or-update.vue @@ -106,7 +106,7 @@ - @@ -128,6 +128,9 @@ + + + @@ -282,6 +285,7 @@ clockIn: 2, teachIn: 0, relationId:0, + abroadPrice: '' }, splitsTypeList: [], dataRule: { @@ -334,6 +338,7 @@ // splits: [ // { required: true, message: '拆分类类型不能为空', trigger: 'blur' } // ] + abroadPrice: [{ required: true, message: '付费价格不能为空', trigger: 'blur' }] } } }, @@ -387,6 +392,7 @@ this.dataForm.teachIn = data.book.teachIn this.dataForm.canListen = data.book.canListen this.dataForm.relationId = data.book.relationId + this.dataForm.abroadPrice = data.book.abroadPrice //价格 var checklist = data.book.type var medicaldeschecklist = data.book.medicaldesBookType var authorList = data.book.authorId @@ -427,16 +433,39 @@ }) } }) + }, + //价格判断逻辑 + formatNumber(num) { + if (typeof num !== 'number' || isNaN(num)) { + this.$message.error('请输入有效价格') + return + } + + // 检查是否有小数部分 + if (Number.isInteger(num)) { + return num; + } + + // 将数字转换为字符串并分割成整数和小数部分 + let numStr = num.toString(); + let parts = numStr.split('.'); + + // 如果有超过两位的小数,则进行舍入 + if (parts.length > 1 && parts[1].length > 2) { + return parseFloat(num.toFixed(2)); + } + // 如果是不超过两位小数,则直接返回原值 + return num; }, // 表单提交 dataFormSubmit() { - console.log('11111', this.dataForm.medicaldesBookType) - // if (this.dataForm.medicaldesBookType.length == 0) { - // this.$message.error("请选择图书类型"); - // return - // } this.$refs['dataForm'].validate((valid) => { if (valid) { + //价格逻辑 + let abroadPrice = this.dataForm.abroadPrice; + if(abroadPrice){ + abroadPrice = this.formatNumber(Number(abroadPrice)); + } this.$http({ url: this.$http.adornUrl(`/book/book/${!this.dataForm.id ? 'save' : 'update'}`), method: 'post', @@ -470,7 +499,8 @@ 'canListen': this.dataForm.canListen, 'relationId': this.dataForm.relationId, 'clockIn': this.dataForm.clockIn, - 'teachIn': this.dataForm.teachIn + 'teachIn': this.dataForm.teachIn, + 'abroadPrice': abroadPrice //价格 }) }).then(({ data