const textValue = (value: any, fallback: string = ''): string => {
|
if (value == null) return fallback
|
return String(value)
|
}
|
|
const encoded = (value: any, fallback: string = ''): string => encodeURIComponent(textValue(value, fallback))
|
|
const inferTargetAction = (merchantType: string): string => {
|
if (merchantType == 'cinema') return 'CINEMA'
|
if (merchantType == 'fuel') return 'FUEL'
|
if (merchantType == 'parking') return 'PARKING'
|
if (merchantType == 'carWash') return 'CAR_WASH'
|
if (merchantType == 'medical') return 'MEDICAL'
|
if (merchantType == 'employment') return 'SPOUSE_EMPLOYMENT'
|
if (merchantType == 'finance') return 'FINANCE'
|
if (merchantType == 'approval') return 'ADMIN_APPROVAL'
|
if (merchantType == 'children') return 'CHILD_ENTRUSTMENT'
|
if (merchantType == 'housing' || merchantType == 'car' || merchantType == 'appliance' || merchantType == 'digital' || merchantType == 'culture' || merchantType == 'telecom' || merchantType == 'shopping') return 'SHOPPING'
|
return 'MERCHANT'
|
}
|
|
export const openMerchantDetail = (item: any) => {
|
if (item == null) return
|
if (item.available === false) {
|
uni.showToast({ title: textValue(item.unavailableReason, '该服务当前不可用'), icon: 'none' })
|
return
|
}
|
|
const merchantId = textValue(item.detailBusinessId, textValue(item.id))
|
const merchantType = textValue(item.merchantType, 'food')
|
const configuredAction = textValue(item.targetAction, textValue(item.detailType))
|
const action = configuredAction == '' || configuredAction == 'MERCHANT' ? inferTargetAction(merchantType) : configuredAction
|
const name = encoded(item.name)
|
const image = encoded(item.image)
|
const address = encoded(item.address)
|
const discount = encoded(item.discount)
|
|
if (action == 'CINEMA') {
|
uni.navigateTo({ url: '/pages/cinema-merchant/cinema-merchant?merchantId=' + encoded(merchantId) + '&name=' + name + '&image=' + image + '&address=' + address + '&discount=' + discount })
|
return
|
}
|
if (action == 'SHOPPING' && merchantType != 'culture') {
|
uni.navigateTo({ url: '/pages/shopping-merchant/shopping-merchant?merchantId=' + encoded(merchantId) })
|
return
|
}
|
if (action == 'MEDICAL') {
|
uni.navigateTo({ url: '/pages/merchant/merchant?type=medical&merchantType=medical&merchantId=' + encoded(merchantId) + '&name=' + name })
|
return
|
}
|
if (action == 'SPOUSE_EMPLOYMENT') {
|
uni.navigateTo({ url: '/pages/spouse-employment/spouse-employment?serviceId=' + encoded(merchantId) })
|
return
|
}
|
if (action == 'FINANCE') {
|
uni.navigateTo({ url: '/pages/finance-merchant/finance-merchant?serviceId=' + encoded(merchantId) + '&merchantId=' + encoded(merchantId) + '&name=' + name + '&discount=' + discount + '&address=' + address + '&image=' + image })
|
return
|
}
|
if (action == 'ADMIN_APPROVAL') {
|
uni.navigateTo({ url: '/pages/admin-approval/admin-approval?serviceId=' + encoded(merchantId) })
|
return
|
}
|
if (action == 'CHILD_ENTRUSTMENT') {
|
uni.navigateTo({ url: '/pages/children-entrustment/children-entrustment?serviceId=' + encoded(merchantId) })
|
return
|
}
|
if (action == 'CAR_WASH') {
|
uni.navigateTo({ url: '/pages/car-wash-merchant/car-wash-merchant?merchantId=' + encoded(merchantId) + '&name=' + name })
|
return
|
}
|
if (action == 'FUEL' || action == 'PARKING') {
|
const transportAction = action == 'PARKING' && textValue(item.discount).indexOf('人才码') >= 0 ? 'talentCode' : ''
|
uni.navigateTo({
|
url: '/pages/merchant/merchant?type=transport&merchantType=' + encoded(merchantType)
|
+ '&merchantId=' + encoded(merchantId)
|
+ '&name=' + name
|
+ '&image=' + image
|
+ '&address=' + address
|
+ '&discount=' + discount
|
+ '&action=' + encoded(transportAction)
|
})
|
return
|
}
|
|
uni.navigateTo({
|
url: '/pages/merchant/merchant?merchantType=' + encoded(merchantType)
|
+ '&merchantId=' + encoded(merchantId)
|
+ '&name=' + name
|
+ '&image=' + image
|
+ '&address=' + address
|
+ '&discount=' + discount
|
})
|
}
|