diff --git a/src/views/system/jd-instruction/fadan-quick-record.vue b/src/views/system/jd-instruction/fadan-quick-record.vue index 055c902..8c3992b 100644 --- a/src/views/system/jd-instruction/fadan-quick-record.vue +++ b/src/views/system/jd-instruction/fadan-quick-record.vue @@ -100,11 +100,15 @@ - + - + + + + +

后改的那一项为准,另一项按付款金额重算。两个都空不能录单。

@@ -262,10 +266,13 @@ export default { buyer: '', paymentText: '', rebateText: '', + costText: '', orderIdText: '', logisticsLink: '', waybillNo: '' }, + /** rebate:以后返为准算成本;cost:以成本为准算后返 */ + moneySource: 'rebate', loading: false, resultText: '', resultListFromLast: [], @@ -381,6 +388,68 @@ export default { if (!Number.isFinite(n)) return '' return n.toFixed(2) }, + /** 空返回 null,非法返回 NaN */ + parseMoneyField(text) { + const s = String(text || '').trim().replace(/,/g, '').replace(/,/g, '') + if (!s) return null + const n = Number(s) + return Number.isFinite(n) ? n : NaN + }, + onPaymentInput() { + if (this.moneySource === 'cost') this.recalcRebate() + else this.recalcCost() + }, + onRebateInput() { + this.moneySource = 'rebate' + this.recalcCost() + }, + onCostInput() { + this.moneySource = 'cost' + this.recalcRebate() + }, + recalcCost() { + const pay = this.parseMoneyField(this.form.paymentText) + const rebate = this.parseMoneyField(this.form.rebateText) + if (pay == null || rebate == null || Number.isNaN(pay) || Number.isNaN(rebate)) return + this.form.costText = (pay - rebate).toFixed(2) + }, + recalcRebate() { + const pay = this.parseMoneyField(this.form.paymentText) + const cost = this.parseMoneyField(this.form.costText) + if (pay == null || cost == null || Number.isNaN(pay) || Number.isNaN(cost)) return + this.form.rebateText = (pay - cost).toFixed(2) + }, + ensureMoneyPair() { + const pay = this.parseMoneyField(this.form.paymentText) + const rebate = this.parseMoneyField(this.form.rebateText) + const cost = this.parseMoneyField(this.form.costText) + if (Number.isNaN(pay) || Number.isNaN(rebate) || Number.isNaN(cost)) { + this.$modal.msgError('金额格式不正确') + return false + } + if (rebate == null && cost == null) { + this.$modal.msgError('请填写成本价或后返金额,至少填一项(填 0 也可以)') + return false + } + if (pay == null) { + this.$modal.msgError('请填写下单付款,才能算出成本价或后返金额') + return false + } + if (this.moneySource === 'cost' && cost != null) { + this.form.costText = cost.toFixed(2) + this.form.rebateText = (pay - cost).toFixed(2) + } else if (rebate != null) { + this.moneySource = 'rebate' + this.form.rebateText = rebate.toFixed(2) + this.form.costText = (pay - rebate).toFixed(2) + } else { + this.moneySource = 'cost' + this.form.costText = cost.toFixed(2) + this.form.rebateText = (pay - cost).toFixed(2) + } + this.form.paymentText = pay.toFixed(2) + return true + }, modelOptionLabel(row) { if (!row || !row.modelNumber) return '' const p = this.formatMoneyText(row.lastPaymentAmount) @@ -499,6 +568,9 @@ export default { const rebateRaw = hit.lastRebateAmount this.form.paymentText = payRaw != null && payRaw !== '' ? this.formatMoneyText(payRaw) : '' this.form.rebateText = rebateRaw != null && rebateRaw !== '' ? this.formatMoneyText(rebateRaw) : '' + this.form.costText = '' + this.moneySource = 'rebate' + this.recalcCost() }, buildCommand() { const mark = this.buildDistributionMark() @@ -552,8 +624,10 @@ export default { } if (rebate) { t = t.replace(/(后返金额(注意核对):)\n\n/, `$1\n${rebate}\n\n`) - } else { - t = t.replace(/(后返金额(注意核对):)\n\n/, `$1\n0.00\n\n`) + } + const cost = (this.form.costText || '').trim() + if (cost) { + t = t.replace(/(成本价(注意核对):)\n\n/, `$1\n${cost}\n\n`) } if (orderId) { t = t.replace(/(订单号(需填):)\n\n/, `$1\n${orderId}\n\n`) @@ -646,6 +720,7 @@ export default { async generate() { const cmd = this.buildCommand() if (!cmd) return + if (!this.ensureMoneyPair()) return this.loading = true this.resultText = '' try { @@ -669,7 +744,7 @@ export default { } if (!this.canPersistOrderFields()) { this.resultText = merged - this.$modal.msgWarning('已生成录单文案。落库需填写:下单人、下单付款、订单号,以及物流链接或物流单号(后返可不填,将按 0.00)') + this.$modal.msgWarning('已生成录单文案。落库需填写:下单人、下单付款、订单号,以及物流链接或物流单号') return } const res2 = await executeInstruction({ command: merged }) @@ -701,6 +776,10 @@ export default { this.$modal.msgError((res && res.msg) || '执行失败') return } + if (!this.ensureMoneyPair()) { + this.verifyDialogVisible = false + return + } const merged = this.injectOptional(this.extractFirstResponse(res.data)) if (!this.formBodyLooksPersistable(merged)) { this.resultText = merged @@ -739,10 +818,12 @@ export default { buyer: '', paymentText: '', rebateText: '', + costText: '', orderIdText: '', logisticsLink: '', waybillNo: '' } + this.moneySource = 'rebate' this.resultText = '' }, openHistory() { @@ -804,7 +885,7 @@ export default { model: field('型号:', ['下单人(需填):', '下单付款(注意核对):']), buyer: field('下单人(需填):', ['下单付款(注意核对):']), payment: field('下单付款(注意核对):', ['后返金额(注意核对):']), - rebate: field('后返金额(注意核对):', ['订单号(需填):']), + rebate: field('后返金额(注意核对):', ['成本价(注意核对):', '订单号(需填):']), orderId: field('订单号(需填):', ['物流链接(需填):']), logistics: field('物流链接(需填):', ['物流单号(无链接时填):', '备注(下单号码有变动', '—————————', '京粉实际价格']), waybill: field('物流单号(无链接时填):', ['备注(下单号码有变动', '—————————', '京粉实际价格']) @@ -1056,6 +1137,9 @@ export default { this.form.buyer = String(row.buyer || '').trim() this.form.paymentText = this.formatHistoryMoney(row.paymentAmount) this.form.rebateText = this.formatHistoryMoney(row.rebateAmount) + this.form.costText = '' + this.moneySource = 'rebate' + this.recalcCost() this.form.orderIdText = String(row.orderId || '').trim() this.form.logisticsLink = String(row.logisticsLink || '').trim() this.form.waybillNo = String(row.waybillNo || '').trim()