xiaojiao
2025-12-26 4279cb4384f7f960d87af8b8ad9db73c2dececa3
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
<template>
    <view>
        <view>
            <u-table font-size="25">
                <u-tr>
                    <u-td>
                        <xfl-select :list="UserArray" :initValue="this.$UserTool.UserInfo.userName" :clearable="false"
                            :disabled="true">
                        </xfl-select>
                    </u-td>
                    <u-td width="25%">现在时间:</u-td>
                    <u-td width="25%">{{date}}</u-td>
                </u-tr>
            </u-table>
        </view>
 
        <view style="padding: 20rpx 0rpx">
            <u-table>
                <u-tr>
                    <u-td width="30%">托盘条码</u-td>
                    <u-td>
                        <u-input v-model="value_rfid" :border="true" :focus="rfidFocus" placeholder="请输入托盘条码"
                            @input="value_rfidChange" />
                    </u-td>
                </u-tr>
                <u-tr>
                    <u-td width="30%">轴承条码</u-td>
                    <u-td>
                        <u-input v-model="value_qrcode" :border="true" :focus="qrcodeFocus"
                            placeholder="请输入轴承条码" />
                    </u-td>
                </u-tr>
                <u-tr>
                    <u-td width="30%">车型</u-td>
                    <!-- <u-td>
                        <u-input v-model="materielId" :border="true"  placeholder="" />
                    </u-td> -->
                    <xfl-select :list="CxTypes" :initValue="'请选择'" :clearable="false" @change="Get_VehicleType_Alls"
                        ref="Get_VehicleType_All">
                    </xfl-select>
                </u-tr>
                <u-tr>
                  <u-td width="30%">轴承型号</u-td>
                  <u-td>
                    <!-- 关键:v-if 条件渲染 -->
                    <xfl-select 
                        v-if="showBearingSelect"
                        :list="BearingModels" 
                        :initValue="'请选择'" 
                        :clearable="false" 
                        @change="BearingModelss"
                        ref="BearingModelsss" 
                        :key="bearingSelectKey">
                    </xfl-select>
                  </u-td>
                </u-tr>
                <u-tr>
                    <u-td width="30%">厂家</u-td>
                    <u-td>
                        <u-input v-model="madeUnit" :border="true" :disabled="true"  placeholder="自动获取厂家" />
                    </u-td>
                </u-tr>
                
                <u-tr>
                    <u-td width="30%">轴承类别</u-td>
                    <!-- <u-td>
                        <u-input v-model="NewOrOld" :border="true"  placeholder="" />
                    </u-td> -->
                    <u-td>
                        <xfl-select :list="StateArray" :initValue="'请选择'" :clearable="false" @change="StateChange"
                            ref="StateSelect">
                        </xfl-select>
                    </u-td>
                    
                </u-tr>
                <u-tr>
                    <u-td width="30%">轴承单号</u-td>
                    <u-td>
                        <u-input v-model="LotNumber" :border="true"  placeholder="轴承单号" />
                    </u-td>
                </u-tr>
                <u-tr>
                    <u-td width="30%">生产日期</u-td>
                    <u-td>
                        <u-input v-model="ProductDate" :border="true" :focus="prdateFocus" placeholder="生产日期" />
                    </u-td>
                </u-tr>
            </u-table>
        </view>
        <view style="padding: 0rpx 0rpx;">
            <u-table>
                <u-tr>
                    <u-td>
                        <u-button style="width:100px" type="primary" @click="SaveInfomation">组盘</u-button>
                    </u-td>
                </u-tr>
            </u-table>
        </view>
    </view>
</template>
 
