zjh
2 天以前 2ba045658a9e6a1a28cf0bdf1a751395ad283c62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<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>