schangxiang@126.com
2025-09-04 e9269528ae01bc4572b68148b9c801b51f23b669
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<template>
    <view class="page-containter page-containter-x">
        <view class="page-header">
            <page-header-x :ctitle="page_ctitle" />
            <user-row></user-row>
        </view>
        <view class="page-content">
            <view class="add_site">
                <view class="list-frame">
                    <view class="list-item">
                        <view class="list-no">序号</view>
                        <view class="list-value">流水号</view>
                        <view class="list-value">操作</view>
                    </view>
                    <view class="list-item" v-for="(item,index) in addForm.dataList" :key="'addsite-list-'+index">
                        <view class="list-no">{{item.id}}</view>
                        <view class="list-value">{{item.serialNumber}}</view>
                        <view class="btn-block"><u-button type="primary" @click="subList(index)">删除</u-button></view>
                    </view>
                </view>
                <u-form :model="addForm" ref="addRef" label-width="180">
                    <u-form-item label="数量:">
                        <text>{{addForm.quantity}}</text>
                    </u-form-item>
                    <!-- 物料编码 -->
                    <u-form-item label="">
                        <u-input v-model="productCode" :focus="focus_productCode"  @input="getCode" placeholder=" 请扫描条码" border></u-input>
                    </u-form-item>
                    <u-form-item label="">
                        <u-input v-model="productCode2"   placeholder=" 请输入条码" border></u-input>
                        &nbsp;&nbsp;&nbsp;&nbsp;<u-button type="primary" @click="getCode2">确定输入</u-button>
                    </u-form-item>
                    <u-form-item label="物料编号:">
                        <!-- <u-input type="textarea" v-model=""></u-input> -->
                        <text>{{addForm.productCode}}</text><!--  -->
                    </u-form-item>
                    <!-- 供应商 -->
                    <u-form-item label="供应商:">
                        <!-- <u-input type="textarea" v-model=""></u-input> -->
                        <text>{{addForm.supplier}}</text><!--  -->
                    </u-form-item>
                    
                    <!-- 物料名称  -->
                    <u-form-item label="物料名称:">
                        <!-- <u-input type="textarea" v-model=""></u-input> -->
                        <text>{{materialName}}</text>
                    </u-form-item>
                    <!-- 托盘号 -->
                    <u-form-item label="托盘号:">
                        <u-input v-model="addForm.containerCode" placeholder="请扫描托盘条码" border></u-input>
                    </u-form-item>
                    <u-form-item label="站点选择:">
                        <u-input placeholder="请选择站点" v-model="addForm.station" type="select" :border="true"
                            @click="siteFlag = true"></u-input>
                        <u-action-sheet :list="siteList" v-model="siteFlag" @click="confirm"></u-action-sheet>
                    </u-form-item>
                    <u-form-item label="目标点选择(可选,如果选择,表示物料不入立库,直达上线点):">
                        <u-input placeholder="请选择目标点" v-model="addForm.toStieCode" type="select" :border="true"
                            @click="to_siteFlag = true"></u-input>
                        <u-action-sheet :list="to_siteList" v-model="to_siteFlag" @click="confirm_toPlace"></u-action-sheet>
                    </u-form-item>
                    
                </u-form>
                <view class="btns-row">
                    <view class="btn-block"><u-button type="error" @click="cancalAdd">取消</u-button></view>
                    <view class="divider-block"></view>
                    <view class="btn-block"><u-button type="primary" @click="confirmAdd">确定</u-button></view>
                </view>
                
            </view>
        </view>
    </view>
</template>
 
