<template>
|
<el-dialog
|
width="60%"
|
title="编辑物料"
|
top="5vh"
|
:visible.sync="innerVisible"
|
append-to-body
|
@close="$emit('update:currshowlist', false)"
|
:show="currshowlist"
|
class="part-dialog"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
label-width="120px"
|
class="l-mes"
|
>
|
<el-form-item label="零件" prop="partId">
|
<el-input v-model="dataForm.partName" placeholder="" readonly>
|
<el-button
|
slot="append"
|
icon="el-icon-search"
|
@click="openPartDialog()"
|
></el-button>
|
</el-input>
|
</el-form-item>
|
<el-form-item label="单位产出所需数量" prop="qpa">
|
<el-input v-model="dataForm.qpa" placeholder=""></el-input>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button @click="innerVisible = false">取 消</el-button>
|
<el-button
|
type="primary"
|
:disabled="isSubmit"
|
v-thinclick="`saveSelectRow`"
|
>保 存</el-button
|
>
|
</div>
|
<!-- 选择弹框 -->
|
<part-dialog
|
:currshowlist.sync="showPart"
|
@listenToPartEvent="selectPart"
|
/>
|
</el-dialog>
|
</template>
|
<script>
|
import {
|
addOperationTaskMaterial,
|
updateOperationTaskMaterial,
|
getOperationTaskMaterial
|
} from '@/api/plan/operationtask'
|
import { mapGetters } from 'vuex'
|
import { validateSixDecimalNotNull } from '@/util/validate'
|
import PartDialog from '@/views/common/part'
|
export default {
|
props: {
|
currshowlist: {
|
type: Boolean,
|
default: false
|
},
|
materialObj: {
|
type: Object,
|
default: () => {
|
return {}
|
}
|
}
|
},
|
data() {
|
return {
|
innerVisible: false,
|
isSubmit: false,
|
showPart: false,
|
dataForm: {
|
partName: null,
|
partNo: null,
|
partId: null,
|
qpa: null,
|
id: 0,
|
operationTaskId: null,
|
quantityRequired: null
|
},
|
dataRule: {
|
partId: [{ required: true, message: '零件不能为空', trigger: 'blur' }],
|
qpa: [
|
{
|
required: true,
|
message: '单位产出所需数量不能为空',
|
trigger: 'blur'
|
},
|
{ validator: validateSixDecimalNotNull, trigger: 'blur' }
|
]
|
}
|
}
|
},
|
components: { PartDialog },
|
watch: {
|
currshowlist() {
|
this.innerVisible = this.currshowlist
|
this.initData()
|
if (this.currshowlist) {
|
this.$nextTick(() => {
|
// this.getData()
|
if (this.materialObj.id != null) {
|
// 查询已有需求物料信息
|
getOperationTaskMaterial(this.materialObj.id).then((response) => {
|
const resData = response.data
|
if (resData.code === 0) {
|
const resObj = resData.data
|
this.dataForm.partName = resObj.partName
|
this.dataForm.partNo = resObj.partNo
|
this.dataForm.partId = resObj.partId
|
this.dataForm.qpa = resObj.qpa
|
this.dataForm.id = resObj.id
|
this.dataForm.quantityRequired = resObj.quantityRequired
|
}
|
})
|
}
|
})
|
}
|
}
|
},
|
computed: {
|
...mapGetters(['permissions'])
|
},
|
created() {},
|
methods: {
|
saveSelectRow() {
|
this.isSubmit = true
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
// 去除零件编号两边的空格
|
if (this.dataForm.id) {
|
updateOperationTaskMaterial(this.dataForm)
|
.then((data) => {
|
this.$message.success('修改成功')
|
this.innerVisible = false
|
this.isSubmit = false
|
this.$emit('refreshOperationMaterialList')
|
})
|
.catch((error) => {
|
this.isSubmit = false
|
console.log(error)
|
})
|
} else {
|
addOperationTaskMaterial(this.dataForm)
|
.then((data) => {
|
this.$message.success('添加成功')
|
this.innerVisible = false
|
this.isSubmit = false
|
this.$emit('refreshOperationMaterialList')
|
})
|
.catch((error) => {
|
this.isSubmit = false
|
console.log(error)
|
})
|
}
|
} else {
|
this.isSubmit = false
|
}
|
})
|
},
|
initData() {
|
this.dataForm.partName = null
|
this.dataForm.partNo = null
|
this.dataForm.partId = null
|
this.dataForm.qpa = null
|
this.dataForm.id = 0
|
this.dataForm.operationTaskId = this.materialObj.opTaskId
|
this.dataForm.quantityRequired = null
|
},
|
// 零件选择
|
openPartDialog() {
|
this.showPart = true
|
},
|
selectPart(part) {
|
if (part) {
|
this.dataForm.partNo = part.partNo
|
this.dataForm.partName = part.partName
|
this.dataForm.partId = part.id
|
}
|
}
|
}
|
}
|
</script>
|