<template>
|
<LoadingLayout :loading="isLoading">
|
<GasBillRechargeBaseForm ref="formRef" v-model:form="form">
|
<template #top>
|
<NutFormItem label="燃气类型" class="bole-form-item" prop="gasOrgType" required>
|
<ChooseInputWithPicker
|
v-model="form.gasOrgType"
|
placeholder="请选择燃气类型"
|
:value-enum="gasParValueList"
|
enum-label-key="gasOrgName"
|
enum-value-key="gasOrgCode"
|
/>
|
</NutFormItem>
|
</template>
|
<NutFormItem label="备注信息" class="bole-form-item" prop="remark">
|
<NutInput
|
v-model.trim="form.remark"
|
class="bole-input-text"
|
placeholder="请输入备注信息"
|
type="text"
|
max-length="30"
|
/>
|
</NutFormItem>
|
<div class="common-content">
|
<NutButton class="recharge-button" type="primary" @click="handleSave">
|
<div class="recharge-button-inner">
|
<div class="recharge-button-text">保存</div>
|
</div>
|
</NutButton>
|
</div>
|
</GasBillRechargeBaseForm>
|
</LoadingLayout>
|
</template>
|
|
<script setup lang="ts">
|
import GasBillRechargeBaseForm from '../GasBillRecharge/GasBillRechargeBaseForm.vue';
|
import { Button as NutButton } from '@nutui/nutui-taro';
|
import { reactive, ref, computed } from 'vue';
|
import {
|
useLifeRechargeContext,
|
LifeRechargeConstants,
|
AddUpdateUserAccountInput,
|
} from '@life-payment/core-vue';
|
import { useAddUpdateUserAccount, useGetGasParValue } from '../../hooks';
|
import LoadingLayout from '../../components//Layout/LoadingLayout.vue';
|
import ChooseInputWithPicker from '../../components//Input/ChooseInputWithPicker.vue';
|
import { useQuery } from '@tanstack/vue-query';
|
import { GasUserAccountExtraProperties } from '../GasBillRecharge/context';
|
|
defineOptions({
|
name: 'EditGasUserAccount',
|
});
|
|
type Props = {
|
id?: string;
|
};
|
|
const props = withDefaults(defineProps<Props>(), {});
|
|
const emit = defineEmits<{
|
(e: 'success'): void;
|
}>();
|
|
const { blLifeRecharge } = useLifeRechargeContext();
|
|
const { gasParValueList } = useGetGasParValue();
|
|
const { isLoading } = useQuery({
|
queryKey: ['blLifeRecharge/getUserAccountDetail', props.id],
|
queryFn: async () => {
|
return await blLifeRecharge.services.getUserAccountDetail(
|
{ id: props.id },
|
{
|
showLoading: false,
|
}
|
);
|
},
|
onSuccess(data) {
|
const currentUserAccountExtraProperties = JSON.parse(
|
data.extraProperties
|
) as GasUserAccountExtraProperties;
|
form.gasAccount = data.content;
|
form.areaList = [data.province, data.city];
|
form.gasOrgType = data.operators as any;
|
|
form.remark = data.remark;
|
},
|
enabled: computed(() => !!props.id),
|
});
|
|
const form = reactive({
|
gasOrgType: '',
|
// province: '',
|
// city: '',
|
gasAccount: '',
|
remark: '',
|
areaList: [] as string[],
|
});
|
|
const formRef = ref<any>(null);
|
|
function handleSave() {
|
if (!formRef.value) return;
|
formRef.value.validate().then(({ valid, errors }: any) => {
|
if (valid) {
|
handleAddUpdateUserAccount();
|
}
|
});
|
}
|
|
const { addUpdateUserAccount } = useAddUpdateUserAccount();
|
|
async function handleAddUpdateUserAccount() {
|
try {
|
let params: AddUpdateUserAccountInput = {
|
userId: blLifeRecharge.accountModel.userId,
|
lifePayType: LifeRechargeConstants.LifePayOrderTypeEnum.燃气订单,
|
content: form.gasAccount,
|
province: form.areaList?.[0] ?? '',
|
city: form.areaList?.[1] ?? '',
|
extraProperties: JSON.stringify(form),
|
remark: form.remark,
|
operators: form.gasOrgType,
|
id: props.id,
|
};
|
await addUpdateUserAccount(params);
|
emit('success');
|
} catch (error) {}
|
}
|
</script>
|