form.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <script lang="ts" setup>
  2. import { computed, ref } from 'vue';
  3. import { useVbenModal } from '@vben/common-ui';
  4. import { useVbenForm, z } from '#/adapter/form';
  5. // import { getCustomerDetailApi } from '#/api/customer-manage';
  6. const data = ref();
  7. const getTitle = computed(() => (data.value?.create ? '新增客户' : '编辑客户'));
  8. const [BaseForm, baseFormApi] = useVbenForm({
  9. showDefaultActions: false,
  10. // 所有表单项共用,可单独在表单内覆盖
  11. commonConfig: {
  12. labelWidth: 120,
  13. // 所有表单项
  14. componentProps: {
  15. class: 'w-full',
  16. },
  17. },
  18. schema: [
  19. // { title: '用户名称', field: 'usersname' },
  20. // { title: '用户性质', field: 'usersnature' },
  21. // { title: '用户证件号码', field: 'usersidcardnumber' },
  22. // { title: '用户开户银行名称', field: 'usersbankname' },
  23. // { title: '用户开户银行账号', field: 'usersbanknumber' },
  24. // { title: '用户手机号', field: 'usersphone' },
  25. // { title: '用户邮箱', field: 'usersemail' },
  26. // { title: '用户地址', field: 'usersaddress' },
  27. // { title: '用户联系手机号', field: 'userscontactphone' },
  28. // { title: '用户联系邮箱', field: 'userscontactemail' },
  29. // { title: '用户联系地址', field: 'userscontactaddress' },
  30. {
  31. component: 'Input',
  32. fieldName: 'usersname',
  33. label: '用户名称',
  34. componentProps: {
  35. placeholder: '请输入用户名称',
  36. allowClear: true,
  37. },
  38. rules: z.string().min(1, { message: '请输入用户名称' }),
  39. },
  40. {
  41. component: 'Input',
  42. fieldName: 'usersnature',
  43. label: '用户性质',
  44. componentProps: {
  45. placeholder: '请输入用户性质',
  46. allowClear: true,
  47. },
  48. rules: z.number().min(1, { message: '请输入用户性质' }),
  49. },
  50. {
  51. component: 'Input',
  52. fieldName: 'usersidcardnumber',
  53. label: '用户证件号码',
  54. componentProps: {
  55. placeholder: '请输入用户证件号码',
  56. allowClear: true,
  57. },
  58. rules: z.string().min(1, { message: '请输入用户证件号码' }),
  59. },
  60. {
  61. component: 'Input',
  62. fieldName: 'usersbankname',
  63. label: '用户开户银行名称',
  64. componentProps: {
  65. placeholder: '请输入用户开户银行名称',
  66. allowClear: true,
  67. },
  68. rules: z.string().min(1, { message: '请输入用户开户银行名称' }),
  69. },
  70. {
  71. component: 'Input',
  72. fieldName: 'usersbanknumber',
  73. label: '用户开户银行账号',
  74. componentProps: {
  75. placeholder: '请输入用户开户银行账号',
  76. allowClear: true,
  77. },
  78. rules: z.string().min(1, { message: '请输入用户开户银行账号' }),
  79. },
  80. {
  81. component: 'Input',
  82. fieldName: 'usersphone',
  83. label: '用户手机号',
  84. componentProps: {
  85. placeholder: '请输入用户手机号',
  86. allowClear: true,
  87. },
  88. rules: z.string().min(1, { message: '请输入用户手机号' }),
  89. },
  90. {
  91. component: 'Input',
  92. fieldName: 'usersemail',
  93. label: '用户邮箱',
  94. componentProps: {
  95. placeholder: '请输入用户邮箱',
  96. allowClear: true,
  97. },
  98. rules: z.string().min(1, { message: '请输入用户邮箱' }),
  99. },
  100. {
  101. component: 'Input',
  102. fieldName: 'usersaddress',
  103. label: '用户地址',
  104. componentProps: {
  105. placeholder: '请输入用户地址',
  106. allowClear: true,
  107. },
  108. rules: z.string().min(1, { message: '请输入用户地址' }),
  109. },
  110. {
  111. component: 'Input',
  112. fieldName: 'userscontactphone',
  113. label: '用户联系手机号',
  114. componentProps: {
  115. placeholder: '请输入用户联系手机号',
  116. allowClear: true,
  117. },
  118. rules: z.string().min(1, { message: '请输入用户联系手机号' }),
  119. },
  120. {
  121. component: 'Input',
  122. fieldName: 'userscontactemail',
  123. label: '用户联系邮箱',
  124. componentProps: {
  125. placeholder: '请输入用户联系邮箱',
  126. allowClear: true,
  127. },
  128. rules: z.string().min(1, { message: '请输入用户联系邮箱' }),
  129. },
  130. {
  131. component: 'Input',
  132. fieldName: 'userscontactaddress',
  133. label: '用户联系地址',
  134. componentProps: {
  135. placeholder: '请输入用户联系地址',
  136. allowClear: true,
  137. },
  138. rules: z.string().min(1, { message: '请输入用户联系地址' }),
  139. },
  140. ],
  141. });
  142. const [Modal, modalApi] = useVbenModal({
  143. onCancel() {
  144. modalApi.close();
  145. },
  146. async onConfirm() {
  147. // 校验输入的数据
  148. const validate = await baseFormApi.validate();
  149. if (!validate.valid) {
  150. return;
  151. }
  152. modalApi.close();
  153. // const values = await baseFormApi.getValues();
  154. // console.log(Object.keys(values));
  155. },
  156. async onOpenChange(isOpen) {
  157. if (isOpen) {
  158. data.value = modalApi.getData();
  159. if (data.value.create) {
  160. return;
  161. }
  162. try {
  163. // modalApi.setState({ loading: true });
  164. // const detailData = await getCustomerDetailApi({
  165. // usersid: data.value.row.usersid,
  166. // });
  167. // baseFormApi.setValues(detailData);
  168. } catch {
  169. // console.log(error);
  170. }
  171. modalApi.setState({ loading: false });
  172. }
  173. },
  174. });
  175. </script>
  176. <template>
  177. <Modal :title="getTitle">
  178. <BaseForm />
  179. </Modal>
  180. </template>