From 7ed1e4f30ba4d8204152cb157ceaee07374da080 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期一, 17 三月 2025 14:29:14 +0800 Subject: [PATCH] fix: 修改支付方式选择 --- packages/components/src/views/PhoneBillRecharge/PhoneBillRecharge.vue | 200 +++++-------------------------------------------- 1 files changed, 22 insertions(+), 178 deletions(-) diff --git a/packages/components/src/views/PhoneBillRecharge/PhoneBillRecharge.vue b/packages/components/src/views/PhoneBillRecharge/PhoneBillRecharge.vue index a8130de..516240a 100644 --- a/packages/components/src/views/PhoneBillRecharge/PhoneBillRecharge.vue +++ b/packages/components/src/views/PhoneBillRecharge/PhoneBillRecharge.vue @@ -1,194 +1,38 @@ <template> - <Form - :model-value="form" - ref="formRef" - :rules="rules" - label-position="top" - class="order-bill-recharge phone" - > - <FormItem label="閫夋嫨杩愯惀鍟�:" class="bole-form-item" prop="ispCode" required> - <RadioGroup v-model="form.ispCode" direction="horizontal"> - <BlRadio - :label="key" - v-for="(val, key) in BlLifeRecharge.constants.IspCodeText" - :key="key" - >{{ val }}</BlRadio - > - </RadioGroup> - </FormItem> - <FormItem label="鍏呭�兼墜鏈哄彿" class="bole-form-item" prop="phone" required> - <Input - v-model.trim="form.phone" - class="bole-input-text" - placeholder="璇峰~鍐欐偍闇�瑕佸厖鍊肩殑鎵嬫満鍙风爜" - type="text" - /> - </FormItem> - <FormItem - label="濮撳悕" - class="bole-form-item" - prop="name" - required - v-if="form.ispCode === BlLifeRecharge.constants.IspCode.dianxin" - > - <Input - v-model.trim="form.name" - class="bole-input-text" - placeholder="璇峰~鍐欐偍鐨勫鍚�" - type="text" - /> - </FormItem> - <FormItem label="閫夋嫨鍏呭�奸噾棰�" class="bole-form-item" prop="parValue" required> - <RadioGroup v-model="form.parValue" direction="horizontal" class="parValue-radio-group"> - <Radio - :label="item" - :key="item" - shape="button" - v-for="item in parValueList" - class="parValue-item" - > - <div class="parValue-item-inner"> - <div class="amount-wrapper"> - <div class="amount">{{ item }}</div> - <div class="unit">鍏�</div> - </div> - <div class="price-wrapper"> - <div class="price-text">鎶樺悗</div> - <div class="price"> - {{ blLifeRecharge.getRechargeParValue(item, lifePayPhoneRate) }}鍏� - </div> - </div> - <div class="discountTag">{{ lifePayPhoneRate * 100 }}鎶�</div> - </div> - </Radio> - </RadioGroup> - </FormItem> - <div class="common-content"> - <nut-button class="recharge-button" type="primary" @click="handleSubmit"> - <div class="recharge-button-inner"> - <div>锟{ form.parValue }}</div> - <div class="recharge-button-text">绔嬪嵆鍏呭��</div> - </div> - </nut-button> - <RechargeTipsView :tips="tips" /> - </div> - <ConfirmDialog v-model:visible="confirmDialogVisible" @ok="goPay"> - <template #info> - <ConfirmDialogInfoItem label="鍏呭�艰处鍙�" :content="form.phone" /> - <ConfirmDialogInfoItem label="鍏呭�奸噾棰�" :content="`锟�${form.parValue.toFixed(2)}`" danger /> - <ConfirmDialogInfoItem label="浼樻儬閲戦" :content="`锟�${discountParValue.toFixed(2)}`" /> - <ConfirmDialogInfoItem label="瀹炰粯閲戦" :content="`锟�${realParValue}`" danger /> - </template> - </ConfirmDialog> - </Form> + <PhoneBillRechargeStep1 v-if="current === 'step1'" /> + <PhoneBillRechargeStep2 + v-else-if="current === 'step2'" + v-bind="props" + @go-pay="emit('goPay', $event)" + @paySuccess="emit('paySuccess', $event)" + /> </template> <script setup lang="ts"> -import { Form, FormItem, RadioGroup, Radio, Input, Button as NutButton } from '@nutui/nutui-taro'; -import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types'; -import { reactive, ref, computed } from 'vue'; -import BlRadio from '../../components/Radio/Radio.vue'; -import { - useLifeRechargeContext, - BlLifeRecharge, - LifePhoneDataCreateLifePayOrderInput, - FormValidator, -} from '../../utils'; -import RechargeTipsView from '../../components/RechargeTipsView/RechargeTipsView.vue'; -import ConfirmDialog from '../../components/Dialog/ConfirmDialog.vue'; -import ConfirmDialogInfoItem from '../../components/Dialog/ConfirmDialogInfoItem.vue'; -import { useGetRate, useGetPhoneParValue } from '../../hooks'; +import { computed, provide, useAttrs } from 'vue'; +import { useStepper } from 'senin-mini/hooks'; +import { PhoneBillRechargeContextKey } from './context'; +import PhoneBillRechargeStep1 from './PhoneBillRechargeStep1.vue'; +import PhoneBillRechargeStep2 from './PhoneBillRechargeStep2.vue'; +import { RechargeProps } from './types'; defineOptions({ name: 'PhoneBillRecharge', }); -const form = reactive({ - ispCode: BlLifeRecharge.constants.IspCode.yidong, - phone: '', - parValue: 0, - name: '', +const props = withDefaults(defineProps<RechargeProps>(), { + isDev: false, }); + +const stepperInfo = useStepper(['step1', 'step2'], 'step2'); +const current = computed(() => stepperInfo.current.value); const emit = defineEmits<{ - ( - e: 'goPay', - form: { - ispCode: typeof BlLifeRecharge.constants.IspCode; - phone: string; - parValue: number; - name: string; - } - ): void; + (e: 'goPay', orderNo: string): void; + (e: 'paySuccess', orderNo: string): void; }>(); -const { lifePayPhoneRate } = useGetRate(); -const { phoneParValueList } = useGetPhoneParValue(); - -const parValueList = [50, 100, 200]; - -const realParValue = computed(() => - blLifeRecharge.getRechargeParValue(form.parValue, lifePayPhoneRate.value) -); -const discountParValue = computed(() => form.parValue - Number(realParValue.value)); - -const { blLifeRecharge } = useLifeRechargeContext(); - -const rules = reactive<FormRules>({ - ispCode: [{ required: true, message: '璇烽�夋嫨杩愯惀鍟�' }], - phone: [ - { required: true, message: '璇疯緭鍏ュ厖鍊兼墜鏈哄彿' }, - { validator: FormValidator.validatorPhoneNumber, message: '璇疯緭鍏ユ纭殑鎵嬫満鍙�' }, - ], - name: [{ required: true, message: '璇疯緭鍏ュ鍚�' }], - parValue: [ - { required: true, message: '璇烽�夋嫨鍏呭�奸噾棰�', validator: FormValidator.validatorNumberNotNull }, - ], +provide(PhoneBillRechargeContextKey, { + ...stepperInfo, }); - -const formRef = ref<any>(null); - -function handleSubmit() { - if (!formRef.value) return; - formRef.value.validate().then(({ valid, errors }: any) => { - if (valid) { - recharge(); - } - }); -} - -const tips = [ - '骞冲彴鎻愪緵鎱㈠厖鏈嶅姟锛岃鍗曟彁浜ゅ悗锛岃瘽璐瑰皢浜�0 - 24灏忔椂鍐呭埌璐︺�傝嫢鏈兘鎸夋椂鍒拌处锛岀郴缁熷皢鑷姩鍙戣捣閫�娆俱��', - '鍏呭�兼湡闂达紝鑻ュ悓涓�鍙风爜娆鹃」鏈埌璐︼紝璇峰嬁鍦ㄥ叾浠栧钩鍙伴噸澶嶅厖鍊硷紱涓诲壇鍗′笉鍙悓鏃跺厖鍊笺�傚洜涓婅堪鎿嶄綔瀵艰嚧鐨勮祫閲戞崯澶憋紝鐢辩敤鎴疯嚜琛屾壙鎷呫��', - '鏈钩鍙拌瘽璐瑰厖鍊兼湇鍔′笉閫傜敤浜庡凡鍋滄満鍙风爜銆傜數淇″彿鐮佽嫢鏈夋瑺璐癸紝涔熸棤娉曞畬鎴愬厖鍊笺�傜數淇″凡瀹屾垚缁存姢鐨勫尯鍩熷寘鎷細骞夸笢銆佹睙鑻忋�佹箹鍖椼�佸洓宸濄�佹睙瑗裤�佹渤鍖椼�佹渤鍗椼�佺寤恒�佽窘瀹併�傚叾瀹冨尯鍩熸鍦ㄥ垎鎵规杩涜缁存姢涓紝鍦ㄦ鏈熼棿鍙兘浼氬嚭鐜板厖鍊间笉鎴愬姛骞惰嚜鍔ㄩ��娆剧殑鎯呭喌锛岃鎮ㄨ皡瑙c��', - '濡傛帴鍒伴檶鐢熸潵鐢碉紝瀵规柟浠ョ即璐规垨璇搷浣滅瓑鐞嗙敱瑕佹眰澶勭悊娆鹃」锛屽姟蹇呯珛鍗虫媺榛戯紝璋ㄩ槻璇堥獥銆�', - '鍞悗鏈嶅姟鏈熶负鍏呭�煎畬鎴愪箣鏃ヨ捣3澶┿�傜敵璇峰敭鍚庢湇鍔℃椂锛岄渶鎻愪緵褰曞睆璇佹嵁锛岃纭鎺ュ彈姝よ姹傚悗鍐嶄笅鍗曪紝閫炬湡骞冲彴涓嶅啀鍙楃悊鍞悗鐢宠銆�', - '鍏呭�煎彂绁ㄧ敱杩愯惀鍟嗘彁渚涳紝鎮ㄥ彲鐧诲綍缃戜笂钀ヤ笟鍘呬笅杞界數瀛愬彂绁ㄣ��', -]; - -const confirmDialogVisible = ref(false); - -function recharge() { - confirmDialogVisible.value = true; -} - -async function createLifePayPhoneOrder() { - try { - let params: LifePhoneDataCreateLifePayOrderInput = { - userId: blLifeRecharge.userId, - // lifePayType: 10, - productData: { - ispCode: form.ispCode, - parValue: 0.1, - phone: '18858418480', - name: form.ispCode === BlLifeRecharge.constants.IspCode.dianxin ? form.name : '', - }, - }; - let res = await blLifeRecharge.services.createLifePayPhoneOrder(params); - } catch (error) {} -} - -function goPay() { - emit('goPay'); -} </script> -- Gitblit v1.9.1