<template>
|
<view class="form-container">
|
<u--form :model="formData" ref="uForm">
|
<u-form-item label="检验单号" label-width="150rpx">
|
<u-input v-model="formData.PI_BILLNO" disabled />
|
</u-form-item>
|
|
<u-form-item label="用户" label-width="150rpx">
|
<u-input v-model="formData.PI_USER" disabled />
|
</u-form-item>
|
|
<u-form-item label="批次数量" label-width="150rpx">
|
<u-input v-model="formData.PI_QTY" disabled />
|
</u-form-item>
|
|
<u-form-item label="不良数量" label-width="150rpx" prop="PI_BADQTY" :required="true">
|
<u-input v-model="formData.PI_BADQTY" type="digit" placeholder="请输入不良数量" />
|
</u-form-item>
|
|
<u-button type="primary" @click="submitForm" class="submit-btn">
|
提交
|
</u-button>
|
</u--form>
|
</view>
|
</template>
|
|
<script>
|
export default {
|
data() {
|
return {
|
formData: {
|
PI_BILLNO: '', // 检验单号
|
PI_USER: '', // 委托人
|
PI_QTY: '', // 批次数量
|
PI_BADQTY: '' // 不良数量
|
},
|
rules: {
|
PI_BILLNO: [{ required: true, message: '请输入检验单号', trigger: 'change' }],
|
PI_USER: [{ required: true, message: '请输入委托人', trigger: 'change' }],
|
PI_BADQTY: [
|
{ required: true, message: '请输入不良数量', trigger: 'change' },
|
{
|
validator: (rule, value, callback) => {
|
if (value === '' || value === null) {
|
return new Error('请输入不良数量');
|
}
|
// 必须是非负数字(整数或小数)
|
if (!/^\d+(\.\d+)?$/.test(value)) {
|
return new Error('请输入非负数字');
|
}
|
// 转成浮点数比较
|
const badQty = parseFloat(value);
|
const totalQty = parseFloat(this.formData.PI_QTY || 0);
|
if (badQty > totalQty) {
|
return new Error('不良数量不能大于批次数量');
|
}
|
return true;
|
},
|
trigger: 'change'
|
}
|
]
|
}
|
};
|
},
|
methods: {
|
onReady() {
|
this.$refs.uForm.setRules(this.rules);
|
},
|
onLoad(options) {
|
this.formData.PI_BILLNO = options.releaseNo || '';
|
this.formData.PI_USER = options.userID || '';
|
this.formData.PI_QTY = options.qty || '';
|
},
|
async submitForm() {
|
try {
|
const valid = await this.$refs.uForm.validate();
|
if (valid) {
|
this.$post({
|
url: "/LLJ/SaveYcczSubmit",
|
data: JSON.stringify(this.formData)
|
}).then(res => {
|
if (res.status == 0) {
|
uni.showToast({ title: '提交成功', icon: 'success' });
|
setTimeout(() => uni.navigateBack(), 2000);
|
} else {
|
uni.showToast({ title: res.message, icon: 'error' });
|
}
|
});
|
}
|
} catch (error) {
|
uni.showToast({ title: '请填写必填项', icon: 'error' });
|
}
|
}
|
}
|
};
|
</script>
|
|
<style>
|
.form-container {
|
padding: 30rpx;
|
}
|
.submit-btn {
|
margin-top: 60rpx;
|
}
|
</style>
|