Files
Wechat/utils/complaint-withdraw.js

58 lines
1.7 KiB
JavaScript

/**
* 提现前投诉拦截:命中则 Toast + 跳转对应投诉 Tab。
* @returns {Promise<boolean>} true=可继续提现;false=已拦截
*/
import request from './request.js'
export async function ensureComplaintWithdrawAllowed() {
try {
const res = await request({
url: '/gongdan/withdraw-block-check/',
method: 'POST',
data: {},
})
const body = res.data || {}
const data = body.data || {}
if ((body.code === 200 || body.code === 0) && data.blocked) {
const tab = data.tab || 'received'
const msg = data.msg || '你有未处理完的投诉,请处理后再提现'
wx.showModal({
title: '暂不可提现',
content: msg,
confirmText: '去处理',
cancelText: '知道了',
success: (r) => {
if (r.confirm) {
wx.navigateTo({ url: `/pages/gongdan/list/list?tab=${tab}` })
}
},
})
return false
}
} catch (e) {
// 检查失败不阻断;后端硬拦兜底
}
return true
}
/** 从提现接口错误体跳转投诉页 */
export function handleComplaintWithdrawError(resBody) {
const data = (resBody && resBody.data) || {}
if (data.code === 'COMPLAINT_BLOCK_WITHDRAW' || /投诉|牵连/.test(resBody?.msg || '')) {
const tab = data.tab || 'received'
wx.showModal({
title: '暂不可提现',
content: resBody.msg || '你有未处理完的投诉,请处理后再提现',
confirmText: '去处理',
cancelText: '知道了',
success: (r) => {
if (r.confirm) {
wx.navigateTo({ url: `/pages/gongdan/list/list?tab=${tab}` })
}
},
})
return true
}
return false
}