| <template> | 
|   <NutForm | 
|     :model-value="form" | 
|     ref="formRef" | 
|     :rules="rules" | 
|     label-position="top" | 
|     class="order-bill-recharge electric" | 
|   > | 
|     <NutFormItem class="bole-form-item" prop="currentUserAccountId"> | 
|       <NutRadioGroup | 
|         v-model="form.currentUserAccountId" | 
|         direction="horizontal" | 
|         class="par-account-list" | 
|         v-if="userAccountAllList.length > 0" | 
|         @change="handleUserAccountChange" | 
|       > | 
|         <NutRadio :label="item.id" shape="button" v-for="item in userAccountAllList" :key="item.id" | 
|           >{{ item.city }}-{{ item.content }}</NutRadio | 
|         > | 
|       </NutRadioGroup> | 
|       <AccountCard | 
|         v-if="userAccountAllList.length > 0" | 
|         title="充值户号" | 
|         :content="`${form.city} ${form.electricAccount}`" | 
|         :remark="form.remark" | 
|       > | 
|         <template #action> | 
|           <div class="account-card-action" @click="handleAddUserAccount">新增</div> | 
|         </template> | 
|       </AccountCard> | 
|       <AccountAddCard text="新增户号" v-else @click="handleAddUserAccount" /> | 
|     </NutFormItem> | 
|   | 
|     <NutFormItem | 
|       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" | 
|           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, lifePayElectricRate) }}元 | 
|               </div> | 
|             </div> | 
|             <div class="discountTag" v-if="lifePayElectricRate > 0"> | 
|               {{ lifePayElectricRate }}折 | 
|             </div> | 
|           </div> | 
|         </NutRadio> | 
|       </NutRadioGroup> | 
|     </NutFormItem> | 
|     <SelectPayTypeFormItem | 
|       v-model="form.lifePayType" | 
|       :showWeixinPay="showWeixinPay" | 
|       :showAliPay="showAliPay" | 
|     ></SelectPayTypeFormItem> | 
|     <div class="common-content"> | 
|       <nut-button class="recharge-button" type="primary" @click="handleSubmit"> | 
|         <div class="recharge-button-inner"> | 
|           <div>¥{{ realParValue }}</div> | 
|           <div class="recharge-button-text">立即充值</div> | 
|         </div> | 
|       </nut-button> | 
|       <RechargeTipsView :lifePayOrderType="LifeRechargeConstants.LifePayOrderTypeEnum.电费订单" /> | 
|     </div> | 
|     <ConfirmDialog v-model:visible="confirmDialogVisible" @ok="goPay"> | 
|       <template #tips> | 
|         该产品为慢充模式,0-72小时内到账,介意请勿付款!充值前请仔细阅读充值须知! | 
|       </template> | 
|       <template #info> | 
|         <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> | 
|     <NutToast :msg="state.msg" v-model:visible="state.show" type="warn" cover /> | 
|   </NutForm> | 
| </template> | 
|   | 
| <script setup lang="ts"> | 
| import { | 
|   Form as NutForm, | 
|   FormItem as NutFormItem, | 
|   RadioGroup as NutRadioGroup, | 
|   Radio as NutRadio, | 
|   Button as NutButton, | 
|   Toast as NutToast, | 
| } from '@nutui/nutui-taro'; | 
| import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types'; | 
| import { reactive, ref, computed, toRef } from 'vue'; | 
| import { | 
|   useLifeRechargeContext, | 
|   LifeElectricDataCreateLifePayOrderInput, | 
|   LifeRechargeConstants, | 
|   UserAccountListOutput, | 
| } 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 { useGetRate, useGetElectricParValue, useSetUserAccountBySelect } from '../../hooks'; | 
| import { FormValidator, initLifePayType } from '../../utils'; | 
| import AccountAddCard from '../../components/Card/AccountAddCard.vue'; | 
| import AccountCard from '../../components/Card/AccountCard.vue'; | 
| import { useElectricBillRechargeContext, ElectricUserAccountExtraProperties } from './context'; | 
| import SelectPayTypeFormItem from '../../components/SelectPayTypeFormItem/SelectPayTypeFormItem.vue'; | 
| import { useSelectPayType, useGetPayStatusByOrderNo } from '../../hooks/selectPayType'; | 
| import { RechargeProps } from '../PhoneBillRecharge/types'; | 
|   | 
| defineOptions({ | 
|   name: 'ElectricBillRechargeStep2', | 
| }); | 
|   | 
| const props = withDefaults(defineProps<RechargeProps>(), { | 
|   isDev: false, | 
| }); | 
|   | 
| const emit = defineEmits<{ | 
|   (e: 'goPay', orderNo: string): void; | 
|   (e: 'paySuccess', orderNo: string): void; | 
|   (e: 'missName', userAccountId: string): void; | 
| }>(); | 
|   | 
| const { goTo } = useElectricBillRechargeContext(); | 
|   | 
| const form = reactive({ | 
|   parValue: 0, | 
|   electricAccount: '', | 
|   electricType: '', | 
|   electricAccountType: '', | 
|   province: '', | 
|   city: '', | 
|   sixID: '', | 
|   currentUserAccountId: '', | 
|   remark: '', | 
|   lifePayType: initLifePayType(props.isInWeChat, props.isInAlipay), | 
|   name: '', | 
| }); | 
|   | 
| const { userAccountAllList, handleUserAccountChange } = useSetUserAccountBySelect({ | 
|   lifePayOrderType: LifeRechargeConstants.LifePayOrderTypeEnum.电费订单, | 
|   onSetUserAccount(currentUserAccount) { | 
|     const currentUserAccountExtraProperties = JSON.parse( | 
|       currentUserAccount.extraProperties | 
|     ) as ElectricUserAccountExtraProperties; | 
|     form.currentUserAccountId = currentUserAccount.id; | 
|     form.electricAccount = currentUserAccount.content; | 
|     form.province = currentUserAccount.province; | 
|     form.city = currentUserAccount.city; | 
|   | 
|     form.electricType = currentUserAccountExtraProperties.electricType; | 
|     form.electricAccountType = currentUserAccountExtraProperties.electricAccountType; | 
|     form.sixID = currentUserAccountExtraProperties.sixID; | 
|     form.remark = currentUserAccount.remark; | 
|     form.name = currentUserAccountExtraProperties.name ?? ''; | 
|     const electricParValueItem = electricParValueList.value.find( | 
|       (x) => x.cityName === form.province | 
|     ); | 
|     if ( | 
|       electricParValueItem && | 
|       electricParValueItem.parValue.every((x) => Number(x) !== form.parValue) | 
|     ) { | 
|       form.parValue = 0; | 
|     } | 
|   }, | 
| }); | 
|   | 
| function handleAddUserAccount() { | 
|   goTo('step1'); | 
| } | 
|   | 
| const { lifePayElectricRate } = useGetRate(); | 
| const { electricParValueList } = useGetElectricParValue(); | 
|   | 
| const { blLifeRecharge } = useLifeRechargeContext(); | 
|   | 
| 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, lifePayElectricRate.value) | 
| ); | 
| const discountParValue = computed(() => form.parValue - Number(realParValue.value)); | 
|   | 
| const rules = reactive<FormRules>({ | 
|   parValue: [ | 
|     { required: true, message: '请选择充值金额', validator: FormValidator.validatorNumberNotNull }, | 
|   ], | 
|   currentUserAccountId: [{ required: true, message: '请选择充值户号' }], | 
|   lifePayType: [{ required: true, message: '请选择支付方式' }], | 
| }); | 
|   | 
| const formRef = ref<any>(null); | 
|   | 
| function handleSubmit() { | 
|   if (!formRef.value) return; | 
|   formRef.value.validate().then(({ valid, errors }: any) => { | 
|     if (valid) { | 
|       if (!form.name) { | 
|         emit('missName', form.currentUserAccountId); | 
|         return; | 
|       } | 
|       recharge(); | 
|     } | 
|   }); | 
| } | 
|   | 
| const confirmDialogVisible = ref(false); | 
|   | 
| function recharge() { | 
|   confirmDialogVisible.value = true; | 
| } | 
|   | 
| const { state, invokeAliPay, invokeWeixinPay } = useSelectPayType({ | 
|   isInWeChat: toRef(props, 'isInWeChat'), | 
|   isH5: toRef(props, 'isH5'), | 
|   appId: toRef(props, 'appId'), | 
|   getOpenId: toRef(props, 'getOpenId'), | 
| }); | 
|   | 
| const currentOrderNo = ref(''); | 
|   | 
| async function goPay() { | 
|   try { | 
|     let params: LifeElectricDataCreateLifePayOrderInput = { | 
|       userId: blLifeRecharge.accountModel.userId, | 
|       channelId: blLifeRecharge.accountModel.channlesNum, | 
|       productData: { | 
|         parValue: form.parValue, | 
|         electricType: form.electricType, | 
|         electricAccountType: form.electricAccountType, | 
|         electricAccount: form.electricAccount, | 
|         province: form.province, | 
|         city: form.city, | 
|         sixID: form.sixID, | 
|         // name: form.name, | 
|       }, | 
|     }; | 
|     let res = await blLifeRecharge.services.createLifePayElectricOrder(params); | 
|     // emit('goPay', res.orderNo); | 
|     if (form.lifePayType === LifeRechargeConstants.LifePayTypeEnum.WxPay) { | 
|       await invokeWeixinPay(res.orderNo); | 
|     } else { | 
|       await invokeAliPay(res.orderNo); | 
|     } | 
|     currentOrderNo.value = res.orderNo; | 
|   } catch (error) {} | 
| } | 
|   | 
| useGetPayStatusByOrderNo({ | 
|   orderNo: currentOrderNo, | 
|   enabled: computed(() => props.isFocus && !!currentOrderNo.value), | 
|   onPaySuccess: (orderNo) => { | 
|     emit('paySuccess', orderNo); | 
|     currentOrderNo.value = ''; | 
|   }, | 
| }); | 
| </script> |