diff --git a/src/views/mobile/fadan/index.vue b/src/views/mobile/fadan/index.vue index f8ded1a..8d84271 100644 --- a/src/views/mobile/fadan/index.vue +++ b/src/views/mobile/fadan/index.vue @@ -19,18 +19,18 @@ - 选填:已下单时一并写入录单表 + 落库必填(与中控录单一致) - + - + - + - +
@@ -129,15 +129,50 @@ 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`) } if (logistics) { t = t.replace(/(物流链接(需填):)\n\n/, `$1\n${logistics}\n\n`) } return t }, + /** 中控「单」录单:表单正文已含「单:」开头,直接作为 command 即可落库 */ + formBodyLooksPersistable(text) { + const t = (text || '').trim() + return t.startsWith('单') + }, + canPersistOrderFields() { + const buyer = (this.form.buyer || '').trim() + const pay = (this.form.paymentText || '').trim() + const logistics = (this.form.logisticsLink || '').trim() + return !!(buyer && pay && logistics) + }, + formatInstructionData(data) { + if (Array.isArray(data)) { + return data.length ? data.join('\n\n') : '' + } + if (typeof data === 'string') { + return data + } + return '' + }, + isPersistFailureText(text) { + const s = String(text || '') + return s.includes('[炸弹]') || s.includes('录单警告') + }, + applyPersistResult(mergedBody, persistMsg) { + const msg = persistMsg || '' + this.resultText = (mergedBody || '') + '\n\n--- 落库回执 ---\n' + msg + if (this.isPersistFailureText(msg)) { + this.$modal.msgError('落库未成功,请查看回执') + } else { + this.$modal.msgSuccess('已生成表单并落库') + } + }, extractFirstResponse(data) { if (Array.isArray(data)) { - return data.length ? data.join('\n\n\n') : '' + return data.length ? String(data[0]) : '' } if (typeof data === 'string') { return data @@ -178,32 +213,48 @@ export default { } this.verifyDialogVisible = true }, - generate() { + async generate() { const cmd = this.buildCommand() if (!cmd) return this.loading = true this.resultText = '' - executeInstruction({ command: cmd }).then(res => { - this.loading = false - if (res && (res.code === 200 || res.msg === '操作成功')) { - const list = Array.isArray(res.data) ? res.data : (res.data ? [String(res.data)] : []) - if (this.checkDuplicateError(list)) { - this.resultListFromLast = list - this.showVerifyDialog(cmd) - return - } - const merged = this.injectOptional(this.extractFirstResponse(res.data)) - this.resultText = merged - this.$modal.msgSuccess('已录单') - } else { - this.$modal.msgError((res && res.msg) || '录单失败') + try { + const res = await executeInstruction({ command: cmd }) + if (!(res && (res.code === 200 || res.msg === '操作成功'))) { + this.$modal.msgError((res && res.msg) || '生成表单失败') + return } - }).catch(() => { - this.loading = false + const list = Array.isArray(res.data) ? res.data : (res.data ? [String(res.data)] : []) + if (this.checkDuplicateError(list)) { + this.resultListFromLast = list + this.showVerifyDialog(cmd) + return + } + const rawForm = this.extractFirstResponse(res.data) + const merged = this.injectOptional(rawForm) + if (!this.formBodyLooksPersistable(merged)) { + this.resultText = merged + this.$modal.msgError('生成结果不是可落库表单,请重试或联系管理员') + return + } + if (!this.canPersistOrderFields()) { + this.resultText = merged + this.$modal.msgWarning('已生成录单文案。落库需填写:下单人、下单付款、物流链接(后返可不填,将按 0.00)') + return + } + const res2 = await executeInstruction({ command: merged }) + if (!(res2 && (res2.code === 200 || res2.msg === '操作成功'))) { + this.$modal.msgError((res2 && res2.msg) || '落库失败') + return + } + this.applyPersistResult(merged, this.formatInstructionData(res2.data)) + } catch (e) { this.$modal.msgError('请求失败') - }) + } finally { + this.loading = false + } }, - handleVerify() { + async handleVerify() { if (!this.verifyInput || this.verifyInput.length !== 4) { this.$modal.msgError('请输入四位验证码') return @@ -214,20 +265,37 @@ export default { return } this.verifyLoading = true - executeInstructionWithForce({ command: this.pendingCommand }).then(res => { - this.verifyLoading = false - this.verifyDialogVisible = false - if (res && (res.code === 200 || res.msg === '操作成功')) { - const merged = this.injectOptional(this.extractFirstResponse(res.data)) - this.resultText = merged - this.$modal.msgSuccess('已强制录单') - } else { + try { + const res = await executeInstructionWithForce({ command: this.pendingCommand }) + if (!(res && (res.code === 200 || res.msg === '操作成功'))) { this.$modal.msgError((res && res.msg) || '执行失败') + return } - }).catch(() => { - this.verifyLoading = false + const merged = this.injectOptional(this.extractFirstResponse(res.data)) + if (!this.formBodyLooksPersistable(merged)) { + this.resultText = merged + this.verifyDialogVisible = false + this.$modal.msgError('生成结果不是可落库表单') + return + } + if (!this.canPersistOrderFields()) { + this.resultText = merged + this.verifyDialogVisible = false + this.$modal.msgWarning('已强制生成表单。落库仍需填写:下单人、下单付款、物流链接') + return + } + const res2 = await executeInstruction({ command: merged }) + this.verifyDialogVisible = false + if (!(res2 && (res2.code === 200 || res2.msg === '操作成功'))) { + this.$modal.msgError((res2 && res2.msg) || '落库失败') + return + } + this.applyPersistResult(merged, this.formatInstructionData(res2.data)) + } catch (e) { this.$modal.msgError('请求失败') - }) + } finally { + this.verifyLoading = false + } }, resetForm() { this.form = {