| | |
| | | <script setup lang="ts"> |
| | | import { PageLayout } from '@/components'; |
| | | import { ResultWithoutBG } from '@life-payment/components'; |
| | | import { |
| | | APIgetChannelConsultationByIdParams, |
| | | APIgetPromoterParams, |
| | | CreateOrUpdatePromoterInput, |
| | | useLifeRechargeContext, |
| | | } from '@life-payment/core-vue'; |
| | | import Taro from '@tarojs/taro'; |
| | | |
| | | defineOptions({ |
| | | name: 'applyAgent', |
| | | name: 'applyResult', |
| | | }); |
| | | |
| | | function generate() { |
| | | RouteHelper.navigateTo({ |
| | | url: RouterPath.promotionQrcode, |
| | | }); |
| | | const router = Taro.useRouter(); |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | | |
| | | const channelConsultationId = router.params?.channelConsultationId ?? ''; |
| | | console.log('channelConsultationId: ', channelConsultationId); |
| | | |
| | | async function getPromoter(phoneNumber: string) { |
| | | try { |
| | | let params: APIgetPromoterParams = { |
| | | phoneNumber: phoneNumber, |
| | | }; |
| | | return await blLifeRecharge.services.getPromoter(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function getChannelConsultationById() { |
| | | try { |
| | | let params: APIgetChannelConsultationByIdParams = { |
| | | id: channelConsultationId, |
| | | }; |
| | | return await blLifeRecharge.services.getChannelConsultationById(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function createOrUpdatePromoter(name: string, phoneNumber: string) { |
| | | try { |
| | | let params: CreateOrUpdatePromoterInput = { |
| | | userId: blLifeRecharge.accountModel.userId, |
| | | name: name, |
| | | phoneNumber: phoneNumber, |
| | | }; |
| | | return await blLifeRecharge.services.createOrUpdatePromoter(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function generate() { |
| | | try { |
| | | if (channelConsultationId) { |
| | | let res = await getChannelConsultationById(); |
| | | if (res) { |
| | | let promoterIdNumber = await getPromoter(res.phoneNumber); |
| | | if (promoterIdNumber) { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${promoterIdNumber}`, |
| | | }); |
| | | } else { |
| | | let promoterIdNumber = await createOrUpdatePromoter(res.name, res.phoneNumber); |
| | | if (promoterIdNumber) { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${res}`, |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | } |
| | | } catch (error) {} |
| | | } |
| | | </script> |