<template>
|
<a-modal
|
:title="title"
|
:maskClosable="true"
|
:width="modalWidth"
|
@cancel="handleModalClose"
|
:visible="visible">
|
<a-spin :spinning="confirmLoading">
|
<a-form-model ref="form" :form="form" :model="model" :rules="validatorRules">
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-model-item prop="componentNo" label="零件号" :labelCol="labelColLong"
|
:wrapperCol="wrapperColLong">
|
<a-input v-model="model.componentNo" placeholder="请输入零件号"></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-model-item prop="componentName" label="零件名称" :labelCol="labelColLong"
|
:wrapperCol="wrapperColLong">
|
<a-input v-model="model.componentName" placeholder="请输入零件名称"></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-model-item prop="scheduleNum" label="班产能" :labelCol="labelCol"
|
:wrapperCol="wrapperCol">
|
<a-input v-model="model.scheduleNum" placeholder="请输入班产能"></a-input>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item prop="dayNum" label="天产能" :labelCol="labelCol"
|
:wrapperCol="wrapperCol">
|
<a-input v-model="model.dayNum" placeholder="请输入天产能"></a-input>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="24">
|
<a-form-model-item prop="productionId" label="生产线" :labelCol="labelColLong"
|
:wrapperCol="wrapperColLong">
|
<a-select v-model="model.productionId" @change="handleProductionLineChange"
|
placeholder="请选择生产线">
|
<a-select-option v-for="(item,index) in productionList" :key="index" :value="item.id">
|
{{item.productionName}}
|
</a-select-option>
|
</a-select>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row :gutter="24">
|
<a-col :span="12">
|
<a-form-model-item prop="overallFlag" label="是否为自动线" :labelCol="{xs: { span: 24 },sm: { span: 8 }}"
|
:wrapperCol="{xs: { span: 24 },sm: { span: 16 }}">
|
<j-switch v-model="model.overallFlag"></j-switch>
|
</a-form-model-item>
|
</a-col>
|
|
<a-col :span="12">
|
<a-form-model-item prop="equipmentId" label="生产设备" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-select v-model="model.equipmentId" placeholder="请选择生产设备" style="width: 100%">
|
<a-select-option v-for="(item,index) in equipmentList" :key="index" :value="item.equipmentId">
|
{{item.equipmentId}}
|
</a-select-option>
|
</a-select>
|
</a-form-model-item>
|
</a-col>
|
|
</a-row>
|
|
</a-form-model>
|
</a-spin>
|
|
|
<template slot="footer">
|
<a-popconfirm title="确定放弃操作?" @confirm="visible=false" okText="确定" cancelText="取消">
|
<a-button style="margin-right: .8rem">取消</a-button>
|
</a-popconfirm>
|
<a-button @click="handleSubmit" type="primary" :loading="confirmLoading">提交</a-button>
|
</template>
|
|
</a-modal>
|
|
</template>
|
|
<script>
|
import pick from 'lodash.pick'
|
import api from '@/api/mdc'
|
|
export default {
|
name: 'SparePartsModal',
|
components: {},
|
props: {
|
driveTypeList: {
|
type: Array
|
}
|
},
|
data() {
|
return {
|
modalWidth: 700,
|
form: this.$form.createForm(this),
|
validatorRules: {
|
componentNo: [
|
{
|
required: true, message: '请输入零件号'
|
}
|
],
|
componentName: [
|
{
|
required: true, message: '请输入零件名称'
|
}
|
],
|
scheduleNum: [
|
{
|
required: true, message: '请输入班产能'
|
}
|
],
|
dayNum: [
|
{
|
required: true, message: '请输入天产能'
|
}
|
],
|
productionId: [
|
{
|
required: true, message: '请选择生产线'
|
}
|
]
|
},
|
title: '操作',
|
visible: false,
|
model: {
|
componentNo: '',
|
componentName: '',
|
scheduleNum: '',
|
dayNum: '',
|
overallFlag: 'Y'
|
},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 6 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 18 }
|
},
|
labelColLong: {
|
xs: { span: 24 },
|
sm: { span: 3 }
|
},
|
wrapperColLong: {
|
xs: { span: 24 },
|
sm: { span: 21 }
|
},
|
confirmLoading: false,
|
productionList: [],
|
equipmentList: []
|
}
|
},
|
created() {
|
|
},
|
methods: {
|
add() {
|
this.visible = true
|
this.model = {
|
componentNo: '',
|
componentName: '',
|
scheduleNum: '',
|
dayNum: '',
|
overallFlag: 'Y'
|
}
|
this.getProductionLineByApi()
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'componentNo', 'componentName', 'scheduleNum', 'dayNum', 'overallFlag'))
|
})
|
},
|
|
edit(record) {
|
this.visible = true
|
this.model = Object.assign({}, record)
|
console.log('model', this.model)
|
this.getProductionLineByApi()
|
this.$nextTick(() => {
|
this.form.setFieldsValue(pick(this.model, 'componentNo', 'componentName', 'scheduleNum', 'dayNum', 'productionId', 'overallFlag', 'equipmentId'))
|
})
|
},
|
|
handleSubmit() {
|
const that = this
|
// 触发表单验证
|
this.$refs.form.validate(valid => {
|
if (valid) {
|
that.confirmLoading = true
|
let obj
|
if (this.title == '新增') {
|
obj = api.addSparePartApi(this.model)
|
} else {
|
obj = api.editSparePartApi(this.model)
|
}
|
obj.then((res) => {
|
if (res.success) {
|
that.$notification.success({
|
message: '消息',
|
description: res.message
|
})
|
that.$emit('ok')
|
} else {
|
that.$notification.warning({
|
message: '消息',
|
description: res.message
|
})
|
}
|
}).finally(() => {
|
that.confirmLoading = false
|
this.visible = false
|
})
|
} else {
|
return false
|
}
|
})
|
},
|
|
getProductionLineByApi() {
|
api.getProductionLineApi()
|
.then(res => {
|
if (res.success) {
|
console.log('res', res)
|
this.productionList = res.result
|
if (this.model.productionId) {
|
if (!this.model.equipmentId) delete this.model.equipmentId
|
this.getEquipmentListByProductionId()
|
}
|
}
|
})
|
},
|
|
/**
|
* 生产线选中后获取对应生产设备
|
*/
|
handleProductionLineChange() {
|
delete this.model.equipmentId
|
this.getEquipmentListByProductionId()
|
},
|
|
getEquipmentListByProductionId() {
|
api.getEquipmentListByProductionIdApi(this.model.productionId)
|
.then(res => {
|
console.log('res=-', res)
|
this.equipmentList = res.result.records
|
})
|
},
|
|
handleModalClose() {
|
this.visible = false
|
this.equipmentList = []
|
},
|
|
/**
|
* 编辑或查看详情数据时清除抽屉表单验证
|
*/
|
removeValidate() {
|
if (this.$refs.form) this.$refs.form.clearValidate()
|
}
|
}
|
|
}
|
</script>
|
|
<style scoped>
|
|
</style>
|