Files
laws-sinotruk-client/src/views/enterpriseStandardLibrary/standard/modules/EnterpriseStandardModal.vue
T

288 lines
9.9 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>
<a-drawer
:title="title"
:width="width"
placement="right"
:closable="true"
@close="handleCancel"
:visible="visible"
:maskClosable="false"
destroyOnClose
class="custom-drawer-style"
>
<div class="custom-drawer-style-scroll">
<a-spin :spinning="confirmLoading" style="width: 100%;height:100%">
<!-- 引用标准可以选国标和外标 -->
<add-form ref="addForm"
:flag="StandardSource.ENTERPRISE.value"
:defaultValue="{year_number: new Date().getFullYear() + '', try_flag: '0'}"
:disabledFieldList="disabledFieldList"
:selectStandardCanUpdateTypeField="['reference_standard']"
:hiddenFieldList="hiddenFieldList"
:special-placeholder="specialPlaceholder"
:get-form-func="getFormFunc"
:get-document-info-func="getDocumentInfoFunc"
:exclude-standard-fields="['substitute_standard_number', 'reference_standard']"
:process-is-allow-upload-doc="false"
@submitFormData="submitFormData" />
<div class="header-text-btn">
<!-- 稽查内容 -->
<p class="header-text">{{ $t('enterpriseStandardLibrary.standard.auditContent') }}</p>
<a-button icon="plus" type="primary" @click="handleAdd">{{ $t('newlyAdded') }}</a-button>
</div>
<div class="check-content-table">
<a-table
:scroll="{x: 500}"
:columns="columns"
:dataSource="dataSource"
:pagination="false"
rowKey="id">
<template slot="text" slot-scope="text">
<a-tooltip overlay-class-name="tooltip-style">
<template slot="title">{{ text || text === 0 ? text : global.emptyLine }}</template>
<div class="table-text">{{ text || text === 0 ? text : global.emptyLine }}</div>
</a-tooltip>
</template>
<!-- 操作栏 -->
<template slot="action" slot-scope="text, record, index" class="action-span-cell">
<a @click="handleEdit(record, index)" class="table-ope-btn">{{ $t('edit') }}</a>
<a @click="handleDelete(index)" class="table-ope-btn" style="margin-left: 8px">{{ $t('delete') }}</a>
</template>
</a-table>
</div>
</a-spin>
</div>
<div class="custom-drawer-style-bottom-btn">
<a-button @click="handleOk" type="primary" style="margin-bottom: 0;">
{{ $t('preservation') }}
</a-button>
<a-button @click="handleCancel" style="margin-bottom: 0;">{{ $t('close') }}</a-button>
</div>
<check-content-modal ref="checkContentModal" @ok="checkContentOk"></check-content-modal>
</a-drawer>
</template>
<script>
import '@assets/less/common.less'
import AddForm from '@/components/customField/AddForm'
import { getEnterpriseStandardAddForm, getEnterpriseStandardInfoById } from '@/api/enterpriseStandardLibraryApi'
import { postAction } from '@/api/manage'
import CheckContentModal from './CheckContentModal'
import { StandardSource } from '@/enums/commonEnums'
export default {
name: 'EnterpriseStandardModal',
components: { CheckContentModal, AddForm },
computed: {
// 需要隐藏的字段
hiddenFieldList () {
if (this.type === 'add') {
return ['standard_number']
} else if (this.type === 'edit') {
return ['standard_code', 'name_code', 'category_code', 'standard_number_temp']
} else {
return []
}
},
// 不可更改的字段
disabledFieldList () {
if (this.type === 'edit') {
return ['standard_number', 'replaced_by_standard_number', 'referenced_standard', 'year_number']
} else {
return ['standard_number', 'replaced_by_standard_number', 'referenced_standard']
}
}
},
data () {
return {
StandardSource,
visible: false,
title: '',
width: 800,
// 存储表单的数据
form: {},
confirmLoading: false,
getFormFunc: getEnterpriseStandardAddForm,
getDocumentInfoFunc: getEnterpriseStandardInfoById,
columns: [
{
title: this.$t('enterpriseStandardLibrary.standard.subjectToClause'),
align: 'center',
width: 180,
dataIndex: 'clause',
scopedSlots: { customRender: 'text' }
},
{
title: this.$t('enterpriseStandardLibrary.standard.standardContentOrRequirements'),
align: 'center',
width: 180,
dataIndex: 'requirement',
scopedSlots: { customRender: 'text' }
},
{ // 整改部门
title: this.$t('enterpriseStandardLibrary.standard.rectificationDepartment'),
align: 'center',
width: 200,
dataIndex: 'rectificationDepartment',
customRender: (value, row, index) => {
return <j-select-depart v-model={this.dataSource[index].rectificationDepartment}
backDepart={true} />
}
},
{
title: this.$t('operation'),
scopedSlots: { customRender: 'action' },
align: 'center',
width: 150
}
],
dataSource: [],
type: '', // 是新增还是编辑
// 特殊的placeholder
specialPlaceholder: {
standard_number_temp: `${this.$t('enterpriseStandardLibrary.standard.inputExample')}0001${this.$t('enterpriseStandardLibrary.standard.nullAutoCreate')}`
},
url: {
add: '/laws/standard/enterprise/commonAdd',
edit: '/laws/standard/enterprise/commonEdit'
}
}
},
methods: {
add () {
this.visible = true
this.type = 'add'
this.$nextTick(() => {
this.$refs.addForm.add()
})
},
edit (record) {
this.visible = true
this.type = 'edit'
this.$nextTick(() => {
this.$refs.addForm.edit(record, (res) => {
this.dataSource = res.checkList
})
})
},
// 稽查内容的添加
handleAdd () {
const value = this.$refs.addForm.formInline
// 过程稿件id 发布稿>修改单>报批稿>送审稿>征求意见稿>草稿
const fieldArr = ['publish_of_original', 'modification_list', 'draft_for_review', 'draft_for_comment', 'draft']
const needSuffixArr = ['doc', 'docx', 'pdf']
let fileId = ''
for (const item of fieldArr) {
if (!fileId && value[item + '_dictText']) {
const fileNameArr = value[item + '_dictText'].split(',')
for (let i = 0; i < fileNameArr.length; i++) {
// 截取文件后缀名
const fileSuffix = (fileNameArr[i] ? fileNameArr[i].split('.')[fileNameArr[i].split('.').length - 1] : '').toLowerCase()
if (needSuffixArr.includes(fileSuffix)) {
// 说明是可以预览的文件格式
console.log('支持文件预览的文件', value[item].split(',')[i], value[item + '_dictText'].split(',')[i])
fileId = value[item].split(',')[i]
}
}
}
}
this.$refs.checkContentModal.title = this.$t('newlyAdded')
this.$refs.checkContentModal.add(fileId)
},
// 稽查内容的编辑
handleEdit (record, index) {
const value = this.$refs.addForm.formInline
// 过程稿件id 发布稿>修改单>报批稿>送审稿>征求意见稿>草稿
const fieldArr = ['publish_of_original', 'modification_list', 'draft_for_review', 'draft_for_comment', 'draft']
const needSuffixArr = ['doc', 'docx', 'pdf']
let fileId = ''
for (const item of fieldArr) {
if (!fileId && value[item + '_dictText']) {
const fileNameArr = value[item + '_dictText'].split(',')
for (let i = 0; i < fileNameArr.length; i++) {
// 截取文件后缀名
const fileSuffix = (fileNameArr[i] ? fileNameArr[i].split('.')[fileNameArr[i].split('.').length - 1] : '').toLowerCase()
if (needSuffixArr.includes(fileSuffix)) {
// 说明是支持文件预览的文件格式
console.log('支持文件预览的文件', value[item].split(',')[i], value[item + '_dictText'].split(',')[i])
fileId = value[item].split(',')[i]
}
}
}
}
this.$refs.checkContentModal.title = this.$t('edit')
this.$refs.checkContentModal.edit(fileId, record, index)
},
// 稽查内容的删除
handleDelete (index) {
this.dataSource.splice(index, 1)
},
// 稽查内容新增编辑完成
checkContentOk (value, index) {
console.log(value, index)
if (index || index === 0) {
// 有下标,说明是编辑
this.dataSource.splice(index, 1, value)
} else {
// 没有下标, 是新增
this.dataSource.push(value)
}
},
handleOk () {
this.$refs.addForm.submit()
},
// 表单提交的回调,获取表单数据
submitFormData (formInline) {
this.confirmLoading = true
let url = ''
if (formInline.id) {
url = this.url.edit
} else {
url = this.url.add
}
const param = Object.assign({}, formInline)
param.checkList = this.dataSource
postAction(url, param).then((res) => {
if (res.success) {
this.$message.success(this.$t('operationSuccessful'))
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
handleCancel () {
this.close()
},
close () {
this.visible = false
this.dataSource = []
this.$refs.addForm.clearValidate()
}
}
}
</script>
<style scoped lang="less">
/deep/ .title-text {
width: 130px;
}
.header-text-btn {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 16px;
.header-text {
margin-bottom: 0;
}
}
.check-content-table {
padding-bottom: 40px;
}
</style>