Files
laws-sinotruk-client/src/views/standardRegulationLibrary/domesticStandard/modules/DomesticStandardModal.vue
T

147 lines
4.3 KiB
Vue

<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.DOMESTIC.value"
:get-form-func="getFormFunc"
:get-document-info-func="getDocumentInfoFunc"
:special-placeholder="specialPlaceholder"
:default-value="defaultValue"
:disabled-field-list="disabledField"
:open-selected-all-field-list="openSelectedAllFieldList"
:exclude-standard-fields="excludeStandardFields"
domestic-special-check
:flag-by-field="{associated_foreign_standards: StandardSource.OVERSEAS.value}"
:needSyncRemarksDataField="['new_model_implementation_date', 'on_the_production_date']"
:process-is-allow-upload-doc="false"
@submitFormData="submitFormData" />
</a-spin>
</div>
<div class="custom-drawer-style-bottom-btn">
<a-button @click="handleCancel" style="margin-bottom: 0;" :loading="confirmLoading">{{ $t('close') }}</a-button>
<a-button @click="handleOk" type="primary" style="margin-bottom: 0;" :loading="confirmLoading">
{{ $t('preservation') }}
</a-button>
</div>
</a-drawer>
</template>
<script>
import AddForm from '../../../../components/customField/AddForm.vue'
import {
getDomesticStandardDocumentInfo,
getDomesticStandardFormModal,
addDomesticStandard,
editDomesticStandard
} from '../../../../api/standardRegulationLibraryApi'
import { StandardSource } from '../../../../enums/commonEnums.js'
export default {
name: 'DomesticStandardModal',
components: { AddForm },
data () {
return {
StandardSource,
visible: false,
title: '',
width: 800,
// 存储表单的数据
form: {},
confirmLoading: false,
getFormFunc: getDomesticStandardFormModal,
getDocumentInfoFunc: getDomesticStandardDocumentInfo,
// 特殊的placeholder
specialPlaceholder: {
standard_number_temp: `${this.$t('standardRegulationLibrary.inputExample')}7258`
},
defaultValue: {
year_number: new Date().getFullYear() + ''
},
// 数据字典多选,需要全选功能的字段
openSelectedAllFieldList: [
'applicable_vehicle', // 适用车型
'dynamic_type' // 动力类型
],
isEdit: null // 是否编辑
}
},
computed: {
// 不可编辑的字段
disabledField () {
if (this.isEdit) {
// 标准编号,被代替标准号,被引用标准号,标准类别,年代号
return ['standard_number_temp', 'replaced_by_standard_number', 'referenced_standard', 'standard_class', 'year_number']
}
return ['replaced_by_standard_number', 'referenced_standard']
},
excludeStandardFields () {
if (this.isEdit) {
return ['substitute_standard_number', 'reference_standard']
}
return []
}
},
methods: {
add () {
this.visible = true
this.isEdit = false
this.$nextTick(() => {
this.$refs.addForm.add()
})
},
edit (record) {
this.visible = true
this.isEdit = true
this.$nextTick(() => {
this.$refs.addForm.edit(record)
})
},
handleOk () {
this.$refs.addForm.submit()
},
// 表单提交的回调,获取表单数据
submitFormData (formInline) {
this.confirmLoading = true
let submitFunc
if (formInline.id) {
submitFunc = editDomesticStandard
} else {
submitFunc = addDomesticStandard
}
submitFunc(formInline).then((res) => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
handleCancel () {
this.close()
},
close () {
this.visible = false
}
}
}
</script>
<style scoped>
</style>