From 866879aaf4b209e4820d21d11f9569e72dd6e0a5 Mon Sep 17 00:00:00 2001 From: zhengyiming <540361168@qq.com> Date: 星期一, 10 三月 2025 18:00:26 +0800 Subject: [PATCH] fix: 二期需求 --- packages/components/src/views/electricBillRecharge/electricBillRecharge.vue | 215 +++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 159 insertions(+), 56 deletions(-) diff --git a/packages/components/src/views/electricBillRecharge/electricBillRecharge.vue b/packages/components/src/views/electricBillRecharge/electricBillRecharge.vue index bd6ffdc..96ee990 100644 --- a/packages/components/src/views/electricBillRecharge/electricBillRecharge.vue +++ b/packages/components/src/views/electricBillRecharge/electricBillRecharge.vue @@ -1,44 +1,76 @@ <template> - <Form + <NutForm :model-value="form" ref="formRef" :rules="rules" label-position="top" class="order-bill-recharge electric" > - <FormItem label="鎵�鍦ㄥ煄甯�" class="bole-form-item" prop="type" required> + <FormItem label="鎵�鍦ㄥ尯鍩�" class="bole-form-item" prop="province" required> <ChooseInputWithPicker - v-model="form.type" + v-model="form.province" + placeholder="璇烽�夋嫨鍖哄煙" + :value-enum="electricParValueList" + enum-label-key="cityName" + enum-value-key="cityName" + /> + </FormItem> + <FormItem label="鎵�鍦ㄥ煄甯�" class="bole-form-item" prop="city" required v-if="form.province"> + <ChooseInputWithPicker + v-model="form.city" placeholder="璇烽�夋嫨鍩庡競" - :value-enum="IspCodeText" + :value-enum="electricCityList" + enum-label-key="cityName" + enum-value-key="cityName" /> </FormItem> - <FormItem label="鐢电綉绫诲瀷" class="bole-form-item" prop="type" required> + <!-- <FormItem label="鐢电綉绫诲瀷" class="bole-form-item" prop="electricType" required> <ChooseInputWithPicker - v-model="form.type" + v-model="form.electricType" placeholder="璇烽�夋嫨鐢电綉绫诲瀷" - :value-enum="IspCodeText" + :value-enum="blLifeRecharge.constants.ElectricTypeText" /> - </FormItem> - <FormItem label="鐢佃垂绫诲瀷" class="bole-form-item" prop="type" required> + </FormItem> --> + <FormItem label="鐢佃垂绫诲瀷" class="bole-form-item" prop="electricAccountType" required> <ChooseInputWithPicker - v-model="form.type" + v-model="form.electricAccountType" placeholder="璇烽�夋嫨鐢佃垂绫诲瀷" - :value-enum="IspCodeText" + :value-enum="blLifeRecharge.constants.ElectricAccountTypeText" /> </FormItem> - <FormItem label="鐢电綉鎴峰彿" class="bole-form-item" prop="phone" required> - <Input - v-model.trim="form.phone" + <FormItem label="鐢电綉鎴峰彿" class="bole-form-item" prop="electricAccount" required> + <NumberInput + v-model.trim="form.electricAccount" class="bole-input-text" placeholder="璇疯緭鍏�13浣嶆暟瀛楃紪鍙�" - type="text" + max-length="13" /> </FormItem> - <FormItem label="閫夋嫨鍏呭�奸噾棰�" class="bole-form-item" prop="parValue" required> - <RadioGroup v-model="form.parValue" direction="horizontal" class="parValue-radio-group"> - <Radio - :label="item" + <FormItem + v-if="form.electricType === blLifeRecharge.constants.ElectricType.nanwang" + label="韬唤璇佸悗鍏綅" + class="bole-form-item" + prop="sixID" + required + > + <NutInput + v-model.trim="form.sixID" + class="bole-input-text" + placeholder="璇疯緭鍏ヨ韩浠借瘉鍚庡叚浣�" + type="text" + max-length="6" + /> + </FormItem> + <FormItem + v-if="!!form.province" + label="閫夋嫨鍏呭�奸噾棰�" + class="bole-form-item" + prop="parValue" + required + > + <NutRadioGroup v-model="form.parValue" direction="horizontal" class="parValue-radio-group"> + <NutRadio + :label="Number(item)" :key="item" shape="button" v-for="item in parValueList" @@ -51,15 +83,17 @@ </div> <div class="price-wrapper"> <div class="price-text">鎶樺悗</div> - <div class="price">{{ blLifeRecharge.getRechargeParValue(item, rate) }}鍏�</div> + <div class="price"> + {{ blLifeRecharge.getRechargeParValue(item, lifePayElectricRate) }}鍏� + </div> </div> - <div class="discountTag">{{ rate * 100 }}鎶�</div> + <div class="discountTag">{{ lifePayElectricRate * 100 }}鎶�</div> </div> - </Radio> - </RadioGroup> + </NutRadio> + </NutRadioGroup> </FormItem> <div class="common-content"> - <nut-button class="recharge-button" type="primary" @click="recharge"> + <nut-button class="recharge-button" type="primary" @click="handleSubmit"> <div class="recharge-button-inner"> <div>锟{ realParValue }}</div> <div class="recharge-button-text">绔嬪嵆鍏呭��</div> @@ -72,56 +106,119 @@ 璇ヤ骇鍝佷负鎱㈠厖妯″紡锛�0-72灏忔椂鍐呭埌璐︼紝浠嬫剰璇峰嬁浠樻锛佸厖鍊煎墠璇蜂粩缁嗛槄璇诲厖鍊奸』鐭ワ紒 </template> <template #info> - <ConfirmDialogInfoItem label="鐢电綉绫诲瀷" content="鍥藉鐢电綉" /> - <ConfirmDialogInfoItem label="鐢佃垂绫诲瀷" content="浣忓畢" /> - <ConfirmDialogInfoItem label="鍏呭�奸噾棰�" :content="`锟�${form.parValue}`" danger /> - <ConfirmDialogInfoItem label="浼樻儬閲戦" :content="`锟�${discountParValue}`" /> + <ConfirmDialogInfoItem + label="鐢电綉绫诲瀷" + :content="blLifeRecharge.constants.ElectricTypeText[form.electricType]" + /> + <ConfirmDialogInfoItem :label-width="96" label="鎴峰彿" :content="form.electricAccount" /> + <ConfirmDialogInfoItem label="鍏呭�奸噾棰�" :content="`锟�${form.parValue.toFixed(2)}`" danger /> + <ConfirmDialogInfoItem label="浼樻儬閲戦" :content="`锟�${discountParValue.toFixed(2)}`" /> <ConfirmDialogInfoItem label="瀹炰粯閲戦" :content="`锟�${realParValue}`" danger /> </template> <template #warning> 鍚屼竴鐢佃垂璐︽埛鍦ㄥ厖鍊兼湡闂达紝鏈埌璐﹀墠鍒囧嬁鍦ㄥ叾浠栦换浣曞钩鍙板啀娆″厖鍊笺�傚洜姝ら�犳垚鐨勮祫閲戞崯澶遍』鐢ㄦ埛鑷鎵挎媴锛侊紒锛� </template> </ConfirmDialog> - </Form> + </NutForm> </template> <script setup lang="ts"> -import { Form, FormItem, RadioGroup, Radio, Input, Button as NutButton } from '@nutui/nutui-taro'; +import { + Form as NutForm, + FormItem, + RadioGroup as NutRadioGroup, + Radio as NutRadio, + Input as NutInput, + 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 { IspCodeText, IspCode } from '../../constants'; -import { useLifeRechargeContext } from '../../utils'; +import { reactive, ref, computed, watch } from 'vue'; +import { + useLifeRechargeContext, + BlLifeRecharge, + LifeElectricDataCreateLifePayOrderInput, +} from '@life-payment/core-vue'; import RechargeTipsView from '../../components/RechargeTipsView/RechargeTipsView.vue'; import ConfirmDialog from '../../components/Dialog/ConfirmDialog.vue'; import ConfirmDialogInfoItem from '../../components/Dialog/ConfirmDialogInfoItem.vue'; import ChooseInputWithPicker from '../../components/Input/ChooseInputWithPicker.vue'; +import NumberInput from '../../components/Input/NumberInput.vue'; +import { useGetRate, useGetElectricParValue } from '../../hooks'; +import { FormValidator } from '../../utils'; +import { CustomerServiceTips } from '../../constants'; defineOptions({ name: 'electricBillRecharge', }); +type Props = { + isDev?: boolean; +}; + +const props = withDefaults(defineProps<Props>(), { + isDev: false, +}); + const emit = defineEmits<{ - (e: 'goPay'): void; + (e: 'goPay', orderNo: string): void; }>(); const form = reactive({ - ispCode: IspCode.yidong, - phone: '', - parValue: 100, - type: IspCodeText.yidong, + parValue: 0, + electricAccount: '', + electricType: '', + electricAccountType: '', + province: '', + city: '', + sixID: '', }); -const rate = 0.96; +const { lifePayElectricRate } = useGetRate(); +const { electricParValueList } = useGetElectricParValue(); -const parValueList = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1500, 2000, 3000]; +const parValueList = computed(() => { + const parValueList = + electricParValueList.value.find((x) => x.cityName === form.province)?.parValue ?? []; + return blLifeRecharge.filterParValueList(parValueList); +}); -const realParValue = computed(() => blLifeRecharge.getRechargeParValue(form.parValue, rate)); +const electricCityList = computed( + () => electricParValueList.value.find((x) => x.cityName === form.province)?.childCityList ?? [] +); + +watch( + () => form.province, + (provinceName) => { + const electricParValue = electricParValueList.value.find( + (item) => item.cityName === provinceName + ); + form.electricType = electricParValue.electricType; + } +); + +const realParValue = computed(() => + blLifeRecharge.getRechargeParValue(form.parValue, lifePayElectricRate.value) +); const discountParValue = computed(() => form.parValue - Number(realParValue.value)); const { blLifeRecharge } = useLifeRechargeContext(); -const rules = reactive<FormRules>({}); +const rules = reactive<FormRules>({ + province: [{ required: true, message: '璇烽�夋嫨鎵�鍦ㄥ尯鍩�' }], + city: [{ required: true, message: '璇烽�夋嫨鎵�鍦ㄥ煄甯�' }], + electricAccountType: [{ required: true, message: '璇烽�夋嫨鐢佃垂绫诲瀷' }], + electricAccount: [{ required: true, message: '璇疯緭鍏ョ數缃戞埛鍙�', regex: /^\d{13}$/ }], + sixID: [ + { + required: true, + message: '璇疯緭鍏ヨ韩浠借瘉鍚庡叚浣�', + validator: FormValidator.validatorIDNumberSix, + }, + ], + parValue: [ + { required: true, message: '璇烽�夋嫨鍏呭�奸噾棰�', validator: FormValidator.validatorNumberNotNull }, + ], +}); const formRef = ref<any>(null); @@ -129,6 +226,7 @@ if (!formRef.value) return; formRef.value.validate().then(({ valid, errors }: any) => { if (valid) { + recharge(); } }); } @@ -139,6 +237,7 @@ '涓虹‘淇濆厖鍊奸『鍒╄繘琛岋紝鐩墠骞冲彴涓嶆敮鎸佸娆犳閲戦瓒呰繃1000鍏冪殑璐︽埛杩涜鍏呭�硷紝涓旀瘡娆″厖鍊奸噾棰濆繀椤婚珮浜庢瑺璐规�婚銆�', '濡傛帴鍒伴檶鐢熸潵鐢碉紝瀵规柟浠ョ即璐规垨璇搷浣滅瓑鐞嗙敱瑕佹眰澶勭悊娆鹃」锛屽姟蹇呯珛鍗虫媺榛戯紝璋ㄩ槻璇堥獥銆�', '涓嬪崟鏃讹紝璇锋偍鍔″繀鍑嗙‘濉啓瀹屾暣鐨勭渷甯傚強鎴峰彿淇℃伅銆傚厖鍊煎畬鎴愬悗锛屽彂绁ㄧ敱杩愯惀鍟嗘彁渚涳紝鎮ㄥ彲鐧诲綍缃戜笂钀ヤ笟鍘呬笅杞藉搴旂殑鐢靛瓙鍙戠エ銆�', + CustomerServiceTips, ]; const confirmDialogVisible = ref(false); @@ -147,18 +246,22 @@ confirmDialogVisible.value = true; } -function goPay() { - emit('goPay'); +async function goPay() { + try { + let params: LifeElectricDataCreateLifePayOrderInput = { + userId: blLifeRecharge.accountModel.userId, + productData: { + parValue: props.isDev ? 0.1 : form.parValue, + electricType: form.electricType, + electricAccountType: form.electricAccountType, + electricAccount: form.electricAccount, + province: form.province, + city: form.city, + sixID: form.sixID, + }, + }; + let res = await blLifeRecharge.services.createLifePayElectricOrder(params); + emit('goPay', res.orderNo); + } catch (error) {} } </script> -<style lang="scss"> -.order-bill-recharge { - &.electric { - .nut-dialog { - .nut-dialog__content { - max-height: 700px; - } - } - } -} -</style> -- Gitblit v1.9.1