yangan
2024-01-10 9cb5cd3735f58bd62c3ad0d20b89646801bc05bf
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
<template>
    <view class="main">
        <u--form labelPosition="top"
            labelWidth="30%"
            :borderBottom="false"
            :rules="rules"
            :errorType="'border-bottom'" 
            :model="dataForm"
            ref="uForm">
            <u-form-item 
            borderBottom=true
            label="一级品类"
                prop="firstClass"
                :borderBottom="false">
                <u-cell-group>
                    <u-cell :title="dataForm.firstClass"
                        value="请选择"
                        @click="firstClassSelect">
                        <u-icon name="arrow-right"
                            slot="right-icon"
                            size="30"></u-icon></u-cell>
                </u-cell-group>
            </u-form-item>
            <u-form-item
            borderBottom=true
            label="二级品名"
                prop="secondClass"
                :borderBottom="false">
                <u-cell-group>
                    <u-cell :title="dataForm.secondClass"
                        value="请选择"
                        @click="secondClassSelect">
                        <u-icon name="arrow-right"
                            slot="right-icon"
                            size="30"></u-icon></u-cell>
                </u-cell-group>
            </u-form-item>
            <u-form-item 
            label="规格"
                prop="specifications"
                borderBottom>
                <u-input v-model="dataForm.specifications"
                    placeholder="请输入规格"
                    border="bottom"
                    @input="$u.debounce(specInputHandle, 500)"></u-input>
            </u-form-item>
            <!-- 新增不合格称重 -->
            <u-form-item label="不合格重量"
                prop="unqualifiedWeight"
                borderBottom>
                <u-input v-model="dataForm.unqualifiedWeight"
                    placeholder="请输入重量"
                    type="digit"
                    border="bottom"
                    @change="v=>checkNum(v,'unqualifiedWeight')"
                    @input="$u.debounce(specInputHandle, 500)"></u-input>
            </u-form-item>
            <!-- <u-form-item label="不合格判定" prop="unqualifiedType">
                <u-radio-group  size='32' v-model="dataForm.unqualifiedType">
                <u-radio  :label-size="25" :name="'1'"  :label="'超尺扣罚'" :disabled="disabled">长度扣罚</u-radio>
                <u-radio  :label-size="25" :name="'2'" :label="'厚度扣罚'" :disabled="disabled">厚度扣罚</u-radio>
                <u-radio  :label-size="25" :name="'3'" :label="'密闭器'" :disabled="disabled">密闭器</u-radio>
                </u-radio-group>
            </u-form-item> -->
            <u-form-item label="单价"
                prop="penaltyUnitPrice"
                borderBottom>
                <u-input v-model="dataForm.penaltyUnitPrice"
                    placeholder="请输入不合格单价"
                    type="digit"
                    border="bottom"
                    @change="v=>checkNum(v,'penaltyUnitPrice')"
                    @input="$u.debounce(specInputHandle, 500)"></u-input>
            </u-form-item>
        </u--form>
        <Transition name="slide-fade">
            <view class="spec-main"
                v-show="specList.length!==0&&haveSelectd">
                <view class="spec-main_content"
                    v-for="item in specList"
                    :key="item.id">
                    <view class="spec-main_item"
                        @click.stop="specSelectHandle(item.spec)">
                        {{item.spec}}
                    </view>
                </view>
            </view>
        </Transition>
        <view style="margin-top: 20rpx;">
            <u-button type="primary"
                shape="circle"
                text="提交"
                @click.stop="formHandle"></u-button>
        </view>
        <!-- 一级 -->
        <u-action-sheet :actions="firstClassActionsList"
            :show="firstClassShow"
            cancelText='取消'
            :closeOnClickOverlay='true'
            @close='firstClassClose'
            @select="firstClassSelectClick"></u-action-sheet>
        <!-- 二级 -->
        <u-action-sheet :actions="secondClassActionsList"
            :show="secondClassShow"
            cancelText='取消'
            :closeOnClickOverlay='true'
            @close='secondClassClose'
            @select="secondClassSelectClick"></u-action-sheet>
    </view>
</template>
 
