#
whycq
2022-02-28 75ea1362b54946c8a8b6aa8260c2f4e5843154ab
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
<template>
    <view>
        <form>
            <view class="cu-form-group margin-top">
                <view class="title">单号</view>
                <input v-model="billNo" placeholder="扫码 / 输入" name="input" autocomplete="off" focus @input="find()">
            </view>
            <view class="cu-form-group margin-top">
                <view class="title">托盘码</view>
                <input v-model="code" placeholder="扫码 / 输入" name="input">
            </view>
        </form>
        <view class="margin-top">
            <uni-table ref="table" border stripe emptyText="暂无更多数据" type="selection" @selection-change="selectionChange">
                <uni-tr>
                    <uni-th align="center" width="90">数量</uni-th>
                    <uni-th align="center" width="90">组托数量</uni-th>
                    <uni-th align="center" width="90">产品代号</uni-th>
                    <uni-th align="center" width="90">产品编码</uni-th>
                    <uni-th align="center" width="90">产品名称</uni-th>
                    <uni-th align="center" width="90">序号</uni-th>
                    <uni-th align="center" width="90">批号</uni-th>
                    
                    
                </uni-tr>
                <uni-tr v-for="(item, index) in matData" :key="index">
                    <uni-td align="center">{{item.count}}</uni-td>
                    <uni-td align="center">
                        <button class ="cu-btn bg-orange margin-xs" @click="confirm(index,item)">修 改</button>
                        <!-- <button class="uni-button" size="mini" type="warn" @click="remove(index,item)">删除</button> -->
                    </uni-td>
                    <uni-td align="center">{{item.size}}</uni-td>
                    <uni-td align="center">{{item.matNo}}</uni-td>
                    <uni-td align="center">{{item.matName}}</uni-td>
                    <uni-td align="center">{{item.seqNo}}</uni-td>
                    <uni-td align="center">{{item.itemBatch}}</uni-td>
                    
                </uni-tr>
            </uni-table>
        </view>
        <view class="flex solid-bottom  justify-between">
            <button class ="cu-btn bg-red margin-xs" @click="delTable">批量删除</button>
            <button class ="cu-btn bg-olive margin-xs" @click="reSelection">反选</button>
            <button class ="cu-btn bg-cyan margin-xs" @click="clearSel">清空选择</button>
        </view>
        <view class="flex solid-bottom padding justify-around">
            <button class="cu-btn bg-yellow  lg" @click="comb()">组 托</button>
            <button class="cu-btn bg-grey lg" @click="reset">重 置</button>
        </view>
        <view>
            <!-- 提示信息弹窗 -->
            <uni-popup ref="message" type="message">
                <uni-popup-message :type="msgType" :message="messageText" :duration="2000"></uni-popup-message>
            </uni-popup>
        </view>
        <view>
            <!-- 输入框示例 -->
            <uni-popup ref="inputDialog" type="dialog">
                <uni-popup-dialog ref="inputClose" mode="input" title="组托数量" 
                    placeholder="请输入组托数量" @confirm="dialogInputConfirm">
                        <uni-number-box :min="minCount" :max="maxCount" v-model="value" />
                </uni-popup-dialog>
            </uni-popup>
        </view>
    </view>
</template>
 
