| | |
| | | <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', |
| | | }); |
| | | |
| | | const router = Taro.useRouter(); |
| | | const { blLifeRecharge } = useLifeRechargeContext(); |
| | | const consultationId = router.params?.consultationId ?? ''; |
| | | |
| | | const promoterIdNumber = router.params?.promoterIdNumber ?? ''; |
| | | async function getPromoter(phoneNumber: string) { |
| | | try { |
| | | let params: APIgetPromoterParams = { |
| | | phoneNumber: phoneNumber, |
| | | }; |
| | | return await blLifeRecharge.services.getPromoter(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | function generate() { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.generatePromotionCode}?promoterIdNumber=${promoterIdNumber}`, |
| | | }); |
| | | async function getChannelConsultationById() { |
| | | try { |
| | | let params: APIgetChannelConsultationByIdParams = { |
| | | id: consultationId, |
| | | }; |
| | | return await blLifeRecharge.services.getChannelConsultationById(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | type CreateOrUpdatePromoterOptions = { |
| | | name?: string; |
| | | phoneNumber?: string; |
| | | }; |
| | | |
| | | async function createOrUpdatePromoter(options: CreateOrUpdatePromoterOptions = {}) { |
| | | try { |
| | | const { name, phoneNumber } = options; |
| | | let params: CreateOrUpdatePromoterInput = { |
| | | userId: blLifeRecharge.accountModel.userId, |
| | | name: name, |
| | | phoneNumber: phoneNumber, |
| | | }; |
| | | return await blLifeRecharge.services.createOrUpdatePromoter(params); |
| | | } catch (error) {} |
| | | } |
| | | |
| | | async function generate() { |
| | | try { |
| | | if (consultationId) { |
| | | let res = await getChannelConsultationById(); |
| | | if (res) { |
| | | let resIdNumber1 = await getPromoter(res.phoneNumber); |
| | | if (resIdNumber1) { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${resIdNumber1}`, |
| | | }); |
| | | } else { |
| | | let resIdNumber2 = await createOrUpdatePromoter({ |
| | | name: res.name, |
| | | phoneNumber: res.phoneNumber, |
| | | }); |
| | | if (resIdNumber2) { |
| | | RouteHelper.navigateTo({ |
| | | url: `${RouterPath.promotionQrcode}?promoterIdNumber=${resIdNumber2}`, |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (error) {} |
| | | } |
| | | </script> |