index.vue 7.8 KB

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