Files
ruoyi-vue/src/views/system/jd-instruction/fadan-quick-record.vue
T
2026-10-08 16:34:02 +08:00

1436 lines
48 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div class="app-container fadan-quick-record" :class="{ 'fadan-quick-record--mobile': isMobile }">
<el-card class="box-card">
<div class="page-toolbar">
<el-button icon="el-icon-time" @click="openHistory">历史记录</el-button>
</div>
<el-form :model="form" label-position="top" class="fadan-form">
<el-form-item label="分销标记">
<div class="mark-row">
<span v-if="!form.markFull" class="mark-prefix" aria-hidden="true">F-</span>
<el-input
v-if="!form.markFull"
v-model="form.markSuffix"
class="mark-suffix-input"
placeholder="后缀,如 李旭、闲鱼;留空则仅为 F"
clearable
/>
<el-input
v-else
v-model="form.markFull"
class="mark-suffix-input"
placeholder="完整分销标记,如 H-TF"
clearable
@clear="form.markFull = ''"
/>
</div>
</el-form-item>
<el-form-item label="型号" required>
<div class="model-row">
<el-autocomplete
v-model="form.model"
class="model-input-base"
:fetch-suggestions="queryModels"
placeholder="型号本体;点选历史型号会拆分店铺并带出付款/后返"
clearable
:trigger-on-focus="true"
@select="onModelSuggestionSelect"
@blur="onModelBlur"
>
<template slot-scope="{ item }">
<span class="model-suggest-label">{{ item.label }}</span>
</template>
</el-autocomplete>
<el-select
v-model="form.shopPrefix"
class="model-shop-select"
:placeholder="shopOptions.length ? '店铺(必选)' : '店铺'"
clearable
filterable
>
<el-option
v-for="opt in shopOptions"
:key="opt.prefix"
:label="opt.label"
:value="opt.prefix"
/>
</el-select>
<el-button
v-if="!isMobile"
type="text"
class="model-shop-config-btn"
icon="el-icon-setting"
title="配置型号店铺选项"
@click="showShopConfig = true"
/>
</div>
<p class="model-shop-hint">
<template v-if="shopOptions.length">
落库型号 = 上方输入 + 所选店铺前缀(如 W5000PLUS2.0白 + 海尔厨房 → W5000PLUS2.0白海尔厨房)
</template>
<template v-else>
尚未配置店铺选项,录单时不强制选择店铺。
</template>
<el-button type="text" size="mini" @click="showShopConfig = true">配置店铺选项</el-button>
</p>
</el-form-item>
<el-form-item label="下单地址" required>
<el-input
v-model="form.address"
type="textarea"
:rows="2"
placeholder="必填;可粘贴多行,失焦或点击录单时会压成一行(去逗号、多空格合并)"
clearable
@blur="normalizeAddressField"
/>
</el-form-item>
<el-form-item label="转链链接(可空)">
<el-input v-model="form.link" type="textarea" :rows="2" placeholder="可空;留空则后台按型号尝试自动填充京粉链接" clearable />
</el-form-item>
<el-form-item label="第三方单号(选填)">
<el-input
v-model="form.thirdPartyOrderNoText"
placeholder="选填;写入录单文案「第三方单号:」行,可覆盖「生」自动带出内容"
clearable
/>
</el-form-item>
<el-divider content-position="left">落库必填(物流链接或物流单号填一项即可)</el-divider>
<el-form-item label="下单人">
<el-input v-model="form.buyer" placeholder="落库必填" clearable />
</el-form-item>
<el-form-item label="下单付款(元)">
<el-input v-model="form.paymentText" placeholder="落库必填,如 2999.00" clearable @input="onPaymentInput" />
</el-form-item>
<el-form-item label="后返金额(元)">
<el-input v-model="form.rebateText" placeholder="与成本价至少填一项,填 0 也可以" clearable @input="onRebateInput" />
</el-form-item>
<el-form-item label="成本价(元)">
<el-input v-model="form.costText" placeholder="与后返至少填一项;成本价 = 下单付款 − 后返金额" clearable @input="onCostInput" />
</el-form-item>
<p class="model-shop-hint">后改的那一项为准,另一项按付款金额重算。两个都空不能录单。</p>
<el-form-item label="订单号(京东)">
<el-input v-model="form.orderIdText" placeholder="落库必填;无京东单号可填 1(仅填物流单号时允许重复)" clearable />
</el-form-item>
<el-form-item label="物流链接">
<el-input v-model="form.logisticsLink" type="textarea" :rows="2" placeholder="有链接就填;没有则可改填下方物流单号" clearable />
</el-form-item>
<el-form-item label="物流单号">
<el-input v-model="form.waybillNo" placeholder="无物流链接时必填,如 SF1234567890" clearable />
</el-form-item>
<div v-if="!isMobile" class="btn-row">
<el-button type="primary" size="medium" :loading="loading" @click="generate">录单</el-button>
<el-button size="medium" @click="resetForm">重置表单</el-button>
<el-button size="medium" icon="el-icon-time" @click="openHistory">历史记录</el-button>
<el-button v-if="resultText" size="medium" @click="copyResult">
{{ resultPieces.length > 1 ? '复制全部(连在一起)' : '复制结果' }}
</el-button>
</div>
</el-form>
<template v-if="resultText">
<el-divider content-position="left">录单结果</el-divider>
<p v-if="resultPieces.length > 1" class="result-pieces-hint">按条复制,每条对应一条聊天消息。</p>
<div class="result-pieces">
<div v-for="(p, i) in resultPieces" :key="i" class="result-piece">
<div class="result-piece-head">
<span class="result-piece-title">{{ p.title }}</span>
<el-button type="primary" plain size="mini" @click="copyPieceText(p.text)">复制本条</el-button>
</div>
<el-input
:value="p.text"
type="textarea"
:autosize="{ minRows: resultPieceMinRows(p.text), maxRows: isMobile ? 22 : 28 }"
readonly
class="result-area"
/>
</div>
</div>
</template>
</el-card>
<el-dialog
title="地址/单号重复验证"
:visible.sync="verifyDialogVisible"
:width="dialogWidth"
:close-on-click-modal="false"
:close-on-press-escape="false"
append-to-body
>
<div class="verify-body">
<el-alert :title="verifyMessage" type="warning" :closable="false" />
<div class="verify-code">{{ verifyCode }}</div>
<el-input v-model="verifyInput" placeholder="请输入上方四位验证码" maxlength="4" @keyup.enter.native="handleVerify" />
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="verifyDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="verifyLoading" @click="handleVerify">确认录单</el-button>
</div>
</el-dialog>
<quick-record-model-shop-config v-model="showShopConfig" @saved="loadShopOptions" />
<el-dialog
title="历史发单记录"
:visible.sync="historyVisible"
:width="isMobile ? '96%' : '720px'"
:top="isMobile ? '6vh' : '8vh'"
append-to-body
custom-class="fadan-history-dialog"
@open="loadHistory"
>
<div class="history-search">
<el-input
v-model="historyKeyword"
clearable
placeholder="搜型号、地址、下单人、订单号、分销标记;待填写在前"
prefix-icon="el-icon-search"
@keyup.enter.native="searchHistory"
@clear="searchHistory"
/>
<el-button type="primary" :loading="historyLoading" @click="searchHistory">搜索</el-button>
</div>
<p class="history-hint">仅查最近 3 天。待填写排在前面,已落库记录也保留。</p>
<div class="history-list" v-loading="historyLoading">
<div v-if="!historyList.length && !historyLoading" class="history-empty">暂无历史记录</div>
<div
v-for="row in historyList"
:key="row.key"
class="history-item"
:class="{ 'is-unfilled': !row.filled }"
@click="applyHistoryItem(row)"
>
<div class="history-item-top">
<span class="history-model">{{ historyItemModel(row) || '无型号' }}</span>
<span class="history-time">{{ formatHistoryTime(row) }}</span>
</div>
<div class="history-item-meta">
<el-tag v-if="!row.filled" type="warning" size="mini">待填写</el-tag>
<el-tag v-else type="success" size="mini">已落库</el-tag>
<span v-if="row.distributionMark">{{ row.distributionMark }}</span>
<span v-if="row.remark">{{ row.remark }}</span>
<span v-if="row.thirdPartyOrderNo">{{ row.thirdPartyOrderNo }}</span>
<span v-if="row.buyer">{{ row.buyer }}</span>
<span v-if="row.paymentAmount != null && row.paymentAmount !== ''">付款 {{ formatHistoryMoney(row.paymentAmount) }}</span>
<span v-if="row.orderId">{{ row.orderId }}</span>
</div>
<div v-if="row.address" class="history-item-addr">{{ row.address }}</div>
</div>
</div>
<div class="history-pager">
<el-pagination
small
layout="prev, pager, next"
:current-page.sync="historyPage"
:page-size="historyPageSize"
:total="historyTotal"
:pager-count="isMobile ? 5 : 7"
@current-change="sliceHistoryPage"
/>
</div>
</el-dialog>
<mobile-floating-actions v-if="isMobile">
<el-button type="primary" :loading="loading" @click="generate">录单</el-button>
<el-button @click="resetForm">重置</el-button>
<el-button @click="openHistory">历史</el-button>
</mobile-floating-actions>
</div>
</template>
<script>
import { executeInstruction, executeInstructionWithForce, getHistory } from '@/api/system/instruction'
import { listJDOrders, listQuickRecordModelOptions, listQuickRecordShopOptions } from '@/api/system/jdorder'
import QuickRecordModelShopConfig from './components/QuickRecordModelShopConfig.vue'
export default {
name: 'FadanQuickRecord',
components: { QuickRecordModelShopConfig },
props: {
isMobile: {
type: Boolean,
default: false
}
},
data() {
return {
form: {
markSuffix: '',
markFull: '',
model: '',
shopPrefix: '',
address: '',
link: '',
thirdPartyOrderNoText: '',
buyer: '',
paymentText: '',
rebateText: '',
costText: '',
orderIdText: '',
logisticsLink: '',
waybillNo: ''
},
/** rebate:以后返为准算成本;cost:以成本为准算后返 */
moneySource: 'rebate',
loading: false,
resultText: '',
resultListFromLast: [],
verifyDialogVisible: false,
verifyCode: '',
verifyInput: '',
verifyMessage: '',
verifyLoading: false,
pendingCommand: '',
modelOptions: [],
shopOptions: [],
showShopConfig: false,
historyVisible: false,
historyLoading: false,
historyKeyword: '',
historyAll: [],
historyList: [],
historyPage: 1,
historyPageSize: 15,
historyTotal: 0
}
},
mounted() {
this.loadModelOptions()
this.loadShopOptions()
},
computed: {
dialogWidth() {
return this.isMobile ? '92%' : '480px'
},
resultPieces() {
return this.splitResultTextIntoMessages(this.resultText)
}
},
methods: {
/**
* 按「落库回执 / 发货摘要」拆成多条,便于逐条复制发送
*/
splitResultTextIntoMessages(full) {
const raw = String(full || '').replace(/\r\n/g, '\n').trim()
if (!raw) return []
const sepReceipt = /\n-{3,}\s*落库回执\s*-{3,}\s*\n/
const m = sepReceipt.exec(raw)
if (!m) {
return [{ title: '录单结果', text: raw }]
}
const formBody = raw.slice(0, m.index).trim()
const receiptRest = raw.slice(m.index + m[0].length).trim()
const shipNeedle = '\n「发货摘要」'
const idxShip = receiptRest.indexOf(shipNeedle)
const out = []
out.push({ title: '第 1 条 · 录单表单', text: formBody })
if (idxShip >= 0) {
const beforeShip = receiptRest.slice(0, idxShip).trim()
const fromShip = receiptRest.slice(idxShip + 1).trim()
out.push({
title: '第 2 条 · 落库回执',
text: `--- 落库回执 ---\n${beforeShip}`.trim()
})
out.push({ title: '第 3 条 · 发货摘要', text: fromShip })
} else {
out.push({
title: '第 2 条 · 落库回执',
text: `--- 落库回执 ---\n${receiptRest}`.trim()
})
}
return out
},
resultPieceMinRows(text) {
const n = String(text || '').split('\n').length
const cap = this.isMobile ? 8 : 6
return Math.min(Math.max(n + 1, cap), this.isMobile ? 18 : 14)
},
copyPieceText(text) {
const t = (text || '').trim()
if (!t) return
if (navigator.clipboard) {
navigator.clipboard.writeText(t).then(() => {
this.$modal.msgSuccess('已复制本条')
}).catch(() => this.fallbackCopy(t, '已复制本条'))
} else {
this.fallbackCopy(t, '已复制本条')
}
},
buildDistributionMark() {
const full = (this.form.markFull || '').trim()
if (full) {
return full
}
let s = (this.form.markSuffix || '').trim()
if (s.startsWith('-')) {
s = s.slice(1).trim()
}
if (!s) {
return 'F'
}
return 'F-' + s
},
/** 地址压成一行:换行/多空格合并为单空格,去掉中英文逗号 */
compressAddressOneLine(raw) {
if (raw == null) return ''
return String(raw)
.replace(/[,,]/g, '')
.replace(/\s+/g, ' ')
.trim()
},
normalizeAddressField() {
this.form.address = this.compressAddressOneLine(this.form.address)
},
formatMoneyText(v) {
if (v == null || v === '') return ''
const n = Number(v)
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)
const r = this.formatMoneyText(row.lastRebateAmount)
if (!p && !r) return row.modelNumber
return `${row.modelNumber}(付款 ${p || '—'} / 后返 ${r || '—'})`
},
async loadModelOptions() {
try {
const res = await listQuickRecordModelOptions()
if (!(res && (res.code === 200 || res.msg === '操作成功'))) {
return
}
this.modelOptions = Array.isArray(res.data) ? res.data : []
} catch (e) {
// 静默失败,不影响手输型号
}
},
async loadShopOptions() {
try {
const res = await listQuickRecordShopOptions()
if (!(res && (res.code === 200 || res.msg === '操作成功'))) {
return
}
const rows = Array.isArray(res.data) ? res.data : []
this.shopOptions = rows
.filter(o => o && String(o.prefix || '').trim())
.map(o => ({
prefix: String(o.prefix).trim(),
fullName: o.fullName || '',
label: o.label || o.prefix
}))
.sort((a, b) => b.prefix.length - a.prefix.length)
} catch (e) {
this.shopOptions = []
}
},
/** 从完整型号末尾匹配店铺前缀(长前缀优先),用于回显 */
parseModelWithShop(fullModel) {
const full = String(fullModel || '').trim()
if (!full || !this.shopOptions.length) {
return { base: full, prefix: '' }
}
for (const opt of this.shopOptions) {
const p = opt.prefix
if (p && full.endsWith(p) && full.length > p.length) {
return { base: full.slice(0, -p.length), prefix: p }
}
}
return { base: full, prefix: '' }
},
applyModelWithShop(fullModel) {
const parsed = this.parseModelWithShop(fullModel)
this.form.model = parsed.base
this.form.shopPrefix = parsed.prefix
return parsed
},
onModelBlur() {
if (!this.form.model || !this.shopOptions.length) return
const parsed = this.parseModelWithShop(this.form.model)
if (parsed.prefix) {
this.form.model = parsed.base
this.form.shopPrefix = parsed.prefix
}
},
buildFullModelNumber() {
const base = (this.form.model || '').trim()
const prefix = (this.form.shopPrefix || '').trim()
if (!base) return ''
return prefix ? base + prefix : base
},
fullModelFromOption(o) {
if (!o) return ''
const base = String(o.modelNumber || '').trim()
const shop = String(o.modelShop || '').trim()
if (!base) return shop
if (!shop) return base
if (base.endsWith(shop)) return base
return base + shop
},
queryModels(queryString, cb) {
const q = (queryString || '').trim().toLowerCase()
const rows = this.modelOptions
.filter(o => {
const full = this.fullModelFromOption(o)
if (!full) return false
if (!q) return true
const parsed = this.parseModelWithShop(full)
return full.toLowerCase().includes(q) || parsed.base.toLowerCase().includes(q)
})
.slice(0, 100)
cb(
rows.map(o => {
const full = this.fullModelFromOption(o)
const parsed = this.parseModelWithShop(full)
return {
value: full,
label: this.modelOptionLabel({ ...o, modelNumber: parsed.base || full })
}
})
)
},
/** 仅从联想列表点选时回填金额;型号拆分为本体 + 店铺前缀 */
onModelSuggestionSelect(item) {
if (!item || !item.value) return
const key = String(item.value).trim()
const hit = this.modelOptions.find(o => this.fullModelFromOption(o) === key)
if (hit && hit.modelShop) {
this.form.model = String(hit.modelNumber || '').trim()
this.form.shopPrefix = String(hit.modelShop || '').trim()
} else {
this.applyModelWithShop(key)
}
if (!hit) return
const payRaw = hit.lastPaymentAmount
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()
this.onModelBlur()
const model = this.buildFullModelNumber()
this.normalizeAddressField()
const address = (this.form.address || '').trim()
if (!(this.form.model || '').trim()) {
this.$modal.msgError('请填写型号')
return null
}
if (this.shopOptions.length && !this.form.shopPrefix) {
this.$modal.msgError('请选择型号对应店铺')
return null
}
if (!model) {
this.$modal.msgError('请填写型号')
return null
}
if (!address) {
this.$modal.msgError('请填写地址')
return null
}
const link = (this.form.link || '').trim()
const lines = ['生', mark, model, link, '1', address]
return lines.join('\n')
},
injectOptional(raw) {
if (!raw) return raw
let t = String(raw).replace(/\r\n/g, '\n')
const buyer = (this.form.buyer || '').trim()
const pay = (this.form.paymentText || '').trim()
const rebate = (this.form.rebateText || '').trim()
const orderId = (this.form.orderIdText || '').trim()
const logistics = (this.form.logisticsLink || '').trim()
const waybill = (this.form.waybillNo || '').trim()
const thirdPartyOrderNo = (this.form.thirdPartyOrderNoText || '').trim()
if (thirdPartyOrderNo) {
// 与 InstructionServiceImpl.WENAN_D 一致:「第三方单号:值」同行,下一行才是分隔线
const reInline = /第三方单号:[^\n]*\n(—————————)/g
t = t.replace(reInline, `第三方单号:${thirdPartyOrderNo}\n$1`)
// 兼容「标签独占一行 + 值独占一行」的旧文案
const reMultiline = /(第三方单号:)\n([^\n]*)\n(—————————)/g
t = t.replace(reMultiline, (_, a, _line, sep) => `${a}\n${thirdPartyOrderNo}\n${sep}`)
}
if (buyer) {
t = t.replace(/(下单人(需填):)\n\n/, `$1\n${buyer}\n\n`)
}
if (pay) {
t = t.replace(/(下单付款(注意核对):)\n\n/, `$1\n${pay}\n\n`)
}
if (rebate) {
t = t.replace(/(后返金额(注意核对):)\n\n/, `$1\n${rebate}\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`)
}
if (logistics) {
t = t.replace(/(物流链接(需填):)\n\n/, `$1\n${logistics}\n\n`)
}
if (waybill) {
t = t.replace(/(物流单号(无链接时填):)\n\n/, `$1\n${waybill}\n\n`)
}
return t
},
formBodyLooksPersistable(text) {
const t = (text || '').trim()
return t.startsWith('单')
},
canPersistOrderFields() {
const buyer = (this.form.buyer || '').trim()
const pay = (this.form.paymentText || '').trim()
const orderId = (this.form.orderIdText || '').trim()
const logistics = (this.form.logisticsLink || '').trim()
const waybill = (this.form.waybillNo || '').trim()
return !!(buyer && pay && orderId && (logistics || waybill))
},
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 ? String(data[0]) : ''
}
if (typeof data === 'string') {
return data
}
return ''
},
checkDuplicateError(resultList) {
if (!resultList || !resultList.length) return false
for (let i = 0; i < resultList.length; i++) {
const s = resultList[i]
if (typeof s === 'string' && (
s.includes('ERROR_CODE:ADDRESS_DUPLICATE') ||
s.includes('ERROR_CODE:ORDER_NUMBER_DUPLICATE')
)) {
return true
}
}
return false
},
showVerifyDialog(cmd) {
this.pendingCommand = cmd
this.verifyCode = String(Math.floor(1000 + Math.random() * 9000))
this.verifyInput = ''
let hasOrder = false
let hasAddr = false
const list = this.resultListFromLast || []
list.forEach(s => {
if (typeof s !== 'string') return
if (s.includes('ERROR_CODE:ORDER_NUMBER_DUPLICATE')) hasOrder = true
if (s.includes('ERROR_CODE:ADDRESS_DUPLICATE')) hasAddr = true
})
if (hasOrder && hasAddr) {
this.verifyMessage = '检测到订单编号与地址可能重复,输入验证码后可强制录单'
} else if (hasOrder) {
this.verifyMessage = '检测到订单编号可能重复,输入验证码后可强制录单'
} else {
this.verifyMessage = '检测到地址可能重复,输入验证码后可强制录单'
}
this.verifyDialogVisible = true
},
async generate() {
const cmd = this.buildCommand()
if (!cmd) return
if (!this.ensureMoneyPair()) return
this.loading = true
this.resultText = ''
try {
const res = await executeInstruction({ command: cmd })
if (!(res && (res.code === 200 || res.msg === '操作成功'))) {
this.$modal.msgError((res && res.msg) || '生成表单失败')
return
}
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('已生成录单文案。落库需填写:下单人、下单付款、订单号,以及物流链接或物流单号')
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
}
},
async handleVerify() {
if (!this.verifyInput || this.verifyInput.length !== 4) {
this.$modal.msgError('请输入四位验证码')
return
}
if (this.verifyInput !== this.verifyCode) {
this.$modal.msgError('验证码不正确')
this.verifyInput = ''
return
}
this.verifyLoading = true
try {
const res = await executeInstructionWithForce({ command: this.pendingCommand })
if (!(res && (res.code === 200 || res.msg === '操作成功'))) {
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
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 = {
markSuffix: '',
markFull: '',
model: '',
shopPrefix: '',
address: '',
link: '',
thirdPartyOrderNoText: '',
buyer: '',
paymentText: '',
rebateText: '',
costText: '',
orderIdText: '',
logisticsLink: '',
waybillNo: ''
}
this.moneySource = 'rebate'
this.resultText = ''
},
openHistory() {
this.historyVisible = true
},
searchHistory() {
this.historyPage = 1
this.loadHistory()
},
sliceHistoryPage() {
const start = (this.historyPage - 1) * this.historyPageSize
this.historyList = this.historyAll.slice(start, start + this.historyPageSize)
},
extractHistoryParts(item) {
const raw = String(item || '')
const idx = raw.indexOf(' | ')
return {
time: idx > 0 ? raw.slice(0, idx) : '',
text: idx > 0 ? raw.slice(idx + 3) : raw
}
},
extractFormBody(full) {
const raw = String(full || '').replace(/\r\n/g, '\n').trim()
if (!raw) return ''
const sep = /\n-{3,}\s*落库回执\s*-{3,}\s*\n/
const m = sep.exec(raw)
return m ? raw.slice(0, m.index).trim() : raw
},
extractFormField(text, startLabel, endLabels) {
const src = String(text || '')
const idx = src.indexOf(startLabel)
if (idx < 0) return ''
let rest = src.slice(idx + startLabel.length)
let end = rest.length
;(endLabels || []).forEach(lab => {
if (!lab) return
const i = rest.indexOf(lab)
if (i >= 0 && i < end) end = i
})
return rest
.slice(0, end)
.replace(/[━—\-]{3,}/g, '')
.replace(/\n{2,}/g, '\n')
.trim()
},
parseOrderFormText(text) {
const raw = String(text || '').replace(/\r\n/g, '\n')
const isNew = raw.includes('下单人(需填):')
|| raw.includes('下单链接(必须用这个):')
|| raw.includes('—————————')
const field = (start, ends) => this.extractFormField(raw, start, ends)
if (isNew) {
return {
remark: field('单:', ['分销标记:']),
mark: field('分销标记:', ['第三方单号:', '—————————', '下单链接(必须用这个):']),
thirdParty: field('第三方单号:', ['—————————', '下单链接(必须用这个):']),
link: field('下单链接(必须用这个):', ['下单地址(注意带分机):', '—————————']),
address: field('下单地址(注意带分机):', ['—————————', '型号:']),
model: field('型号:', ['下单人(需填):', '下单付款(注意核对):']),
buyer: field('下单人(需填):', ['下单付款(注意核对):']),
payment: field('下单付款(注意核对):', ['后返金额(注意核对):']),
rebate: field('后返金额(注意核对):', ['成本价(注意核对):', '订单号(需填):']),
orderId: field('订单号(需填):', ['物流链接(需填):']),
logistics: field('物流链接(需填):', ['物流单号(无链接时填):', '备注(下单号码有变动', '—————————', '京粉实际价格']),
waybill: field('物流单号(无链接时填):', ['备注(下单号码有变动', '—————————', '京粉实际价格'])
}
}
return {
remark: field('单:', ['备注:', '分销标记:']),
mark: field('分销标记:', ['第三方单号:', '型号:']),
thirdParty: field('第三方单号:', ['型号:']),
model: field('型号:', ['链接:']),
link: field('链接:', ['下单付款:']),
payment: field('下单付款:', ['后返金额:']),
rebate: field('后返金额:', ['地址:']),
address: field('地址:', ['物流链接:']),
logistics: field('物流链接:', ['订单号:']),
orderId: field('订单号:', ['下单人:']),
buyer: field('下单人:', ['京粉实际价格:'])
}
},
isPersistFilledText(parsed) {
if (!parsed) return false
return !!(
String(parsed.buyer || '').trim()
&& String(parsed.payment || '').trim()
&& String(parsed.orderId || '').trim()
&& (String(parsed.logistics || '').trim() || String(parsed.waybill || '').trim())
)
},
isPersistFilledOrder(row) {
if (!row) return false
return !!(
String(row.buyer || '').trim()
&& row.paymentAmount != null && row.paymentAmount !== ''
&& String(row.orderId || '').trim()
&& (String(row.logisticsLink || '').trim() || String(row.waybillNo || '').trim())
)
},
historyItemMatchesKeyword(item, kw) {
if (!kw) return true
const blob = [
item.modelNumber,
item.modelShop,
this.historyItemModel(item),
item.address,
item.buyer,
item.orderId,
item.distributionMark,
item.thirdPartyOrderNo,
item.waybillNo,
item.logisticsLink,
item.remark
].join(' ').toLowerCase()
return blob.includes(kw.toLowerCase())
},
splitOrderFormBodies(text) {
const raw = this.extractFormBody(text).replace(/\r\n/g, '\n').trim()
if (!raw) return []
const idxs = []
const re = /^单:/gm
let m
while ((m = re.exec(raw)) !== null) {
idxs.push(m.index)
}
if (!idxs.length) {
return this.formBodyLooksPersistable(raw) ? [raw] : []
}
const out = []
for (let i = 0; i < idxs.length; i++) {
const chunk = raw.slice(idxs[i], i + 1 < idxs.length ? idxs[i + 1] : raw.length).trim()
if (this.formBodyLooksPersistable(chunk)) out.push(chunk)
}
return out
},
draftDedupeKey(item) {
const third = String((item && item.thirdPartyOrderNo) || '').trim()
if (third) return 't:' + third
const remark = String((item && item.remark) || '').trim()
const addr = this.compressAddressOneLine((item && item.address) || '')
if (remark || addr) return 'r:' + remark + '|' + addr
return String((item && item.key) || '')
},
normalizeDraftItemFromBody(body, time, seq) {
if (!this.formBodyLooksPersistable(body)) return null
const parsed = this.parseOrderFormText(body)
const modelFull = String(parsed.model || '').split('\n')[0].trim()
const shopParsed = this.parseModelWithShop(modelFull)
const third = String(parsed.thirdParty || '').trim()
const remark = String(parsed.remark || '').trim()
const addr = this.compressAddressOneLine(parsed.address)
return {
key: 'draft-' + (third || [remark, addr, time, seq].filter(Boolean).join('|')),
source: 'draft',
filled: this.isPersistFilledText(parsed),
remark,
distributionMark: String(parsed.mark || '').trim(),
modelNumber: shopParsed.base || modelFull,
modelShop: shopParsed.prefix,
address: addr,
link: String(parsed.link || '').trim(),
thirdPartyOrderNo: third,
buyer: String(parsed.buyer || '').trim(),
paymentAmount: String(parsed.payment || '').trim(),
rebateAmount: String(parsed.rebate || '').trim(),
orderId: String(parsed.orderId || '').trim(),
logisticsLink: String(parsed.logistics || '').trim(),
waybillNo: String(parsed.waybill || '').trim(),
orderTime: time,
rawText: body
}
},
normalizeDraftItems(rawItem) {
const parts = this.extractHistoryParts(rawItem)
return this.splitOrderFormBodies(parts.text)
.map((body, i) => this.normalizeDraftItemFromBody(body, parts.time, i))
.filter(Boolean)
},
normalizeOrderItem(row) {
if (!row) return null
return {
key: 'order-' + (row.id || row.remark || row.orderId),
source: 'order',
filled: this.isPersistFilledOrder(row),
remark: row.remark || '',
distributionMark: row.distributionMark || '',
modelNumber: row.modelNumber || '',
modelShop: row.modelShop || '',
address: row.address || '',
link: row.link || '',
thirdPartyOrderNo: row.thirdPartyOrderNo || '',
buyer: row.buyer || '',
paymentAmount: row.paymentAmount,
rebateAmount: row.rebateAmount,
orderId: row.orderId || '',
logisticsLink: row.logisticsLink || '',
waybillNo: row.waybillNo || '',
orderTime: row.orderTime || row.createTime,
id: row.id
}
},
historyDateRange(days) {
const end = new Date()
const start = new Date()
start.setDate(start.getDate() - (days || 3))
const fmt = d => {
const y = d.getFullYear()
const m = String(d.getMonth() + 1).padStart(2, '0')
const day = String(d.getDate()).padStart(2, '0')
return `${y}-${m}-${day}`
}
return { beginTime: fmt(start), endTime: fmt(end) }
},
async loadHistory() {
this.historyLoading = true
try {
const kw = (this.historyKeyword || '').trim()
const range = this.historyDateRange(3)
const [histRes, orderRes] = await Promise.all([
getHistory('response', 300, kw || undefined, 3),
listJDOrders({
pageNum: 1,
pageSize: 100,
orderBy: 'id',
isAsc: 'desc',
beginTime: range.beginTime,
endTime: range.endTime,
quickRecordSearch: kw || undefined
})
])
const orders = ((orderRes && orderRes.rows) || []).map(this.normalizeOrderItem).filter(Boolean)
const persistedKeys = new Set(orders.map(o => this.draftDedupeKey(o)).filter(Boolean))
const draftMap = new Map()
;((histRes && histRes.data) || []).forEach(raw => {
this.normalizeDraftItems(raw).forEach(draft => {
if (kw && !this.historyItemMatchesKeyword(draft, kw)) return
const dk = this.draftDedupeKey(draft)
if (dk && persistedKeys.has(dk)) return
if (draftMap.has(draft.key) || (dk && draftMap.has(dk))) return
draftMap.set(dk || draft.key, draft)
})
})
const drafts = Array.from(draftMap.values()).filter(d => !d.filled)
const unfilledOrders = orders.filter(o => !o.filled)
const filledOrders = orders.filter(o => o.filled)
this.historyAll = [...drafts, ...unfilledOrders, ...filledOrders]
this.historyTotal = this.historyAll.length
if ((this.historyPage - 1) * this.historyPageSize >= this.historyTotal) {
this.historyPage = 1
}
this.sliceHistoryPage()
} catch (e) {
this.historyAll = []
this.historyList = []
this.historyTotal = 0
this.$modal.msgError('加载历史记录失败')
} finally {
this.historyLoading = false
}
},
historyItemModel(row) {
if (!row) return ''
const base = String(row.modelNumber || '').trim()
const shop = String(row.modelShop || '').trim()
if (!base) return shop
if (!shop) return base
if (base.endsWith(shop)) return base
return base + shop
},
formatHistoryMoney(v) {
if (v == null || v === '') return ''
if (typeof v === 'number') return this.formatMoneyText(v)
return String(v)
},
formatHistoryTime(row) {
const raw = (row && (row.orderTime || row.createTime)) || ''
if (!raw) return ''
const s = String(raw).replace('T', ' ')
return s.length >= 16 ? s.slice(0, 16) : s
},
applyMarkSuffixFromText(mark) {
const v = String(mark || '').trim()
this.form.markFull = ''
this.form.markSuffix = ''
if (!v || v === 'F') {
return
}
if (v.startsWith('F-')) {
this.form.markSuffix = v.slice(2).trim()
return
}
if (v === 'F' || (v.startsWith('F') && v.length > 1 && !v.includes('-'))) {
this.form.markSuffix = v.slice(1).replace(/^-/, '').trim()
return
}
// H-TF、PDD 等非 F 标记:原样回填,不再拼 F-
this.form.markFull = v
},
applyHistoryItem(row) {
if (!row) return
this.applyMarkSuffixFromText(row.distributionMark)
if (row.modelShop) {
this.form.model = String(row.modelNumber || '').trim()
this.form.shopPrefix = String(row.modelShop || '').trim()
} else {
this.applyModelWithShop(this.historyItemModel(row))
}
this.form.address = this.compressAddressOneLine(row.address)
this.form.link = String(row.link || '').trim()
this.form.thirdPartyOrderNoText = String(row.thirdPartyOrderNo || '').trim()
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()
this.resultText = row.rawText || ''
this.historyVisible = false
this.$modal.msgSuccess(row.filled ? '已回填历史记录,可修改后录单' : '已回填待填写表单,请补全后录单')
this.$nextTick(() => {
const formEl = this.$el && this.$el.querySelector('.fadan-form')
if (formEl && formEl.scrollIntoView) {
formEl.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
})
},
copyResult() {
const t = this.resultText || ''
if (!t) return
if (navigator.clipboard) {
navigator.clipboard.writeText(t).then(() => {
this.$modal.msgSuccess('已复制全部')
}).catch(() => this.fallbackCopy(t, '已复制全部'))
} else {
this.fallbackCopy(t, '已复制全部')
}
},
fallbackCopy(text, successMsg) {
const ta = document.createElement('textarea')
ta.value = text
document.body.appendChild(ta)
ta.focus()
ta.select()
try {
document.execCommand('copy')
this.$modal.msgSuccess(successMsg || '已复制')
} catch (e) {
this.$modal.msgError('复制失败')
}
document.body.removeChild(ta)
}
}
}
</script>
<style scoped>
.fadan-quick-record {
padding-bottom: 16px;
}
.fadan-quick-record--mobile {
padding-bottom: 80px;
}
.fadan-quick-record--mobile .box-card {
margin: 0 12px 20px;
}
.fadan-quick-record:not(.fadan-quick-record--mobile) .box-card {
max-width: 960px;
}
.page-toolbar {
display: flex;
justify-content: flex-end;
margin-bottom: 12px;
}
.fadan-form ::v-deep .el-form-item {
margin-bottom: 14px;
}
.mark-row {
display: flex;
align-items: center;
gap: 8px;
width: 100%;
}
.mark-prefix {
flex-shrink: 0;
color: #606266;
font-weight: 500;
user-select: none;
}
.mark-suffix-input {
flex: 1;
min-width: 0;
}
.model-row {
display: flex;
align-items: flex-start;
gap: 8px;
width: 100%;
}
.model-input-base {
flex: 1;
min-width: 0;
}
.model-shop-select {
width: 220px;
flex-shrink: 0;
}
.model-shop-config-btn {
flex-shrink: 0;
padding: 8px 4px;
}
.model-shop-hint {
margin: 6px 0 0;
font-size: 12px;
color: #909399;
line-height: 1.4;
}
.fadan-quick-record--mobile .model-row {
flex-wrap: wrap;
}
.fadan-quick-record--mobile .model-shop-select {
width: 100%;
}
.model-input-full {
width: 100%;
}
.model-suggest-label {
display: block;
line-height: 1.45;
white-space: normal;
word-break: break-all;
}
.btn-row {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-top: 8px;
}
.result-area ::v-deep .el-textarea__inner {
font-family: Consolas, 'Courier New', monospace;
font-size: 13px;
}
.result-pieces-hint {
margin: 0 0 10px;
font-size: 13px;
color: #909399;
}
.result-pieces {
display: flex;
flex-direction: column;
gap: 16px;
}
.result-piece-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 6px;
}
.result-piece-title {
font-weight: 600;
color: #303133;
font-size: 14px;
}
.history-search {
display: flex;
gap: 8px;
margin-bottom: 12px;
}
.history-search .el-input {
flex: 1;
}
.history-hint {
margin: 0 0 10px;
font-size: 12px;
color: #909399;
}
.history-list {
max-height: 52vh;
overflow-y: auto;
-webkit-overflow-scrolling: touch;
}
.history-empty {
padding: 32px 0;
text-align: center;
color: #909399;
}
.history-item {
padding: 12px;
margin-bottom: 8px;
border: 1px solid #ebeef5;
border-radius: 10px;
background: #fff;
cursor: pointer;
}
.history-item:active,
.history-item:hover {
border-color: #409eff;
background: #f5faff;
}
.history-item.is-unfilled {
border-color: #f5dab1;
background: #fdf6ec;
}
.history-item-top {
display: flex;
justify-content: space-between;
gap: 8px;
margin-bottom: 6px;
}
.history-model {
font-weight: 600;
color: #303133;
word-break: break-all;
}
.history-time {
flex-shrink: 0;
font-size: 12px;
color: #909399;
}
.history-item-meta {
display: flex;
flex-wrap: wrap;
gap: 8px 12px;
font-size: 12px;
color: #606266;
margin-bottom: 4px;
}
.history-item-addr {
font-size: 12px;
color: #909399;
line-height: 1.4;
word-break: break-all;
}
.history-pager {
margin-top: 10px;
text-align: right;
}
.verify-body .verify-code {
text-align: center;
font-size: 26px;
font-weight: 700;
color: #409eff;
margin: 16px 0;
}
@media (max-width: 768px) {
.fadan-quick-record--mobile .box-card {
margin: 0 8px 16px;
}
.page-toolbar .el-button {
width: 100%;
height: 40px;
}
.history-search {
flex-direction: column;
}
.history-list {
max-height: 48vh;
}
.history-pager {
text-align: center;
}
}
</style>