zhengyiming
2025-03-17 b19e3c0ba4db231b82b2655efe0b73a81571fb84
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
<template>
  <NutForm
    :model-value="form"
    ref="formRef"
    :rules="rules"
    label-position="top"
    class="order-bill-recharge electric"
  >
    <NutFormItem label="所在区域" class="bole-form-item" prop="province" required>
      <ChooseInputWithPicker
        v-model="form.province"
        placeholder="请选择区域"
        :value-enum="electricParValueList"
        enum-label-key="cityName"
        enum-value-key="cityName"
      />
    </NutFormItem>
    <NutFormItem label="所在城市" class="bole-form-item" prop="city" required v-if="form.province">
      <ChooseInputWithPicker
        v-model="form.city"
        placeholder="请选择城市"
        :value-enum="electricCityList"
        enum-label-key="cityName"
        enum-value-key="cityName"
      />
    </NutFormItem>
    <!-- <NutFormItem label="电网类型" class="bole-form-item" prop="electricType" required>
      <ChooseInputWithPicker
        v-model="form.electricType"
        placeholder="请选择电网类型"
        :value-enum="blLifeRecharge.constants.ElectricTypeText"
      />
    </NutFormItem> -->
    <NutFormItem label="电费类型" class="bole-form-item" prop="electricAccountType" required>
      <ChooseInputWithPicker
        v-model="form.electricAccountType"
        placeholder="请选择电费类型"
        :value-enum="blLifeRecharge.constants.ElectricAccountTypeText"
      />
    </NutFormItem>
    <NutFormItem label="电网户号" class="bole-form-item" prop="electricAccount" required>
      <NumberInput
        v-model.trim="form.electricAccount"
        class="bole-input-text"
        placeholder="请输入13位数字编号"
        max-length="13"
      />
    </NutFormItem>
    <NutFormItem
      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"
      />
    </NutFormItem>
    <slot />
  </NutForm>
</template>
 
<script setup lang="ts">
import { Form as NutForm, FormItem as NutFormItem, Input as NutInput } from '@nutui/nutui-taro';
import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types';
import { reactive, ref, computed, watch } from 'vue';
import { useLifeRechargeContext } from '@life-payment/core-vue';
import ChooseInputWithPicker from '../../components/Input/ChooseInputWithPicker.vue';
import NumberInput from '../../components/Input/NumberInput.vue';
import { useGetElectricParValue } from '../../hooks';
import { FormValidator } from '../../utils';
 
defineOptions({
  name: 'ElectricBillRechargeBaseForm',
});
const form = defineModel<{
  electricAccount: string;
  electricType: string;
  electricAccountType: string;
  province: string;
  city: string;
  sixID: string;
}>('form');
 
const { electricParValueList } = useGetElectricParValue();
 
const electricCityList = computed(
  () =>
    electricParValueList.value.find((x) => x.cityName === form.value.province)?.childCityList ?? []
);
 
watch(
  () => form.value.province,
  (provinceName) => {
    const electricParValue = electricParValueList.value.find(
      (item) => item.cityName === provinceName
    );
    form.value.electricType = electricParValue.electricType;
  }
);
 
const { blLifeRecharge } = useLifeRechargeContext();
 
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,
    },
  ],
});
 
const formRef = ref<any>(null);
 
defineExpose({
  validate: computed(() => formRef.value.validate),
});
</script>