index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <template>
  2. <div class="card-search">
  3. <a-form ref="formRef" name="advanced_search" class="ant-advanced-search-form" :model="searchParams" >
  4. <a-row :gutter="24">
  5. <a-col :span="6">
  6. <a-form-item label="人员名称" :label-col="{span:8}" name="siteUserName">
  7. <a-input v-model:value="searchParams.siteUserName" placeholder="" :allow-clear="true"/>
  8. </a-form-item>
  9. </a-col>
  10. <a-col :span="6">
  11. <a-form-item label="工号" :label-col="{span:8}" name="userNo">
  12. <a-input v-model:value="searchParams.userNo" placeholder="" :allow-clear="true"/>
  13. </a-form-item>
  14. </a-col>
  15. <a-col :span="6">
  16. <a-form-item label="所属驿站" :label-col="{span:8}" name="siteID">
  17. <a-select
  18. ref="select"
  19. v-model:value="searchParams.siteID"
  20. :options="allSites"
  21. @change="loadData"
  22. :field-names="{ label: 'siteName', value: 'siteID' }"
  23. :allow-clear="true"
  24. style="width: 200px" >
  25. </a-select>
  26. </a-form-item>
  27. </a-col>
  28. <a-col :span="6" style="text-align: left">
  29. <a-button type="primary" html-type="submit" @click="onSearch">查询</a-button>
  30. <a-button
  31. style="margin: 0 8px"
  32. @click="
  33. () => {
  34. formRef.resetFields();
  35. loadData();
  36. }
  37. ">重置</a-button>
  38. </a-col>
  39. </a-row>
  40. <a-row class="edit-operation">
  41. <a-col :span="24" class="flex-space-between">
  42. <div>
  43. <!-- 表格字段筛选按钮 -->
  44. <ColumnsSetting :table-columns="originalColumns" :checked-table-columns="columns"
  45. @on-check="columnsCheckSub"></ColumnsSetting>
  46. </div>
  47. <div>
  48. <a-button type="primary" html-type="submit" functioncode="T01010302" @click='onAdd'>新增</a-button>
  49. <BImportExcel functioncode="T01010306"
  50. :options="importOptions"
  51. @success="loadData"
  52. ></BImportExcel>
  53. <BExportExcel :title="'导出'" :filename="'驿站人员信息'" :url="'userInfo/export'"
  54. :params="{...exportSearchParams, rows:100000,siteUserIDList:formState.selectedRowKeys.join(',')}"></BExportExcel>
  55. </div>
  56. </a-col>
  57. </a-row>
  58. </a-form>
  59. <div class="search-result-list">
  60. <a-table :columns="columns" :data-source="dataList" :scroll="{ x:'100%', y: 500 }" :pagination="pagination"
  61. :loading="formState.loading"
  62. @change="handleTableChange"
  63. :row-selection="{ selectedRowKeys: formState.selectedRowKeys, onChange: onSelectChange}"
  64. :row-key="record=>record.siteUserID"
  65. bordered>
  66. <template #bodyCell="{ column, text, record }">
  67. <template v-if="column.key === 'operation'">
  68. <div class="table-operation">
  69. <a-button type="link" size="small" functioncode="T01010301" @click='onDetail(record.siteUserID)'>查看
  70. </a-button>
  71. <a-button type="link" size="small" functioncode="T01010303" @click='onEdit(record.siteUserID)' >编辑</a-button>
  72. <a-button type="link" size="small" functioncode="T01010304" @click="onDel(record)" >删除</a-button>
  73. <a-button type="link" size="small" functioncode="T01010307" @click="onChangeStatus(record.userID,record.recordStatus==1?0:1)" >{{ record.recordStatus==1?"禁用":"启用" }}</a-button>
  74. </div>
  75. </template>
  76. </template>
  77. </a-table>
  78. </div>
  79. </div>
  80. </template>
  81. <script lang="ts">
  82. import {computed, createVNode, defineComponent, reactive, ref} from 'vue';
  83. import {useTabsViewStore} from "@/store/modules/tabsView";
  84. import {DownOutlined, ExclamationCircleOutlined, UpOutlined} from '@ant-design/icons-vue';
  85. import type {FormInstance, TableProps} from 'ant-design-vue';
  86. import {message, Modal} from "ant-design-vue";
  87. import {delSiteUser, getSiteUserList} from '@/api/baseSettings/userInfo';
  88. import BExportExcel from "@/components/basic/excel/exportExcel/exportExcel.vue";
  89. import {getPaginationTotalTitle} from "@/utils/common";
  90. import {getSiteList} from "@/api/baseSettings/siteInfo";
  91. import BImportExcel from "@/components/basic/excel/importExcel/importExcel.vue";
  92. import type {ImportProps} from "@/components/basic/excel/importExcel/ImportProps";
  93. import {updateUserStatus} from "@/api/system/user";
  94. import ColumnsSetting from "@/components/common/ColumnsSetting.vue";
  95. export default defineComponent({
  96. name: 'UserInfoList',
  97. components: {ColumnsSetting, BImportExcel, DownOutlined, UpOutlined, BExportExcel},
  98. setup() {
  99. const formRef = ref<FormInstance>();
  100. const tabsViewStore = useTabsViewStore();
  101. const allSites = ref<any>([]);
  102. const searchParams = reactive({
  103. pageIndex: 1,
  104. pageSize: 20,
  105. siteUserName: '',
  106. siteID: '',
  107. userNo: ""
  108. });
  109. // 导出Excel查询参数
  110. const exportSearchParams = computed(() => {
  111. let data = JSON.parse(JSON.stringify(searchParams));
  112. data.pageSize = formState.total;
  113. return data;
  114. })
  115. const formState = reactive({
  116. total: 0,
  117. selectedRowKeys: [],
  118. loading: false
  119. });
  120. // 原始表格定义数据
  121. const originalColumns = [
  122. {
  123. title: '序号',
  124. align: "center",
  125. key: 'siteUserID',
  126. customRender: item => `${searchParams.pageSize * (searchParams.pageIndex - 1) + item.index + 1}`,
  127. isDisabled: true
  128. },
  129. {title: '工号', dataIndex: 'userNo', key: 'userNo', align: "center"},
  130. {title: '人员名称', dataIndex: 'siteUserName', key: 'siteUserName', align: "center"},
  131. {title: '是否驿站站长', dataIndex: 'isSiteAdmin', key: 'isSiteAdmin', align: "center"},
  132. {title: '性别', dataIndex: 'genderName', key: 'genderName', align: "center"},
  133. {title: '联系电话', dataIndex: 'mobile', key: 'mobile', align: "center"},
  134. {
  135. title: '年龄', dataIndex: 'age', key: 'age', align: "center",
  136. customRender: item => {
  137. return calculateAge(item.record.idCard);
  138. }
  139. },
  140. {title: '所属驿站', dataIndex: 'siteName', key: 'siteName', align: "center"},
  141. {title: '用户类型', dataIndex: 'roleName', key: 'roleName', width: 120, align: "center", isDefaultClose: true},
  142. {
  143. title: '状态', dataIndex: 'recordStatus', key: 'recordStatus', align: "center",
  144. customRender: ({record}) => record.recordStatus == 1 ? "正常" : "禁用",
  145. isDefaultClose: true
  146. },
  147. {title: '操作', key: 'operation', fixed: 'right', width: 200, align: "center", isDisabled: true},
  148. ];
  149. // 响应式表格定义
  150. const columns = ref<Array<any>>(originalColumns.filter(item => !item.isDefaultClose));
  151. const importOptions = ref<ImportProps>({
  152. title: '导入',
  153. url: 'userInfo/importSiteUser',
  154. columns: [
  155. {cnName: '姓名', enName: 'siteUserName', width: 100},
  156. {cnName: '工号', enName: 'userNo', width: 100},
  157. {cnName: '性别', enName: 'genderName', width: 100},
  158. {cnName: '联系电话', enName: 'mobile', width: 100},
  159. {cnName: '身份证号码', enName: 'idCard', width: 140},
  160. {cnName: '用户类型', enName: 'roleName', width: 100},
  161. {cnName: '所属驿站', enName: 'siteName', width: 100},
  162. {cnName: '社会保障卡号', enName: 'socialSecurityCard', width: 150},
  163. {cnName: '民族', enName: 'nationName', width: 100},
  164. {cnName: '政治面貌', enName: 'politicsStatusName', width: 100},
  165. {cnName: '最高学历', enName: 'cultureRankName', width: 100},
  166. {cnName: '毕业院校', enName: 'finishSchool', width: 100},
  167. {cnName: '专业', enName: 'profession', width: 100},
  168. {cnName: '是否全日制', enName: 'isFullTimeName', width: 130},
  169. {cnName: '职业资格类别', enName: 'occupationalCategoryName', width: 140},
  170. {cnName: '职业资格等级', enName: 'occupationalLevelName', width: 140},
  171. {cnName: '籍贯', enName: 'nativePlace', width: 120},
  172. {cnName: '电子邮箱', enName: 'email', width: 150},
  173. {cnName: '现住址', enName: 'address', width: 150},
  174. ],
  175. template: {
  176. tempFileName: '站点人员导入模板.xlsx',
  177. url: '',
  178. params: null,
  179. },
  180. });
  181. const pagination = computed(() => ({
  182. total: formState.total,
  183. current: searchParams.pageIndex,
  184. pageSize: searchParams.pageSize,
  185. showSizeChanger: true,
  186. showTotal: total => getPaginationTotalTitle(total)
  187. }));
  188. const calculateAge = (idCardNumber) => {
  189. if (!idCardNumber) {
  190. return "";
  191. }
  192. try {
  193. // 假设身份证号中出生日期的格式为YYYYMMDD
  194. const birthYear = parseInt(idCardNumber.substring(6, 10), 10);
  195. const birthMonth = parseInt(idCardNumber.substring(10, 12), 10);
  196. const birthDay = parseInt(idCardNumber.substring(12, 14), 10);
  197. // 获取当前日期
  198. const currentDate = new Date();
  199. const currentYear = currentDate.getFullYear();
  200. const currentMonth = currentDate.getMonth() + 1; // 月份从 0 开始
  201. const currentDay = currentDate.getDate();
  202. // 计算年龄
  203. let age = currentYear - birthYear;
  204. if (currentMonth < birthMonth || (currentMonth === birthMonth && currentDay < birthDay)) {
  205. age--; // 生日还未过,减去一岁
  206. }
  207. if (Number.isNaN(age) || !Number.isInteger(age)) {
  208. return "";
  209. }
  210. return age;
  211. } catch (e) {
  212. return "";
  213. }
  214. }
  215. const getAllSites = () => {
  216. getSiteList({
  217. pageIndex:1,
  218. pageSize:9999
  219. }).then((result :any) => {
  220. allSites.value = result.list;
  221. })
  222. }
  223. const dataList = ref([]);
  224. const handleTableChange: TableProps['onChange'] = (pag: { pageSize: number; current: number },) => {
  225. searchParams.pageIndex = pag.current;
  226. searchParams.pageSize = pag.pageSize;
  227. loadData();
  228. };
  229. const onSelectChange = (selectedRowKeys: any) => {
  230. formState.selectedRowKeys = selectedRowKeys;
  231. };
  232. const onSearch = () => {
  233. loadData();
  234. }
  235. const onDel= (item: any) => {
  236. formState.selectedRowKeys = [];
  237. if (item) {
  238. formState.selectedRowKeys.push(item.siteUserID as never)
  239. }
  240. if (formState.selectedRowKeys.length <= 0) {
  241. message.warning('请选择需要删除的数据!');
  242. return false;
  243. }
  244. Modal.confirm({
  245. title: '确认删除选中的站点人员?',
  246. icon: createVNode(ExclamationCircleOutlined),
  247. content: '',
  248. okText: '确认删除',
  249. okType: 'danger',
  250. okButtonProps: {},
  251. cancelText: '取消',
  252. onOk() {
  253. delSiteUser(formState.selectedRowKeys).then(() => {
  254. loadData();
  255. });
  256. },
  257. onCancel() {
  258. formState.selectedRowKeys = [];
  259. },
  260. });
  261. };
  262. const onChangeStatus = (userID: any,statusValue:any) => {
  263. updateUserStatus({ userId: userID,status:statusValue });
  264. loadData();
  265. };
  266. const loadData = async function () {
  267. formState.loading = true;
  268. await getAllSites();
  269. const result: any = await getSiteUserList(searchParams);
  270. dataList.value = result.list;
  271. formState.total = result.total;
  272. if (result.nextPage <= 1) {
  273. // 设置分页最大页码
  274. searchParams.pageIndex = 1;
  275. }
  276. formState.loading = false;
  277. }
  278. const onAdd =()=>{
  279. tabsViewStore.addTabByPath('/baseSettings/user/add', {id:null,op:1});
  280. };
  281. const onEdit = (id: string) => {
  282. tabsViewStore.addTabByPath('/baseSettings/user/edit', {id: id, op: 1});
  283. };
  284. const onDetail = (id: string) => {
  285. tabsViewStore.addTabByPath('/baseSettings/user/detail', {id: id, op: 2});
  286. };
  287. // 字段展示列选择完毕
  288. function columnsCheckSub(columnsKeys: Array<string>) {
  289. // 从原始表格定义数据中过滤出已选择的字段
  290. columns.value = originalColumns.filter((item: any) => columnsKeys.includes(item.key));
  291. }
  292. return {
  293. formRef,
  294. allSites,
  295. searchParams,
  296. formState,
  297. originalColumns,
  298. columns,
  299. pagination,
  300. dataList,
  301. handleTableChange,
  302. onSelectChange,
  303. onSearch,
  304. onAdd,
  305. onEdit,
  306. onDel,
  307. onChangeStatus,
  308. loadData,
  309. onDetail,
  310. importOptions,
  311. exportSearchParams,
  312. columnsCheckSub
  313. };
  314. },
  315. created() {
  316. this.loadData();
  317. },
  318. activated() {
  319. if (history.state.params?.reload)
  320. this.loadData();
  321. }
  322. });
  323. </script>