adddetailsModal.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @cancel="resetFields"
  5. @register="register"
  6. :title="title"
  7. @ok="handlestd"
  8. >
  9. <div class="BasicForms">
  10. <Select
  11. v-model:value="undefined"
  12. show-search
  13. placeholder="请输入姓名/手机号码/身份证号码搜索"
  14. style="width: 350px"
  15. :default-active-first-option="false"
  16. :show-arrow="false"
  17. :filter-option="false"
  18. not-found-content="暂无数据"
  19. :options="options"
  20. @search="fetchUser"
  21. @change="handleChange"
  22. />
  23. <div class="from" v-if="active && active.name">
  24. <div class="form-item">
  25. <div>姓名</div>{{active.name}} </div>
  26. <div class="form-item">
  27. <div>手机号码</div>{{active.phone || '暂无手机号'}} </div>
  28. <div class="form-item">
  29. <div>身份证</div>{{active.idCard || '暂无身份证'}} </div>
  30. <div class="form-item">
  31. <div>平台</div>{{active.platformName || '未分配'}} </div>
  32. </div>
  33. </div>
  34. </BasicModal>
  35. </template>
  36. <script lang="ts">
  37. import { defineComponent, ref, computed, reactive } from 'vue';
  38. import { checkUserApi, saveAddApi, updateApi, getRoleListByParam } from '/@/api/staff/list'; //roleLIstApi
  39. import { BasicModal, useModalInner } from '/@/components/Modal';
  40. import { BasicForm, FormSchema, useForm } from '/@/components/Form/index';
  41. import { useI18n } from '/@/hooks/web/useI18n';
  42. import { useMessage } from '/@/hooks/web/useMessage';
  43. import { useUserStore } from '/@/store/modules/user';
  44. import { debounce } from 'lodash-es';
  45. import { Select } from 'ant-design-vue';
  46. import { jyPlatformlist, delplatformList } from '/@/api/jyUserPlatform/index'; //roleLIstApi
  47. import { platformallList, jyUserPlatformadd, queryByKey } from '/@/api/jyUserPlatform/index';
  48. const { t } = useI18n();
  49. export default defineComponent({
  50. components: { BasicModal, BasicForm, Select },
  51. props: {
  52. userData: { type: Object },
  53. },
  54. emits: ['ok'],
  55. setup(_, context) {
  56. const modelRef = ref(undefined);
  57. const active = ref({})
  58. const options = ref([]);
  59. const userStore = useUserStore();
  60. const userinfo = computed(() => userStore.getUserInfo);
  61. const preventAutoFill = ref(true);
  62. const { companyId } = userinfo.value;
  63. let lastFetchId = 0;
  64. const fetchUser = debounce((value) => {
  65. if (!value) {
  66. return;
  67. }
  68. lastFetchId += 1;
  69. const fetchId = lastFetchId;
  70. options.value = [];
  71. setFieldsValue({
  72. id: null,
  73. });
  74. queryByKey({ queryKey: value }).then((res) => {
  75. console.log('queryByKey', res);
  76. const data = res.map((user) => ({
  77. ...user,
  78. label: `${user.name}/${user.phone || '暂无手机号码'}/${user.idCard || ''}/${
  79. user.platformName || '未分配'
  80. }`,
  81. value: user.id,
  82. }));
  83. options.value = data;
  84. updateSchema([
  85. {
  86. field: 'id',
  87. ifShow: true,
  88. componentProps: {
  89. options: options.value,
  90. },
  91. },
  92. ]);
  93. });
  94. }, 300);
  95. const schemas: FormSchema[] = [
  96. {
  97. field: 'idkey',
  98. component: 'Input',
  99. label: '账号查询',
  100. required: true,
  101. colProps: {
  102. span: 20,
  103. },
  104. componentProps: {
  105. placeholder: '请输入姓名/手机号码/身份证号码搜索',
  106. onChange: fetchUser,
  107. },
  108. },
  109. {
  110. field: 'id',
  111. component: 'Select',
  112. label: '查询结果',
  113. required: true,
  114. ifShow: false,
  115. colProps: {
  116. span: 20,
  117. },
  118. componentProps: {
  119. placeholder: '请选择平台',
  120. 'label-in-value': true,
  121. options: options.value,
  122. showSearch: true,
  123. onSearch: fetchUser,
  124. numberToString: true,
  125. labelField: 'name',
  126. valueField: 'id',
  127. immediate: true,
  128. // onChange: handleChange,
  129. },
  130. },
  131. ];
  132. const title = ref('添加用户');
  133. const { createMessage, createConfirm } = useMessage();
  134. const [registerForm, { setFieldsValue, validate, updateSchema, resetFields }] = useForm({
  135. labelWidth: 120,
  136. schemas,
  137. showActionButtonGroup: false,
  138. actionColOptions: {
  139. span: 24,
  140. },
  141. });
  142. const [register, { closeModal }] = useModalInner((data) => {
  143. data && onDataReceive(data);
  144. });
  145. function onDataReceive(data) {
  146. console.log('onDataReceive', data);
  147. modelRef.value = undefined;
  148. active.value = {};
  149. // 方式1;
  150. setTimeout(() => {
  151. preventAutoFill.value = false;
  152. updateSchema([
  153. {
  154. field: 'userName',
  155. componentProps: {
  156. readonly: false,
  157. },
  158. },
  159. {
  160. field: 'password',
  161. componentProps: {
  162. readonly: false,
  163. },
  164. },
  165. ]);
  166. // updateSchema(schemas);
  167. }, 500);
  168. }
  169. function companyIdChange(companyId) {
  170. // resetFields(['permList'])
  171. updateSchema([
  172. {
  173. field: 'permList',
  174. componentProps: {
  175. params: {
  176. companyId: companyId,
  177. },
  178. },
  179. },
  180. ]);
  181. setFieldsValue({
  182. permList: [],
  183. });
  184. }
  185. function handlestd(){
  186. if(active.value.platformId){
  187. createConfirm({
  188. title: '提示',
  189. content: '该用户已属其他平台,确定为其更换平台?',
  190. onOk: async () => {
  191. handleOk()
  192. },
  193. });
  194. }else{
  195. handleOk()
  196. }
  197. }
  198. async function handleOk() {
  199. let res = await jyUserPlatformadd({
  200. id: modelRef.value,
  201. });
  202. context && context.emit('ok', res);
  203. createMessage.success(t('common.optSuccess'));
  204. closeModal();
  205. resetFields();
  206. }
  207. function handleChange(value, b ) {
  208. active.value = b;
  209. }
  210. return {
  211. register,
  212. title,
  213. preventAutoFill,
  214. schemas,
  215. registerForm,
  216. modelRef,
  217. handleOk,
  218. resetFields,
  219. fetchUser,
  220. options,
  221. handleChange,
  222. active,
  223. handlestd,
  224. };
  225. },
  226. });
  227. </script>
  228. <style lang="less" scoped>
  229. .BasicForms {
  230. margin: 0 auto;
  231. text-align: center;
  232. }
  233. .from{
  234. width: 350px;
  235. margin: 0 auto;
  236. .form-item{
  237. display: flex;
  238. margin-top: 10px;
  239. div{
  240. width: 60px;
  241. text-align: right;
  242. margin-right: 10px;
  243. }
  244. }
  245. }
  246. </style>