<template>
|
<a-spin :spinning="confirmLoading">
|
<a-form-model ref="form" :model="model" :rules="validatorRules" :labelCol="labelCol" :wrapperCol="wrapperCol">
|
<a-row>
|
<a-col :span="12">
|
<a-form-model-item label="刀具编号">
|
<a-input v-model="model.cutterCode" placeholder="请输入刀具编号" :readOnly="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="刀具名称" prop="cutterName">
|
<a-input v-model="model.cutterName" placeholder="请输入刀具名称" :readOnly="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row>
|
<a-col :span="12">
|
<a-form-model-item label="刀具简称" prop="cutterType">
|
<a-input v-model="model.cutterType" placeholder="请输入刀具简称" :readOnly="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="额定寿命">
|
<a-input-number v-model="model.lifetime" :min="0" placeholder="请输入额定寿命" style="width: 100%"
|
:disabled="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row>
|
<a-col :span="12">
|
<a-form-model-item label="刀位" prop="cutterSpacing">
|
<a-input v-model="model.cutterSpacing" placeholder="请输入刀位" :readOnly="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
<a-col :span="12">
|
<a-form-model-item label="刀具数量">
|
<a-input-number v-model="model.quantity" placeholder="请输入刀具数量" :min="1" style="width: 100%"
|
:disabled="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
|
<a-row>
|
<a-col :span="24">
|
<a-form-model-item label="描述" :labelCol="labelColLong" :wrapperCol="wrapperColLong">
|
<a-textarea v-model="model.description" placeholder="请输入描述" :readOnly="disableSubmit"/>
|
</a-form-model-item>
|
</a-col>
|
</a-row>
|
</a-form-model>
|
</a-spin>
|
</template>
|
|
<script>
|
import { httpAction } from '@/api/manage'
|
|
export default {
|
name: 'CutterModalForm',
|
components: {},
|
props: {
|
disableSubmit: {
|
type: Boolean
|
}
|
},
|
data() {
|
return {
|
model: {
|
quantity: 1
|
},
|
labelCol: {
|
xs: { span: 24 },
|
sm: { span: 8 }
|
},
|
wrapperCol: {
|
xs: { span: 24 },
|
sm: { span: 14 }
|
},
|
labelColLong: {
|
xs: { span: 24 },
|
sm: { span: 4 }
|
},
|
wrapperColLong: {
|
xs: { span: 24 },
|
sm: { span: 19 }
|
},
|
confirmLoading: false,
|
validatorRules: {
|
cutterType: [
|
{ required: true, message: '请输入刀具简称!' }
|
],
|
cutterName: [
|
{ required: true, message: '请输入刀具名称!' }
|
],
|
cutterSpacing: [
|
{ required: true, message: '请输入刀位!' }
|
]
|
},
|
url: {
|
add: '/nc/cutter/add',
|
edit: '/nc/cutter/edit'
|
}
|
}
|
},
|
created() {
|
//备份model原始值
|
this.modelDefault = JSON.parse(JSON.stringify(this.model))
|
},
|
methods: {
|
add(params) {
|
this.edit({ ...this.modelDefault, ...params })
|
},
|
edit(record) {
|
this.model = Object.assign({}, record)
|
console.log('model', this.model)
|
},
|
submitForm() {
|
const that = this
|
// 触发表单验证
|
this.$refs.form.validate(valid => {
|
if (valid) {
|
that.confirmLoading = true
|
let httpUrl, method
|
if (!this.model.id) {
|
httpUrl = this.url.add
|
method = 'post'
|
} 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')
|
} else {
|
that.$notification.warning({
|
message: '消息',
|
description: res.message
|
})
|
}
|
}).finally(() => {
|
that.confirmLoading = false
|
})
|
}
|
|
})
|
}
|
}
|
}
|
</script>
|