<script>
    import { mapState, mapMutations } from "vuex"
    export default {
        data() {
            return {
                dataForm: {
                    firstClass: "",
                    secondClass: "",
                    specifications: "",
                    unqualifiedWeight:'',
                    // unqualifiedType:'',
                    penaltyUnitPrice:''
                },
                index: '',
                takeCoalId: "",
                params:{},
                // 一级品类操作菜单
                firstClassActionsList: [],
                firstClassShow: false,
                // 二级品类操作菜单
                secondClassActionsList: [],
                secondClassShow: false,
                // 规格选择
                specList: [],
                haveSelectd: true,
                // 判断是修改品名与规格还是不合格品名
                productName: false,
                unqualified: false,
                rules: {
                'firstClass': {
                    type: 'string',
                    required: true,
                    message: '请选择值',
                    trigger: ['blur', 'change']
                },
                'secondClass': {
                    type: 'string',
                    required: true,
                    message: '请选择值',
                    trigger: ['blur', 'change']
                },
                'specifications': {
                    type: 'string',
                    required: true,
                    message: '请选择值',
                    trigger: ['blur', 'change']
                },
                'unqualifiedWeight': {
                    required: true,
                    message: '请选择值',
                    trigger: ['blur', 'change']
                },
                // 'unqualifiedType':{
                //     required: true,
                //     message: '请选择值',
                //     trigger: ['blur', 'change']
                // },
                'penaltyUnitPrice':{
                    required: true,
                    message: '请选择值',
                    trigger: ['blur', 'change']
                }
            },
                // 
                showWeighCopyStorge: []
            }
        },
        computed: {
            ...mapState(["globalShowWeigh"]),
        },
        onReady() {
        //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
        this.$refs.uForm.setRules(this.rules)
            },
        onLoad(params) {
            this.index = params.index || ""
            this.takeCoalId = params.takeCoalId || ''
            this.getFirstCategoryName(params)
            this.params = params;
            this.productName = params.productName === "true" || false
            this.unqualified = params.unqualified === "true" || false
            this.showWeighCopyStorge = JSON.parse(JSON.stringify(uni.getStorageSync('showWeighCopyStorgeOther')))
            console.log(params,'paramsparamsparams');
            if(params.type == 'edit'){
                this.init(params)
            }
        },
        methods: {
            ...mapMutations(['changeglobalShowWeigh']),
            getFirstCategoryName(params) {
                uni.showLoading({
                    title: "加载中"
                })
                this.$reqGet("getFirstCategoryName").then(res => {
                    if (res.code === 0) {
                        uni.hideLoading()
                        this.firstClassActionsList = res.data.filter(Boolean).map(v => {
                            return {
                                ...v,
                                name: v &&  v.firstCategoryName
                            }
                        })
                        if(params.type !== 'edit')    this.dataForm.firstClass = this.firstClassActionsList[0].firstCategoryName
                    } else {
                        uni.hideLoading()
                        this.$u.toast('加载失败')
                    }
                })
            },
            init(params){
             let arr =  this.showWeighCopyStorge[params.index];
             console.log(this.showWeighCopyStorge,'arr')
             let {firstClass,secondClass,specifications} = arr.tempArr[params.indexTo];
             Object.assign(this.dataForm,{firstClass,secondClass,specifications});
             this.dataForm.unqualifiedWeight = this.showWeighCopyStorge[params.index].unqualifiedWeights.split(',')[params.indexTo];
             //不合格类判定
            //  this.dataForm.unqualifiedType = this.showWeighCopyStorge[params.index].unqualifiedType.split(',')[params.indexTo];
             //单价
            this.dataForm.penaltyUnitPrice = this.showWeighCopyStorge[params.index].penaltyUnitPrice.split(',')[params.indexTo];
            },
            //一级品类菜单
            firstClassSelect() {
                this.firstClassShow = true
            },
            firstClassClose() {
                this.firstClassShow = false
            },
            firstClassSelectClick(val) {
                this.dataForm.firstClass = val.name
            },
            // 二级品类选择
            getSecondCategoryName() {
                uni.showLoading({
                    title: "加载中"
                })
                this.$reqGet('getSecondCategoryName', { firstCategoryName: this.dataForm.firstClass }).then(
                    res => {
                        if (res.code === 0) {
                            uni.hideLoading()
                            this.secondClassActionsList = res.data.map(v => {
                                return {
                                    ...v,
                                    name: v.secondCategoryName
                                }
                            })
                        } else {
                            uni.hideLoading()
                            this.$u.toast('加载失败')
                        }
                    })
            },
            //二级品类菜单
            async secondClassSelect() {
                await this.getSecondCategoryName()
                this.secondClassShow = true
            },
            secondClassClose() {
                this.secondClassShow = false
            },
            secondClassSelectClick(val) {
                this.dataForm.secondClass = val.name
            },
            // 选择规格
            specInputHandle() {
                if (!this.dataForm.secondClass) return this.$u.toast('请先选择上方品名')
                this.$reqGet('getSpec', {
                    firstCategoryName: this.dataForm.firstClass,
                    secondCategoryName: this.dataForm
                        .secondClass,
                    specText: this.dataForm.specifications
                }).then(res => {
                    if (res.code === 0) {
                        this.specList = res.data
                    } else {
                        uni.hideLoading()
                        this.$u.toast('加载失败')
                    }
                })
            },
            specSelectHandle(val) {
                this.dataForm.specifications = val
                this.haveSelectd = false
            },
            formHandle() {
                console.log(this.globalShowWeigh,    this.$refs.uForm,'this.globalShowWeigh');
                this.$refs.uForm.validate().then(res => {
                        // uni.$u.toast('校验通过')
                    
                        this.showWeighCopyStorge = this.globalShowWeigh;
                        console.log(this.showWeighCopyStorge,this.index,'this.showWeighCopyStorge[this.index]');
                if(this.params.type == 'edit'){
                    if (this.productName) {
                    this.showWeighCopyStorge[this.index].modifyProductName = this.dataForm.secondClass + '/' + this
                        .dataForm.specifications
                    this.showWeighCopyStorge[this.index].breed = this.dataForm.secondClass
                    this.showWeighCopyStorge[this.index].spec = this.dataForm.specifications
                }
                if (this.unqualified) {
                    let str = this.dataForm.secondClass + '/' + this.dataForm
                        .specifications;
                     let tempArr =     this.showWeighCopyStorge[this.index].unqualifiedBreed.split(",")
                     let tempWeightArr =     this.showWeighCopyStorge[this.index].unqualifiedWeights.split(",")
                     let noPinArr =this.showWeighCopyStorge[this.index].unqualifiedType.split(",")
                     let noPriceArr = this.showWeighCopyStorge[this.index].penaltyUnitPrice.split(",");
                    tempArr[this.params.indexTo] = str;
                    tempWeightArr[this.params.indexTo] = this.dataForm.unqualifiedWeight;
                    // noPinArr[this.params.indexTo] = this.dataForm.unqualifiedType;
                    noPriceArr[this.params.indexTo] = this.dataForm.penaltyUnitPrice;
                    this.showWeighCopyStorge[this.index].unqualifiedBreed = tempArr.join(',');
                    this.showWeighCopyStorge[this.index].unqualifiedWeights = tempWeightArr.join(',');
                    this.showWeighCopyStorge[this.index].unqualifiedType = noPinArr.join(',');
                    this.showWeighCopyStorge[this.index].penaltyUnitPrice = noPriceArr.join(',');
                    this.showWeighCopyStorge[this.index].breed = this.dataForm.secondClass
                    this.showWeighCopyStorge[this.index].spec = this.dataForm.specifications
                    //如果这个  tempArr不为 空
                    if(this.showWeighCopyStorge[this.index].tempArr){
                    this.showWeighCopyStorge[this.index].tempArr[this.params.indexTo].firstClass = this.dataForm.firstClass;
                    this.showWeighCopyStorge[this.index].tempArr[this.params.indexTo].secondClass = this.dataForm.secondClass;
                    this.showWeighCopyStorge[this.index].tempArr[this.params.indexTo].specifications = this.dataForm.specifications;
                    }else{
 
                        
                    }
                    
                }
                }else{
                    if (this.productName) {
                    this.showWeighCopyStorge[this.index].modifyProductName = this.dataForm.secondClass + '/' + this
                        .dataForm.specifications
                    this.showWeighCopyStorge[this.index].breed = this.dataForm.secondClass
                    this.showWeighCopyStorge[this.index].spec = this.dataForm.specifications
                }
                if (this.unqualified) {
                    let str = this.dataForm.secondClass + '/' + this.dataForm
                        .specifications;
                    let tempArr;
                    if(    this.showWeighCopyStorge[this.index].unqualifiedBreed){
                        tempArr =     this.showWeighCopyStorge[this.index].unqualifiedBreed.split(",").filter(Boolean);
                    }else{
                        tempArr =  []
                    }
                
                    let tempWeightArr;
                    if(this.showWeighCopyStorge[this.index].unqualifiedWeights){
                        tempWeightArr =     this.showWeighCopyStorge[this.index].unqualifiedWeights.split(",").filter(Boolean)
                    }else{
                        tempWeightArr =  [];
                    }
                    // 添加不合格品类判定
                    // let noPin;
                    // if(this.showWeighCopyStorge[this.index].unqualifiedType){
                    //     noPin = this.showWeighCopyStorge[this.index].unqualifiedType.split(",").filter(Boolean)
                    // }else{
                    //     noPin = []
                    // }
                    //添加不合格单价
                    let noPrice;
                    if(this.showWeighCopyStorge[this.index].penaltyUnitPrice){
                        noPrice = this.showWeighCopyStorge[this.index].penaltyUnitPrice.split(",").filter(Boolean)
                    }else{
                        noPrice = []
                    }
 
                    tempWeightArr.push(this.dataForm.unqualifiedWeight);
                    tempArr.push(str);
                    // noPin.push(this.dataForm.unqualifiedType)
                    noPrice.push(this.dataForm.penaltyUnitPrice)
                    this.showWeighCopyStorge[this.index].unqualifiedBreed = tempArr.join(',')
                    this.showWeighCopyStorge[this.index].unqualifiedWeights = tempWeightArr.join(',')
                    // this.showWeighCopyStorge[this.index].unqualifiedType = noPin.join(',') 
                    this.showWeighCopyStorge[this.index].penaltyUnitPrice = noPrice.join(',') 
 
                    this.showWeighCopyStorge[this.index].breed = this.dataForm.secondClass
                    this.showWeighCopyStorge[this.index].spec = this.dataForm.specifications
 
 
                    this.showWeighCopyStorge[this.index].firstClass = this.dataForm.firstClass;
                    this.showWeighCopyStorge[this.index].secondClass = this.dataForm.secondClass;
                    this.showWeighCopyStorge[this.index].specifications = this.dataForm.specifications;
 
                    if(!this.showWeighCopyStorge[this.index].tempArr){
                        this.showWeighCopyStorge[this.index].tempArr = [];
                    }
                        this.showWeighCopyStorge[this.index].tempArr.push({
                            firstClass: this.dataForm.firstClass,
                            secondClass:this.dataForm.secondClass,
                            specifications:this.dataForm.specifications
                        })
                    
                
                }
 
                }
                
            
                
                this.changeglobalShowWeigh(this.showWeighCopyStorge)
                uni.setStorageSync('showWeighCopyStorgeOther', this.globalShowWeigh)
                uni.navigateBack({
                    url: `/pages/driver-page/driver-index/bill-of-lading-details/weighDetail/weighDetail?dataForm=${JSON.stringify(this.dataForm)}&orderPlanId=${this.takeCoalId}&index=${this.index}&havedSubmit=${true}`
                })
                uni.$emit("handClick",{data:this.dataForm,tempArr:this.showWeighCopyStorge[this.index].tempArr,index:this.index});
                    }).catch(errors => {
                        console.log(errors,'errors')
                        uni.$u.toast('校验失败')
                    })
    
            },
            checkNum(value,name){
                if (
                    value &&
                    value.indexOf(".") < 0 &&
                    value != ""
                    ) {
                        value = parseFloat(value);
                        value = value + ""; // 变回为字符串
                    }else{
                        value =  value.replace(/^(-)*(\d+)\.(\d\d).*$/,"$1$2.$3");
                        
                    } // 如果没有小数点,首位不能为类似于 01、02的值
                    this.$nextTick(()=>{
                            this.dataForm[name]  = value.replace(/[^\d.]/g, "");
                        });
                
            }
        }
    }
</script>
 
<style lang="scss"
    scoped>
    .main {
        width: 94%;
        margin: 10px;
        position: relative;
    }
 
    .slide-fade-enter-active {
        transition: all 0.3s ease-out;
    }
 
    .spec-main {
        width: 96%;
        margin: auto;
        height: 600rpx;
        overflow: scroll;
        background: #f0f0f0;
        box-shadow: 4rpx 6rpx 51rpx 0rpx rgba(73, 120, 240, 0.11);
        border-radius: 20rpx;
        position: relative;
        top: vww(5);
 
        &_content {
            width: 90%;
            margin: auto;
            padding-top: vww(10);
 
            .spec-main_item {
                padding: vww(5);
                color: #515151;
                border-bottom: 1px solid #e3e3e3;
                font-size: 40rpx;
            }
        }
    }
</style>