fix(huifu): 修复汇付进件表单回显失败及小程序端渲染异常问题
- 后端优化 primary 角色选择逻辑,优先使用包含 draft 回显的角色 - 后端增加兜底机制,本地 payload 为空时远程查询汇付接口重建回显数据 - 后端接口顶层新增 draft 字段,防止前端漏读嵌套数据导致页面空白 - 前端表单组件新增 draft 属性,解决小程序端深层监听不稳定问题 - 前端优化表单数据赋值逻辑,使用 $set 和 $forceUpdate 确保视图更新 - 前端调整数据加载顺序并增加延迟重试,修复小程序首屏偶发未刷出问题
这个提交包含在:
@@ -260,6 +260,16 @@ class UserWalletApply extends Base
|
||||
$primary = $binding;
|
||||
}
|
||||
}
|
||||
// 已通过场景:优先选「可换卡且有 draft 回显」的角色
|
||||
if (!$primary || (($primary['huifu_onboard']['status'] ?? '') === 'approved' && empty($primary['huifu_onboard']['draft']))) {
|
||||
foreach ($bindings as $binding) {
|
||||
$h = $binding['huifu_onboard'];
|
||||
if (!empty($h['can_modify_card']) && !empty($h['draft'])) {
|
||||
$primary = $binding;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$primary) {
|
||||
foreach ($bindings as $binding) {
|
||||
if (!empty($binding['huifu_onboard']['can_modify_card'])
|
||||
@@ -274,6 +284,15 @@ class UserWalletApply extends Base
|
||||
}
|
||||
|
||||
$huifu = $primary['huifu_onboard'];
|
||||
// 若当前 primary 无 draft,从其他角色补一份回显(避免页面空白)
|
||||
if (empty($huifu['draft'])) {
|
||||
foreach ($bindings as $binding) {
|
||||
if (!empty($binding['huifu_onboard']['draft'])) {
|
||||
$huifu['draft'] = $binding['huifu_onboard']['draft'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$show = count($bindings) > 0;
|
||||
$canSubmitBind = false;
|
||||
$canModifyCardBind = false;
|
||||
@@ -305,6 +324,8 @@ class UserWalletApply extends Base
|
||||
'role_type' => $primary['role_type'],
|
||||
'role_ref_id' => intval($primary['role_ref_id']),
|
||||
'huifu_onboard' => $huifu,
|
||||
// 顶层再挂一份,避免前端漏读嵌套 draft
|
||||
'draft' => $huifu['draft'] ?? null,
|
||||
'can_submit_bind' => $canSubmitBind,
|
||||
'can_modify_card_bind' => $canModifyCardBind,
|
||||
'onboard_config' => $config,
|
||||
@@ -316,6 +337,7 @@ class UserWalletApply extends Base
|
||||
'status' => $b['huifu_onboard']['status'] ?? null,
|
||||
'can_modify_card' => !empty($b['huifu_onboard']['can_modify_card']),
|
||||
'card_modify_pending' => !empty($b['huifu_onboard']['card_modify_pending']),
|
||||
'has_draft' => !empty($b['huifu_onboard']['draft']),
|
||||
];
|
||||
}, $bindings),
|
||||
];
|
||||
|
||||
@@ -550,18 +550,187 @@ class HuifuOnboardAdminView
|
||||
if (!$row) {
|
||||
return null;
|
||||
}
|
||||
// 优先读模型原始字段,避免 toArray 丢失 payload
|
||||
$payload = self::payloadArrayFromRow($row);
|
||||
if (!$payload) {
|
||||
return null;
|
||||
}
|
||||
return self::normalizeClientForm($payload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 本地 payload 为空时,用汇付用户信息查询结果重建回显,并回写 payload
|
||||
*/
|
||||
public static function ensureClientForm($row, $allowRemote = true)
|
||||
{
|
||||
$form = self::clientFormFromRow($row);
|
||||
if ($form || !$allowRemote || !$row) {
|
||||
return $form;
|
||||
}
|
||||
$huifuId = '';
|
||||
if (is_object($row) && method_exists($row, 'getData')) {
|
||||
$huifuId = (string) ($row->getData('huifu_id') ?: ($row['huifu_id'] ?? ''));
|
||||
} elseif (is_array($row)) {
|
||||
$huifuId = (string) ($row['huifu_id'] ?? '');
|
||||
} elseif (is_object($row)) {
|
||||
$huifuId = (string) ($row['huifu_id'] ?? '');
|
||||
}
|
||||
if ($huifuId === '') {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
$query = new HuifuOnboardQuery();
|
||||
$basic = $query->queryBasic($huifuId);
|
||||
$form = self::draftFromHuifuBasic($basic);
|
||||
if (!$form) {
|
||||
return null;
|
||||
}
|
||||
// 回写本地,下次不再远程查
|
||||
if (is_object($row) && method_exists($row, 'save')) {
|
||||
$exist = self::payloadArrayFromRow($row) ?: [];
|
||||
$cardModify = $exist['_card_modify'] ?? null;
|
||||
$merged = array_merge($exist, $form);
|
||||
if (is_array($cardModify)) {
|
||||
$merged['_card_modify'] = $cardModify;
|
||||
}
|
||||
$row->payload = json_encode($merged, JSON_UNESCAPED_UNICODE);
|
||||
$row->save();
|
||||
}
|
||||
return $form;
|
||||
} catch (\Throwable $e) {
|
||||
\think\Log::error('[shopro_huifu] ensureClientForm fail huifu_id=' . $huifuId . ' ' . $e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static function draftFromHuifuBasic(array $basic)
|
||||
{
|
||||
if (!$basic) {
|
||||
return null;
|
||||
}
|
||||
$indv = self::decodeJsonField($basic['indv_base_info'] ?? null);
|
||||
$ent = self::decodeJsonField($basic['ent_base_info'] ?? null);
|
||||
$card = self::decodeJsonField($basic['card_info'] ?? null);
|
||||
if (!$card && !empty($basic['qry_cash_card_info_list'])) {
|
||||
$list = self::decodeJsonField($basic['qry_cash_card_info_list']);
|
||||
if (isset($list[0]) && is_array($list[0])) {
|
||||
$card = $list[0];
|
||||
}
|
||||
}
|
||||
|
||||
$form = self::defaultFormData();
|
||||
if ($indv) {
|
||||
$form['account_type'] = 'indv';
|
||||
$form['name'] = (string) ($indv['name'] ?? '');
|
||||
$form['cert_no'] = (string) ($indv['cert_no'] ?? '');
|
||||
$form['cert_validity_type'] = (string) ($indv['cert_validity_type'] ?? '1');
|
||||
$form['cert_begin_date'] = (string) ($indv['cert_begin_date'] ?? '');
|
||||
$form['cert_end_date'] = (string) ($indv['cert_end_date'] ?? '');
|
||||
$form['mobile_no'] = (string) ($indv['mobile_no'] ?? '');
|
||||
$form['mp'] = (string) ($indv['mobile_no'] ?? '');
|
||||
$form['prov_id'] = (string) ($indv['prov_id'] ?? '');
|
||||
$form['area_id'] = (string) ($indv['area_id'] ?? '');
|
||||
$form['district_id'] = (string) ($indv['district_id'] ?? '');
|
||||
$form['reg_detail'] = (string) ($indv['address'] ?? $indv['reg_detail'] ?? '');
|
||||
} elseif ($ent) {
|
||||
$form['account_type'] = 'ent';
|
||||
$form['reg_name'] = (string) ($ent['reg_name'] ?? '');
|
||||
$form['license_code'] = (string) ($ent['license_code'] ?? '');
|
||||
$form['license_validity_type'] = (string) ($ent['license_validity_type'] ?? '1');
|
||||
$form['license_begin_date'] = (string) ($ent['license_begin_date'] ?? '');
|
||||
$form['license_end_date'] = (string) ($ent['license_end_date'] ?? '');
|
||||
$form['legal_name'] = (string) ($ent['legal_name'] ?? '');
|
||||
$form['legal_cert_no'] = (string) ($ent['legal_cert_no'] ?? '');
|
||||
$form['legal_cert_validity_type'] = (string) ($ent['legal_cert_validity_type'] ?? '1');
|
||||
$form['legal_cert_begin_date'] = (string) ($ent['legal_cert_begin_date'] ?? '');
|
||||
$form['legal_cert_end_date'] = (string) ($ent['legal_cert_end_date'] ?? '');
|
||||
$form['legal_mobile'] = (string) ($ent['contact_mobile_no'] ?? $ent['legal_mobile'] ?? '');
|
||||
$form['mobile_no'] = $form['legal_mobile'];
|
||||
$form['mp'] = $form['legal_mobile'];
|
||||
$form['prov_id'] = (string) ($ent['reg_prov_id'] ?? '');
|
||||
$form['area_id'] = (string) ($ent['reg_area_id'] ?? '');
|
||||
$form['district_id'] = (string) ($ent['reg_district_id'] ?? '');
|
||||
$form['reg_detail'] = (string) ($ent['reg_detail'] ?? '');
|
||||
} else {
|
||||
// 兼容扁平返回
|
||||
if (!empty($basic['name'])) {
|
||||
$form['account_type'] = 'indv';
|
||||
$form['name'] = (string) $basic['name'];
|
||||
$form['cert_no'] = (string) ($basic['cert_no'] ?? '');
|
||||
$form['mobile_no'] = (string) ($basic['mobile_no'] ?? '');
|
||||
$form['mp'] = $form['mobile_no'];
|
||||
} elseif (!empty($basic['reg_name'])) {
|
||||
$form['account_type'] = 'ent';
|
||||
$form['reg_name'] = (string) $basic['reg_name'];
|
||||
$form['legal_name'] = (string) ($basic['legal_name'] ?? '');
|
||||
}
|
||||
}
|
||||
|
||||
if ($card) {
|
||||
$cardType = (string) ($card['card_type'] ?? '1');
|
||||
// 汇付 0=对公;系统 bank_account_type 1=对公
|
||||
$form['bank_account_type'] = $cardType === '0' ? '1' : '0';
|
||||
$form['card_no'] = (string) ($card['card_no'] ?? '');
|
||||
$form['card_name'] = (string) ($card['card_name'] ?? '');
|
||||
$form['branch_code'] = (string) ($card['branch_code'] ?? '');
|
||||
$form['branch_name'] = (string) ($card['branch_name'] ?? '');
|
||||
if (!empty($card['prov_id'])) {
|
||||
$form['prov_id'] = (string) $card['prov_id'];
|
||||
}
|
||||
if (!empty($card['area_id'])) {
|
||||
$form['area_id'] = (string) $card['area_id'];
|
||||
}
|
||||
if (!empty($card['mp'])) {
|
||||
$form['mp'] = (string) $card['mp'];
|
||||
if ($form['account_type'] === 'indv') {
|
||||
$form['mobile_no'] = $form['mp'];
|
||||
} else {
|
||||
$form['legal_mobile'] = $form['mp'];
|
||||
}
|
||||
}
|
||||
if ($form['account_type'] === 'indv' && !empty($card['cert_no']) && empty($form['cert_no'])) {
|
||||
$form['cert_no'] = (string) $card['cert_no'];
|
||||
}
|
||||
}
|
||||
|
||||
return self::normalizeClientForm($form);
|
||||
}
|
||||
|
||||
protected static function payloadArrayFromRow($row)
|
||||
{
|
||||
$payloadRaw = '';
|
||||
if (is_object($row) && isset($row['payload'])) {
|
||||
$payloadRaw = $row['payload'];
|
||||
if (is_object($row) && method_exists($row, 'getData')) {
|
||||
$payloadRaw = $row->getData('payload');
|
||||
if ($payloadRaw === null || $payloadRaw === '') {
|
||||
$payloadRaw = $row['payload'] ?? '';
|
||||
}
|
||||
} elseif (is_array($row)) {
|
||||
$payloadRaw = $row['payload'] ?? '';
|
||||
} else {
|
||||
$data = method_exists($row, 'toArray') ? $row->toArray() : [];
|
||||
$payloadRaw = $data['payload'] ?? '';
|
||||
} elseif (is_object($row)) {
|
||||
$payloadRaw = $row['payload'] ?? '';
|
||||
}
|
||||
$payload = self::parsePayload($payloadRaw);
|
||||
if (isset($payload['payload']) && is_array($payload['payload'])) {
|
||||
$payload = $payload['payload'];
|
||||
}
|
||||
if (isset($payload['form']) && is_array($payload['form']) && empty($payload['card_no']) && empty($payload['name'])) {
|
||||
$payload = $payload['form'];
|
||||
}
|
||||
if (!$payload || !is_array($payload)) {
|
||||
return [];
|
||||
}
|
||||
return $payload;
|
||||
}
|
||||
|
||||
protected static function normalizeClientForm(array $payload)
|
||||
{
|
||||
$hasContent = false;
|
||||
foreach (['name', 'card_no', 'cert_no', 'reg_name', 'legal_name', 'mobile_no'] as $k) {
|
||||
if (!empty($payload[$k])) {
|
||||
$hasContent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$hasContent) {
|
||||
return null;
|
||||
}
|
||||
$form = array_merge(self::defaultFormData(), $payload);
|
||||
@@ -577,6 +746,18 @@ class HuifuOnboardAdminView
|
||||
return $form;
|
||||
}
|
||||
|
||||
protected static function decodeJsonField($value)
|
||||
{
|
||||
if (is_array($value)) {
|
||||
return $value;
|
||||
}
|
||||
if ($value === null || $value === '') {
|
||||
return [];
|
||||
}
|
||||
$decoded = json_decode((string) $value, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
|
||||
public static function formDataFromRow($row)
|
||||
{
|
||||
$data = is_array($row) ? $row : $row->toArray();
|
||||
|
||||
@@ -161,7 +161,11 @@ class HuifuOnboardGate
|
||||
'apply_no' => $row['apply_no'] ?? '',
|
||||
'role_type' => $row['role_type'] ?? $roleType,
|
||||
'role_ref_id' => intval($row['role_ref_id'] ?? $roleRefId),
|
||||
'draft' => HuifuOnboardAdminView::clientFormFromRow($row),
|
||||
// 本地无 payload 时,已通过进件会查汇付并回填
|
||||
'draft' => HuifuOnboardAdminView::ensureClientForm(
|
||||
$row,
|
||||
($row['onboard_status'] ?? '') === Onboard::STATUS_APPROVED
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,6 +237,8 @@ export default {
|
||||
props: {
|
||||
required: { type: Boolean, default: false },
|
||||
statusInfo: { type: Object, default: () => ({}) },
|
||||
/** 单独传入 draft,避免 statusInfo 深层监听在小程序端不稳定 */
|
||||
draft: { type: [Object, String], default: null },
|
||||
readonly: { type: Boolean, default: false },
|
||||
/** full=完整进件;bank_only=仅更换结算卡 */
|
||||
editMode: { type: String, default: 'full' }
|
||||
@@ -357,41 +359,64 @@ export default {
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
draft: {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
handler(val) {
|
||||
if (val) this.applyDraft(val);
|
||||
}
|
||||
},
|
||||
statusInfo: {
|
||||
immediate: true,
|
||||
deep: true,
|
||||
handler(val) {
|
||||
const draft = val && (val.draft || val.form);
|
||||
if (draft && typeof draft === 'object') {
|
||||
this.applyDraft(draft);
|
||||
}
|
||||
if (draft) this.applyDraft(draft);
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.loadArea();
|
||||
// 兜底:父组件异步赋值后若 watch 未及时触发,再刷一次
|
||||
this.$nextTick(() => {
|
||||
const draft = this.statusInfo && (this.statusInfo.draft || this.statusInfo.form);
|
||||
if (draft) this.applyDraft(draft);
|
||||
});
|
||||
this.$nextTick(() => this.tryApplyDraftFromProps());
|
||||
},
|
||||
methods: {
|
||||
applyDraft(draft) {
|
||||
if (!draft || typeof draft !== 'object') return;
|
||||
const next = { ...this.form };
|
||||
Object.keys(next).forEach(key => {
|
||||
if (draft[key] !== undefined && draft[key] !== null && draft[key] !== '') {
|
||||
next[key] = draft[key];
|
||||
tryApplyDraftFromProps() {
|
||||
const draft = this.draft || (this.statusInfo && (this.statusInfo.draft || this.statusInfo.form));
|
||||
if (draft) this.applyDraft(draft);
|
||||
},
|
||||
normalizeDraft(draft) {
|
||||
if (!draft) return null;
|
||||
if (typeof draft === 'string') {
|
||||
try {
|
||||
draft = JSON.parse(draft);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (typeof draft !== 'object') return null;
|
||||
// 兼容数组包一层
|
||||
if (Array.isArray(draft) && draft[0] && typeof draft[0] === 'object') {
|
||||
draft = draft[0];
|
||||
}
|
||||
return draft;
|
||||
},
|
||||
applyDraft(draft) {
|
||||
draft = this.normalizeDraft(draft);
|
||||
if (!draft) return;
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
console.log('[huifu-onboard] applyDraft keys', Object.keys(draft), 'name=', draft.name, 'card_no=', draft.card_no);
|
||||
} catch (e) {}
|
||||
// #endif
|
||||
Object.keys(this.form).forEach(key => {
|
||||
if (draft[key] === undefined || draft[key] === null || draft[key] === '') return;
|
||||
this.$set(this.form, 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.$set(this.form, key, String(draft[key]));
|
||||
}
|
||||
});
|
||||
this.form = next;
|
||||
this.originalCardNo = String(this.form.card_no || '').replace(/\s+/g, '');
|
||||
this.branchKeyword = draft.branch_name || this.form.branch_name || this.branchKeyword || '';
|
||||
const setList = (url, listKey) => {
|
||||
@@ -405,6 +430,7 @@ export default {
|
||||
setList(this.form.bank_card_url, 'bankList');
|
||||
setList(this.form.account_permit_url, 'permitList');
|
||||
this.resolveRegionText();
|
||||
this.$forceUpdate();
|
||||
},
|
||||
resolveRegionText() {
|
||||
const f = this.form;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
ref="huifuForm"
|
||||
:required="huifuRequired"
|
||||
:statusInfo="huifuStatus"
|
||||
:draft="onboardDraft"
|
||||
:readonly="huifuFormReadonly"
|
||||
:editMode="formEditMode"
|
||||
></huifu-onboard-form>
|
||||
@@ -42,6 +43,7 @@ export default {
|
||||
canModifyCard: false,
|
||||
roleType: '',
|
||||
roleRefId: 0,
|
||||
onboardDraft: null,
|
||||
onboardSubmitting: false
|
||||
};
|
||||
},
|
||||
@@ -93,19 +95,47 @@ export default {
|
||||
this.loadOnboardBind();
|
||||
},
|
||||
methods: {
|
||||
pickDraft(data) {
|
||||
const h = (data && data.huifu_onboard) || {};
|
||||
let draft = (data && data.draft) || h.draft || h.form || null;
|
||||
if (typeof draft === 'string') {
|
||||
try { draft = JSON.parse(draft); } catch (e) { draft = null; }
|
||||
}
|
||||
return draft;
|
||||
},
|
||||
applyOnboardData(data) {
|
||||
this.huifuRequired = !!data.required;
|
||||
this.huifuStatus = data.huifu_onboard || {};
|
||||
this.onboardDraft = this.pickDraft(data);
|
||||
this.onboardRoleLabels = Array.isArray(data.role_labels) ? data.role_labels : [];
|
||||
this.canSubmitOnboard = !!data.can_submit_bind;
|
||||
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());
|
||||
// #ifdef MP-WEIXIN
|
||||
try {
|
||||
console.log('[onboard-bind] draft?', !!this.onboardDraft, this.onboardDraft);
|
||||
console.log('[onboard-bind] status', this.huifuStatus && this.huifuStatus.status, 'can_modify', this.canModifyCard);
|
||||
} catch (e) {}
|
||||
// #endif
|
||||
this.$nextTick(() => {
|
||||
this.fillFormFromStatus();
|
||||
// 小程序偶发首屏未刷出,延迟再补一次
|
||||
setTimeout(() => this.fillFormFromStatus(), 80);
|
||||
});
|
||||
},
|
||||
fillFormFromStatus() {
|
||||
const draft = this.huifuStatus && (this.huifuStatus.draft || this.huifuStatus.form);
|
||||
if (!draft || !this.$refs.huifuForm || typeof this.$refs.huifuForm.applyDraft !== 'function') {
|
||||
const draft = this.onboardDraft || (this.huifuStatus && (this.huifuStatus.draft || this.huifuStatus.form));
|
||||
if (!this.$refs.huifuForm || typeof this.$refs.huifuForm.applyDraft !== 'function') {
|
||||
return;
|
||||
}
|
||||
if (!draft) {
|
||||
// #ifdef MP-WEIXIN
|
||||
try { console.warn('[onboard-bind] 接口未返回 draft,无法回显'); } catch (e) {}
|
||||
// #endif
|
||||
if (this.canModifyCard || (this.huifuStatus && this.huifuStatus.status === 'approved')) {
|
||||
this.$u.toast('未获取到历史进件资料,请核对后端 payload 或重新编译后重试');
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.$refs.huifuForm.applyDraft(draft);
|
||||
@@ -123,11 +153,10 @@ export default {
|
||||
setTimeout(() => this.$Router.back(), 1500);
|
||||
return;
|
||||
}
|
||||
// 先挂载表单,再写入状态并回显,避免 draft 赋值时组件尚未创建
|
||||
// 先写入 draft/状态,再挂载表单,保证子组件首屏就能拿到资料
|
||||
this.applyOnboardData(data);
|
||||
this.loaded = true;
|
||||
this.$nextTick(() => {
|
||||
this.applyOnboardData(data);
|
||||
});
|
||||
this.$nextTick(() => this.fillFormFromStatus());
|
||||
});
|
||||
},
|
||||
submitOnboardBind() {
|
||||
|
||||
在新工单中引用
屏蔽一个用户