Files
laws-sinotruk-client/src/views/workCenter/enterpriseStandardInspectionPlan/modules/InspectionPlanTable.vue
T

491 lines
18 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<template>
<div>
<div class="table-operator" v-if="hasTableOperator">
<!-- 新增 -->
<a-button icon="plus" type="primary" @click="handleAdd">{{ $t('newlyAdded') }}</a-button>
<!-- 下载模板 -->
<a-button icon="download" type="primary" ghost @click="downTemplate($t('workCenter.esInspectionPlan.downloadTemplate'))">{{ $t('templateDownload') }}</a-button>
<!-- 导入 -->
<a-upload name="file" :data="{projectId}" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
<a-button icon="upload" type="primary" ghost>{{ $t('import') }}</a-button>
</a-upload>
<!-- 批量删除 -->
<a-button icon="delete" type="primary" ghost @click="batchDel">{{ $t('batchDelete') }}</a-button>
</div>
<div>
<j-table
v-if="columns && columns.length > 0"
:columns="columns"
:dataSource="dataSource"
:can-drag="true"
:rowKey="(_, index) => index"
:loading="loading"
:pagination="false"
:row-selection="hasTableOperator ? { selectedRowKeys: selectedRowKeys, onChange: onSelectChange, getCheckboxProps } : null"
:scroll="{x: '100%', y: '50vh'}"
@change="tableOnChange">
<!-- 企标号、企标名称 -->
<template v-slot:standard="{text, record}">
<a-tooltip overlay-class-name="tooltip-style">
<template slot="title">{{ text || text === 0 ? text : global.emptyLine }}</template>
<a v-if="text" class="link-a" @click="detailClick(record)">{{ text }}</a>
<div v-else class="table-text">{{ global.emptyLine }}</div>
</a-tooltip>
</template>
<!-- 所属部门意见 -->
<template v-slot:departOpinion="{text, record}">
<a class="table-text can-click-table-text" @click="showDepartOpinion(record)" v-if="text && text.length">{{ $t('view') }}</a>
<div class="table-text" v-else>{{ global.emptyLine }}</div>
</template>
<!-- 操作 -->
<template slot="action" slot-scope="{text, record, index}">
<!-- 编辑 and 删除:节点1 或 节点3 或 节点2且当前登录人是创建人 -->
<template v-if="isInitiateOrLiaisonCollect || (currentNode === EsInspectionPlan.fillInComments.value && currentUserName === record.createBy)">
<a @click="handleEdit(record, index)" >{{ $t('edit') }}</a>
<a-divider type="vertical" />
<a @click="handleDelete(index)" >{{ $t('delete') }}</a>
</template>
<!-- 意见 or 填写意见:节点2非自己创建的就是意见和填写意见 -->
<template v-else-if="currentNode === EsInspectionPlan.fillInComments.value">
<a v-if="isShowOpinion(record)" @click="handleWriteOpinion(record, index)" >{{ $t('workCenter.esInspectionPlan.opinion') }}</a>
<a v-else @click="handleWriteOpinion(record, index)" >{{ $t('workCenter.esInspectionPlan.writeOpinion') }}</a>
</template>
</template>
</j-table>
</div>
<!-- 新增/编辑稽查计划 -->
<inspection-plan-drawer ref="modalForm" @ok="handleAddOrEditCallback" :project-id="projectId"/>
<!-- 节点2:填写意见、意见回显 -->
<write-opinion-modal ref="writeOpinionModal" @ok="handleWriteOpinionCallback"/>
<!-- 节点3:所属部门意见-查看 -->
<show-opinion-modal ref="showOpinionModal"/>
</div>
</template>
<script>
import { JeroListMixin } from '@/mixins/JeroListMixin'
import JTable from '@comp/jero/JTable'
import InspectionPlanDrawer from '@views/workCenter/enterpriseStandardInspectionPlan/modules/InspectionPlanDrawer'
import WriteOpinionModal from '@views/workCenter/enterpriseStandardInspectionPlan/modules/WriteOpinionModal'
import ShowOpinionModal from '@views/workCenter/enterpriseStandardInspectionPlan/modules/ShowOpinionModal'
import { EsInspectionPlan } from '@/enums/commonEnums'
import Vue from 'vue'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import store from '@/store'
let importModalLoading
export default {
name: 'InspectionPlanTable',
components: { ShowOpinionModal, WriteOpinionModal, InspectionPlanDrawer, JTable },
mixins: [JeroListMixin],
props: {
// 当前节点
currentNode: {
type: String,
required: true
},
// 项目id
projectId: {
type: String,
required: true
}
},
data () {
return {
EsInspectionPlan,
disableMixinCreated: true,
url: {
// list: '/process/processEsInspectPlan/list',
delete: '/process/processEsInspectPlan/delete',
deleteBatch: '/process/processEsInspectPlan/deleteBatch',
// 默认是发起节点的导入和 下载模板,如果是节点2就用没有 征求意见对象 的模板和导入接口
importExcelUrl: '/process/processEsInspectPlan/importExcelByStart',
downTemplateUrl: '/process/processEsInspectPlan/templateDownloadByStart',
// 节点2 的导入和下载模板
nodeTwoImportUrl: '/process/processEsInspectPlan/importExcelByOpinionFill',
nodeTwoDownTemplateUrl: '/process/processEsInspectPlan/templateDownloadByStartByOpinionFill'
},
model: {},
dataSource: [],
// 需要删除的数据id(前端添加后没有保存表的数据没有id)
delIds: [],
allColumns: [
{
title: this.$t('serialNumber'),
dataIndex: '',
key: 'rowIndex',
align: 'center',
width: 80,
customRender: function (t, r, index) {
return parseInt(index) + 1
}
},
{ // 稽查依据标准号
title: this.$t('workCenter.esInspectionPlan.inspectionBasisStandardNumber'),
align: 'center',
width: 180,
dataIndex: 'inspectNo',
scopedSlots: { customRender: 'standard' }
},
{ // 稽查依据标准名称
title: this.$t('workCenter.esInspectionPlan.inspectionBasisStandardName'),
align: 'center',
width: 180,
dataIndex: 'inspectName',
scopedSlots: { customRender: 'standard' }
},
{ // 计划稽查对象
title: this.$t('workCenter.esInspectionPlan.planInspectionObjects'),
align: 'center',
width: 120,
dataIndex: 'inspectObject_dictText',
scopedSlots: { customRender: 'text' }
},
{ // 主责标准化工作组
title: this.$t('workCenter.esInspectionPlan.mainDutyStandardizationGroup'),
align: 'center',
width: 150,
dataIndex: 'standardizationWorkGroup',
scopedSlots: { customRender: 'text' }
},
{ // 所属部门
title: this.$t('workCenter.esInspectionPlan.department'),
align: 'center',
width: 120,
dataIndex: 'belongDept_dictText',
scopedSlots: { customRender: 'text' }
},
{ // 计划稽查日期
title: this.$t('workCenter.esInspectionPlan.planInspectionDate'),
align: 'center',
width: 120,
dataIndex: 'planInspectDate',
scopedSlots: { customRender: 'text' }
},
{ // 稽查负责人
title: this.$t('workCenter.esInspectionPlan.inspectionDirector'),
align: 'center',
width: 120,
dataIndex: 'inspectUserDictText',
scopedSlots: { customRender: 'text' }
},
{ // 标准化组对接人
title: this.$t('workCenter.esInspectionPlan.standardizationGroupContactPerson'),
align: 'center',
width: 140,
dataIndex: 'standardizationDockingUserDictText',
scopedSlots: { customRender: 'text' }
},
{ // 所属部门人员
title: this.$t('workCenter.esInspectionPlan.departmentPersonnel'),
align: 'center',
width: 120,
dataIndex: 'objectOfConsultationDictText',
showCodeList: [EsInspectionPlan.initiate.value],
scopedSlots: { customRender: 'text' }
},
{ // 创建人
title: this.$t('workCenter.esInspectionPlan.creator'),
align: 'center',
width: 120,
dataIndex: 'createByDictText',
showCodeList: [EsInspectionPlan.fillInComments.value],
scopedSlots: { customRender: 'text' }
},
{ // 发起人
title: this.$t('workCenter.esInspectionPlan.initiator'),
align: 'center',
width: 120,
dataIndex: 'createByDictText',
showCodeList: [
EsInspectionPlan.liaisonCollect.value,
EsInspectionPlan.relevantPersonnelCountersign.value,
EsInspectionPlan.liaisonLeaderApproval.value
],
scopedSlots: { customRender: 'text' }
},
{ // 所属部门意见
title: this.$t('workCenter.esInspectionPlan.departOpinion'),
align: 'center',
width: 120,
dataIndex: 'processEsInspectPlanOpinionList',
showCodeList: [EsInspectionPlan.liaisonCollect.value],
scopedSlots: { customRender: 'departOpinion' }
},
{
fixed: 'right',
// 操作
showCodeList: [
EsInspectionPlan.initiate.value,
EsInspectionPlan.fillInComments.value,
EsInspectionPlan.liaisonCollect.value
],
title: this.$t('operation'),
dataIndex: 'action',
align: 'center',
width: 180,
scopedSlots: { customRender: 'action' }
}
]
}
},
watch: {
// 监听当前节点变化
currentNode: {
immediate: true,
handler () {
// 节点2填写意见,用没有“征求意见对象”的模板和导入接口
if (this.currentNode === EsInspectionPlan.fillInComments.value) {
this.url.importExcelUrl = this.url.nodeTwoImportUrl
this.url.downTemplateUrl = this.url.nodeTwoDownTemplateUrl
}
}
}
},
computed: {
// 当前登录用户名
currentUserName () {
return this.$store.getters.userInfo.username
},
// 是否前两个节点:显示表格操作按钮
hasTableOperator () {
const arr = [
EsInspectionPlan.initiate.value,
EsInspectionPlan.fillInComments.value
]
return arr.includes(this.currentNode)
},
// 是否发起节点和联络人汇总节点
isInitiateOrLiaisonCollect () {
const arr = [EsInspectionPlan.initiate.value, EsInspectionPlan.liaisonCollect.value]
return arr.includes(this.currentNode)
},
// 按节点进行过滤
columns () {
return this.allColumns.filter(item => {
// 没有这个属性,就默认显示
if (!item.showCodeList) {
return true
}
// 如果有,就根据当前节点显示
return item.showCodeList.includes(this.currentNode)
})
}
},
created () {
this.filters.taskId = this.$route.query.taskId
},
methods: {
setData (list) {
this.dataSource = list || []
},
// 父组件获取删除的ids
getDelIds () {
return Array.from(new Set(this.delIds)).filter(item => item).join(',')
},
// 批量删除
batchDel () {
if (this.selectedRowKeys.length <= 0) {
this.$message.warning(this.$t('selectARecord'))
} else {
this.$confirm({
title: this.$t('confirmBatchDeletion'),
content: this.$t('deleteAData'),
onOk: () => {
// 将删除的id进行收集,提交节点的时候后端进行删除
this.selectedRowKeys.forEach(key => {
if (this.dataSource[key].id) {
this.delIds.push(this.dataSource[key].id)
}
})
this.dataSource = this.dataSource.filter((item, index) => !this.selectedRowKeys.includes(index))
this.onClearSelected()
}
})
}
},
// 删除
handleDelete (index) {
this.$confirm({
title: this.$t('confirmDeletion'),
content: this.$t('areYouSure'),
onOk: () => {
// 将删除的id进行收集,提交节点的时候后端进行删除
if (this.dataSource[index].id) {
this.delIds.push(this.dataSource[index].id)
}
this.dataSource.splice(index, 1)
}
})
},
handleAdd () {
this.$refs.modalForm.add()
this.$refs.modalForm.title = this.$t('newlyAdded')
this.$refs.modalForm.disableSubmit = false
},
// 编辑弹框
handleEdit (record, index) {
this.$refs.modalForm.edit(record, index)
this.$refs.modalForm.title = this.$t('edit')
this.$refs.modalForm.disableSubmit = false
},
// 添加或编辑回调
handleAddOrEditCallback (row, index) {
console.log('添加或编辑回调', row, index)
// index -1就是添加
if (index === undefined || index === -1) {
this.dataSource.push(row)
} else {
this.dataSource.splice(index, 1, row)
}
},
// 是否显示意见
isShowOpinion (record) {
if (record.processEsInspectPlanOpinion && record.processEsInspectPlanOpinion.opinion) {
return true
}
const list = record.processEsInspectPlanOpinionList || []
// 意见列表是否有当前用户的意见
return !!(list.find(item => item.createBy === this.currentUserName))
},
getCheckboxProps (record) {
const obj = { props: { disabled: false } }
// 第二个节点,只有自己的才能勾选删除
if (this.currentNode === EsInspectionPlan.fillInComments.value) {
obj.props.disabled = record.createBy !== this.currentUserName
}
return obj
},
getData () {
return this.dataSource
},
// 更新表格数据
updateData (list) {
this.dataSource = list || []
},
// 跳转详情
detailClick (record) {
this.$openPageNewSheet({
path: '/enterpriseStandardLibrary/enterpriseStandardDetail',
query: {
standardNumber: record.inspectNo
}
})
},
tableOnChange (pagination, filters, sorter) {
this.orderBy = sorter.order === 'ascend' ? '1' : '2'
this.orderByField = sorter.columnKey
this.ipagination = pagination
this.getTableList()
},
// 填写意见
handleWriteOpinion (record, index) {
this.$refs.writeOpinionModal.show(record, index)
},
// 填写意见回调
handleWriteOpinionCallback (data, index) {
console.log(data, index)
this.dataSource.splice(index, 1, {
...this.dataSource[index],
// 填写意见的数据
processEsInspectPlanOpinion: data
})
},
// 查看所属部门意见
showDepartOpinion (record) {
this.$refs.showOpinionModal.show(record)
},
/* 导入 */
handleImportExcel (info) {
// 限制导入大于500MB
if (info.file.size > 1024 * 1024 * 500) {
this.$message.error('导入文件最大500MB!')
info.fileList.pop()
return
}
// 加一个大的提示
if (!this.loading) {
importModalLoading = this.$info({
title: '提示',
content: <span>正在导入,请稍候 <a-spin size="small" /></span>,
keyboard: false
})
}
this.loading = true
// 把知道了这个按钮去掉
this.$nextTick(() => {
document.getElementsByClassName('ant-modal-confirm-btns')[0].style = 'display:none'
})
if (info.file.status !== 'uploading') {
console.log(info.file, info.fileList)
}
if (info.file.status === 'done') {
// 销毁这个提示
importModalLoading && importModalLoading.destroy()
this.loading = false
if (info.file.response.success) {
// this.$message.success(`${info.file.name} 文件上传成功`);
if (info.file.response.code === 201) {
const { message, result: { msg, fileUrl, fileName } } = info.file.response
const href = window._CONFIG.domianURL + fileUrl
this.$warning({
title: message,
content: (<div>
<span>{msg}</span><br />
<span>具体详情请 <a href={href} target="_blank" download={fileName}>点击下载</a> </span>
</div>
)
})
} else {
this.$message.success(info.file.response.message || `${info.file.name} 文件上传成功`)
}
// 前端存储
const data = info.file.response.result || []
this.dataSource.push(...data)
} else {
if (Array.isArray(info.file.response.result) && info.file.response.result.length > 0) {
this.messageLineFeed(this.$t('fileImportError'), info.file.response.result)
} else if (/<br>|<\/br>|<br\/>/.test(info.file.response.message)) {
this.messageLineFeedByBr(this.$t('fileImportError'), info.file.response.message)
} else {
this.$message.warning(`${info.file.name} ${info.file.response.message}`)
}
}
} else if (info.file.status === 'error') {
// 销毁这个提示
importModalLoading && importModalLoading.destroy()
this.loading = false
if (info.file.response.status === 500) {
const data = info.file.response
const token = Vue.ls.get(ACCESS_TOKEN)
if (token && data.message.includes('Token失效')) {
this.error({
title: '登录已过期',
content: '很抱歉,登录已过期,请重新登录',
okText: '重新登录',
mask: false,
onOk: () => {
store.dispatch('Logout').then(() => {
Vue.ls.remove(ACCESS_TOKEN)
window.location.reload()
})
}
})
}
} else {
this.$message.warning(`文件上传失败: ${info.file.msg} `)
}
}
}
}
}
</script>
<style scoped>
</style>