<script>
    var _this;
    var _user;
    export default {
        data() {
            return {
                bearingSelectKey: 0, // 保留key作为双保险
                showBearingSelect: true, // 新增:控制组件销毁/创建
                date: '',
                CurrentUser: '', //当前用户
                value_rfid: '',
                value_qrcode: '',
                //厂家
                madeUnit: '',
                //车型
                materielId: '',
                //轴承型号
                selectedBearingModel: '', // 新增:当前选中的轴承型号值
                materielType: '',
                //检修类型
                NewOrOld: '',
                //批次   --2024.6.20新增
                LotNumber: '',
                //生产日期   --2024.6.20新增
                ProductDate: '',
                rfidFocus: false,
                qrcodeFocus: false,
                prdateFocus: false,
                CxTypes:[],      //所有车型
                BearingModels:[], // 对应车型下面的所有轴承型号
                templists:[], // 临时保存 轴承型号 和 厂家
                StateArray: [{
                        label: 'RO',
                        value: '新造'
                    },{
                        label: 'R1',
                        value: '检修'
                    }]
            }
        },
        methods: {
            UserChange(value) {
 
            },
            VehicleType(){
                let data = {};
                _this.$AjaxRequest.Params('post', 'Dt_materielinfo/Get_VehicleType_All',
                    data, _user.token);
                _this.$AjaxRequest.Request().then(function(result) {
                    if (result.data.status) {
                        _this.CxTypes = result.data.data
                    } else {
                        uni.showToast({
                            icon: 'none',
                            title: "请求错误:" + result.data.message,
                            duration: 2000
                        });
                    }
                    console.log("车型的所有数据",result)
                }).catch(function(err) {
                    uni.showToast({
                        icon: 'none',
                        title: "请求后台异常,错误信息." + err.errMsg,
                        duration: 2000
                    });
                });
            },
            Get_VehicleType_Alls(value){
              _this.materielId = value.orignItem; // 给车型赋值
              
              console.log(_this.materielId);
              
              // ==================== 核心:完全销毁并重建轴承型号下拉框 ====================
              
              // 1. 立即销毁组件(清除所有内部状态)
              _this.showBearingSelect = false;
              
              // 2. 清空所有相关数据
              _this.BearingModels = [];
              _this.selectedBearingModel = '';
              _this.madeUnit = '';
              _this.materielType = '';
              
              // 3. 延迟重建组件(确保销毁完成)
              setTimeout(() => {
                _this.showBearingSelect = true;
                _this.bearingSelectKey += 1; // 同时改变key,双保险
                
                // 确保渲染完成后再请求数据
                _this.$nextTick(() => {
                  // 请求新数据
                  let data = { MainData: { "materielId": _this.materielId } };
                  _this.$AjaxRequest.Params('post', 'Dt_materiel_zc_info/GetBearingModel', data, _user.token);
                  
                  _this.$AjaxRequest.Request().then(function(result) {
                    const backendList = result.data.data || [];
                    _this.templists = backendList;
                    
                    if (backendList.length === 0) {
                      _this.BearingModels = [];
                      return;
                    }
                    
                    _this.BearingModels = backendList.map(item => item.materiel_zc_id_list);
                    
                    console.log("车型对应的轴承数据", result);
                    console.log("轴承型号的数据", _this.BearingModels);
                    console.log("轴承型号和厂家的数据", _this.templists);
                  }).catch(function(err) {
                    uni.showToast({
                      icon: 'none',
                      title: "请求后台异常,错误信息." + err.errMsg,
                      duration: 2000
                    });
                  });
                });
              }, 150); // 150ms延迟确保销毁完成
            },
            BearingModelss(value){
                console.log("选择的轴承型号是",value.orignItem)
                // 这里赋值厂家
                _this.templists.forEach(x => { // 关键:forEach 小写e
                    if(value.orignItem == x.materiel_zc_id_list){
                        _this.madeUnit = x.materiel_zc_name_list
                        _this.materielType = value.orignItem
                    }
                });
            },
            StateChange(value) { // 选择轴承类别
                _this.NewOrOld = value.orignItem.label;
            },
            setTimer() {
                if (this.timer == null) {
                    this.timer = setInterval(() => {
                        this.date = this.$DateTool.getDate();
                    }, 1000)
                }
 
            },
            value_rfidChange() {
                if (_this.value_rfid.length == 6) {
                    _this.qrcodeFocus = true;
                }
            },
            initInfo() {
                _this.madeUnit = '';
                _this.materielId = '';
                _this.materielType = '';
                _this.NewOrOld = '';
                _this.LotNumber = '';
                _this.ProductDate = '';
            },
            SaveInfomation() {
                //_this.LotNumber == '' ||
                if (_this.value_rfid.length == 0 || _this.value_qrcode.length == 0 ||
                    _this.madeUnit == '' || _this.materielId == '' ||
                    _this.materielType == '' || _this.NewOrOld == '' ||
                     _this.ProductDate == '') {
 
                    uni.showToast({
                        title: "组盘信息不能为空",
                        duration: 2000,
                        icon: 'none',
                    });
                    return;
                }
                if (_this.value_rfid.length > 6) {
                    uni.showToast({
                        title: "托盘长度不能大于6位数。",
                        duration: 2000,
                        icon: 'none',
                    });
                    return;
                }
 
                uni.showModal({
                    title: '提示',
                    content: '是否确认组盘?',
                    success: function(res) {
                        if (res.confirm) {
                            let data = {
                                MainData: {
                                    rfid: _this.value_rfid,
                                    qrcode: _this.value_qrcode,
                                    madeUnit: _this.madeUnit,
                                    materielId: _this.materielId,
                                    materielType: _this.materielType,
                                    NewOrOld: _this.NewOrOld,
                                    LotNumber: _this.LotNumber,
                                    ProductDate: _this.ProductDate
                                },
                            };
                            console.log("最后提交的组盘信息",data)
                            _this.$AjaxRequest.Params('post', 'ToAPP/InboundBoxingAction',
                                data, _user.token);
                            _this.$AjaxRequest.Request().then(function(result) {
                                if (result.data.status) {
                                    uni.showToast({
                                        title: "组盘成功!",
                                        duration: 2000
                                    });
                                    _this.value_rfid = "";
                                    _this.value_qrcode = "";
                                    _this.initInfo();
                                    _this.rfidFocus = true;
                                } else {
                                    uni.showToast({
                                        icon: 'none',
                                        title: "请求错误:" + result.data.message,
                                        duration: 2000
                                    });
                                }
                            }).catch(function(err) {
                                uni.showToast({
                                    icon: 'none',
                                    title: "请求后台异常,错误信息." + err.errMsg,
                                    duration: 2000
                                });
                            });
                        } else if (res.cancel) {}
                    }
                });
            },
        },
        created: function() {
            // 每次进入界面时,先清除之前的所有定时器,然后启动新的定时器
            clearInterval(this.timer)
            this.timer = null;
            this.setTimer();
            _user = this.$UserTool.UserInfo;
            this.CurrentUser = _user.userName;
            this.UserArray = [this.$UserTool.AllUserInfo];
            
        },
        destroyed: function() {
            // 每次离开当前界面时,清除定时器
            clearInterval(this.timer);
            this.timer = null;
        },
        mounted() {
            _this = this;
            _this.rfidFocus = true;
            this.VehicleType();
        },
 
 
    }
</script>
 
<style scoped lang="scss">
    .tdHeight {
        height: 80rpx;
    }
 
    .loopView {
        height: 160px;
        background-color: #f0f0f0;
        margin-top: 10px;
    }
 
    .loopItem {
        margin-top: 5px;
        margin-left: 15px;
 
    }
 
    .deleteBtn {
        margin-top: 25px;
        margin-left: 10px;
        width: 120px;
        background-color: orangered;
    }
</style>