detailsModal.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @cancel="resetFields"
  5. @register="register"
  6. :title="title"
  7. :min-height="150"
  8. @ok="handleOk"
  9. >
  10. <BasicForm @register="registerForm" />
  11. </BasicModal>
  12. </template>
  13. <script lang="ts">
  14. import { defineComponent, ref, computed, h } from 'vue';
  15. import { updateUcenterUser } from '/@/api/staff/list'; //roleLIstApi
  16. import { BasicModal, useModalInner } from '/@/components/Modal';
  17. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  18. import { useI18n } from '/@/hooks/web/useI18n';
  19. import { useMessage } from '/@/hooks/web/useMessage';
  20. import { useUserStore } from '/@/store/modules/user';
  21. import { addOrUpdate } from '/@/api/jyUserPlatform/index';
  22. const { t } = useI18n();
  23. export default defineComponent({
  24. components: { BasicModal, BasicForm },
  25. props: {
  26. userData: { type: Object },
  27. },
  28. emits: ['ok'],
  29. setup(_, context) {
  30. const modelRef = ref({});
  31. const userStore = useUserStore();
  32. const userinfo = computed(() => userStore.getUserInfo);
  33. const preventAutoFill = ref(true);
  34. const { companyId } = userinfo.value;
  35. console.log('companyId', companyId);
  36. const schemas: FormSchema[] = [
  37. {
  38. field: 'label1',
  39. component: 'Divider',
  40. label: '平台首页',
  41. colProps: {
  42. span: 24,
  43. },
  44. },
  45. {
  46. field: 'platformName',
  47. component: 'Input',
  48. label: '平台名称',
  49. required: true,
  50. colProps: {
  51. span: 20,
  52. },
  53. componentProps: {
  54. maxLength: 50,
  55. required: true,
  56. },
  57. },
  58. {
  59. field: 'label2',
  60. component: 'Divider',
  61. label: '平台管理员',
  62. colProps: {
  63. span: 24,
  64. },
  65. },
  66. {
  67. field: 'name',
  68. component: 'Input',
  69. label: '姓名',
  70. colProps: {
  71. span: 20,
  72. },
  73. required: true,
  74. componentProps: {
  75. maxLength: 18,
  76. },
  77. },
  78. {
  79. field: 'idCard',
  80. component: 'Input',
  81. required: true,
  82. label: '身份证',
  83. colProps: {
  84. span: 20,
  85. },
  86. componentProps: {
  87. maxLength: 18,
  88. },
  89. },
  90. // {
  91. // field: 'phone',
  92. // component: 'Input',
  93. // required: true,
  94. // label: '手机号码',
  95. // colProps: {
  96. // span: 20,
  97. // },
  98. // componentProps: {
  99. // maxLength: 15,
  100. // },
  101. // },
  102. {
  103. field: 'id',
  104. component: 'Input',
  105. label: 'id',
  106. show: false,
  107. },
  108. ];
  109. const title = ref('创建平台');
  110. const { createMessage, createConfirm } = useMessage();
  111. const [registerForm, { setFieldsValue, validate, updateSchema, resetFields }] = useForm({
  112. labelWidth: 120,
  113. schemas,
  114. showActionButtonGroup: false,
  115. actionColOptions: {
  116. span: 24,
  117. },
  118. });
  119. const [register, { closeModal }] = useModalInner((data) => {
  120. data && onDataReceive(data);
  121. });
  122. function onDataReceive(data) {
  123. // 方式1;
  124. title.value = data.id ? '修改平台' : '启用平台';
  125. // preventAutoFill.value = false
  126. setTimeout(() => {
  127. console.log('useModalInner', data);
  128. setFieldsValue({
  129. ...data,
  130. userName: '',
  131. password: '',
  132. roleId: data.roleId != 2 ? data.roleId : '',
  133. });
  134. }, 200);
  135. }
  136. function companyIdChange(companyId) {
  137. // resetFields(['permList'])
  138. updateSchema([
  139. {
  140. field: 'permList',
  141. componentProps: {
  142. params: {
  143. companyId: companyId,
  144. },
  145. },
  146. },
  147. ]);
  148. setFieldsValue({
  149. permList: [],
  150. });
  151. }
  152. async function handleOk() {
  153. let data = await validate();
  154. let res = await addOrUpdate({
  155. ...data,
  156. // userName: data.phone,
  157. phone: data.phone,
  158. nickName: data.nickName,
  159. roleId: data.roleId,
  160. id: data.id,
  161. });
  162. console.log('res', res);
  163. context && context.emit('ok', res);
  164. createConfirm({
  165. iconType: 'warning',
  166. title: () => h('span', data.id ? '修改成功' : '平台创建成功'),
  167. content: () =>
  168. h('div', {}, [
  169. h('div', null, `平台名称:${res.platformName}`),
  170. h('div', null, `平台地址:${res.platformAddress}`),
  171. h('div', null, `平台管理员:${res.name}`),
  172. ]),
  173. onOk: async () => {
  174. // await this.logout(true);
  175. },
  176. });
  177. createMessage.success(t('common.optSuccess'));
  178. closeModal();
  179. resetFields();
  180. }
  181. return {
  182. register,
  183. title,
  184. preventAutoFill,
  185. schemas,
  186. registerForm,
  187. modelRef,
  188. handleOk,
  189. resetFields,
  190. };
  191. },
  192. });
  193. </script>
  194. .