Files
laws_chery_client/src/views/enterpriseStandardLibrary/standard/modules/EnterpriseStandardModal.vue
T

260 lines
8.2 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() + ''}"
: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']"
:selectStandardValueNeedNameField="['substitute_standard_number', 'reference_standard']"
@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: '50%',
// 存储表单的数据
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_dictText',
scopedSlots: { customRender: 'text' }
},
{
title: this.$t('operation'),
scopedSlots: { customRender: 'action' },
align: 'center',
width: 150
}
],
dataSource: [],
type: '', // 是新增还是编辑
// 特殊的placeholder
specialPlaceholder: {
standard_number_temp: `${this.$t('enterpriseStandardLibrary.standard.inputExample')}001${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 () {
this.$refs.checkContentModal.title = this.$t('newlyAdded')
this.$refs.checkContentModal.add()
},
// 稽查内容的编辑
handleEdit (record, index) {
this.$refs.checkContentModal.title = this.$t('edit')
this.$refs.checkContentModal.edit(record, index)
},
// 稽查内容的删除
handleDelete (index) {
this.dataSource.splice(index, 1)
},
// 稽查内容新增编辑完成
checkContentOk (value, index) {
console.log(value, index)
if (index || index === 0) {
// 有下标,说明是编辑
if (!value.clause && !value.rectificationDepartment && !value.requirement) {
// 三个字段都没有数据,删除该行
this.dataSource.splice(index, 1)
} else {
this.dataSource.splice(index, 1, value)
}
} else {
// 没有下标, 是新增
if (!value.clause && !value.rectificationDepartment && !value.requirement) {
// 三个字段都没有数据不新增
return
}
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;
}
/deep/ .ant-drawer-content-wrapper {
min-width: 800px;
}
</style>