NewCustomerForm.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <a-modal :visible="visible" :title="editMode ? $t('customer.editCustomer') : $t('customer.addCustomer')"
  3. :loading="loading" @ok="handleSubmit" @cancel="handleCancel" :width="800" :okText="$t('form.Confirm')"
  4. :cancelText="$t('form.Cancel')">
  5. <a-tabs>
  6. <!-- 基本信息 Tab -->
  7. <a-tab-pane key="1" :title="$t('customer.basicInfo')">
  8. <a-form :model="formData" :rules="rules" ref="formRef" :label-col-props="{ span: 6 }"
  9. :wrapper-col-props="{ span: 18 }">
  10. <a-divider>{{ $t('customer.basicInfoSection') }}</a-divider>
  11. <!-- Customer Code -->
  12. <a-form-item field="zip" :label="$t('customer.customerCode')" required validate-trigger="blur">
  13. <a-input v-model="formData.zip" :placeholder="$t('customer.enterCustomerCode')" :max-length="60"
  14. show-word-limit />
  15. </a-form-item>
  16. <a-form-item field="email" :label="$t('customer.emailName')" required validate-trigger="blur">
  17. <a-input v-model="formData.email" :placeholder="$t('customer.emailType')" :max-length="60"
  18. show-word-limit />
  19. </a-form-item>
  20. <a-form-item field="phone" :label="$t('customer.phoneName')" required validate-trigger="blur">
  21. <a-input v-model="formData.phone" :placeholder="$t('customer.phoneType')" show-word-limit />
  22. </a-form-item>
  23. <!-- Customer Name -->
  24. <a-form-item field="name" :label="$t('customer.customerName')" required validate-trigger="blur">
  25. <a-input v-model="formData.name" :placeholder="$t('customer.enterCustomerName')" :max-length="60"
  26. show-word-limit />
  27. </a-form-item>
  28. <!-- Account Number -->
  29. <a-form-item field="username" :label="$t('customer.accountNumber')" required validate-trigger="blur">
  30. <a-input v-model="formData.username" :placeholder="$t('customer.enterAccountNumber')" :max-length="60"
  31. show-word-limit />
  32. </a-form-item>
  33. <!-- Password -->
  34. <a-form-item :label="$t('customer.password')" required validate-trigger="blur">
  35. <a-input-password v-model="formData.password" :placeholder="$t('customer.enterPassword')" :max-length="60"
  36. show-word-limit />
  37. <a-button type="primary" @click="generatePassword">{{ $t('customer.generatePassword') }}</a-button>
  38. </a-form-item>
  39. <div class="note">
  40. {{ $t('customer.note') }}
  41. </div>
  42. <a-form-item field="note" :label="$t('customer.remark')" required validate-trigger="blur">
  43. <a-input v-model="formData.note" :placeholder="$t('customer.enterRemark')" :max-length="60"
  44. show-word-limit />
  45. </a-form-item>
  46. <!-- Account Balance -->
  47. <a-form-item field="amount" :label="$t('customer.accountBalance')" required validate-trigger="blur">
  48. <a-input-number v-model="formData.amount" :min="0" :precision="2" :step="100"
  49. :suffix="$t('customer.currency')" />
  50. </a-form-item>
  51. <!-- Address -->
  52. <a-form-item field="addr" :label="$t('customer.address')" required validate-trigger="blur">
  53. <a-input v-model="formData.addr" :placeholder="$t('customer.addressMessage')" :max-length="50"
  54. show-word-limit />
  55. </a-form-item>
  56. <!-- Status -->
  57. <a-form-item field="state" :label="$t('customer.statusName')" required validate-trigger="blur">
  58. <a-radio-group v-model="formData.state">
  59. <a-radio :value="item.value" v-for="item in userTypes">{{
  60. item.value == 1 ? $t('customer.status.normal') : (item.value == 2 ? $t('customer.status.disabled') :
  61. (item.value == 3 ? $t('customer.status.pending') : $t('customer.status.suspended')))
  62. }} </a-radio>
  63. </a-radio-group>
  64. </a-form-item>
  65. </a-form>
  66. </a-tab-pane>
  67. <!-- SMS 信息 Tab -->
  68. <a-tab-pane key="2" :title="$t('customer.smsInfoSection')">
  69. <a-form :model="formData" :rules="rules" ref="formRef" :label-col-props="{ span: 6 }"
  70. :wrapper-col-props="{ span: 18 }">
  71. <a-divider>{{ $t('customer.smsInfoSection') }}</a-divider>
  72. <a-form-item field="sms" :label="$t('customer.smsSubCode')" required validate-trigger="blur">
  73. <a-input v-model="formData.sms" :placeholder="$t('customer.enterSmsSubCode')" :max-length="60"
  74. show-word-limit />
  75. </a-form-item>
  76. <a-form-item field="smsSignature" :label="$t('customer.smsName')" required validate-trigger="blur">
  77. <a-input v-model="formData.smsSignature" :placeholder="$t('customer.enterSmsName')" :max-length="60"
  78. show-word-limit />
  79. </a-form-item>
  80. <a-form-item field="loginSms" :label="$t('customer.loginSmsTemplate')" required validate-trigger="blur">
  81. <a-input v-model="formData.loginSms" :placeholder="$t('customer.enterLoginSmsTemplate')" :max-length="60"
  82. show-word-limit />
  83. </a-form-item>
  84. <a-form-item field="warnSms" :label="$t('customer.alarmSmsTemplate')" required validate-trigger="blur">
  85. <a-input v-model="formData.warnSms" :placeholder="$t('customer.enterAlarmSmsTemplate')" :max-length="60"
  86. show-word-limit />
  87. </a-form-item>
  88. </a-form>
  89. </a-tab-pane>
  90. <!-- Billing Information Tab -->
  91. <a-tab-pane key="3" :title="$t('customer.billingInfo')">
  92. <a-form :model="formData" :rules="rules" ref="formRef" :label-col-props="{ span: 6 }"
  93. :wrapper-col-props="{ span: 18 }">
  94. <a-divider>{{ $t('customer.InvoiceInformation') }}</a-divider>
  95. <a-form-item field="invoiceTitle" :label="$t('customer.invoiceTitle')" required validate-trigger="blur">
  96. <a-input v-model="formData.invoiceTitle" :placeholder="$t('customer.enterInvoiceTitle')" :max-length="60"
  97. show-word-limit />
  98. </a-form-item>
  99. <a-form-item field="invoiceType" :label="$t('customer.invoice_vatTextType')" required validate-trigger="blur">
  100. <a-select v-model="formData.invoiceType" :style="{ width: '100%' }"
  101. :placeholder="$t('customer.invoice_vatTextTypeSelect')">
  102. <a-option v-for="item of invoiceList" :value="item.value" :label="item.label" />
  103. </a-select>
  104. </a-form-item>
  105. <a-form-item field="invoiceAddr" :label="$t('customer.registeredAddress')" required validate-trigger="blur">
  106. <a-input v-model="formData.invoiceAddr" :placeholder="$t('customer.enterRegisteredAddress')"
  107. :max-length="60" show-word-limit />
  108. </a-form-item>
  109. <a-form-item field="invoiceZip" :label="$t('customer.invoiceCode')" required validate-trigger="blur">
  110. <a-input v-model="formData.invoiceZip" :placeholder="$t('customer.InvoiceCodeName')" :max-length="60"
  111. show-word-limit />
  112. </a-form-item>
  113. <a-form-item field="invoiceEmail" :label="$t('customer.invoiceEmailName')" required validate-trigger="blur">
  114. <a-input v-model="formData.invoiceEmail" :placeholder="$t('customer.invoiceEmailNameType')" :max-length="60"
  115. show-word-limit />
  116. </a-form-item>
  117. <a-form-item field="bankName" :label="$t('customer.bankName')" required validate-trigger="blur">
  118. <a-input v-model="formData.bankName" :placeholder="$t('customer.enterBankName')" :max-length="60"
  119. show-word-limit />
  120. </a-form-item>
  121. <a-form-item field="bankAccount" :label="$t('customer.BankNumber')" required validate-trigger="blur">
  122. <a-input v-model="formData.bankAccount" :placeholder="$t('customer.BankNumberName')" :max-length="60"
  123. show-word-limit />
  124. </a-form-item>
  125. <a-form-item field="bankBranch" :label="$t('customer.bank_branchName')" required validate-trigger="blur">
  126. <a-input v-model="formData.bankBranch" :placeholder="$t('customer.bank_branchNameType')" show-word-limit />
  127. </a-form-item>
  128. <a-form-item field="businessLicense" :label="$t('customer.BusinessLicense')" required validate-trigger="blur">
  129. <upload v-model="formData.businessLicense" />
  130. </a-form-item>
  131. </a-form>
  132. </a-tab-pane>
  133. <!-- Tax Registration Tab -->
  134. <a-tab-pane key="4" :title="$t('customer.TaxRegistration')">
  135. <a-form :model="formData" :rules="rules" ref="formRef" :label-col-props="{ span: 8 }"
  136. :wrapper-col-props="{ span: 16 }">
  137. <a-divider>{{ $t('customer.TaxRegistrationText') }}</a-divider>
  138. <a-form-item field="taxRegistrationCertificate" :label="$t('customer.photocopy')" required
  139. validate-trigger="blur">
  140. <upload v-model:modelValue="formData.taxRegistrationCertificate" />
  141. </a-form-item>
  142. <a-form-item field="taxpayerQualification" :label="$t('customer.CertificationQualification')" required
  143. validate-trigger="blur">
  144. <upload v-model:modelValue="formData.taxpayerQualification" />
  145. </a-form-item>
  146. </a-form>
  147. </a-tab-pane>
  148. <a-tab-pane key="5" :title="$t('forewarning.forewarning')">
  149. <a-form :model="formData" :rules="rules" ref="formRef" :label-col-props="{ span: 4 }"
  150. :wrapper-col-props="{ span: 20 }">
  151. <a-divider>{{ $t('forewarning.EarlyWarningSetting') }}</a-divider>
  152. <a-form-item field="amountWarn" :label="$t('forewarning.AccountBalanceAlarm')" required
  153. validate-trigger="blur">
  154. <a-input v-model="formData.amountWarn" :placeholder="$t('form.datapoolForm.pleaseEnter')" :max-length="60"
  155. :style="{ width: '320px' }" show-word-limit />
  156. </a-form-item>
  157. <a-form-item field="arriveWarn" :label="$t('forewarning.ReachWarning')" required validate-trigger="blur">
  158. <a-input-number v-model="formData.arriveWarn" :style="{ width: '320px' }"
  159. :placeholder="$t('form.datapoolForm.pleaseEnter')" allow-clear hide-button>
  160. <template #suffix>
  161. %
  162. </template>
  163. </a-input-number>
  164. </a-form-item>
  165. <a-form-item field="arriveNetwork" :label="$t('forewarning.NetworkOutage')" required validate-trigger="blur">
  166. <a-input-number v-model="formData.arriveNetwork" :style="{ width: '320px' }"
  167. :placeholder="$t('form.datapoolForm.pleaseEnter')" allow-clear hide-button>
  168. <template #suffix>
  169. %
  170. </template>
  171. </a-input-number>
  172. <a-radio-group v-model="formData.arriveStopNetwork" :options="reachList"></a-radio-group>
  173. </a-form-item>
  174. <a-form-item field="warnPhone" :label="$t('forewarning.EarlyWarningPhone')" required validate-trigger="blur">
  175. <a-input v-model="formData.warnPhone" :style="{ width: '320px' }"
  176. :placeholder="$t('form.datapoolForm.pleaseEnter')" allow-clear hide-button>
  177. </a-input>
  178. </a-form-item>
  179. <a-form-item field="warnEmail" :label="$t('forewarning.WarningMailbox')" required validate-trigger="blur">
  180. <a-input v-model="formData.warnEmail" :style="{ width: '320px' }"
  181. :placeholder="$t('form.datapoolForm.pleaseEnter')" allow-clear>
  182. </a-input>
  183. </a-form-item>
  184. </a-form>
  185. </a-tab-pane>
  186. </a-tabs>
  187. </a-modal>
  188. </template>
  189. <script setup>
  190. import { ref, watch, onMounted } from 'vue';
  191. import { Message } from '@arco-design/web-vue';
  192. import { useI18n } from 'vue-i18n';
  193. import { dictionaryDetail } from '@/api/path/dict.js'
  194. import Upload from "@/components/upload/index.vue";
  195. import { systemFindRoleList } from "@/api/path/system.api.js";
  196. import { addCustomer, updateCustomer } from "@/api/customer.js";
  197. import { Getdictionary } from '@/mixins/index.js'
  198. const { t } = useI18n();
  199. import { encryptByDES } from '@/utils/crypto.js'
  200. const props = defineProps({
  201. visible: Boolean,
  202. editMode: Boolean,
  203. editData: Object,
  204. loading: Boolean,
  205. });
  206. const invoiceList = ref([])
  207. const roles = ref([])
  208. const userTypes = ref([])
  209. watch(
  210. () => props.editData,
  211. (newVal) => {
  212. if (newVal && props.editMode) {
  213. // 深拷贝编辑数据
  214. const editDataCopy = JSON.parse(JSON.stringify(newVal));
  215. delete editDataCopy.alert.id
  216. delete editDataCopy.alert.userId
  217. delete editDataCopy.alert.createdAt
  218. delete editDataCopy.alert.deletedAt
  219. delete editDataCopy.alert.updatedAt
  220. // 检查并展平嵌套的 info 对象
  221. let flattenedFormData = {};
  222. let flasAlert = {}
  223. if (editDataCopy.info) {
  224. flattenedFormData = { ...editDataCopy.info }; // 展平 info 的键值对
  225. flasAlert = { ...editDataCopy.alert }
  226. delete editDataCopy.info; // 删除原始 info 字段
  227. delete editDataCopy.alert; // 删除原始 info 字段
  228. }
  229. // 合并 editDataCopy 和 flattenedFormData
  230. const formDataList = {
  231. ...editDataCopy,
  232. ...flattenedFormData, // 此处直接使用展开后的 flattenedFormData
  233. ...flasAlert
  234. };
  235. // 更新 formData 的值
  236. formData.value = formDataList;
  237. }
  238. }
  239. );
  240. const emit = defineEmits(['update:visible', 'submit']);
  241. const formRef = ref(null);
  242. const reachList = ref([])
  243. const formData = ref({
  244. username: "",
  245. state: "",
  246. name: "",
  247. password: "",
  248. phone: "",
  249. email: "",
  250. addr: "",
  251. zip: "",
  252. note: "",
  253. sms: "",
  254. smsSignature: "",
  255. loginSms: "",
  256. warnSms: "",
  257. amount: "",
  258. invoiceTitle: "",
  259. invoiceType: "",
  260. invoiceAddr: "",
  261. invoiceZip: "",
  262. invoiceEmail: "",
  263. bankName: "",
  264. bankAccount: "",
  265. bankBranch: "",
  266. businessLicense: "",
  267. taxRegistrationCertificate: "",
  268. taxpayerQualification: "",
  269. amountWarn: '',
  270. arriveWarn: '',
  271. // arriveStop: '',
  272. arriveNetwork: '',
  273. arriveStopOperation: '',
  274. arriveStopNetwork: '',
  275. warnPhone: '',
  276. warnEmail: ''
  277. });
  278. const rules = {
  279. userName: [{ required: true, message: t('customer.enterAccountNumber') }],
  280. state: [{ required: true, message: t('customer.stateType') }],
  281. name: [{ required: true, message: t('customer.nameType') }],
  282. // password: [{ required: true, message: t('customer.passwordRequired') }],
  283. // roleIds: [{required: true, message: t('customer.roleIdsType')}],
  284. // userType: [{required: true, message: t('customer.userTypeType')}],
  285. phone: [{ required: true, message: t('customer.phoneType') }],
  286. email: [{ required: true, message: t('customer.emailType') }],
  287. addr: [{ required: true, message: t('customer.addressRequired') }],
  288. amount: [{ required: true, message: t('customer.amountRequired') }],
  289. bankAccount: [{ required: true, message: t('customer.bankAccountRequired') }],
  290. bankBranch: [{ required: true, message: t('customer.bankBranchRequired') }],
  291. bankName: [{ required: true, message: t('customer.bankNameRequired') }],
  292. businessLicense: [{ required: true, message: t('customer.businessLicenseRequired') }],
  293. invoiceAddr: [{ required: true, message: t('customer.invoiceAddressRequired') }],
  294. invoiceEmail: [{ required: true, message: t('customer.invoiceEmailRequired') }],
  295. invoiceTitle: [{ required: true, message: t('customer.invoiceTitleRequired') }],
  296. invoiceType: [{ required: true, message: t('customer.invoiceTypeRequired') }],
  297. invoiceZip: [{ required: true, message: t('customer.invoiceZipRequired') }],
  298. loginSms: [{ required: true, message: t('customer.loginSMSTemplateRequired') }],
  299. note: [{ required: true, message: t('customer.noteRequired') }],
  300. sms: [{ required: true, message: t('customer.smsRequired') }],
  301. smsSignature: [{ required: true, message: t('customer.smsSignatureRequired') }],
  302. warnSms: [{ required: true, message: t('customer.warnSMSTemplateRequired') }],
  303. zip: [{ required: true, message: t('customer.zipCodeRequired') }],
  304. taxRegistrationCertificate: [{ required: true, message: t('customer.taxRegistrationCertificateRequired') }],
  305. taxpayerQualification: [{ required: true, message: t('customer.taxpayerQualificationRequired') }],
  306. };
  307. const handleSubmit = () => {
  308. if (activeKey.value != 5 && !props.editData?.id) {
  309. Message.error('请继续填写下一步骤')
  310. } else {
  311. formRef.value.validate(async (values, errors) => {
  312. if (!errors) {
  313. if (formData.value.password) {
  314. formData.value.password = encryptByDES(formData.value.password);
  315. }
  316. formData.value.amountWarn = Number(formData.value.amountWarn);
  317. formData.value.warnPhone = String(formData.value.warnPhone);
  318. formData.value.warnEmail = String(formData.value.warnEmail);
  319. let response;
  320. if (props.editMode) {
  321. response = await updateCustomer(formData.value);
  322. } else {
  323. response = await addCustomer(formData.value);
  324. }
  325. if (response.code === 200) {
  326. Message.success(props.editMode ? t('customer.updateSuccess') : t('customer.addSuccess'));
  327. emit('submit', true);
  328. emit('update:visible', false);
  329. } else {
  330. Message.error(response.message || (props.editMode ? t('customer.updateFailed') : t('customer.addFailed')));
  331. }
  332. }
  333. });
  334. }
  335. };
  336. const handleCancel = () => {
  337. Object.keys(formData.value).forEach(key => {
  338. formData.value[key] = ''
  339. })
  340. formRef.value = null
  341. emit('update:visible', false);
  342. };
  343. const generatePassword = () => {
  344. formData.value.password = Math.random().toString(36).slice(-8);
  345. Message.success(t('customer.passwordGenerated'));
  346. };
  347. const getDistList = async () => {
  348. let code = ['invoiceVat', 'reach'];
  349. for (let i = 0; i < code.length; i++) {
  350. let res = await dictionaryDetail({ typeKey: code[i] });
  351. if (res.code === 200) {
  352. if (i == 0) {
  353. invoiceList.value = res.data;
  354. } else {
  355. reachList.value = res.data;
  356. }
  357. }
  358. }
  359. }
  360. const getRolesData = async () => {
  361. let res = await systemFindRoleList()
  362. if (res.code === 200) {
  363. roles.value = res.data
  364. }
  365. }
  366. const getList = async () => {
  367. let res = await Getdictionary('userType')
  368. userTypes.value = res
  369. }
  370. watch(() => props.visible, val => {
  371. if (!val) {
  372. Object.keys(formData.value).forEach(key => {
  373. formData.value[key] = ''
  374. })
  375. } else {
  376. getRolesData()
  377. getDistList()
  378. getList()
  379. }
  380. }, { immediate: true })
  381. </script>
  382. <style scoped>
  383. .upload-description {
  384. font-size: 12px;
  385. color: #999;
  386. margin-top: 4px;
  387. }
  388. .note {
  389. color: #f73f3f;
  390. text-align: center;
  391. position: relative;
  392. top: -20px;
  393. left: 65px;
  394. }
  395. </style>