spring
4 天以前 435881d494e2be4ba5ce8bfccb02d6ef49e07314
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<template>
    <layout title="报检" @scanHandle="addScanCode">
        <view style="padding-top: 100rpx;" v-if="list.length == 0">
            <u-empty text="请扫码" mode="list" icon-color="black" color="black"></u-empty>
        </view>
        <view class="formWrap">
            <view class="formBox" v-for="(item, index) in list" :key="item.certificateNo" :index="index">
                <u-form class="form" :model="item" :rules="rules" :ref="item.certificateNo" label-position="left">
                    <u-form-item label="报检流水号" prop="no" label-width="180" >
                        <input v-model="item.no" placeholder="保存后自动生成" :disabled="true"></input>
                    </u-form-item>
                    <u-form-item label="合格证号" prop="certificateNo" label-width="180" >
                        <input v-model="item.certificateNo" placeholder="" :disabled="true"></input>
                    </u-form-item>
                    <u-form-item label="长度(km)" prop="len" label-width="180" >
                        <input v-model="item.len" placeholder="请输入长度" type="digit" ></input>
                    </u-form-item>
                    <u-form-item label="创建时间" prop="createTime" label-width="180" >
                        <input v-model="item.createTime" placeholder="" :disabled="true"></input>
                    </u-form-item>
                </u-form>
                <view class="delBtnWrap">
                    <u-button class="delBtn" type="primary" size="mini"  @click="deleteItem(item)">
                        <u-icon size="30" name="trash" class="icon"/>删除
                    </u-button>
                </view>    
            </view>
            <view class="form-footer" v-if="list.length > 0">
                <u-button class="btn" type="primary" @click="submit">报检</u-button>
            </view>
        </view>
        <scan></scan>
    </layout>
</template>
 
<script>
    import scan from "@/components/scan/scan.vue";
    import util from "@/util/ble/util.js";
    import layout from "./layout";
    export default {
        components: {
            scan,layout
        },
        data() {
            return {
                type: 'inspDeclaration',//inspDeclaration:报检  sampling:抽检  declaration:检测  packaging:包装  stock:入库
                list: [
                    // {
                    // id: 0,
                    // no: null,
                    // certificateNo:'00004',
                    // len:0.2,
                    // createTime:util.formatTime(new Date())
                    // },
                ],
                rules: {
                    // len: [{
                    //     required: true,
                    //     message: '长度不能为空',
                    //     trigger: 'blur'
                    // }],
                },
                nowTime:util.formatTime(new Date())
            }
        },
        onShow() {
        
            let that = this
        
            uni.$off('scan') // 每次进来先 移除全局自定义事件监听器
            uni.$on('scan', function(data) {
                console.log('onscan');
                //扫码成功后的回调,你可以写自己的逻辑代码在这里
                console.log('扫码结果:', data.code);
                that.addScanCode(data.code)
                that.$forceUpdate();
        
            })
        },
        methods: {
            //获取扫一扫数据
            addScanCode(code){
                //检测是否已扫过
                let that = this
                // that.$u.api.outsource.queryReportExist().then(res => {
                //     let exist = false
                //     if (exist) {
                //         this.$u.toast('该合格证号已报检')
                //     } else {
                        //查看列表中存不存在
                        let result = that.list.find(item => item.certificateNo==code)
                        if (result) {
                            this.$u.toast('已存在列表中')
                        } else {
                            //添加一条报检数据
                            that.list.push({
                                id: 0,
                                no: null,
                                certificateNo:code,
                                len:0.2,
                                createTime:util.formatTime(new Date())
                                
                            })
                        }
                        
                //     }
                // });
                
            },
            //提交
            submit(){
                for (var i = 0; i < this.list.length; i++) {
                    if (!this.list[i].len) {
                        this.$u.toast('请填写长度')
                        return
                    }
                }
                let param = []
                for (var i = 0; i < this.list.length; i++) {
                    param.push({
                        // "id": null,
                        // "createTime": "",//创建时间
                        // "createUser": "",//创建人
                        "certificateNumber": this.list[i].certificateNo,//合格证号
                        // "inspState": null,// 检测状态   unInsp:待检测 inspPass:检测合格  insp_un_pass:检测不合格  insp_reverse:检测退回  insp_release:检测放行
                        "inspectionQuantity": this.list[i].len,//报检长度
                        // "inspectionSerialNo": null,//报检流水号
                        // "packagingOperator": null,//包装人员
                        // "packagingState": null,//是否包装 0-否,1-是
                        // "samplingState": 1,//是否抽检 0-否,1-是
                        // "state": '',//状态  unSampling:待抽检  unInsp:待检测  insped:已检测  packaging:已包装  stock:已入库
                        // "stockOperator": '',//入库人员
                        // "stockState": '',//是否入库 0-否,1-是
                        
                    }) 
                }
                this.$u.api.outsource.submitReport(param, this.type).then(res => {
                    if (res.code == 0) { 
                        this.$u.toast('提交成功')
                        this.list = []
                    } else {
                        this.$u.toast('提交失败')
                    }
                });
            },
            deleteItem(model) {
                uni.showModal({
                    title: '提示',
                    content: '是否确定删除?',
                    success: res => {
                        if (res.confirm) {
                            this.list = this.list.filter(item => item.certificateNo!=model.certificateNo)
                        }
                    }
                });
                
            }
        }
    }
</script>