diff --git a/config/index.js b/config/index.js index ad43742..3b43552 100644 --- a/config/index.js +++ b/config/index.js @@ -20,7 +20,7 @@ module.exports = { }, // Various Dev Server settings - host: '192.168.0.37', // can be overwritten by process.env.HOST + host: '192.168.0.118', // can be overwritten by process.env.HOST port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, diff --git a/src/views/personStrucManage/components/list.vue b/src/views/personStrucManage/components/list.vue index 61d6040..fb19807 100644 --- a/src/views/personStrucManage/components/list.vue +++ b/src/views/personStrucManage/components/list.vue @@ -1,21 +1,21 @@ @@ -152,12 +152,16 @@ import Pagination from '@/components/Pagination' import { requestFN } from '@/utils/request' import waves from '@/directive/waves' +import axios from 'axios' +import moment from 'moment' export default { components: { Pagination }, directives: { waves }, + data() { return { + config: config, searchParmas: { enterpriseName: '', groupUnit: '', @@ -175,11 +179,12 @@ export default { }, total: 0, // 选择展示的字段数组 - optionsColumns: [ + dataSourceForTree: [ { id: '1', label: '企业名称', value: 'RELEVANT_UNIT_NAME', + disabled: false, show: true, children: [] }, @@ -187,14 +192,15 @@ export default { id: '2', label: '集团单位', value: 'CORP_TYPE_NAME', + disabled: false, show: true, children: [] - }, { id: '3', label: '股份主管部门', value: 'MAIN_DEPARTMENT_NAME', + disabled: false, show: true, children: [] }, @@ -202,20 +208,23 @@ export default { id: '4', label: '企业规模', value: 'CORP_SIZE_NAME', + disabled: false, show: true, children: [] }, { id: '5', - label: '企业名称', - value: 'enterpriseName', + label: '主要负责人', + value: 'CONTACT_PERSON', + disabled: false, show: true, children: [] }, { id: '6', - label: '主要负责人', - value: 'CONTACT_PERSON', + label: '主要负责人联系电话', + value: 'CONTACT_TEL', + disabled: false, show: true, children: [] }, @@ -223,6 +232,7 @@ export default { id: '7', label: '注册人数', value: 'REGISTER_COUNT', + disabled: false, show: true, children: [] }, @@ -230,19 +240,22 @@ export default { id: '8', label: '培训合格人数', value: 'PASS_COUNT', + disabled: false, show: true, children: [] }, { id: '9', label: '人员年龄结构', - value: 'personAgeStruct', + disabled: false, + value: 'personAgeStruc', show: true, children: [ { id: '9-1', label: '平均年龄', value: 'AVG_AGE', + disabled: false, show: true, children: [] }, @@ -250,6 +263,7 @@ export default { id: '9-2', label: '大于60岁人数', value: 'MORE_THAN_60_COUNT', + disabled: false, show: true, children: [] }, @@ -257,6 +271,7 @@ export default { id: '9-3', label: '55-60岁人数:', value: 'BETWEEN_55_AND_60_COUNT', + disabled: false, show: true, children: [] }, @@ -264,21 +279,16 @@ export default { id: '9-4', label: '55岁以下人数', value: 'LESS_THAN_55_COUNT', + disabled: false, show: true, children: [] } ] }, - { - id: '10', - label: '在港工作经历(年)', - value: 'workExprien', - show: true, - children: [] - }, { id: '11', label: '人员学历', + disabled: false, value: 'personEducation', show: true, children: [ @@ -286,6 +296,7 @@ export default { id: '11-1', label: '高中以下', value: 'BELOW_HIGH_SCHOOL', + disabled: false, show: true, children: [] }, @@ -293,6 +304,7 @@ export default { id: '11-2', label: '高中', value: 'HIGH_SCHOOL', + disabled: false, show: true, children: [] }, @@ -300,6 +312,7 @@ export default { id: '11-3', label: '技工', value: 'TECHNICAL_SCHOOL', + disabled: false, show: true, children: [] }, @@ -307,6 +320,7 @@ export default { id: '11-4', label: '中专或中等技术学校', value: 'TECHNICAL_SECONDARY_SCHOOL', + disabled: false, show: true, children: [] }, @@ -314,6 +328,7 @@ export default { id: '11-5', label: '大学专科或专科院校', value: 'JUNIOR_COLLEGE', + disabled: false, show: true, children: [] }, @@ -321,6 +336,7 @@ export default { id: '11-6', label: '大学本科', value: 'UNDERGRADUATE', + disabled: false, show: true, children: [] }, @@ -328,6 +344,7 @@ export default { id: '11-7', label: '大学本科以上', value: 'ABOVE_UNDERGRADUATE', + disabled: false, show: true, children: [] } @@ -338,11 +355,13 @@ export default { label: '男职工', value: 'man', show: true, + disabled: false, children: [ { id: '12-1', label: '人数', value: 'MAN_COUNT', + disabled: false, show: true, children: [] }, @@ -350,6 +369,7 @@ export default { id: '12-2', label: '占比', value: 'MAN_PERCENT', + disabled: false, show: true, children: [] } @@ -358,13 +378,15 @@ export default { { id: '13', label: '女职工', - value: 'woman', show: true, + value: 'woman', + disabled: false, children: [ { id: '13-1', label: '人数', value: 'WOMAN_COUNT', + disabled: false, show: true, children: [] }, @@ -372,6 +394,7 @@ export default { id: '13-2', label: '占比', value: 'WOMAN_PERCENT', + disabled: false, show: true, children: [] } @@ -381,12 +404,14 @@ export default { id: '14', label: '保险相关', value: 'insurance', + disabled: false, show: true, children: [ { id: '14-1', label: '有社保人数', value: 'SOCIAL', + disabled: false, show: true, children: [] }, @@ -394,6 +419,7 @@ export default { id: '14-2', label: '有工伤保险人数', value: 'OCCUPATIONAL_INJURY', + disabled: false, show: true, children: [] }, @@ -401,6 +427,7 @@ export default { id: '14-3', label: '有商业保险人数', value: 'COMMERCIAL_INSURANCE', + disabled: false, show: true, children: [] }, @@ -408,6 +435,7 @@ export default { id: '14-4', label: '其他保险人数', value: 'OTHER_INSURANCE', + disabled: false, show: true, children: [] }, @@ -415,6 +443,7 @@ export default { id: '14-5', label: '无保险人数', value: 'NO_INSURANCE', + disabled: false, show: true, children: [] } @@ -424,12 +453,14 @@ export default { id: '15', label: '取得特种作业证书人数', value: 'numOfSpecialOperation', + disabled: false, show: true, children: [ { id: '15-1', label: '总人数', value: 'SPECIAL_TOTAL', + disabled: false, show: true, children: [] }, @@ -437,6 +468,7 @@ export default { id: '15-2', label: '电工作业', value: 'ELECTRICIAN', + disabled: false, show: true, children: [] }, @@ -444,6 +476,7 @@ export default { id: '15-3', label: '焊接与热切割作业', value: 'WELDING', + disabled: false, show: true, children: [] }, @@ -451,6 +484,7 @@ export default { id: '15-4', label: '高处作业', value: 'HIGH_WORK', + disabled: false, show: true, children: [] }, @@ -458,6 +492,7 @@ export default { id: '15-5', label: '起重机械作业', value: 'CRANE_OPERATION', + disabled: false, show: true, children: [] }, @@ -465,6 +500,7 @@ export default { id: '15-6', label: '企业内机动车辆作业', value: 'MOTOR_VEHICLE', + disabled: false, show: true, children: [] }, @@ -472,24 +508,30 @@ export default { id: '15-7', label: '其他特种作业', value: 'OTHER_SPECIAL', + disabled: false, show: true, children: [] } ] } ], + treeCheckedIds: [], // 保存被选中的树节点 id defaultProps: { children: 'children', label: 'label' }, + checked: true, // 全选状态 popoverVisible: false, - checkedColumns: [], // 选中的列的字段id - isIndeterminate: false + indeterminate: false, // 半选状态 + selectionSelected: [], + head: [] } }, created() { // 当页面初始化后立刻计算 el-table 表格的动态高度值 this.tableMaxHeight = window.innerHeight - 230 + // 页面初始化渲染后,立刻调用的处理函数等方法 + this.getList() // 调用获取列表数据的方法 }, mounted() { // 当前页面挂载之后立刻计算 el-table 表格的动态高度值 @@ -497,20 +539,12 @@ export default { window.onresize = () => { this.tableMaxHeight = window.innerHeight - 230 } + this.$refs.treeRef.setCheckedNodes( + this.dataSourceForTree.filter(node => !node.disabled) + ) }) - this.checkedColumns = this.getIds(this.optionsColumns) }, methods: { - getIds(optionsColumns) { - let ids = [] - for (const column of optionsColumns) { - ids.push(column.id) - if (column.children && column.children.length > 0) { - ids = ids.concat(this.getIds(column.children)) - } - } - return ids - }, handleSelectWithDifferentStatus(row, rowIndex) { return true }, @@ -532,65 +566,195 @@ export default { } this.getQuery() }, + /** 获取列表数据 */ getList() { this.loading = true requestFN( - '/openApi/user/statistics?showCount=' + this.listQuery.limit + '¤tPage=' + this.listQuery.page, + '/openApi/user/statistics?showCount=' + + this.listQuery.limit + + '¤tPage=' + + this.listQuery.page, { KEYWORDS: this.KEYWORDS, ISSMALL: '2' } - ).then((data) => { - this.loading = false - this.varList = data.list - this.total = data.page.totalResult - }).catch((e) => { - console.log(e) - this.loading = false - }) + ) + .then(data => { + this.loading = false + this.varList = data.list + this.total = data.page.totalResult + }) + .catch(e => { + console.log(e) + this.loading = false + }) }, selectionChange(row) { - console.log('row :>> ', row) + this.selectionSelected = row }, selectAll(selection) { - console.log('selection :>> ', selection) + this.selectionSelected = selection }, rowClick(row, column, event) { console.log('row :>> ', row) }, handleExportBtn() { - console.log('批量导出暂未开发!') + const ids = this.selectionSelected + .map(item => { + return item.CORPINFO_ID + }) + .toString(',') + const result = this.collectValues(this.dataSourceForTree) + this.head = result.toString(',') + + if ( + this.selectionSelected.map(item => { + return item.CORPINFO_ID + }).length === 0 + ) { + this.$message.error('请选择数据项后导出!') + } + this.exportExcelHandler(ids, this.head) + }, + collectValues(data, resultArray = []) { + data.forEach(item => { + if (item.show) { + resultArray.push(item.value) // 将满足条件的 value 存入结果数组中 + } + if (item.children && item.children.length > 0) { + this.collectValues(item.children, resultArray) // 递归处理子节点 + } + }) + return resultArray + }, + // 导出指定数据项至 excel 表格 + exportExcelHandler(ids, head) { + return new Promise((resolve, reject) => { + axios + .post( + config.httpurl + '/openApi/excel?' + `ids=${ids}&head=${head}`, + {}, + { + responseType: 'blob' + } + ) + .then(res => { + setTimeout(() => { + const blob = new Blob([res.data], { + type: 'application/vnd.ms-excel' + }) + const downloadElement = document.createElement('a') + const href = window.URL.createObjectURL(blob) + downloadElement.style.display = 'none' + downloadElement.href = href + downloadElement.download = moment().format('YYYY-MM-DD HH:mm:ss') + document.body.appendChild(downloadElement) + downloadElement.click() + document.body.removeChild(downloadElement) + window.URL.revokeObjectURL(href) + resolve(res) + }, 2000) + }) + .catch(e => { + reject(e) + this.$message.error('导出失败,或未查询到隐患') + }) + }) }, // 点击操作打开菜单选择框 openPopover() { this.popoverVisible = true - this.$nextTick(() => { - document.getElementsByClassName('el-popover el-popper')[0].style.display = 'none' - }) - }, - // 处理多选框全部选中 - handleCheckAllChange(val) { - const columnsValueList = [] - this.getIds(this.optionsColumns).map(item => { - columnsValueList.push(item) - }) - this.checkedColumns = val ? columnsValueList : [] - - console.log('this.checkedColumns :>> ', this.checkedColumns) - // const treeRef = this.$refs.treeRef - // if (val) { - // treeRef.setCheckedNodes(this.getIds(this.optionsColumns)) - // } else { - // treeRef.setCheckedNodes([]) - // } }, + // 点击取消关闭菜单选择框 canclePopover() { this.popoverVisible = false }, - // 处理多选框发生改变 - handleCheckChange(currentRow, selfCheck, subCheck) { - console.log('currentRow :>> ', currentRow) + // 处理多选框全部选中 + handleCheckAllChange() { + if (this.checked) { + this.$refs.treeRef.setCheckedNodes( + this.dataSourceForTree.filter(node => !node.disabled) + ) + this.treeCheckedIds = this.$refs.treeRef + .getCheckedNodes(false, true) + .map(i => i.id) + this.head = this.$refs.treeRef.getCheckedNodes(false, true).map(i => i.value) + } else { + this.$refs.treeRef.setCheckedNodes([]) + this.treeCheckedIds = [] + this.head = [] + } }, - // 弹出框确认 + // 多选框发生改变的事件处理 + changeCheck(checkedNode, isChecked, selfNode) { + const res = this.updateShowProperty( + this.dataSourceForTree, + checkedNode, + isChecked + ) + this.dataSourceForTree = res + }, + updateShowProperty(dataSource, curNode, isChecked) { + // 定义递归函数 + function recursiveUpdate(node) { + // 记录所有子节点是否都未选中 + let allChildrenUnchecked = true + + // 递归处理子节点 + if (node.children && node.children.length > 0) { + node.children.forEach(child => { + const childChecked = recursiveUpdate(child) + if (childChecked) { + allChildrenUnchecked = false + } + }) + } + + // 更新当前节点的 show 属性 + if (node.id === curNode.id) { + node.show = isChecked + } + + // 更新父节点的 show 属性 + if (node.children && node.children.length > 0) { + if (allChildrenUnchecked) { + node.show = false + } else { + node.show = true + } + } + + return node.show // 返回当前节点的 show 属性值 + } + // 遍历整个数据源进行更新 + dataSource.forEach(node => recursiveUpdate(node)) + return dataSource + }, + // 弹出框确认的事件处理 confirmPopover() { this.popoverVisible = false + }, + // 控制表格列的显示与隐藏 + showColumn(columnValue) { + // 在数据源中查找与传入列值匹配的项 + const findItem = (data, value) => { + for (let i = 0; i < data.length; i++) { + const item = data[i] + if (item.value === value) { + return item + } + if (item.children && item.children.length > 0) { + const foundInChildren = findItem(item.children, value) + if (foundInChildren) { + return foundInChildren + } + } + } + return null + } + + // 查找数据源中对应的列项 + const foundItem = findItem(this.dataSourceForTree, columnValue) + + // 返回该列项的 show 属性,如果不存在则返回 false + return foundItem ? foundItem.show : false } } } diff --git a/src/views/personStrucManage/mock/dataSource.js b/src/views/personStrucManage/mock/dataSource.js deleted file mode 100644 index 17687c7..0000000 --- a/src/views/personStrucManage/mock/dataSource.js +++ /dev/null @@ -1,234 +0,0 @@ -var mockVarList = [ - { - enterpriseName: '风力杭天', - groupUnit: '集团企业', - shareSuperdepart: '供水除尘部', - scale: '大型', - mainerPerson: '小美', - mainerPersonPhone: '13933293932', - enrollment: 90, - numQualiTrain: 120, - averageAge: 55, - ageUpperSixty: 4, - fiftyFiveAndSixty: 8, - ageUnderFiftyFive: 18, - workExprien: null, - belowHigh: 50, - high: 4, - mechanic: 40, - technicalOrSecondary: 20, - collegeOrCollege: 39, - graduateCollege: 1, - undergraduateCollege: 9, - manpersonNum: 2, - manRatio: '80%', - womanPersonNum: 9, - womanRatio: '30%', - numOfSecure: 40, - numOfworkRelated: 98, - numOfCommercial: 20, - numOfOther: 12, - numOfNone: 6, - totalPerson: 1200, - electricianWork: 9, - weldingAndHotCuttingWork: 3, - heightsWork: 1, - hoistingMachineryWork: 90, - motorVehiclesWork: 130, - otherSpecialWork: 34 - }, - { - enterpriseName: '行里力杭天', - groupUnit: '集团企业', - shareSuperdepart: '火力除尘部', - scale: '中小型', - mainerPerson: '轩里', - mainerPersonPhone: '150244938491', - enrollment: 90, - numQualiTrain: 120, - averageAge: 55, - ageUpperSixty: 4, - fiftyFiveAndSixty: 8, - ageUnderFiftyFive: 18, - workExprien: null, - belowHigh: 50, - high: 4, - mechanic: 40, - technicalOrSecondary: 20, - collegeOrCollege: 39, - graduateCollege: 1, - undergraduateCollege: 9, - manpersonNum: 2, - manRatio: '80%', - womanPersonNum: 9, - womanRatio: '30%', - numOfSecure: 40, - numOfworkRelated: 98, - numOfCommercial: 20, - numOfOther: 12, - numOfNone: 6, - totalPerson: 1200, - electricianWork: 9, - weldingAndHotCuttingWork: 3, - heightsWork: 1, - hoistingMachineryWork: 90, - motorVehiclesWork: 130, - otherSpecialWork: 34 - }, - { - enterpriseName: '意下提取', - groupUnit: '集团企业', - shareSuperdepart: '火力除尘部', - scale: '中小型', - mainerPerson: '轩里', - mainerPersonPhone: '150244938491', - enrollment: 90, - numQualiTrain: 120, - averageAge: 55, - ageUpperSixty: 4, - fiftyFiveAndSixty: 8, - ageUnderFiftyFive: 18, - workExprien: null, - belowHigh: 50, - high: 4, - mechanic: 40, - technicalOrSecondary: 20, - collegeOrCollege: 39, - graduateCollege: 1, - undergraduateCollege: 9, - manpersonNum: 2, - manRatio: '80%', - womanPersonNum: 9, - womanRatio: '30%', - numOfSecure: 40, - numOfworkRelated: 98, - numOfCommercial: 20, - numOfOther: 12, - numOfNone: 6, - totalPerson: 1200, - electricianWork: 9, - weldingAndHotCuttingWork: 3, - heightsWork: 1, - hoistingMachineryWork: 90, - motorVehiclesWork: 130, - otherSpecialWork: 34 - }, - { - enterpriseName: '燕来客机民众', - groupUnit: '集团企业', - shareSuperdepart: '火力除尘部', - scale: '中小型', - mainerPerson: '轩里', - mainerPersonPhone: '150244938491', - enrollment: 90, - numQualiTrain: 120, - averageAge: 55, - ageUpperSixty: 4, - fiftyFiveAndSixty: 8, - ageUnderFiftyFive: 18, - workExprien: null, - belowHigh: 50, - high: 4, - mechanic: 40, - technicalOrSecondary: 20, - collegeOrCollege: 39, - graduateCollege: 1, - undergraduateCollege: 9, - manpersonNum: 2, - manRatio: '80%', - womanPersonNum: 9, - womanRatio: '30%', - numOfSecure: 40, - numOfworkRelated: 98, - numOfCommercial: 20, - numOfOther: 12, - numOfNone: 6, - totalPerson: 1200, - electricianWork: 9, - weldingAndHotCuttingWork: 3, - heightsWork: 1, - hoistingMachineryWork: 90, - motorVehiclesWork: 130, - otherSpecialWork: 34 - }, - { - enterpriseName: '天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星', - groupUnit: '集团企业', - shareSuperdepart: '火力除尘部', - scale: '中小型', - mainerPerson: '轩里', - mainerPersonPhone: '150244938491', - enrollment: 90, - numQualiTrain: 120, - averageAge: 55, - ageUpperSixty: 4, - fiftyFiveAndSixty: 8, - ageUnderFiftyFive: 18, - workExprien: null, - belowHigh: 50, - high: 4, - mechanic: 40, - technicalOrSecondary: 20, - collegeOrCollege: 39, - graduateCollege: 1, - undergraduateCollege: 9, - manpersonNum: 2, - manRatio: '80%', - womanPersonNum: 9, - womanRatio: '30%', - numOfSecure: 40, - numOfworkRelated: 98, - numOfCommercial: 20, - numOfOther: 12, - numOfNone: 6, - totalPerson: 1200, - electricianWork: 9, - weldingAndHotCuttingWork: 3, - heightsWork: 1, - hoistingMachineryWork: 90, - motorVehiclesWork: 130, - otherSpecialWork: 34 - }, - { - enterpriseName: '天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星天河夜星', - groupUnit: '集团企业', - shareSuperdepart: '火力除尘部', - scale: '中小型', - mainerPerson: '轩里', - mainerPersonPhone: '150244938491', - enrollment: 90, - numQualiTrain: 120, - averageAge: 55, - ageUpperSixty: 4, - fiftyFiveAndSixty: 8, - ageUnderFiftyFive: 18, - workExprien: null, - belowHigh: 50, - high: 4, - mechanic: 40, - technicalOrSecondary: 20, - collegeOrCollege: 39, - graduateCollege: 1, - undergraduateCollege: 9, - manpersonNum: 2, - manRatio: '80%', - womanPersonNum: 9, - womanRatio: '30%', - numOfSecure: 40, - numOfworkRelated: 98, - numOfCommercial: 20, - numOfOther: 12, - numOfNone: 6, - totalPerson: 1200, - electricianWork: 9, - weldingAndHotCuttingWork: 3, - heightsWork: 1, - hoistingMachineryWork: 90, - motorVehiclesWork: 130, - otherSpecialWork: 34 - } -] - -export { - mockVarList -}