<script>
    import {
        getMaterial,
        addSite,
        getInCode,
        validateSingalSerialNumber
    } from '../../api/addSite/addSite.js'
    import PageHeaderX from '../../compontents/PageHeaderX.vue'
    import UserRow from '../../compontents/UserRow.vue'
    import $config from '../../util/config.js'
    export default {
        components: {
            "page-header-x": PageHeaderX,
            UserRow
        },
        data() {
            return {
                addEditFlag:'add',//新增或编辑标记 【EditBy shaocx,2022-03-31】
                focus_productCode:true,
                page_ctitle:'新建组盘',
                materialList: [], //物料列表数据
                addForm: {
                    orderCodeId:0,//组盘表单的ID,编辑用【EditBy shaocx,2022-03-31】
                    type:'', //类型:body header
                    productCode: '扫描后可自动获取',
                    station: '',
                    supplier:'扫描后可自动获取',//供应商
                    quantity: 0,
                    containerCode: '',//托盘号
                    dataList: []
                },
                productCode: '',
                productCode2:'',
                materialName: '扫描后可自动获取', //物料名称
                result: {},
                siteFlag: false,
                to_siteFlag: false,
                siteList: [],
                to_siteList: [],
            }
        },
        watch: {
            addForm: {
                handler(val) {
                    if (val.productCode == '') {
                        this.materialName = '扫描后可自动获取';
                    } else {
 
                        this.materialList.forEach(item => {
                            if (item.productCode == this.addForm.productCode) {
                                this.materialName = item.materialName;
                            }
                        })
                    }
                },
                deep: true
            }
        },
        /* 通常只用于获取传递参数 */
        onLoad(options) {
            console.log('load')
            this.addEditFlag=options.addEditFlag;//新增或编辑标记 【EditBy shaocx,2022-03-31】
            if(this.addEditFlag=='edit'){
                //debugger
                this.addForm.orderCodeId=options.orderCodeId;
            }
            this.addForm.type=options.type;//记住type值 【EditBy shaocx,2022-03-16】
            if (options.type === 'body') {
                this.siteList = $config.sites.offlineBody;
                this.to_siteList=$config.sites.onLineBody;
                this.page_ctitle='组盘(缸体)';
            } else {
                this.siteList = $config.sites.offlineHeader;
                this.to_siteList=$config.sites.onLineHeader;
                this.page_ctitle='组盘(缸盖)';
            }
        },
        //页面加载事件
        onReady() {
 
            this.getMaterialList();
            if(this.addForm.orderCodeId!=0){
                this.getInCode();
            }
        },
 
        //下拉刷新
        onPullDownRefresh() {
            this.clearAddForm();
            //重新获取物料列表
            uni.stopPullDownRefresh();
        },
        methods: {
            confirm(index) {
                this.addForm.station = this.siteList[index].text;
            },
            confirm_toPlace(index) {
                this.addForm.toStieCode = this.to_siteList[index].text;
            },
            change(e) {
                console.log(e.detail);
            },
            edit(item) {
                uni.showToast({
                    title: item.name,
                    icon: 'none'
                });
            },
            subList(index)
            {
                //debugger;
                this.addForm.dataList.splice(index,1);
                this.addForm.quantity = this.addForm.dataList.length;
            },
            getCode2(){
                this.productCode=this.productCode2;
                this.getCode();
            },
            //分割数据
            getCode() {
                
                if(this.productCode.trim().split('*').length==3)
                {
                    uni.hideKeyboard();
                    var splits = this.productCode.trim().split('*');
                    if(this.addForm.productCode!=='扫描后可自动获取' )
                    {
                        if(this.addForm.productCode!== splits[0])
                        {
                            uni.showToast({
                                icon: 'none',
                                title: '不同物料不可组盘-'+splits[0]
                            });
                            this.getFocus();
                            return;
                        }
                    }
                    if(this.addForm.supplier!=='扫描后可自动获取' )
                    {
                        if(this.addForm.supplier!== splits[1])
                        {
                            uni.showToast({
                                icon: 'none',
                                title: '不同供应商不可组盘-'+splits[1]
                            });
                            this.getFocus();
                            return;
                        }
                        
                    }
                    this.addForm.supplier = splits[1];
                    this.addForm.productCode = splits[0];
                    let num = this.addForm.dataList.length;
                    var obj = {};
                    obj.id = num + 1;
                    var serials=splits[2].split(' ');//两个空格
                    
                    obj.serialNumber =serials.length>1?serials[0].trim():splits[2] ;
                    var ishave=0;
                    this.addForm.dataList.forEach(item=>{
                        if(item.serialNumber==obj.serialNumber)
                        {
                        
                            uni.showToast({
                                icon: 'none',
                                title: '已存在流水号'+obj.serialNumber
                            });
                                ishave=1;
                        };
                        
                    });
                    if(ishave==1)
                     {
                         this.$nextTick(function(){
                               this.productCode =''; 
                         })
                         this.getFocus();
                          return;
                     }
                     
                     //增加验证流水号校验【Editby shaocx,2022-03-31】
                     validateSingalSerialNumber(this.addForm.orderCodeId,obj.serialNumber,this.addForm.productCode).then(res => {
                                         //debugger
                                        //this.addForm = res.data;
                                        
                                        this.addForm.dataList=this.addForm.dataList.reverse();
                                        this.addForm.dataList.push(obj);
                                        this.addForm.dataList=this.addForm.dataList.reverse();
                                        this.addForm.quantity = this.addForm.dataList.length;
                                        let matObj = this.materialList.find(item => item.materialCode == this.result);
                                        if (matObj != undefined) {
                                            this.materialName = matObj.materialName;
                                        }
                                        this.$nextTick(function(){
                                              this.productCode =''; 
                                        })
                                        this.getFocus();
                                        
                                     }).catch(() => {
                                 
                                     })
                    
                    
                }
                else{
                    this.$nextTick(function(){
                         this.productCode =''; 
                    })
                    this.getFocus();
                    uni.showToast({
                        icon: 'none',
                        title: '条码格式错误-'+this.productCode
                    })
                    
                }
                
            },
            getFocus(){
                this.focus_productCode=false;
                this.$nextTick(function(){
                    this.focus_productCode=true;
                })
            },
            //获取物料列表
            getMaterialList() {
                getMaterial().then(res => {
                    //debugger
                    this.materialList = res.data;
                }).catch(() => {
 
                })
            },
            //获取组盘数据
            getInCode() {
                getInCode(this.addForm.orderCodeId).then(res => {
                    //debugger
                    this.addForm = res.data;
                }).catch(() => {
            
                })
            },
            //清空添加数据
            clearAddForm() {
                this.addForm.productCode = '';
                this.addForm.station = '';
                this.addForm.toStieCode = '';
                this.addForm.quantity = 0;
                this.addForm.containerCode = '';
                this.addForm.dataList = [];
                this.productCode = '扫码可自动获取';
                this.materialName = '扫码可自动获取';
 
            },
            //聚焦事件
            focus() {
                //阻止软件盘弹出
                uni.hideKeyboard()
                
 
            },
            //取消添加
            cancalAdd() {
                uni.navigateBack({
                    delta: 1
                })
            },
            //提交添加
            confirmAdd() {
 
                //debugger
                //this.addForm.quantity -= 0;
                if (this.addForm.productCode && this.addForm.station&&this.addForm.containerCode) {
                    addSite(this.addForm).then(res => {
                        uni.showToast({
                            title: '添加成功',
                            icon: 'success'
                        })
                        //关闭当前页面
                        setTimeout(() => {
                            //关闭当前页面
                            //this.cancalAdd();
                            //跳转到前一页
                            var url='';
                            //debugger
                            if(this.addForm.type ==='body'){
                                url='cylinder/cylinder';
                            }else{
                                url='cylinderHead/cylinderHead';
                            }
                            uni.navigateTo({
                                url:`../`+url
                            })
                        }, 2000)
                    }).catch(() => {
 
                    })
                } else {
                    uni.showToast({
                        title: '参数不规范'
                    })
                }
            }
        }
    }
</script>
 
<style lang="scss" scoped>
    .add_site {
        width: 94%;
        margin: 10rpx auto;
        font-size: 30rpx;
        text-align: left;
 
        .btns-row{
            display: flex;
            padding: 12rpx 0;
            .btn-block{
                width: 10rpx;
                flex: 1;
            }
            .divider-block{
                width: 8px;
                flex-shrink: 0;
            }
        }
        
        .list-item{
            display: flex;
            padding-bottom: 16rpx;
            border-bottom: 1px solid #dcdcdc;
            .list-no{
                width: 100rpx;
                flex-shrink: 0;
                display: flex;
                align-items: center;
            }
            .list-value{
                flex: 1;
                word-break:break-all;
                word-wrap:break-word;
            }
        }
    }
</style>