zhengyiming
2025-03-25 dca624a7e4c877dc4bfd8c496a6c2a6b29ad4b46
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
131
132
133
134
135
<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">
        <NutTextarea
          placeholder="请输入备注信息"
          placeholderClass="bole-input-text-placeholder"
          autoSize
          class="bole-input-textarea"
          v-model="form.remark"
          :max-length="30"
          limit-show
        >
        </NutTextarea>
      </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, Textarea as NutTextarea } 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;
    form.name = currentUserAccountExtraProperties.name ?? '';
  },
  enabled: computed(() => !!props.id),
});
 
const form = reactive({
  gasOrgType: '',
  // province: '',
  // city: '',
  gasAccount: '',
  remark: '',
  areaList: [] as string[],
  name: '',
});
 
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>