<template>
|
<el-dialog
|
:title="!dataForm.id ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="dataRule"
|
ref="dataForm"
|
label-width="160px"
|
class="l-mes"
|
>
|
<el-row>
|
<el-col :span="20">
|
<el-form-item label="备注" prop="remark">
|
<el-input v-model="dataForm.remark" placeholder=""></el-input>
|
</el-form-item>
|
<el-form-item label="检测标准编号(计划)" prop="moTestStandardId">
|
<el-select
|
v-model="dataForm.moTestStandardId"
|
placeholder=""
|
filterable
|
style="width: 100%"
|
@change="selectChanged"
|
>
|
<el-option
|
v-for="item in dataForm.testStandardList"
|
:key="item.id"
|
:label="item.standardNo"
|
:value="item.id"
|
/>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="20">
|
<el-form-item label="已有的合格数量" prop="qtyArrived">
|
<el-input v-model="dataForm.qtyArrived" placeholder=""></el-input>
|
</el-form-item>
|
<el-form-item label="不合格数量" prop="unqualifiedArrived">
|
<el-input
|
v-model="dataForm.unqualifiedArrived"
|
placeholder=""
|
@change="updataQtyArrived()"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button type="primary" @click="dataFormSubmit()">确定</el-button>
|
</span>
|
</el-dialog>
|
</template>
|
|
<script>
|
import { getApplyPart, batchUpdateApplyPart } from '@/api/quality/apply'
|
import {
|
accSub,
|
validateInteger,
|
validatePositiveInteger,
|
validateSixDecimalPositive,
|
validateSixDecimalPositives
|
} from '../../../util/validate'
|
|
export default {
|
data() {
|
return {
|
booleanOptions: [
|
{ value: true, label: '是' },
|
{ value: false, label: '否' }
|
],
|
visible: false,
|
unqualifiedArrivedNumber: '',
|
dataForm: {
|
id: 0,
|
isQualified: null,
|
testStandardNo: '',
|
moTestStandardId: 0,
|
remark: '',
|
testStandardList: [],
|
unqualifiedArrived: '',
|
qtyArrived: ''
|
},
|
dataRule: {
|
unqualifiedArrived: [
|
{ validator: validateSixDecimalPositives, trigger: 'blur' }
|
]
|
}
|
}
|
},
|
methods: {
|
init(id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.dataForm.resetFields()
|
if (this.dataForm.id) {
|
getApplyPart(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
this.qtyArrivedNumber = this.dataForm.qtyArrived
|
this.unqualifiedArrivedNumber = this.dataForm.unqualifiedArrived
|
})
|
}
|
})
|
},
|
updataQtyArrived() {
|
if (
|
Number(this.dataForm.unqualifiedArrived) > Number(this.qtyArrivedNumber)
|
) {
|
this.$message.error('不合格数量不能超过合格数量')
|
this.dataForm.qtyArrived = this.qtyArrivedNumber
|
this.dataForm.unqualifiedArrived = this.unqualifiedArrivedNumber
|
return
|
}
|
if (this.dataForm.unqualifiedArrived < 0) {
|
return
|
}
|
var number = accSub(
|
this.dataForm.unqualifiedArrived,
|
this.unqualifiedArrivedNumber
|
)
|
this.dataForm.qtyArrived = accSub(this.qtyArrivedNumber, number)
|
},
|
selectChanged(value) {
|
if (value) {
|
const testStandard = this.dataForm.testStandardList.find(
|
(e) => e.id === value
|
)
|
if (testStandard && testStandard.standardNo) {
|
this.dataForm.testStandardNo = testStandard.standardNo
|
}
|
}
|
},
|
// 表单提交
|
dataFormSubmit() {
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
if (this.dataForm.id) {
|
const arr = []
|
arr.push(this.dataForm)
|
batchUpdateApplyPart(arr, 0).then((data) => {
|
this.$message.success('修改成功')
|
this.visible = false
|
this.$emit('refreshDataList')
|
})
|
}
|
}
|
})
|
}
|
}
|
}
|
</script>
|