#
whycq
2022-08-15 2957f2337bd9da4c1ca421e83adb019bc545cf99
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
    <view>
    <!-- 检索窗口 -->
        <view class="square-2">
            <view class="square-title">
                <view class="title-sign"><view class="sign"></view></view>
                <view class="title-text"><text>检索商品</text></view>
            </view>
            <view class="square-content">
                <view class="content-input">
                    <input v-model="barcode" placeholder="扫码 / 输入" @input="addMat" :focus="barcodeFocus">
                    <uni-icons type="closeempty" size="20" color="#dadada" @click="clearInput('barcode')"></uni-icons>
                </view>
            </view>
        </view>
    <!-- 商品列表 -->
        <view class="square-1">
            <view class="square-title">
                <view class="title-sign"><view class="sign"></view></view>
                <view class="title-text"><text>商品列表</text></view>
            </view>
        </view>
        <view class="square-none"  v-show="matList.length === 0">
            <view class="v-show">暂无更多数据...</view>
        </view>
        <checkbox-group>
            <view v-for="(item,index) in matList" :key="index" class="data-list bg-false" :class="'bg-'+item.checked" >
                <view class="data-list-left">
                    <view class="matnr">No:{{listLen-index}}</view>
                    <view class="matnr">{{item}}</view>
                </view>
                <view class="data-list-right">
                    <uni-icons type="trash" size="20" color="#a5a5a5" @click="remove(item,index)"></uni-icons>
                </view>
            </view>
        </checkbox-group>
    <!-- 提示信息弹窗 -->
        <view>
            <uni-popup ref="message" type="message">
                <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
            </uni-popup>
        </view>
        
    <!-- 底部按钮 -->
        <view class="footer flex justify-around">
            <view>
                <button class="cu-btn lg" @click="reset">重置</button>
            </view>
            <view>
                <button class="cu-btn lg pakin-btn bg-blue" @click="confirm()">确认</button>
            </view>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                commonUrl:null,
                barcode:null,
                matnr:null,
                matList:[],
                listLen:0, // 商品列表长度 默认0
                barcodeFocus:true,
                msgType:null,
                messageText:null
            }
        },
        mounted(){
            const UIP = uni.getStorageSync('UIP');
            this.baseIP = UIP;
            const UPORT = uni.getStorageSync('UPORT');
            this.basePORT = UPORT
            const PROJ = uni.getStorageSync('UPROJ');
            this.baseUrl = PROJ
            this.getUrl()
        },
        onLoad() {
            // #ifdef APP
            setInterval(()=>{
                uni.hideKeyboard()
            },20)
            // #endif
        },
        methods: {
            // 获取url
            getUrl() {
                this.commonUrl = this.baseHttp + this.baseIP + ':' +this.basePORT + "/" +this.baseUrl
            },
            // 扫码重置
            barcodeFocuss() {
                let that = this;
                that.barcodeFocus = false;
                setTimeout(()=>{
                    that.barcode = '';
                    that.barcodeFocus = true;
                }, 100);
            },
            // 添加商品列表
            addMat() {
                let item = null
                item = this.barcode
                if(this.matList.length > 0) {
                    //    遍历matList
                    for (var i = 0;i < this.matList.length; i++) {
                        if (this.matList[i] == item) {
                            this.msgType = "warn"
                            this.messageText = this.barcode + ",已添加!"
                            this.$refs.message.open()
                            this.resetAdd()
                            return;
                        } else {
                            this.matList.unshift(item)
                            this.resetAdd()
                            return;
                        }
                    }
                } else {
                    this.matList.push(item)
                    this.resetAdd()
                }
            },
            // 商品添加重置
            resetAdd() {
                this.listLen = this.matList.length
                this.barcodeFocuss()
            },
            // 清空搜索框
            clearInput(type) {
                switch (type) {
                    case 'barcode':
                        this.barcodeFocuss()
                        break;
                }
            },
            // 重置
            reset() {
                this.barcodeFocuss()
                this.matList = []
            },
            // 确认列表
            confirm() {
                let that = this
                console.log('进入')
                uni.request({
                    url: that.commonUrl + '/mobile/matnr/danger/report/auth',
                    data:JSON.stringify(that.matList),
                    header: {
                        // 'token':uni.getStorageSync('token'),
                    },
                    method:"POST",
                    success(result) {
                        console.log(result)
                        var res = result.data
                        if (res.code === 200) {
                            that.msgType = "success"
                            that.messageText = '上报成功!'
                            that.$refs.message.open()
                            that.reset()
                        } else if(res.code === 403) {
                            uni.showToast({title: res.msg, icon: "none", position: 'top'})
                            that.returnIndex();
                        } else {
                            uni.showToast({title: res.msg, icon: "none",position: 'top'})
                        }
                    }
                })
            },
            remove(item,index) {
                this.matnr = ''
                this.matList.splice(index,1)
                this.listLen = this.matList.length
            },
            // 403跳转登录页
            returnIndex() {
                setTimeout(() => {
                    uni.reLaunch({
                        url: '../login/login'
                    });
                }, 1000);
            },
            
        },
    }
</script>
 
<style>
    .data-list {
        border-bottom: 1px solid #d8d8d8;
        height: 130rpx;
        margin: 15rpx;
        border-radius: 20rpx;
    }
    .data-list:first-child {
        margin-top: 20rpx;
    }
    .data-list:last-child {
        margin-bottom: 200rpx;
    }
    .bg-false {
        background-color: #FFFFFF;
    }
    .bg-true {
        background-color: #ebebeb;
    }
    .data-list-left {
        display: inline-block;
        float: left;
        margin-left: 6%;
        height: 130rpx;
        /* line-height: 100rpx; */
        color: #676767;
    }
    .matnr {
        font-size: 14px;
        font-weight: 700;
        /* padding-top: 15rpx; */
        padding-top: 15rpx;
    }
    .data-list-right {
        display: inline-block;
        float: right;
        height: 130rpx;
        line-height: 130rpx;
        margin-right: 10%;
    }
</style>