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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<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.certificateNumber" :index="index">
                <u-form class="form" :model="item" :rules="rules" :ref="item.certificateNumber" label-position="left">
                    <u-form-item label="报检流水号" prop="inspectionSerialNo" label-width="180" >
                        <text>{{item.inspectionSerialNo}}</text>
                    </u-form-item>
                    <u-form-item label="合格证号" prop="certificateNumber" label-width="180" >
                        <text>{{item.certificateNumber}}</text>
                    </u-form-item>
                    <u-form-item label="长度(km)" prop="inspectionQuantity" label-width="180" >
                        <text>{{item.inspectionQuantity}}</text>
                    </u-form-item>
                    <!-- <u-form-item label="抽检状态" prop="samplingState" label-width="180" >
                        <text>{{item.samplingState=='1'?'已抽检':'未抽检'}}</text>
                    </u-form-item> -->
                    <u-form-item label="检测结果" prop="result" label-width="180" >
                        <view>{{formatResult(item.inspState) || ''}}</view>
                    </u-form-item>
                    <u-form-item label="是否包装" prop="packing" label-width="180" >
                        <text>{{item.packagingState=='1'?'是':'否'}}</text>
                    </u-form-item>
                    <u-form-item label="包装时间" prop="createTime" label-width="180" >
                        <text>{{nowTime}}</text>
                    </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>
        <view class="form-footer" v-if="list.length > 0">
            <u-button class="btn" type="primary" @click="submit">包装</u-button>
        </view>
        <scan></scan>
    </layout>
</template>
 
<script>
    import scan from "@/components/scan/scan.vue";
    import util from "@/util/ble/util.js";
    import layout from "./layout";
    let defaultState = '已抽检'
    let defaultPacking = '是'
    export default {
        components: {
            scan,layout
        },
        data() {
            return {
                type: 'packaging',//inspDeclaration:报检  sampling:抽检  declaration:检测  packaging:包装  stock:入库
                list: [
                    // {
                    // id: 0,
                    // no: 'BJ00001',
                    // certificateNo:'00001',
                    // len:0.2,
                    // state:defaultState,
                    // result:'r0',
                    // packing:defaultPacking,
                    // createTime:util.formatTime(new Date())
                    // },
                ],
                selectIndex:0,
                results:[{
                    value: 'inspPass',
                    label: '合格'
                },
                {
                    value: 'insp_release',
                    label: '让步放行'
                },{
                    value: 'insp_reverse',
                    label: '退回'
                }],
                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();
        
            })
        },
        onNavigationBarButtonTap(e) {
            uni.scanCode({
                success: res => {
                    try {
                        // uni.showToast({
                        //     title:res.result
                        // })
                        // const result = JSON.parse(res.result)
                        // console.log('扫码结果:', result);
                        this.addScanCode(res.result)
                    } catch (e) {}
                }
            });
        },
        onLoad(){
            // this.addScanCode('00004')
            // this.addScanCode('00001')
        },
        methods: {
            selectResult(e){
                console.log(e);
                this.list[this.selectIndex].result = e[0].value
            },
            formatResult(value){
                let res = ''
                for (var i = 0; i < this.results.length; i++) {
                    if(this.results[i].value == value) {
                        res = this.results[i].label
                        break
                    }
                }
                return res
            },
            //获取扫一扫数据
            addScanCode(code){
                //检测是否已扫过
                let result = this.list.find(item => item.certificateNumber==code)
                if (result) {
                    this.$u.toast('已存在列表中')
                } else {
                    //添加一条数据
                    let param = {
                        current: 1,
                        size: 100,
                        certificateNumber:code
                    }
                    this.$u.api.outsource.queryData(param).then(res => {
                        if (res.code === 0) {
                            let data = res.data.records
                            console.log(data);
                            let exist = false
                            if (data.length > 0) {
                                for (var i = 0; i < data.length; i++) {
                                    if (data[i].state == 'insped') {
                                        //取已检测的
                                        this.list.push(data[i])
                                        exist = true
                                    }
                                }
                            } 
                            if (!exist){
                                this.$u.toast('没有可包装的数据')
                            }
                            
                        }
                        
                    });
                }
                
            },
            //提交
            submit(){
                this.$u.api.outsource.submitReport(this.list, 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>
 
<style>
 
</style>