index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div id="index">
  3. <el-col class="main animate__animated animate__backInRight">
  4. <el-col :span="24" class="one">
  5. <component :is="partsSearch" :is_search="true" :fields="fields" @search="partSearch">
  6. <template #status>
  7. <el-option v-for="i in statusList" :key="i.model" :label="i.dict_label" :value="i.dict_value"></el-option>
  8. </template>
  9. </component>
  10. </el-col>
  11. <el-col :span="24" class="two">
  12. <component
  13. :is="CTable"
  14. :fields="fields"
  15. :opera="opera"
  16. :select="false"
  17. :selected="selected"
  18. @handleSelect="handleSelect"
  19. @query="search"
  20. :data="tableData"
  21. :total="total"
  22. @view="toView"
  23. @exam="toExam"
  24. @del="toDel"
  25. >
  26. </component>
  27. </el-col>
  28. </el-col>
  29. </div>
  30. <component :is="CDialog" :dialog="dialog" @handleClose="handleClose">
  31. <template v-slot:info>
  32. <component :is="CForm" :fields="infoFields" :rules="rules" :form="form" labelWidth="auto" @save="toSave">
  33. <template #status>
  34. <el-option v-for="(item, index) in statusList" :key="index" :label="item.dict_label" :value="item.dict_value"></el-option>
  35. </template>
  36. </component>
  37. </template>
  38. </component>
  39. </template>
  40. <script setup lang="ts">
  41. import store from '@/stores/counter';
  42. import moment from 'moment';
  43. // #region 组件
  44. import partsSearch from '@/components/c-search.vue';
  45. import CTable from '@/components/c-table.vue';
  46. import CForm from '@/components/c-form.vue';
  47. import CDialog from '@/components/c-dialog.vue';
  48. // #endregion
  49. import type { Ref } from 'vue';
  50. import { ref, onMounted, getCurrentInstance, reactive } from 'vue';
  51. import type { FormRules } from 'element-plus';
  52. import { ElMessage } from 'element-plus';
  53. import { useRouter } from 'vue-router';
  54. // #region 接口
  55. import { UserStudioApplyStore } from '@common/src/stores/studio/role/userStudioApply'; // 列表
  56. import { DictDataStore } from '@common/src/stores/users/sysdictdata'; // 字典表
  57. import { MessageStore } from '@common/src/stores/studio/other/message'; // 系统消息
  58. import { UsersStore } from '@common/src/stores/users/users';
  59. import { RoleStore } from '@common/src/stores/admin/role';
  60. import type { IQueryResult } from '@/util/types.util';
  61. const userStudioApply = UserStudioApplyStore();
  62. const sysdictdata = DictDataStore();
  63. const message = MessageStore();
  64. const role = RoleStore();
  65. const users = UsersStore();
  66. const { proxy } = getCurrentInstance() as any;
  67. const router = useRouter();
  68. // #endregion
  69. // 列表数据
  70. let tableData: Ref<any[]> = ref([]);
  71. // 列表
  72. let fields: Ref<any[]> = ref([
  73. { label: '序号', options: { type: 'index' } },
  74. { label: '姓名', model: 'name', isSearch: true },
  75. { label: '出生年月', model: 'brith' },
  76. { label: '居住地', model: 'live_place' },
  77. { label: '手机号', model: 'phone.phone' },
  78. { label: '电子邮箱', model: 'email.email' },
  79. { label: '团队联系人', model: 'team_name' },
  80. { label: '团队联系电话', model: 'team_phone.phone' },
  81. { label: '所在单位全称', model: 'company', isSearch: true },
  82. {
  83. label: '审核状态',
  84. model: 'status',
  85. type: 'select',
  86. format: (i) => {
  87. let data = statusList.value.find((r) => r.dict_value == i);
  88. if (data) return data.dict_label;
  89. },
  90. isSearch: true,
  91. },
  92. ]);
  93. // 操作
  94. let opera: Ref<any[]> = ref([
  95. { label: '详情', method: 'view' },
  96. { label: '审核', method: 'exam', type: 'warning', display: (i) => i.status == '0' },
  97. { label: '删除', method: 'del', type: 'danger', confirm: true },
  98. ]);
  99. // 多选
  100. let selected: Ref<any[]> = ref([]);
  101. // 总数
  102. let total: Ref<number> = ref(0);
  103. let skip = 0;
  104. let limit: number = proxy.$limit;
  105. // 查询数据
  106. let searchForm: Ref<{}> = ref({});
  107. // 弹框
  108. const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' });
  109. // 审核表单
  110. let form: Ref<{}> = ref({});
  111. // 必填项
  112. const rules = reactive<FormRules>({
  113. status: [{ required: true, message: '请选择审核状态', trigger: 'change' }],
  114. remark: [{ required: true, message: '请输入审核意见', trigger: 'blur' }],
  115. });
  116. // 表单
  117. let infoFields: Ref<any[]> = ref([
  118. { label: '审核状态', model: 'status', type: 'select' },
  119. { label: '审核意见', model: 'remark', type: 'textarea' },
  120. ]);
  121. // 角色
  122. let roleInfo: Ref<{ _id: string }> = ref({ _id: '' });
  123. // 状态
  124. let statusList: Ref<any[]> = ref([]);
  125. onMounted(async () => {
  126. await searchOther();
  127. await search({ skip, limit });
  128. });
  129. // 查询
  130. const search = async (e: { skip: number; limit: number }) => {
  131. const { skip, limit } = e;
  132. let info = { limit: limit, skip: skip, ...searchForm.value };
  133. const res: IQueryResult = await userStudioApply.query(info);
  134. tableData.value = res.data as any[];
  135. total.value = res.total;
  136. };
  137. // 查询
  138. const partSearch = (form: { [x: string]: any }) => {
  139. searchForm.value = form;
  140. search({ skip, limit });
  141. };
  142. // 修改
  143. const toView = async (data: { _id: string }) => {
  144. router.push({ path: '/center/users/scientist/info', query: { id: data._id } });
  145. };
  146. // 审核
  147. const toExam = (data: object) => {
  148. form.value = data;
  149. dialog.value = { title: '信息管理', show: true, type: '1' };
  150. };
  151. // 审核保存
  152. const toSave = async (data: { _id: string; status: string }) => {
  153. let obj = { _id: data._id, status: data.status };
  154. let res: IQueryResult = await userStudioApply.update(obj);
  155. if (obj.status == '1') updateRole(data);
  156. if (res.errcode == 0) {
  157. ElMessage({ type: 'success', message: '维护信息成功' });
  158. createMess(data);
  159. } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  160. };
  161. // // 分配角色
  162. const updateRole = async (e) => {
  163. let userInfo = await users.fetch(e.user_id);
  164. if (userInfo.errcode == 0) {
  165. let object = {
  166. _id: userInfo.data._id,
  167. role: [...userInfo.data.role, roleInfo.value._id],
  168. };
  169. let res = await users.update(object);
  170. if (res.errcode == 0) ElMessage({ type: 'success', message: '分配角色成功' });
  171. }
  172. };
  173. // // 发送系统消息
  174. const createMess = async (data) => {
  175. let user = store.state.user;
  176. let res = await users.fetch(data.user_id);
  177. if (res.errcode == 0) {
  178. let obj = {
  179. user_id: user._id,
  180. title: '审核通知',
  181. send_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  182. type: '3',
  183. user: [{ id: data.user_id, company: data.name, phone: data.phone }],
  184. content: '您好,权限申请,' + `${data.status == '1' ? '已通过审核' : '未通过审核'}` + ',原因:' + data.remark,
  185. };
  186. let arr = await message.create(obj);
  187. if (arr.errcode == 0) {
  188. ElMessage({ type: 'success', message: '系统信息发送成功' });
  189. handleClose();
  190. }
  191. }
  192. };
  193. // 删除
  194. const toDel = async (data: { _id: string; user_id: string }) => {
  195. const res: IQueryResult = await users.fetch(data.user_id);
  196. if (res.errcode == 0) {
  197. if (res.data && res.data._id) {
  198. ElMessage({ type: 'warning', message: '科学家账号暂无删除,无法删除' });
  199. } else {
  200. const p1: IQueryResult = await userStudioApply.delete(data._id);
  201. if (p1.errcode == 0) {
  202. ElMessage({ type: 'success', message: '删除成功' });
  203. search({ skip, limit });
  204. }
  205. }
  206. }
  207. };
  208. // 关闭弹窗
  209. const handleClose = () => {
  210. form.value = {};
  211. search({ skip, limit });
  212. dialog.value = { title: '信息管理', show: false, type: '' };
  213. };
  214. // 选择
  215. const handleSelect = () => {};
  216. // 查询其他信息
  217. const searchOther = async () => {
  218. // 字典表---审核状态
  219. const p1: IQueryResult = await sysdictdata.query({ dict_type: 'studio_status' });
  220. statusList.value = p1.data as [];
  221. // 角色
  222. const p2 = await role.query({ code: 'studio-users', account_type: '3', status: 'Y' });
  223. roleInfo.value = p2.data[0];
  224. };
  225. </script>
  226. <style scoped>
  227. .main .one {
  228. margin: 0 0 10px 0;
  229. }
  230. </style>