From 37eedba5612616fcb82eff191842362b2a9cd3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=AF=E4=B9=90=E5=8A=A0=E5=86=B0?= <11869599+addie66@user.noreply.gitee.com> Date: Sun, 15 Nov 2026 01:01:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(huifu-onboard):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=B1=87=E4=BB=98=E8=BF=9B=E4=BB=B6=E8=A1=A8=E5=8D=95=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E5=9B=9E=E6=98=BE=E5=8F=8A=E7=9C=81=E5=B8=82=E5=8C=BA?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 后端优先读取模型原始字段,避免 toArray 导致 payload 丢失 - 前端优化草稿应用逻辑,增加 nextTick 兜底防止组件未挂载时赋值失败 - 修复 account_type 等字段值为 '0' 时被错误过滤的问题 - 重构省市区文本解析逻辑,确保地址数据加载后正确回显名称而非 ID --- .../library/onboard/HuifuOnboardAdminView.php | 15 ++++- .../huifu-onboard-form/huifu-onboard-form.vue | 63 +++++++++++++++---- .../pages/user/wallet/onboard-bind.vue | 13 +++- 3 files changed, 74 insertions(+), 17 deletions(-) diff --git a/addons/shopro_huifu/library/onboard/HuifuOnboardAdminView.php b/addons/shopro_huifu/library/onboard/HuifuOnboardAdminView.php index 6cf4cb7..8588fe8 100644 --- a/addons/shopro_huifu/library/onboard/HuifuOnboardAdminView.php +++ b/addons/shopro_huifu/library/onboard/HuifuOnboardAdminView.php @@ -550,9 +550,18 @@ class HuifuOnboardAdminView if (!$row) { return null; } - $data = is_array($row) ? $row : $row->toArray(); - $payload = self::parsePayload($data['payload'] ?? ''); - if (!$payload) { + // 优先读模型原始字段,避免 toArray 丢失 payload + $payloadRaw = ''; + if (is_object($row) && isset($row['payload'])) { + $payloadRaw = $row['payload']; + } elseif (is_array($row)) { + $payloadRaw = $row['payload'] ?? ''; + } else { + $data = method_exists($row, 'toArray') ? $row->toArray() : []; + $payloadRaw = $data['payload'] ?? ''; + } + $payload = self::parsePayload($payloadRaw); + if (!$payload || !is_array($payload)) { return null; } $form = array_merge(self::defaultFormData(), $payload); diff --git a/xgsc.gynhc.com_wx/components/huifu-onboard-form/huifu-onboard-form.vue b/xgsc.gynhc.com_wx/components/huifu-onboard-form/huifu-onboard-form.vue index 9252c61..f4a877a 100644 --- a/xgsc.gynhc.com_wx/components/huifu-onboard-form/huifu-onboard-form.vue +++ b/xgsc.gynhc.com_wx/components/huifu-onboard-form/huifu-onboard-form.vue @@ -361,29 +361,41 @@ export default { immediate: true, deep: true, handler(val) { - if (val && val.draft) { - this.applyDraft(val.draft); + const draft = val && (val.draft || val.form); + if (draft && typeof draft === 'object') { + this.applyDraft(draft); } } } }, mounted() { this.loadArea(); + // 兜底:父组件异步赋值后若 watch 未及时触发,再刷一次 + this.$nextTick(() => { + const draft = this.statusInfo && (this.statusInfo.draft || this.statusInfo.form); + if (draft) this.applyDraft(draft); + }); }, methods: { applyDraft(draft) { if (!draft || typeof draft !== 'object') return; - Object.keys(this.form).forEach(key => { + const next = { ...this.form }; + Object.keys(next).forEach(key => { if (draft[key] !== undefined && draft[key] !== null && draft[key] !== '') { - this.form[key] = draft[key]; + next[key] = draft[key]; } }); + // account_type / bank_account_type 允许为 '0' + ['account_type', 'bank_account_type', 'cert_validity_type', 'license_validity_type', 'legal_cert_validity_type'].forEach(key => { + if (draft[key] !== undefined && draft[key] !== null && draft[key] !== '') { + next[key] = String(draft[key]); + } + }); + this.form = next; this.originalCardNo = String(this.form.card_no || '').replace(/\s+/g, ''); - if (draft.branch_name) { - this.branchKeyword = draft.branch_name; - } + this.branchKeyword = draft.branch_name || this.form.branch_name || this.branchKeyword || ''; const setList = (url, listKey) => { - if (url) this[listKey] = [{ url }]; + this[listKey] = url ? [{ url }] : []; }; setList(this.form.id_card_front_url, 'frontList'); setList(this.form.id_card_back_url, 'backList'); @@ -392,12 +404,36 @@ export default { setList(this.form.legal_id_back_url, 'legalBackList'); setList(this.form.bank_card_url, 'bankList'); setList(this.form.account_permit_url, 'permitList'); - if (draft.shopro_province_id || draft.prov_id) { - // 区域文案在无完整省市区树时先用编码占位,用户可重选支行补齐 - if (!this.regionText) { - this.regionText = [draft.prov_id, draft.area_id, draft.district_id].filter(Boolean).join(' / '); - } + this.resolveRegionText(); + }, + resolveRegionText() { + const f = this.form; + const pid = String(f.shopro_province_id || f.prov_id || ''); + const cid = String(f.shopro_city_id || f.area_id || ''); + const did = String(f.shopro_district_id || f.district_id || ''); + if (!pid) { + this.regionText = ''; + return; } + const list = this.addressAreaList || []; + if (!list.length) { + this.regionText = [pid, cid, did].filter(Boolean).join(' / '); + return; + } + const matchId = (item, id) => String(item.value) === String(id) || String(item.id || '') === String(id); + const province = list.find(p => matchId(p, pid) || matchId(p, f.shopro_province_id)); + if (!province) { + this.regionText = [pid, cid, did].filter(Boolean).join(' / '); + return; + } + const city = (province.children || []).find(c => matchId(c, cid) || matchId(c, f.shopro_city_id)); + const district = city + ? (city.children || []).find(d => matchId(d, did) || matchId(d, f.shopro_district_id)) + : null; + const labels = [province.label || province.name]; + if (city) labels.push(city.label || city.name); + if (district) labels.push(district.label || district.name); + this.regionText = labels.filter(Boolean).join(' / '); }, loadArea() { this.$http('address.area').then(res => { @@ -412,6 +448,7 @@ export default { }); }); this.addressAreaList = list; + this.resolveRegionText(); }); }, setAccountType(value) { diff --git a/xgsc.gynhc.com_wx/pages/user/wallet/onboard-bind.vue b/xgsc.gynhc.com_wx/pages/user/wallet/onboard-bind.vue index 42830f8..563b8c8 100644 --- a/xgsc.gynhc.com_wx/pages/user/wallet/onboard-bind.vue +++ b/xgsc.gynhc.com_wx/pages/user/wallet/onboard-bind.vue @@ -101,6 +101,14 @@ export default { this.canModifyCard = !!data.can_modify_card_bind || !!(this.huifuStatus && this.huifuStatus.can_modify_card); this.roleType = data.role_type || (this.huifuStatus.role_type || ''); this.roleRefId = parseInt(data.role_ref_id || this.huifuStatus.role_ref_id || 0, 10) || 0; + this.$nextTick(() => this.fillFormFromStatus()); + }, + fillFormFromStatus() { + const draft = this.huifuStatus && (this.huifuStatus.draft || this.huifuStatus.form); + if (!draft || !this.$refs.huifuForm || typeof this.$refs.huifuForm.applyDraft !== 'function') { + return; + } + this.$refs.huifuForm.applyDraft(draft); }, loadOnboardBind() { this.$http('money.walletOnboard', {}, '', false).then(res => { @@ -115,8 +123,11 @@ export default { setTimeout(() => this.$Router.back(), 1500); return; } - this.applyOnboardData(data); + // 先挂载表单,再写入状态并回显,避免 draft 赋值时组件尚未创建 this.loaded = true; + this.$nextTick(() => { + this.applyOnboardData(data); + }); }); }, submitOnboardBind() {