Files
laws-sinotruk-client/src/views/standardRegulationLibrary/overseasStandard/modules/OverseasStandardModal.vue
T

144 lines
4.0 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.OVERSEAS.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"
@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 {
getOverseasStandardForm,
getOverseasStandardDocumentInfo,
addOverseasStandard,
editOverseasStandard
} from '../../../../api/standardRegulationLibraryApi'
import { StandardSource } from '../../../../enums/commonEnums.js'
export default {
name: 'OverseasStandardModal',
components: { AddForm },
data () {
return {
StandardSource,
visible: false,
title: '',
width: 800,
// 存储表单的数据
form: {},
confirmLoading: false,
getFormFunc: getOverseasStandardForm,
getDocumentInfoFunc: getOverseasStandardDocumentInfo,
// 特殊的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 () {
console.log(this.isEdit)
if (this.isEdit) {
// 标准编号,被代替标准号,被引用标准号
return ['standard_class', 'year_number', 'standard_number_temp', 'replaced_by_standard_number', 'referenced_standard']
}
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 = editOverseasStandard
} else {
submitFunc = addOverseasStandard
}
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>