index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div id="index">
  3. <el-row>
  4. <el-col :span="24" class="main animate__animated animate__backInRight" v-loading="loading">
  5. <el-col :span="24" class="one">
  6. <cSearch :is_title="false" :is_search="true" :fields="fields" @search="toSearch"> </cSearch>
  7. </el-col>
  8. <el-col :span="24" class="two">
  9. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @exam="toExam" @edit="toEdit" @del="toDel"> </cTable>
  10. </el-col>
  11. </el-col>
  12. </el-row>
  13. <cDialog :dialog="dialog" @toClose="toClose">
  14. <template v-slot:info>
  15. <el-col :span="24" class="dialog_one" v-if="dialog.type == '1'">
  16. <cForm :span="24" :fields="formFields" :form="form" :rules="{}" @save="toSave" label-width="auto">
  17. <template #status>
  18. <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  19. </template>
  20. </cForm>
  21. </el-col>
  22. </template>
  23. </cDialog>
  24. </div>
  25. </template>
  26. <script setup lang="ts">
  27. // 基础
  28. import type { Ref } from 'vue';
  29. import { onMounted, ref, getCurrentInstance } from 'vue';
  30. import { ElMessage } from 'element-plus';
  31. import { useRouter } from 'vue-router';
  32. // 接口
  33. import { UserStore } from '@/stores/users/user';
  34. import { DictDataStore } from '@/stores/dict/dictData'; // 字典表
  35. import type { IQueryResult } from '@/util/types.util';
  36. const userAxios = UserStore();
  37. const dictAxios = DictDataStore();
  38. const { proxy } = getCurrentInstance() as any;
  39. // 路由
  40. const router = useRouter();
  41. // 加载中
  42. const loading: Ref<any> = ref(false);
  43. let list: Ref<any> = ref([]);
  44. let total: Ref<number> = ref(0);
  45. let skip = 0;
  46. let limit: number = proxy.$limit;
  47. let fields: Ref<any[]> = ref([
  48. { label: '微信用户标识', model: 'openid' },
  49. { label: '手机号', model: 'tel', isSearch: true },
  50. { label: '用户姓名', model: 'name', isSearch: true },
  51. { label: '姓名', model: 'name', isSearch: true },
  52. { label: '性别', model: 'gender', format: (i: any) => getDict(i, 'gender') },
  53. { label: '角色', model: 'role', format: (i: any) => getDict(i, 'role') },
  54. { label: '所属', model: 'belong', format: (i: any) => getDict(i, 'belong') },
  55. { label: '状态', model: 'status', format: (i: any) => getDict(i, 'status') }
  56. ]);
  57. // 操作
  58. let opera: Ref<any[]> = ref([
  59. { label: '审核', method: 'exam', type: 'warning', display: (i) => i.status == '0' },
  60. { label: '修改', method: 'edit' },
  61. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  62. ]);
  63. // 查询数据
  64. let searchForm: Ref<any> = ref({});
  65. // 字典表
  66. const genderList: Ref<any> = ref([]);
  67. const roleList: Ref<any> = ref([]);
  68. const belongList: Ref<any> = ref([]);
  69. const statusList: Ref<any> = ref([]);
  70. // 弹框
  71. const dialog: Ref<any> = ref({ title: '审核管理', show: false, type: '1' });
  72. const form: Ref<any> = ref({ file: [] });
  73. const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
  74. // 请求
  75. onMounted(async () => {
  76. loading.value = true;
  77. await searchOther();
  78. await search({ skip, limit });
  79. loading.value = false;
  80. });
  81. const search = async (e: { skip: number; limit: number }) => {
  82. const info = { skip: e.skip, limit: e.limit, ...searchForm.value, type: '0' };
  83. const res: IQueryResult = await userAxios.query(info);
  84. if (res.errcode == '0') {
  85. list.value = res.data;
  86. total.value = res.total;
  87. }
  88. };
  89. const toSearch = (query) => {
  90. searchForm.value = query;
  91. search({ skip, limit });
  92. };
  93. const getDict = (e, model) => {
  94. if (model == 'role') {
  95. let data: any = roleList.value.find((i: any) => i.value == e);
  96. if (data) return data.label;
  97. else return '暂无';
  98. } else if (model == 'status') {
  99. let data: any = statusList.value.find((i: any) => i.value == e);
  100. if (data) return data.label;
  101. else return '暂无';
  102. }
  103. };
  104. // 审核
  105. const toExam = async (data) => {
  106. let res: IQueryResult = await userAxios.fetch(data._id);
  107. if (res.errcode == '0') {
  108. form.value = res.data;
  109. dialog.value = { title: '审核管理', show: true, type: '1' };
  110. }
  111. };
  112. // 提交保存
  113. const toSave = async (data) => {
  114. let res: IQueryResult = await userAxios.update(data);
  115. if (res.errcode == '0') {
  116. ElMessage({ message: '信息审核成功', type: 'success' });
  117. toClose();
  118. } else {
  119. ElMessage({ message: `${res.errmsg}`, type: 'error' });
  120. }
  121. };
  122. // 修改
  123. const toEdit = (data) => {
  124. router.push({ path: '/users/match/detail', query: { id: data._id } });
  125. };
  126. // 删除
  127. const toDel = async (data: any) => {
  128. let res: IQueryResult = await userAxios.del(data._id);
  129. if (res.errcode == 0) {
  130. ElMessage({ type: `success`, message: `刪除信息成功` });
  131. search({ skip, limit });
  132. }
  133. };
  134. // 关闭弹框
  135. const toClose = () => {
  136. form.value = {};
  137. dialog.value = { show: false };
  138. search({ skip, limit });
  139. };
  140. // 查询其他信息
  141. const searchOther = async () => {
  142. let res: IQueryResult;
  143. // 性别
  144. res = await dictAxios.query({ type: 'gender' });
  145. if (res.errcode == '0') genderList.value = res.data;
  146. // 角色
  147. res = await dictAxios.query({ type: 'role' });
  148. if (res.errcode == '0') roleList.value = res.data;
  149. // 所属
  150. res = await dictAxios.query({ type: 'type' });
  151. if (res.errcode == '0') belongList.value = res.data;
  152. // 状态
  153. res = await dictAxios.query({ type: 'status' });
  154. if (res.errcode == '0') statusList.value = res.data;
  155. };
  156. </script>
  157. <style scoped lang="scss">
  158. .main {
  159. .two {
  160. margin: 0 0 10px 0;
  161. }
  162. }
  163. </style>