zhengyiming
2025-03-12 db365a5eff31c040c42463df4966bf34a5de6a6d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<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>