<template>
|
<j-modal
|
:title="title"
|
:width="1200"
|
:visible="visible"
|
:confirmLoading="confirmLoading"
|
switchFullscreen
|
@ok="handleOk"
|
@cancel="handleCancel"
|
cancelText="关闭">
|
<a-spin :spinning="spinning">
|
<a-form-model ref="form" :model="model" :rules="validatorRules" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-row :gutter="24">
|
<a-col :span="8">
|
<a-form-model-item prop="standardCode" label="规范编码">
|
<a-input placeholder="编码系统自动生成" v-model="model.standardCode" disabled/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="8">
|
<a-form-model-item prop="standardName" label="规范名称">
|
<a-input placeholder="请输入规范名称" v-model="model.standardName"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="8">
|
<a-form-model-item prop="equipmentId" label="统一编码">
|
<lx-search-equipment-select placeholder="请输入统一编码或名称搜索" v-model="model.equipmentId" :disabled="!editable"/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="8">
|
<a-form-model-item prop="maintenanceCategory" label="保养分类">
|
<j-dict-select-tag dict-code="maintenance_category" placeholder="请选择保养分类"
|
@change="handleMaintenanceCategoryChange"
|
v-model="model.maintenanceCategory" :disabled="!editable"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="8">
|
<a-form-model-item label="保养周期单位">
|
<a-input readOnly v-model="model.periodUnit" placeholder="根据保养分类自动带出"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="8">
|
<a-form-model-item prop="maintenancePeriod" label="保养周期">
|
<a-input-number v-model="model.maintenancePeriod" placeholder="请输入保养周期" :min="1" :precision="0"
|
style="width: 100%"/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="8">
|
<a-form-model-item prop="initialDate" label="初始日期">
|
<a-date-picker placeholder="请选择初始日期" v-model="model.initialDate" value-format="YYYY-MM-DD"
|
style="width: 100%"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="8">
|
<a-form-model-item label="规范状态">
|
<j-dict-select-tag dict-code="maintenance_standard_status" placeholder="根据流程进度自动带出"
|
v-model="model.standardStatus" disabled/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="8">
|
<a-form-model-item label="规范版本">
|
<a-input-number v-model="model.standardVersion" placeholder="根据流程进度自动带出" style="width: 100%" disabled/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<j-vxe-table
|
ref="editableDetailTable"
|
:rowNumber="true"
|
:rowSelection="true"
|
:bordered="true"
|
:alwaysEdit="true"
|
:toolbar="true"
|
:toolbarConfig="detail.toolbarConfig"
|
keep-source
|
:height="300"
|
:loading="detail.loading"
|
:dataSource="detail.dataSource"
|
:columns="detail.columns"
|
style="margin-top: 8px;">
|
<template v-slot:itemPart="props">
|
<a-textarea v-model="props.row.itemPart" allowClear @blur="$refs.editableDetailTable.validateTable()"
|
:placeholder="!Boolean(model.maintenanceCategory)?'请选择保养分类':'请输入部位'" :rows="1"
|
autoSize :disabled="!Boolean(model.maintenanceCategory)"/>
|
</template>
|
|
<template v-slot:itemCategory="props">
|
<j-dict-select-tag v-model="props.row.itemCategory" :dict-code="encodedDictCode"
|
@change="$refs.editableDetailTable.validateTable()"
|
:placeholder="!Boolean(model.maintenanceCategory)?'请选择保养分类':'请选择项保养分类'"
|
:disabled="!Boolean(model.maintenanceCategory)"/>
|
</template>
|
</j-vxe-table>
|
</a-row>
|
</a-form-model>
|
</a-spin>
|
</j-modal>
|
</template>
|
|
<script>
|
import { getAction, httpAction } from '@/api/manage'
|
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
|
import { JVXETypes } from '@/components/jeecg/JVxeTable'
|
import LxSearchEquipmentSelect from '@views/eam/equipment/modules/LxSearchEquipmentSelect'
|
|
export default {
|
name: 'EamMaintenanceStandardModal',
|
mixins: [JVxeTableModelMixin],
|
components: {
|
LxSearchEquipmentSelect
|
},
|
data() {
|
return {
|
title: '操作',
|
visible: false,
|
model: {},
|
editable: true,
|
upgradeFlag: false,
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 7 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 16 }
|
},
|
confirmLoading: false,
|
spinning: false,
|
validatorRules: {
|
standardName: [
|
{ required: true, message: '请输入规范名称', trigger: 'change' }
|
],
|
maintenanceCategory: [
|
{ required: true, message: '请选择保养分类', trigger: 'change' }
|
],
|
initialDate: [
|
{ required: true, message: '请选择初始日期', trigger: 'change' }
|
],
|
maintenancePeriod: [
|
{ required: true, message: '请输入保养周期', trigger: 'change' }
|
],
|
equipmentId: [
|
{ required: true, message: '请输入统一编码或名称搜索', trigger: 'change' }
|
]
|
},
|
url: {
|
add: '/eam/maintenanceStandard/add',
|
edit: '/eam/maintenanceStandard/edit',
|
detail: '/eam/eamMaintenanceStandardDetail/queryList',
|
upgrade: '/eam/maintenanceStandard/upgrade'
|
},
|
detail: {
|
loading: false,
|
dataSource: [],
|
columns: [
|
{
|
title: 'ID',
|
key: 'id',
|
type: JVXETypes.hidden
|
},
|
{
|
title: 'standardId',
|
key: 'standardId',
|
type: JVXETypes.hidden
|
},
|
{
|
title: '项目序号',
|
key: 'itemCode',
|
type: JVXETypes.inputNumber,
|
align: 'center',
|
placeholder: '请输入项目序号',
|
width: 150,
|
validateRules: [
|
{ required: true, message: '请输入项目序号' },
|
{ unique: true, message: '项目序号不能重复' }
|
]
|
},
|
{
|
title: '部位',
|
key: 'itemPart',
|
type: JVXETypes.slot,
|
slotName: 'itemPart',
|
placeholder: '请输入部位',
|
align: 'center',
|
validateRules: [{ handler: this.itemPartValidate }]
|
},
|
{
|
title: '保养项分类',
|
key: 'itemCategory',
|
type: JVXETypes.slot,
|
slotName: 'itemCategory',
|
align: 'center',
|
validateRules: [{ handler: this.itemCategoryValidate }]
|
},
|
{
|
title: '保养项目',
|
key: 'itemName',
|
placeholder: '请输入保养项目',
|
type: JVXETypes.textarea,
|
align: 'center',
|
validateRules: [
|
{ required: true, message: '请输入保养项目' }
|
]
|
},
|
{
|
title: '保养规范或要求',
|
key: 'itemDemand',
|
placeholder: '请输入保养规范或要求',
|
type: JVXETypes.textarea,
|
align: 'center',
|
validateRules: [
|
{ required: true, message: '请输入保养规范或要求' }
|
]
|
}
|
],
|
defaultColumns: [
|
{
|
title: 'ID',
|
key: 'id',
|
type: JVXETypes.hidden
|
},
|
{
|
title: 'standardId',
|
key: 'standardId',
|
type: JVXETypes.hidden
|
},
|
{
|
title: '项目序号',
|
key: 'itemCode',
|
type: JVXETypes.inputNumber,
|
align: 'center',
|
placeholder: '请输入项目序号',
|
width: 150,
|
validateRules: [
|
{ required: true, message: '请输入项目序号' },
|
{ unique: true, message: '项目序号不能重复' }
|
]
|
},
|
{
|
title: '部位',
|
key: 'itemPart',
|
type: JVXETypes.slot,
|
slotName: 'itemPart',
|
placeholder: '请输入部位',
|
align: 'center',
|
validateRules: [{ handler: this.itemPartValidate }]
|
},
|
{
|
title: '保养项分类',
|
key: 'itemCategory',
|
type: JVXETypes.slot,
|
slotName: 'itemCategory',
|
align: 'center',
|
validateRules: [{ handler: this.itemCategoryValidate }]
|
},
|
{
|
title: '保养项目',
|
key: 'itemName',
|
placeholder: '请输入保养项目',
|
type: JVXETypes.textarea,
|
align: 'center',
|
validateRules: [
|
{ required: true, message: '请输入保养项目' }
|
]
|
},
|
{
|
title: '保养规范或要求',
|
key: 'itemDemand',
|
placeholder: '请输入保养规范或要求',
|
type: JVXETypes.textarea,
|
align: 'center',
|
validateRules: [
|
{ required: true, message: '请输入保养规范或要求' }
|
]
|
}
|
],
|
toolbarConfig: {
|
// prefix 前缀;suffix 后缀
|
slot: ['prefix', 'suffix'],
|
// add 新增按钮;remove 删除按钮;clearSelection 清空选择按钮
|
btn: ['add', 'remove', 'clearSelection']
|
}
|
}
|
}
|
},
|
|
watch: {
|
'model.maintenanceCategory': {
|
handler(val) {
|
if (val) {
|
if (val != 'THIRD_MAINTENANCE') this.detail.columns = [...this.detail.defaultColumns.filter(item => item.key != 'itemPart')]
|
else this.detail.columns = [...this.detail.defaultColumns.filter(item => item.key != 'itemCategory')]
|
}
|
else this.detail.columns = [...this.detail.defaultColumns]
|
}
|
}
|
},
|
computed: {
|
encodedDictCode() {
|
let suffix
|
if (!Boolean(this.model.maintenanceCategory) || this.model.maintenanceCategory === 'THIRD_MAINTENANCE') return
|
else suffix = this.model.maintenanceCategory.split('_')[1]
|
|
const dictCode = `sys_dict_item,item_text,item_value,item_value like '%${suffix}' and dict_id='1940598438685134850'`
|
return encodeURIComponent(dictCode)
|
}
|
},
|
methods: {
|
// 主页面点击新增后触发
|
add() {
|
this.model = {}
|
this.visible = true
|
this.editable = true
|
this.upgradeFlag = false
|
this.detail.dataSource = []
|
},
|
|
/**
|
* 主页面点击编辑后触发
|
* @param record 主页面列表行记录
|
*/
|
edit(record) {
|
this.model = Object.assign({}, record)
|
this.visible = true
|
this.editable = false
|
this.upgradeFlag = false
|
this.detail.dataSource = []
|
this.loadDetail(record.id)
|
},
|
|
/**
|
* 点击升版后触发
|
* @param record 主页面列表行记录
|
*/
|
upgrade(record) {
|
this.model = Object.assign({}, record)
|
this.visible = true
|
this.editable = false
|
this.upgradeFlag = true
|
this.detail.dataSource = []
|
this.loadDetail(record.id)
|
},
|
|
/**
|
* 保养分类值改变时同时改变保养周期单位以及保养项分类
|
* @param value 保养分类值
|
*/
|
handleMaintenanceCategoryChange(value) {
|
switch (value) {
|
case 'THIRD_MAINTENANCE':
|
this.model.periodUnit = '年'
|
break
|
case 'SECOND_MAINTENANCE':
|
this.model.periodUnit = '月'
|
break
|
case 'POINT_INSPECTION':
|
this.model.periodUnit = '天'
|
break
|
default:
|
delete this.model.periodUnit
|
}
|
|
const tableData = this.$refs.editableDetailTable.getTableData()
|
tableData.forEach(item => {
|
if (value !== 'THIRD_MAINTENANCE') delete item.itemPart
|
delete item.itemCategory
|
})
|
|
this.detail.dataSource = [...tableData]
|
this.$refs.editableDetailTable.validateTable()
|
},
|
|
/**
|
* 保养部位校验
|
* @param cellValue 输入值
|
* @param callback 回调函数
|
*/
|
itemPartValidate({ cellValue }, callback) {
|
if (this.model.maintenanceCategory === 'THIRD_MAINTENANCE') {
|
if (cellValue) callback(true)
|
else callback(false, '请选择${title}')
|
} else {
|
callback(true)
|
}
|
},
|
|
/**
|
* 保养项分类校验
|
* @param cellValue 输入值
|
* @param callback 回调函数
|
*/
|
itemCategoryValidate({ cellValue }, callback) {
|
if (this.model.maintenanceCategory === 'THIRD_MAINTENANCE') {
|
callback(true)
|
} else {
|
if (cellValue) callback(true)
|
else callback(false, '请选择${title}')
|
}
|
},
|
|
// 提交事件
|
async handleOk() {
|
const that = this
|
let errMap = await that.$refs.editableDetailTable.validateTable()
|
if (errMap) return false
|
// 触发表单验证
|
this.$refs.form.validate(valid => {
|
if (valid) {
|
let tableData = that.$refs.editableDetailTable.getTableData()
|
let removeData = that.$refs.editableDetailTable.getDeleteData()
|
that.model.tableDetailList = [...tableData]
|
that.model.removeDetailList = [...removeData]
|
|
that.confirmLoading = that.spinning = true
|
let httpUrl = ''
|
let method = ''
|
if (!this.model.id) {
|
httpUrl += this.url.add
|
method = 'post'
|
} else {
|
if (this.upgradeFlag) {
|
httpUrl += this.url.upgrade
|
} else {
|
httpUrl += this.url.edit
|
}
|
method = 'put'
|
}
|
httpAction(httpUrl, this.model, method)
|
.then((res) => {
|
if (res.success) {
|
that.$notification.success({
|
message: '消息',
|
description: res.message
|
})
|
that.$emit('ok')
|
that.close()
|
} else {
|
that.$notification.warning({
|
message: '消息',
|
description: res.message
|
})
|
}
|
})
|
.finally(() => {
|
that.confirmLoading = that.spinning = false
|
})
|
} else {
|
return false
|
}
|
})
|
},
|
|
handleCancel() {
|
this.close()
|
},
|
|
close() {
|
this.$emit('close')
|
this.visible = false
|
this.$refs.form.clearValidate()
|
},
|
|
//加载详情数据
|
loadDetail(standardId) {
|
this.spinning = true
|
this.detail.dataSource = []
|
if (standardId) {
|
getAction(this.url.detail, { standardId })
|
.then(res => {
|
if (res.success) {
|
this.detail.dataSource = [...res.result]
|
}
|
})
|
.finally(() => {
|
this.spinning = false
|
})
|
}
|
}
|
|
}
|
}
|
</script>
|
|
<style scoped lang="less">
|
/deep/ .ant-select-dropdown-menu {
|
text-align: left;
|
}
|
|
/deep/ textarea.ant-input {
|
resize: none;
|
margin-bottom: 0;
|
}
|
</style>
|