index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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' },
  97. // { label: '审核', method: 'exam', type: 'warning', display: (i) => i.status == '0' },
  98. { label: '删除', method: 'del', type: 'danger', confirm: true },
  99. ]);
  100. // 多选
  101. let selected: Ref<any[]> = ref([]);
  102. // 总数
  103. let total: Ref<number> = ref(0);
  104. let skip = 0;
  105. let limit: number = proxy.$limit;
  106. // 查询数据
  107. let searchForm: Ref<{}> = ref({});
  108. // 弹框
  109. const dialog: Ref<{ type: string; show: boolean; title: string }> = ref({ type: '1', show: false, title: '信息管理' });
  110. // 审核表单
  111. let form: Ref<{}> = ref({});
  112. // 必填项
  113. const rules = reactive<FormRules>({
  114. status: [{ required: true, message: '请选择审核状态', trigger: 'change' }],
  115. remark: [{ required: true, message: '请输入审核意见', trigger: 'blur' }],
  116. });
  117. // 表单
  118. let infoFields: Ref<any[]> = ref([
  119. { label: '审核状态', model: 'status', type: 'select' },
  120. { label: '审核意见', model: 'remark', type: 'textarea' },
  121. ]);
  122. // 角色
  123. let roleInfo: Ref<{ _id: string }> = ref({ _id: '' });
  124. // 状态
  125. let statusList: Ref<any[]> = ref([]);
  126. let user = store.state.user as { _id: string };
  127. onMounted(async () => {
  128. await searchOther();
  129. await search({ skip, limit });
  130. });
  131. // 查询
  132. const search = async (e: { skip: number; limit: number }) => {
  133. const { skip, limit } = e;
  134. let info = { limit: limit, skip: skip, ...searchForm.value };
  135. const res: IQueryResult = await userStudioApply.query(info);
  136. tableData.value = res.data as any[];
  137. total.value = res.total;
  138. };
  139. // 查询
  140. const partSearch = (form: { [x: string]: any }) => {
  141. searchForm.value = form;
  142. search({ skip, limit });
  143. };
  144. // 修改
  145. const toView = async (data: { _id: string }) => {
  146. router.push({ path: '/center/users/scientist/info', query: { id: data._id } });
  147. };
  148. // 审核
  149. const toExam = (data: object) => {
  150. form.value = data;
  151. dialog.value = { title: '信息管理', show: true, type: '1' };
  152. };
  153. // 审核保存
  154. const toSave = async (data: { _id: string; status: string }) => {
  155. let obj = { _id: data._id, status: data.status };
  156. let res: IQueryResult = await userStudioApply.update(obj);
  157. if (obj.status == '1') updateRole(data);
  158. if (res.errcode == 0) {
  159. ElMessage({ type: 'success', message: '维护信息成功' });
  160. createMess(data);
  161. } else ElMessage({ type: 'warning', message: `${res.errmsg}` });
  162. };
  163. // // 分配角色
  164. const updateRole = async (e) => {
  165. let userInfo = await users.fetch(e.user_id);
  166. let info: any = userInfo.data as {};
  167. if (userInfo.errcode == 0) {
  168. let object = {
  169. _id: info._id,
  170. role: [...info.role, roleInfo.value._id],
  171. };
  172. let res = await users.update(object);
  173. console.log(res.data);
  174. if (res.errcode == 0) ElMessage({ type: 'success', message: '分配角色成功' });
  175. }
  176. };
  177. // // 发送系统消息
  178. const createMess = async (data) => {
  179. let res = await users.fetch(data.user_id);
  180. if (res.errcode == 0) {
  181. let obj = {
  182. user_id: user._id,
  183. title: '审核通知',
  184. send_time: moment().format('YYYY-MM-DD HH:mm:ss'),
  185. type: '3',
  186. user: [{ id: data.user_id, company: data.name, phone: data.phone }],
  187. content: '您好,权限申请,' + `${data.status == '1' ? '已通过审核' : '未通过审核'}` + ',原因:' + data.remark,
  188. };
  189. let arr = await message.create(obj);
  190. if (arr.errcode == 0) {
  191. ElMessage({ type: 'success', message: '系统信息发送成功' });
  192. handleClose();
  193. }
  194. }
  195. };
  196. // 删除
  197. const toDel = async (data: { _id: string; user_id: string }) => {
  198. const res: IQueryResult = await users.fetch(data.user_id);
  199. let p1: any = res.data as {};
  200. if (res.errcode == 0) {
  201. if (p1 && p1._id) {
  202. ElMessage({ type: 'warning', message: '科学家账号暂无删除,无法删除' });
  203. } else {
  204. const p1: IQueryResult = await userStudioApply.del(data._id);
  205. if (p1.errcode == 0) {
  206. ElMessage({ type: 'success', message: '删除成功' });
  207. search({ skip, limit });
  208. }
  209. }
  210. }
  211. };
  212. // 关闭弹窗
  213. const handleClose = () => {
  214. form.value = {};
  215. search({ skip, limit });
  216. dialog.value = { title: '信息管理', show: false, type: '' };
  217. };
  218. // 选择
  219. const handleSelect = () => {};
  220. // 查询其他信息
  221. const searchOther = async () => {
  222. // 字典表---审核状态
  223. const p1: IQueryResult = await sysdictdata.query({ dict_type: 'studio_status' });
  224. statusList.value = p1.data as [];
  225. // 角色
  226. const p2 = await role.query({ code: 'studio-user', account_type: '2', status: 'Y' });
  227. roleInfo.value = p2.data[0] as { _id: string };
  228. };
  229. </script>
  230. <style scoped>
  231. .main .one {
  232. margin: 0 0 10px 0;
  233. }
  234. </style>