index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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">
  7. <template #area>
  8. <el-option v-for="i in areaList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  9. </template>
  10. <template #status>
  11. <el-option v-for="i in statusList" :key="i.value" :label="i.label" :value="i.value"></el-option>
  12. </template>
  13. </cSearch>
  14. </el-col>
  15. <el-col :span="24" class="two">
  16. <cButton @toAdd="toAdd()"> </cButton>
  17. </el-col>
  18. <el-col :span="24" class="thr">
  19. <cTable :fields="fields" :opera="opera" :list="list" @query="search" :total="total" @view="toView" @edit="toEdit" @exam="toExam" @del="toDel">
  20. </cTable>
  21. </el-col>
  22. </el-col>
  23. </el-row>
  24. <cDialog :dialog="dialog" @handleClose="toClose">
  25. <template v-slot:info>
  26. <cForm v-if="dialog.type == '1'" :span="24" :fields="formFields" :form="form" :rules="{}" @save="onSubmit">
  27. <template #status>
  28. <el-option v-for="(i, index) in statusList" :key="index" :label="i.label" :value="i.value"></el-option>
  29. </template>
  30. <template #role>
  31. <el-select v-model="form.role" multiple placeholder="请选择角色" style="width: 100%">
  32. <el-option v-for="i in roleList" :key="i._id" :label="`${i.name}(${i.code})`" :value="i._id"> </el-option>
  33. </el-select>
  34. </template>
  35. </cForm>
  36. </template>
  37. </cDialog>
  38. </div>
  39. </template>
  40. <script lang="ts" setup>
  41. import _ from 'lodash';
  42. import type { Ref } from 'vue';
  43. import { ref, onMounted, getCurrentInstance } from 'vue';
  44. import { useRouter } from 'vue-router';
  45. import { ElMessage } from 'element-plus';
  46. // 接口
  47. import { ExpertStore } from '@common/src/stores/admins/expert';
  48. import { DictDataStore } from '@common/src/stores/system/dictData'; // 字典表
  49. import { RoleStore } from '@common/src/stores/system/role'; // 角色
  50. import type { IQueryResult } from '@/util/types.util';
  51. const expert = ExpertStore();
  52. const dictData = DictDataStore();
  53. const roleAxios = RoleStore();
  54. const { proxy } = getCurrentInstance() as any;
  55. // 路由
  56. const router = useRouter();
  57. // 加载中
  58. const loading = ref(false);
  59. // 列表数据
  60. let list: Ref<any> = ref([]);
  61. // 总数
  62. let total: Ref<number> = ref(0);
  63. let skip = 0;
  64. let limit: number = proxy.$limit;
  65. // 列表
  66. let fields: Ref<any[]> = ref([
  67. { label: '邀请码', model: 'code', isSearch: true },
  68. { label: '账号', model: 'account', isSearch: true },
  69. { label: '用户名', model: 'name', isSearch: true },
  70. { label: '手机号', model: 'phone', isSearch: true },
  71. { label: '所属辖区', model: 'area', format: (i) => getDict(i, 'area'), isSearch: true, type: 'select' },
  72. { label: '审核状态', model: 'status', format: (i) => getDict(i, 'status'), isSearch: true, type: 'select' }
  73. ]);
  74. // 操作
  75. let opera: Ref<any[]> = ref([
  76. { label: '查看', method: 'view', type: 'success' },
  77. { label: '审核/角色', method: 'exam' },
  78. { label: '修改', method: 'edit' },
  79. { label: '删除', method: 'del', confirm: true, type: 'danger' }
  80. ]);
  81. const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' });
  82. let form: Ref<any> = ref({});
  83. // 表单
  84. let formFields: Ref<any[]> = ref([
  85. { label: '状态', model: 'status', type: 'select' },
  86. { label: '角色', model: 'role', custom: true }
  87. ]);
  88. // 查询数据
  89. let searchForm: Ref<any> = ref({});
  90. // 字典表
  91. let statusList: Ref<any> = ref([]);
  92. let areaList: Ref<any> = ref([]);
  93. const roleList: Ref<any> = ref([]);
  94. onMounted(async () => {
  95. loading.value = true;
  96. await searchOther();
  97. await search({ skip, limit });
  98. loading.value = false;
  99. });
  100. // 查询
  101. const search = async (e: { skip: number; limit: number }) => {
  102. const { skip, limit } = e;
  103. const condition = _.cloneDeep(searchForm.value);
  104. let info = { limit: limit, skip: skip, ...condition, type: '6' };
  105. let res: IQueryResult = await expert.query(info);
  106. if (res.errcode == 0) {
  107. list.value = res.data;
  108. total.value = res.total;
  109. }
  110. };
  111. const toSearch = (query) => {
  112. searchForm.value = query;
  113. search({ skip, limit });
  114. };
  115. const getDict = (e, model) => {
  116. if (model == 'status') {
  117. let data: any = statusList.value.find((i: any) => i.value == e);
  118. if (data) return data.label;
  119. else return '暂无';
  120. } else if (model == 'area') {
  121. let data: any = areaList.value.find((i: any) => i.value == e);
  122. if (data) return data.label;
  123. else return '暂无';
  124. }
  125. };
  126. // 新增
  127. const toAdd = () => {
  128. router.push({ path: '/user/expert/detail' });
  129. };
  130. const toView = (data) => {
  131. router.push({ path: '/user/expert/detail', query: { id: data._id, isdisabled: `${true}` } });
  132. };
  133. // 修改
  134. const toEdit = async (data) => {
  135. router.push({ path: '/user/expert/detail', query: { id: data._id } });
  136. };
  137. const toExam = async (data) => {
  138. let res: IQueryResult = await expert.fetch(data._id);
  139. if (res.errcode == 0) {
  140. form.value = res.data;
  141. dialog.value = { title: '信息管理', show: true, type: '1' };
  142. }
  143. };
  144. // 提交
  145. const onSubmit = async (data) => {
  146. let res: IQueryResult;
  147. if (data._id) res = await expert.update(data);
  148. else res = await expert.create(data);
  149. if (res.errcode == 0) {
  150. ElMessage({ type: `success`, message: `审核成功` });
  151. toClose();
  152. }
  153. };
  154. // 弹框关闭
  155. const toClose = () => {
  156. form.value = {};
  157. searchForm.value = {};
  158. dialog.value = { title: '信息管理', show: false, type: '1' };
  159. search({ skip, limit });
  160. };
  161. // 删除
  162. const toDel = async (data) => {
  163. let res: IQueryResult = await expert.del(data._id);
  164. if (res.errcode == 0) {
  165. ElMessage({ type: `success`, message: `刪除信息成功` });
  166. search({ skip, limit });
  167. }
  168. };
  169. const searchOther = async () => {
  170. let res: IQueryResult;
  171. // 状态
  172. res = await dictData.query({ type: 'common_status' });
  173. if (res.errcode == 0) statusList.value = res.data;
  174. // 状态
  175. res = await dictData.query({ type: 'jl_area' });
  176. if (res.errcode == 0) areaList.value = res.data;
  177. // 角色
  178. res = await roleAxios.query({ account_type: '6', is_use: '0' });
  179. if (res.errcode == 0) roleList.value = res.data;
  180. };
  181. </script>
  182. <style lang="scss" scoped>
  183. .main {
  184. .one {
  185. margin: 0 0 10px 0;
  186. }
  187. .two {
  188. margin: 0 0 10px 0;
  189. }
  190. }
  191. </style>