<script>
    export default {
        data() {
            return {
                billNo:'',
                code:'',
                matData:[],
                type: '',
                msgType: '',
                messageText: '',
                minCount:0,
                maxCount:1,
                rowNum:'',
                value:'',
                couChange:true,
                baseIP:'',
                selectArr : [],
                selectedIndexs:[],
                
                
            }
        },
        mounted(){
            const UIP = uni.getStorageSync('UIP');
            this.baseIP = UIP
        },
        methods: {
            // 多选
            selectionChange(e) {
                // 获取选中状态
                this.selectedIndexs = e.detail.index
                this.selectedIndexs.sort(function(a,b){
                    return a-b
                });// 重新排序(升序)
            },
            
            // 全选
            // 批量删除的方法
            toggleSelection(rows) {
                console.log(rows)
                if (rows) {
                this.$refs["table"].toggleAllSelection(rows);
                } else {
                    this.$refs["table"].clearSelection();
                }
            },
            //批量删除
            delTable() {
                // 实现全选删除和多选删除
                let len = this.selectedIndexs.length
                // len.forEach(index => {
                //     console.log(index)
                //            this.matData.splice(index,1);
                //            })
                for (let i = len-1; i >= 0; i--) {
                    console.log(this.selectedIndexs[i])
                    this.matData.splice(this.selectedIndexs[i],1)    // splice删除数组会改变原数组,所以需要逆向删除
                }
                this.$refs["table"].clearSelection(); // 清空选择
                
            },
            // 反选
            reSelection(){
                this.toggleSelection(this.selectedIndexs)
            },
            // 清空
            clearSel() {
                this.toggleSelection()
            },
                reset:function() {
                    this.billNo = '';
                    this.code = '';
                    this.matData = [];
                    this.toggleSelection()
                },
                messageToggle(type) {
                    this.msgType = type
                    this.messageText = '提取失败'
                    this.$refs.message.open()
                },
                
                // 根据通知单号查询物料详情
                find(){
                    let billNo = this.billNo
                    let that = this
                    if(this.billNo.length === 0){
                        return
                    }
                    if(billNo.indexOf('=')>-1){
                        billNo = billNo.split(",")[0].split("=")[1];
                    }
                    if(billNo.length===0){
                        return
                    }
                    this.matData = []
                    uni.request({
                        url: that.baseHttp + that.baseIP + that.baseUrl + "/mobile/bill/query/auth",
                        header: {
                            'content-type':'application/x-www-form-urlencoded',
                            'token':uni.getStorageSync('token')},
                        data: {
                            billNo: billNo
                        },
                        method: 'POST',
                        success(res){
                            if(res.data.code === 200){
                                if(res.data.data != null){
                                    that.addTableData(res.data.data)
                                }else if(res.data.code === 403){
                                    
                                }else {
                                    
                                }
                            }
                        }
                    })
                    
                },
                addTableData(data){
                    for(var i=0;i<data.length;i++){
                        var toPush = true;
                        for(var j=0;j<this.matData.length;j++){
                            if(data[i].matNo ===this.matData[j].matNo ){
                                this.matData[j].count = Number(this.matData[j].count) + Number(data[i].count);
                                toPush = false;
                            }
                        }
                        if(toPush) {
                            this.matData.push(data[i]);
                        }
                    }
 
                },
                
                // 修改数量
                confirm(index,item){
                    this.couChange=false
                    this.$refs.inputDialog.open()
                    this.maxCount = item.count
                    this.rowNum = index
                    this.value = this.minCount
                },
                // 修改数量弹窗
                dialogInputConfirm() {
                    this.matData[this.rowNum].count = this.value
                    this.messageToggle('success')
                    this.messageText = '修改成功'    
                },
                // 删除
                remove(index,item){
                    this.matData.splice(index,1)
                    this.messageToggle('success')
                    this.messageText = '删除成功'
                },
                comb(){
                    let that = this
                    let barcode = that.code
                    let billNo = this.billNo
                    if(billNo.length === 0){
                        that.messageToggle('error')
                        that.messageText = '入库单号为空'
                        return;
                    }
                    if(barcode.length === 0){
                        that.messageToggle('error')
                        that.messageText = '请输入托盘码'
                        return;
                    }
                    if (barcode.length !== 8) {
                        that.messageToggle('error')
                        that.messageText = '托盘码必须为8位'
                        return;
                    }
                    if(that.couChange){
                        that.messageToggle('error')
                        that.messageText = '请先确认入库数量'
                        return;
                    }
                    uni.request({
                        url: that.baseHttp + that.baseIP + that.baseUrl + "/mobile/comb/auth",
                        header: {'token':uni.getStorageSync('token')},
                        data:{
                            barcode:barcode,
                            combMats:that.matData,
                            billNo: billNo,
                        },
                        method:'POST',
                        success(res) {
                            
                            if(res.data.code === 200){
                                that.reset()
                                that.matData = []
                                that.messageToggle('success')
                                that.messageText = '组托成功'
                            }
                        }
                    })
                },
        },
        onShow() {
        }
    }
</script>
 
<style>
    .delTable {
        margin-left:0;
        margin-right: auto;
        width: 200rpx;
        height: 80rpx;
        font-size: 30upx;
        font-weight: bold;
    }
</style>