diff --git a/anrui-scm/anrui-scm-ui/src/views/manufacturerrebates/huikuanguanli/collectionrebatemanagementAdd.vue b/anrui-scm/anrui-scm-ui/src/views/manufacturerrebates/huikuanguanli/collectionrebatemanagementAdd.vue index 4944c69b90..edbc15f93b 100644 --- a/anrui-scm/anrui-scm-ui/src/views/manufacturerrebates/huikuanguanli/collectionrebatemanagementAdd.vue +++ b/anrui-scm/anrui-scm-ui/src/views/manufacturerrebates/huikuanguanli/collectionrebatemanagementAdd.vue @@ -57,7 +57,7 @@ - + @@ -67,13 +67,13 @@ 运费 - + 计算标准(%) - + 预计返利 @@ -142,6 +142,7 @@ export default { freight: '', manufaSaleChannel: '', manufaSaleChannelValue: '', + isReduceFreight: '', remarks: '', state: '', uploadDate: '', @@ -158,6 +159,20 @@ export default { submitdisabled: false } }, + computed: { + // 计算预计返利 + estimateRebateSum() { + let estimateRebate = '0' + // 是否减运费为是时 预计返利 = (回款金额 - 运费) * 计算标准 + if (this.formobj.isReduceFreight === '1') { + estimateRebate = Math.round((parseFloat(estimateRebate) + (parseFloat(this.formobj.collectionMoney !== '' ? this.formobj.collectionMoney : 0) - parseFloat(this.formobj.freight !== '' ? this.formobj.freight : 0)) * (parseFloat(this.formobj.calculationStandard !== '' ? this.formobj.calculationStandard : 0) / 100)) * 100) / 100 + } else { + // 为否时 预计返利 = 回款金额 * 计算标准 + estimateRebate = Math.round((parseFloat(estimateRebate) + parseFloat(this.formobj.collectionMoney !== '' ? this.formobj.collectionMoney : 0) * (parseFloat(this.formobj.calculationStandard !== '' ? this.formobj.calculationStandard : 0) / 100)) * 100) / 100 + } + return estimateRebate + } + }, methods: { init() { fetchBySid(this.formobj.createOrgSid).then((res) => { @@ -167,44 +182,23 @@ export default { } }) }, - UpNumber(e) { - if (this.formobj.isReduceFreight === '') { - this.formobj.calculationStandard = '' - this.$message({ showClose: true, type: 'error', message: '是否减运费请选择是或否' }) - return + getNumber(val, limit) { + val = val.replace(/[^0-9.]/g, '') // 保留数字 + val = val.replace(/^00/, '0.') // 开头不能有两个0 + val = val.replace(/^\./g, '0.') // 开头为小数点转换为0. + val = val.replace(/\.{2,}/g, '.') // 两个以上的小数点转换成一个 + val = val.replace('.', '$#$').replace(/\./g, '').replace('$#$', '.'); // 只保留一个小数点 + /^0\d+/.test(val) ? val = val.slice(1) : '' // 两位以上数字开头不能为0 + const str = '^(\\d+)\\.(\\d{' + limit + '}).*$' + const reg = new RegExp(str) + if (limit === 0) { + // 不需要小数点 + val = val.replace(reg, '$1') } else { - e.target.value = e.target.value.replace(/[^\d]/g, '') // 清除“数字”和“.”"-"以外的字符 - e.target.value = e.target.value.replace(/^00/, '0') // 开头不能有两个0 - // e.target.value = e.target.value.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的 - // e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数 - if (e.target.value.indexOf('.') < 0 && e.target.value !== '' && e.target.value !== '-') { - // 以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 - e.target.value = parseFloat(e.target.value) - } - } - }, - UpInput(e) { - e.target.value = e.target.value.replace(/[^\d.]/g, '') // 清除“数字”和“.”"-"以外的字符 - e.target.value = e.target.value.replace(/^00/, '0.') // 开头不能有两个0 - e.target.value = e.target.value.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的 - e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3') // 只能输入两个小数 - if (e.target.value.indexOf('.') < 0 && e.target.value !== '' && e.target.value !== '-') { - // 以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额 - e.target.value = parseFloat(e.target.value) - } - }, - handleRadio(value) { - if (value === '1') { - this.formobj.freight = '' - } else { - this.formobj.freight = '0' - } - }, - estimateRebateSum() { - if (this.formobj.freight !== '' && this.formobj.calculationStandard !== '') { - this.formobj.estimateRebate = (parseInt(this.formobj.collectionMoney) - parseInt(this.formobj.freight)) * (parseFloat(this.formobj.calculationStandard) / 100) - return this.formobj.estimateRebate + // 通过正则保留小数点后指定的位数 + val = val.replace(reg, '$1.$2') } + return val }, showEdit(row, createOrgSid) { this.$nextTick(() => { @@ -218,7 +212,8 @@ export default { this.formobj = resp.data if (this.formobj.scmCollectionRebateVehs.length !== 0) { for (var i = 0; i < this.formobj.scmCollectionRebateVehs.length; i++) { - this.aggregate = parseInt(0) + parseInt(this.formobj.scmCollectionRebateVehs[i].costPrice) + // 计算车辆回款返利列表--厂家结算价总和 + this.aggregate = parseFloat(this.aggregate !== '' ? this.aggregate : 0) + parseFloat(this.formobj.scmCollectionRebateVehs[i].costPrice) } } } @@ -231,21 +226,19 @@ export default { return } else { for (var i = 0; i < this.formobj.scmCollectionRebateVehs.length; i++) { - this.formobj.scmCollectionRebateVehs[i].estimateRebate = parseFloat(this.formobj.estimateRebate) * (parseFloat(this.formobj.scmCollectionRebateVehs[i].costPrice / parseFloat(this.aggregate))) + // 计算每台车的预计返利 = 总预计返利 * (单台结算价 / 总结算价) + this.formobj.scmCollectionRebateVehs[i].estimateRebate = Math.round((parseFloat(this.estimateRebateSum) * (parseFloat(this.formobj.scmCollectionRebateVehs[i].costPrice !== '' ? this.formobj.scmCollectionRebateVehs[i].costPrice : 0) / parseFloat(this.aggregate !== '' ? this.aggregate : 0))) * 100) / 100 } } }, save() { this.$refs['form_obj'].validate((valid) => { if (valid) { + this.formobj.estimateRebate = this.estimateRebateSum this.submitdisabled = true req.save(this.formobj).then((resp) => { if (resp.success) { - this.$message({ - showClose: true, - type: 'success', - message: resp.msg - }) + this.$message({ showClose: true, type: 'success', message: resp.msg }) this.handleReturn('true') } }).catch(() => { @@ -275,6 +268,7 @@ export default { freight: '', manufaSaleChannel: '', manufaSaleChannelValue: '', + isReduceFreight: '', remarks: '', state: '', uploadDate: '',