<template>
|
<div>
|
<el-dialog :visible.sync="dialogVisible" :title="title" :close-on-click-modal="false" width="30%" :modal-append-to-body="false" v-if="dialogVisible">
|
<el-form size="mini" :model="form" label-width="120px" ref="form" :rules="formRules">
|
<el-form-item label="批次:" prop="batchName">
|
{{batchInfo.batchName}}
|
</el-form-item>
|
<el-form-item label="批次描述:" prop="batchDesc">
|
{{batchInfo.batchDesc}}
|
</el-form-item>
|
<el-form-item label="箱码个数:" prop="boxCount">
|
<el-input-number @keydown.native="limiInputType" @change="getBottleNum" v-model="form.boxCount"></el-input-number>
|
</el-form-item>
|
<el-form-item label="包装规格:" prop="specification">
|
<el-input-number disabled v-model="form.proportion"></el-input-number> :<el-input-number @keydown.native="limiInputType" @change="getBottleNum" v-model="form.specification"></el-input-number>
|
</el-form-item>
|
<el-form-item label="瓶码个数:" prop="bottleNum">
|
<el-input-number disabled v-model="form.bottleNum"></el-input-number>
|
</el-form-item>
|
</el-form>
|
<div slot="footer" class="dialog-footer">
|
<el-button size="mini" @click="submit" type="primary" :loading="loading">保存</el-button>
|
<el-button size="mini" @click="dialogVisible = false">取消</el-button>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
<script>
|
// import { objectCopy } from '@/utils/objectCopyHelper'
|
import { limiInputType } from '@/utils/limiInputType'
|
import QRCodeApi from '@/api/QRCode'
|
|
export default {
|
props: {
|
show: {
|
type: Boolean,
|
default: false
|
},
|
title: {
|
type: String,
|
default: '新增二维码'
|
},
|
batchInfo: {
|
type: Object,
|
default: function () {
|
return {}
|
}
|
}
|
},
|
data () {
|
const inputNumberValid = (rule, value, callback) => {
|
const reg = /^[0-9]*$/ // 只能输入正整数
|
if (!value || !reg.test(value)) {
|
callback(new Error('请输入大于0的整数'))
|
} else {
|
callback()
|
}
|
}
|
return {
|
dialogVisible: false,
|
form: {
|
boxCount: null,
|
proportion: 1,
|
specification: null,
|
bottleNum: null
|
},
|
formRules: {
|
boxCount: [
|
{ required: true, message: '请输入箱码个数' },
|
{ type: 'number', max: 999, message: '箱码个数不能超过999' },
|
{ validator: inputNumberValid }
|
],
|
specification: [
|
{ required: true, message: '请输入包装规格' },
|
{ validator: inputNumberValid },
|
{ type: 'number', max: 24, message: '箱码个数不能超过24' }
|
]
|
},
|
loading: false
|
}
|
},
|
watch: {
|
/**
|
* 监控外部显示变量变化
|
* 传递到dialog组件
|
*/
|
show: function (newShow, oldShow) {
|
this.dialogVisible = newShow
|
},
|
/**
|
* 监控内部显示属性变化
|
* 传递到外部调用变量
|
*/
|
dialogVisible: function (newDialogShow, oldDialogShow) {
|
this.$emit('update:show', newDialogShow)
|
if (!newDialogShow) {
|
for (const key in this.form) {
|
if (key !== 'proportion') this.form[key] = null
|
}
|
}
|
}
|
},
|
methods: {
|
getBottleNum () {
|
if (this.form.boxCount && this.form.specification) {
|
this.form.bottleNum = this.form.boxCount * this.form.specification
|
}
|
},
|
/**
|
* 限制不能输入数字
|
*/
|
limiInputType (e) {
|
limiInputType(e)
|
},
|
/**
|
* 提交
|
*/
|
submit () {
|
this.$refs.form.validate().then(res => {
|
this.addInfo() // 新增推送
|
})
|
},
|
/**
|
* 增加活动
|
*/
|
addInfo () {
|
this.loading = true
|
this.form.batchId = this.batchInfo.id
|
QRCodeApi.qrcodeAdd(this.form).then(res => {
|
if (res.data) {
|
this.$message({
|
message: '操作成功',
|
type: 'success'
|
})
|
this.loading = false
|
this.$parent.queryData()
|
this.dialogVisible = false
|
} else {
|
this.loading = false
|
}
|
}).catch(() => {
|
this.loading = false
|
})
|
}
|
}
|
}
|
</script>
|