index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 { OfficeStore } from '@/stores/office/office';
  35. import { RoleStore } from '@/stores/role/role'; // 角色
  36. import { DictDataStore } from '@/stores/dict/dictData'; // 字典表
  37. import type { IQueryResult } from '@/util/types.util';
  38. const userAxios = UserStore();
  39. const dictAxios = DictDataStore();
  40. const officeAxios = OfficeStore();
  41. const roleAxios = RoleStore();
  42. const { proxy } = getCurrentInstance() as any;
  43. // 路由
  44. const router = useRouter();
  45. // 加载中
  46. const loading: Ref<any> = ref(false);
  47. let list: Ref<any> = ref([]);
  48. let total: Ref<number> = ref(0);
  49. let skip = 0;
  50. let limit: number = proxy.$limit;
  51. let fields: Ref<any[]> = ref([
  52. { label: '微信用户标识', model: 'openid' },
  53. { label: '手机号', model: 'tel', isSearch: true },
  54. { label: '姓名', model: 'name', isSearch: true },
  55. { label: '性别', model: 'gender', format: (i: any) => getDict(i, genderList.value, 'dict') },
  56. { label: '角色', model: 'role', format: (i: any) => getDict(i, roleList.value, 'role') },
  57. { label: '所属街道', model: 'street', format: (i: any) => getDict(i, belongList.value) },
  58. { label: '所属社区', model: 'community', format: (i: any) => getDict(i, belongList.value) },
  59. { label: '状态', model: 'status', format: (i: any) => getDict(i, statusList.value, 'dict') }
  60. ]);
  61. // 操作
  62. let opera: Ref<any[]> = ref([
  63. { label: '审核', method: 'exam', type: 'warning', display: (i) => i.status == '0' },
  64. { label: '修改', method: 'edit' },
  65. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  66. ]);
  67. // 查询数据
  68. let searchForm: Ref<any> = ref({});
  69. // 字典表
  70. const genderList: Ref<any> = ref([]);
  71. const roleList: Ref<any> = ref([]);
  72. const belongList: Ref<any> = ref([]);
  73. const statusList: Ref<any> = ref([]);
  74. // 弹框
  75. const dialog: Ref<any> = ref({ title: '审核管理', show: false, type: '1' });
  76. const form: Ref<any> = ref({ file: [] });
  77. const formFields: Ref<any> = ref([{ label: '状态', model: 'status', type: 'select' }]);
  78. // 请求
  79. onMounted(async () => {
  80. loading.value = true;
  81. await searchOther();
  82. await search({ skip, limit });
  83. loading.value = false;
  84. });
  85. const search = async (e: { skip: number; limit: number }) => {
  86. const info = { skip: e.skip, limit: e.limit, ...searchForm.value, role: 'ld' };
  87. const res: IQueryResult = await userAxios.query(info);
  88. if (res.errcode == '0') {
  89. list.value = res.data;
  90. total.value = res.total;
  91. }
  92. };
  93. const toSearch = (query) => {
  94. searchForm.value = query;
  95. search({ skip, limit });
  96. };
  97. const getDict = (e, model, type) => {
  98. if (type == 'dict') {
  99. let data: any = model.find((i: any) => i.value == e);
  100. if (data) return data.label;
  101. else return '暂无';
  102. } else if (type == 'role') {
  103. let data: any = model.find((i: any) => i.code == e);
  104. if (data) return data.name;
  105. else return '暂无';
  106. } else {
  107. let data: any = model.find((i: any) => i._id == e);
  108. if (data) return data.name;
  109. else return '暂无';
  110. }
  111. };
  112. // 审核
  113. const toExam = async (data) => {
  114. let res: IQueryResult = await userAxios.fetch(data._id);
  115. if (res.errcode == '0') {
  116. form.value = res.data;
  117. dialog.value = { title: '审核管理', show: true, type: '1' };
  118. }
  119. };
  120. // 提交保存
  121. const toSave = async (data) => {
  122. let res: IQueryResult = await userAxios.update(data);
  123. if (res.errcode == '0') {
  124. ElMessage({ message: '信息审核成功', type: 'success' });
  125. toClose();
  126. } else {
  127. ElMessage({ message: `${res.errmsg}`, type: 'error' });
  128. }
  129. };
  130. // 修改
  131. const toEdit = (data) => {
  132. router.push({ path: '/users/match/detail', query: { id: data._id } });
  133. };
  134. // 删除
  135. const toDel = async (data: any) => {
  136. let res: IQueryResult = await userAxios.del(data._id);
  137. if (res.errcode == 0) {
  138. ElMessage({ type: `success`, message: `刪除信息成功` });
  139. search({ skip, limit });
  140. }
  141. };
  142. // 关闭弹框
  143. const toClose = () => {
  144. form.value = {};
  145. dialog.value = { show: false };
  146. search({ skip, limit });
  147. };
  148. // 查询其他信息
  149. const searchOther = async () => {
  150. let res: IQueryResult;
  151. // 性别
  152. res = await dictAxios.query({ type: 'gender', is_use: '0' });
  153. if (res.errcode == '0') genderList.value = res.data;
  154. // 角色
  155. res = await roleAxios.query({ type: 'role', is_use: '0' });
  156. if (res.errcode == '0') roleList.value = res.data;
  157. // 所属
  158. res = await officeAxios.query({ is_use: '0' });
  159. if (res.errcode == '0') belongList.value = res.data;
  160. // 状态
  161. res = await dictAxios.query({ type: 'status', is_use: '0' });
  162. if (res.errcode == '0') statusList.value = res.data;
  163. };
  164. </script>
  165. <style scoped lang="scss">
  166. .main {
  167. .two {
  168. margin: 0 0 10px 0;
  169. }
  170. }
  171. </style>