<template>
|
<el-dialog
|
:title="!dataForm.id ? '新增' : '修改'"
|
:close-on-click-modal="false"
|
:visible.sync="visible"
|
>
|
<el-form
|
:model="dataForm"
|
:rules="rules"
|
ref="dataForm"
|
label-width="100px"
|
class="l-mes"
|
>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="规则编号" prop="ruleNo">
|
<el-input v-model="dataForm.ruleNo" disabled></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="规则名称" prop="ruleName">
|
<el-input
|
v-model="dataForm.ruleName"
|
placeholder="规则名称"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="抽检工序" prop="samplingOperationName">
|
<el-input
|
v-model="dataForm.samplingOperationName"
|
placeholder="抽检工序"
|
disabled
|
>
|
<el-button
|
slot="append"
|
icon="el-icon-search"
|
@click="openOperatePart"
|
></el-button>
|
</el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="追溯工序" prop="retrospectOperationName">
|
<el-input
|
v-model="dataForm.retrospectOperationName"
|
placeholder="追溯工序"
|
disabled
|
>
|
<el-button
|
slot="append"
|
icon="el-icon-search"
|
@click="openSecondOperatePart"
|
></el-button>
|
</el-input>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="检测类型" prop="applyType">
|
<el-select
|
v-model="dataForm.applyType"
|
filterable
|
placeholder="请选择"
|
style="width: 100%;"
|
>
|
<el-option
|
v-for="(item, index) in reportTypeOptions"
|
:key="index"
|
:label="item.label"
|
:value="item.value"
|
>
|
</el-option>
|
</el-select>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12">
|
<el-form-item label="抽检比例">
|
<div style="display:flex;">
|
<div>
|
<el-input
|
v-model="dataForm.samplingNumerator"
|
placeholder="分子"
|
class="sampling-numerator-input"
|
></el-input>
|
</div>
|
<div style="width:20px;text-align:center;">/</div>
|
<div>
|
<el-input
|
v-model="dataForm.samplingDenominator"
|
placeholder="分母"
|
class="sampling-denominator-input"
|
></el-input>
|
</div>
|
</div>
|
</el-form-item>
|
</el-col>
|
</el-row>
|
<el-row>
|
<el-col :span="12">
|
<el-form-item label="抽检位置" prop="samplingPosition">
|
<el-input
|
v-model="dataForm.samplingPosition"
|
placeholder="抽检位置"
|
></el-input>
|
</el-form-item>
|
</el-col>
|
<el-col :span="12"> </el-col>
|
</el-row>
|
</el-form>
|
<span slot="footer" class="dialog-footer">
|
<el-button @click="visible = false">取消</el-button>
|
<el-button
|
type="primary"
|
:disabled="isSubmit"
|
v-thinclick="`dataFormSubmit`"
|
>确定</el-button
|
>
|
</span>
|
<operationDialog
|
:currshowlist.sync="showOperation"
|
@listenToOperationEvent="insertOperation"
|
/>
|
<operationSecondDialog
|
:currshowlist.sync="showSecondOperation"
|
@listenToOperationEvent="insertSecondOperation"
|
/>
|
</el-dialog>
|
</template>
|
<style scoped>
|
.sampling-numerator-input >>> input {
|
text-align: center;
|
}
|
.sampling-denominator-input >>> input {
|
text-align: center;
|
}
|
</style>
|
<script>
|
import {
|
getSamplingRule,
|
addSamplingRule,
|
updateSamplingRule
|
} from '@/api/quality/samplingrule'
|
import operationDialog from '@/views/common/operation.vue'
|
import operationSecondDialog from '@/views/common/operation.vue'
|
import { remote } from '@/api/admin/dict'
|
|
export default {
|
props: {},
|
components: {
|
operationDialog,
|
operationSecondDialog
|
},
|
data() {
|
return {
|
visible: false,
|
dataForm: {
|
id: 0,
|
ruleNo: null,
|
ruleName: null,
|
samplingOperationId: null,
|
samplingOperationName: null,
|
retrospectOperationId: null,
|
retrospectOperationName: null,
|
applyType: null,
|
samplingDenominator: null,
|
samplingNumerator: null,
|
samplingPosition: '1'
|
},
|
isSubmit: false,
|
showOperation: false,
|
showSecondOperation: false,
|
reportTypeOptions: []
|
}
|
},
|
computed: {
|
rules: function() {
|
return {
|
ruleName: [
|
{ required: true, message: '规则名称不能为空', trigger: 'blur' }
|
],
|
samplingOperationName: [
|
{ required: true, message: '抽检工序不能为空', trigger: 'blur' }
|
],
|
applyType: [
|
{ required: true, message: '检测类型不能为空', trigger: 'blur' }
|
],
|
samplingPosition: [
|
{ required: true, message: '抽检位置不能为空', trigger: 'blur' }
|
]
|
}
|
}
|
},
|
methods: {
|
init(id) {
|
this.dataForm.id = id || 0
|
this.visible = true
|
this.$nextTick(() => {
|
this.$refs.dataForm.resetFields()
|
if (this.dataForm.id) {
|
getSamplingRule(this.dataForm.id).then((response) => {
|
this.dataForm = response.data.data
|
})
|
} else {
|
this.dataForm.samplingDenominator = ''
|
this.dataForm.samplingNumerator = ''
|
}
|
})
|
},
|
openOperatePart() {
|
this.showOperation = true
|
},
|
insertOperation(operation) {
|
if (operation) {
|
this.dataForm.samplingOperationId = operation.id
|
this.dataForm.samplingOperationName = operation.name
|
}
|
},
|
openSecondOperatePart() {
|
this.showSecondOperation = true
|
},
|
insertSecondOperation(operation) {
|
if (operation) {
|
this.dataForm.retrospectOperationId = operation.id
|
this.dataForm.retrospectOperationName = operation.name
|
}
|
},
|
// 表单提交
|
dataFormSubmit() {
|
this.isSubmit = true
|
this.$refs.dataForm.validate((valid) => {
|
if (valid) {
|
// 校验各种
|
if (
|
this.dataForm.samplingDenominator != null &&
|
this.dataForm.samplingDenominator != '' &&
|
this.dataForm.samplingNumerator != null &&
|
this.dataForm.samplingNumerator != ''
|
) {
|
if (
|
!this.checkNumber(this.dataForm.samplingDenominator) ||
|
!this.checkNumber(this.dataForm.samplingNumerator)
|
) {
|
this.$message.error('抽检比例需填写正整数')
|
this.isSubmit = false
|
} else {
|
if (
|
Number(this.dataForm.samplingNumerator) >
|
Number(this.dataForm.samplingDenominator)
|
) {
|
this.$message.error('分子需小于等于分母')
|
this.isSubmit = false
|
} else {
|
if (this.dataForm.id) {
|
updateSamplingRule(this.dataForm)
|
.then((data) => {
|
this.$message.success('修改成功')
|
this.visible = false
|
this.isSubmit = false
|
this.$emit('refreshDataList')
|
})
|
.catch((error) => {
|
this.isSubmit = false
|
console.log(error)
|
})
|
} else {
|
addSamplingRule(this.dataForm)
|
.then((data) => {
|
this.$message.success('新增成功')
|
this.visible = false
|
this.isSubmit = false
|
this.$emit('refreshDataList')
|
})
|
.catch((error) => {
|
this.isSubmit = false
|
console.log(error)
|
})
|
}
|
}
|
}
|
} else {
|
this.isSubmit = false
|
this.$message.error('抽检比例不能为空')
|
}
|
} else {
|
this.isSubmit = false
|
}
|
})
|
},
|
initReportTypeSelect() {
|
remote('apply_report_type').then((response) => {
|
const code = response.data.code
|
if (code === 0) {
|
const _data = response.data.data
|
this.reportTypeOptions = _data
|
}
|
})
|
},
|
// 判断正整数
|
checkNumber(value) {
|
if (!/(^[1-9]\d*$)/.test(value)) {
|
return false
|
} else {
|
return true
|
}
|
}
|
},
|
created() {
|
this.initReportTypeSelect()
|
},
|
watch: {}
|
}
|
</script>
|