qingyiay
2023-05-09 01e96c8855927df67ac8a6831e345b6cb33140d1
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
<template>
    <!-- 转发 -->
    <view class="forward">
        <view v-if="roleType == 1"><u-notice-bar :text="text" :fontSize="30" mode="link"></u-notice-bar></view>
        <view v-else-if="roleType == 2"><u-notice-bar :text="text1" :fontSize="30" mode="link"></u-notice-bar></view>
        <view class="forward-card" v-for="(val, index) in jhOrderPlanForwardList" :key="index">
            <u--form labelPosition="top" :model="forwardForm" ref="form1">
                <u-form-item label="转发对象" labelWidth="20%" ref="item1" @click="forwardObjectClick(index)">
                    <u--input v-model="val.name" placeholder="点击选择转发对象" :readonly="true"></u--input>
                </u-form-item>
                <u-form-item label="输入数量" labelWidth="20%" ref="item1">
                    <view class="forward-card-amount">
                        <view class="forward-card-amount-input"><u--input v-model="val.carNum" placeholder="请输入转发数量"></u--input></view>
                        <u-checkbox-group v-model="val.checkboxValue1" placement="column" @change="v => checkboxChange(v, index, val)">
                            <u-checkbox :customStyle="{ marginBottom: '8px' }" size="30" labelSize="30" label="全部转发" name="全部转发" :disabled="val.ischecked"></u-checkbox>
                        </u-checkbox-group>
                    </view>
                </u-form-item>
                <u-form-item><u-button text="删除本组" :hairline="false" type="error" @click="deleteGroup(index, val)"></u-button></u-form-item>
            </u--form>
        </view>
        <!-- 增加按钮 -->
        <view class="AdddBtn"><u-button text="添加" :hairline="false" type="primary" :customStyle="{ marginBottom: '8px' }" @click="addForm"></u-button></view>
        <!-- 按钮 -->
        <view class="forwardBtn"><u-button text="提交" :hairline="false" type="warning" @click="submitForm"></u-button></view>
 
        <!-- 选择货代或车队弹出框 -->
        <view class="selectHuoDaiOrFleet-container">
            <u-popup :show="selectPopupShow" mode="bottom" @close="selectPopupClose" @open="selectPopupOpen">
                <view class="selectHuoDaiOrFleet-container-box">
                    <u-tabs :list="list1" @click="tabClick"></u-tabs>
                    <view class="" v-if="!tabHuoDai">
                        <u-cell-group>
                            <u-cell v-for="(item, index) in fleetData" :key="index" :title="item.name">
                                <view class="cell-util" slot="value">
                                    <u-button @click="forwardFleetObjectSelect(item, index)" text="选择" type="primary" size="mini"></u-button>
                                </view>
                            </u-cell>
                        </u-cell-group>
                    </view>
                    <view class="" v-else-if="tabHuoDai">
                        <u-cell-group>
                            <u-cell v-for="(item, index) in huoDaiData" :key="index" :title="item.name">
                                <view class="cell-util" slot="value">
                                    <u-button @click="forwardHuoDaiObjectSelect(item, index)" text="选择" type="primary" size="mini"></u-button>
                                </view>
                            </u-cell>
                        </u-cell-group>
                    </view>
                </view>
            </u-popup>
        </view>
    </view>
</template>
 
<script>
import { customerId } from '@/utils/status';
 
export default {
    onLoad(params) {
        console.log(params, '转发页面的参数');
        // 客户
        this.cars2 = Number(params.cars2);
        this.carNumSurplus1 = Number(params.carNumSurplus1);
        // 货代
        this.carNum = Number(params.carNum);
        this.carNumSurplusHuodai = this.forwardSurplus = Number(params.carNumSurplusHuodai);
        this.orderPlanId = params.orderPlanId;
        this.$reqGet('forwardList', { OrderPlanId: params.orderPlanId }).then(res => {
            if (res.data.length !== 0 && this.roleType == 1) {
                this.jhOrderPlanForwardList = res.data.map(item => {
                    return {
                        id: item.id,
                        orderPlanId: item.orderPlanId,
                        name: item.xsUserName === null ? item.fleetName : item.xsUserName,
                        carNum: item.carNum,
                        xsUserId: item.xsUserId === null ? 0 : item.xsUserId,
                        fleetId: item.fleetId === null ? 0 : item.fleetId,
                        checkboxValue1: ''
                    };
                });
            } else if (res.data.length !== 0 && this.roleType == 2) {
                this.jhOrderPlanForwardList = res.data.map(item => {
                    return {
                        id: item.id,
                        orderPlanId: item.orderPlanId,
                        name: item.fleetName,
                        carNum: item.carNum,
                        xsUserId: item.xsUserId === null ? 0 : item.xsUserId,
                        fleetId: item.fleetId === null ? 0 : item.fleetId,
                        checkboxValue1: ''
                    };
                });
            } else {
                this.jhOrderPlanForwardList = this.jhOrderPlanForwardList.map(v => {
                    if (!v.orderPlanId) {
                        return {
                            ...v,
                            orderPlanId: params.orderPlanId
                        };
                    }
                });
            }
        });
    },
    data() {
        return {
            forwardSurplus: 0,
            paramsName: {},
            huoDaiData: [],
            fleetData: [],
            // 日计划id
            orderPlanId: '',
            jhOrderPlanForwardList: [
                {
                    orderPlanId: '',
                    name: '',
                    carNum: null,
                    xsUserId: 0,
                    fleetId: 0,
                    checkboxValue1: ''
                }
            ],
            // 索引,利用索引正确显示
            index: '',
            checkboxValue1: '',
            selectPopupShow: false,
            list1: [{ name: '车队' }, { name: '货代' }],
            tabHuoDai: false,
            carNumSurplus1: '',
            cars2: '',
            carNum: '',
            carNumSurplusHuodai: '',
            formNum: 1,
            // 个人转发数据
            personalForward: {}
        };
    },
    onShow() {
        this.init();
        if (this.roleType == 2) {
            this.list1.splice(1, 1);
            this.tabHuoDai = false;
        }
    },
    computed: {
        roleType() {
            return uni.getStorageSync('roleType');
        },
        text() {
            return `已领取${this.cars2}张提煤单,剩余${this.carNumSurplus1}张提煤单`;
        },
        text1() {
            return `已拥有${this.carNum}张提煤单,剩余${this.carNumSurplusHuodai}张提煤单`;
        }
    },
    methods: {
        init() {
            switch (this.roleType) {
                case 1:
                    this.getAllHuoDaiByCustomerId();
                    this.getFleet();
                    break;
                case 2:
                    this.getFleet();
                    break;
                default:
                    break;
            }
        },
        allrelay(x, y) {
            let a = 0;
            if (y != 0) {
                a = Number(x) + Number(y);
                return a;
            } else {
                return Number(x);
            }
        },
        allrelayto(x, y) {
            let a = 0;
            if (y != 0) {
                a = Number(x) - Number(y);
                return a;
            } else {
                return Number(x);
            }
        },
        checkboxChange(value, index, v) {
            uni.setStorageSync('allrelay', this.jhOrderPlanForwardList[index].carNum);
            this.jhOrderPlanForwardList = this.jhOrderPlanForwardList.map((v, i) => {
                return {
                    ...v,
                    ischecked: false
                };
            });
            if (value.length != 0) {
                let tempforwardSurplus = this.forwardSurplus;
                let tempcarNumSurplus1 = this.carNumSurplus1;
                if (v.id) {
                    this.$reqGet('jhorderplanforward', { forwardId: v.id }).then(res => {
                        this.personalForward = res.data;
                        // 计算全部转发数
                        // 客户
                        if (this.roleType == 1) {
                            this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.personalForward.carNum, tempcarNumSurplus1);
                            if (this.jhOrderPlanForwardList[index].carNum == 0) {
                                this.jhOrderPlanForwardList[index].carNum == tempcarNumSurplus1;
                            }
                        }
                        tempcarNumSurplus1 = 0;
                        // 货代
                        if (this.roleType == 2) {
                            this.jhOrderPlanForwardList[index].carNum = this.allrelay(this.personalForward.carNum, tempforwardSurplus);
                        }
                        tempforwardSurplus = 0;
                    });
                } else {
                    if (this.roleType == 1) {
                        this.jhOrderPlanForwardList[index].carNum = this.carNumSurplus1;
                        // this.allrelay(this.jhOrderPlanForwardList[index].carNum, this.carNumSurplus1);
                    }
                    tempcarNumSurplus1 = 0;
                    if (this.roleType == 2) {
                        this.jhOrderPlanForwardList[index].carNum = this.forwardSurplus;
                        // this.allrelay(this.jhOrderPlanForwardList[index].carNum, this.forwardSurplus);
                    }
                    tempforwardSurplus = 0;
                }
                // 选择一个后其余禁止复选
                this.jhOrderPlanForwardList.forEach((v, i) => {
                    if (i !== index) {
                        v.ischecked = true;
                    }
                });
            } else {
                let tempforwardSurplus = this.forwardSurplus;
                let tempcarNumSurplus1 = this.carNumSurplus1;
                // 货代
                if (this.roleType == 2) {
                    this.jhOrderPlanForwardList[index].carNum = 0;
                    if (this.jhOrderPlanForwardList[index].carNum <= 0) {
                        this.jhOrderPlanForwardList[index].carNum = 0;
                    }
                }
                // 客户
                if (this.roleType == 1) {
                    this.jhOrderPlanForwardList[index].carNum = 0;
                    if (this.jhOrderPlanForwardList[index].carNum <= 0) {
                        this.jhOrderPlanForwardList[index].carNum = 0;
                    }
                }
            }
        },
        // 获取货代列表
        getAllHuoDaiByCustomerId() {
            this.$reqGet('getAllHuoDaiByCustomerId').then(res => {
                this.huoDaiData = res.data;
            });
        },
        // 获取车队列表
        getFleet() {
            this.$reqGet('getFleet').then(res => {
                this.fleetData = res.data;
            });
        },
        // 转发
        forwardObjectClick(index) {
            this.selectPopupShow = true;
            this.index = index;
        },
        selectPopupClose() {
            this.selectPopupShow = false;
        },
        selectPopupOpen() {},
        // 转发选择货代
        forwardHuoDaiObjectSelect(item, index) {
            this.$nextTick(() => {
                let isableAdd = this.jhOrderPlanForwardList.filter(v => item.name === v.name);
                if (isableAdd.length > 0) {
                    this.$u.toast('存在重复添加');
                    this.selectPopupShow = true;
                } else {
                    this.selectPopupShow = false;
                    this.jhOrderPlanForwardList[this.index].xsUserId = item.userId;
                    this.jhOrderPlanForwardList[this.index].name = item.name;
                    this.jhOrderPlanForwardList[this.index].fleetId = 0;
                }
            });
        },
        // 转发选择车队
        forwardFleetObjectSelect(item, index) {
            this.$nextTick(() => {
                let isableAdd = this.jhOrderPlanForwardList.filter(v => item.name === v.name);
                if (isableAdd.length > 0) {
                    this.$u.toast('存在重复添加');
                    this.selectPopupShow = true;
                } else {
                    this.selectPopupShow = false;
                    this.jhOrderPlanForwardList[this.index].fleetId = item.id;
                    this.jhOrderPlanForwardList[this.index].name = item.name;
                    this.jhOrderPlanForwardList[this.index].xsUserId = 0;
                }
            });
        },
        // 添加一组表单
        addForm() {
            // 判断是否有一个复选,如果有则禁止新加的复选,没有则不禁止
            let ischeck = this.jhOrderPlanForwardList.some(v => v.ischecked == true);
            if (!ischeck) {
                this.jhOrderPlanForwardList.push({
                    orderPlanId: this.orderPlanId,
                    name: '',
                    carNum: 0,
                    xsUserId: 0,
                    fleetId: 0,
                    checkboxValue1: '',
                    ischecked: false
                });
            } else {
                this.jhOrderPlanForwardList.push({
                    orderPlanId: this.orderPlanId,
                    name: '',
                    carNum: 0,
                    xsUserId: 0,
                    fleetId: 0,
                    checkboxValue1: '',
                    ischecked: true
                });
            }
        },
        // 删除一组表单
        deleteGroup(index, v) {
            let tempcarNum = v.carNum;
            if (v.id && this.jhOrderPlanForwardList[index].carNum !== tempcarNum) {
                this.$reqPost('deleteForward', { id: v.id }, 'params').then(res => {
                    if (res.code === 0) {
                        this.jhOrderPlanForwardList.splice(index, 1);
                        this.$u.toast('删除成功');
                    } else if (res.code === 1) {
                        this.$u.toast(res.msg);
                    }
                });
            } else {
                this.jhOrderPlanForwardList.splice(index, 1);
                this.$u.toast('删除成功');
            }
        },
        // 提交
        submitForm() {
            let isPass = false;
            if (this.jhOrderPlanForwardList.length === 0) {
                this.$u.toast('请至少选择一组转发对象');
            }
            let reg = /^[1-9]\d*$/;
            this.jhOrderPlanForwardList.forEach(v => {
                if (!reg.test(v.carNum) || Number(v.carNum) <= 0) {
                    this.$u.toast('请输入合法数字');
                    isPass = false;
                    return isPass;
                }
                // else if (Number(v.carNum) > Number(this.forwardSurplus)) {
                //     this.$u.toast('超过最大订单剩余量');
                //     isPass = false;
                //     return isPass;
                // }
                else {
                    isPass = true;
                    return isPass;
                }
            });
            if (isPass) {
                this.$reqPost('forward', this.jhOrderPlanForwardList, 'json').then(res => {
                    console.log(res, 'zh');
                    if (res.code == 0) {
                        this.$u.toast('提交成功');
                        setTimeout(() => {
                            uni.navigateBack({ delta: 1 });
                        }, 1000);
                    } else {
                        this.$u.toast(res.msg);
                    }
                });
            }
        },
        tabClick(item) {
            if (item.name == '货代') {
                this.tabHuoDai = true;
            } else {
                this.tabHuoDai = false;
            }
        }
    }
};
</script>
 
<style lang="scss" scoped>
::v-deep.forward {
    width: 90%;
    margin: 0 auto;
 
    // 卡片
    .forward-card {
        margin-top: vww(10);
        .notice-bar {
            width: 100%;
            height: vww(24);
        }
        .u-form {
            .u-form-item {
                .u-form-item__body {
                    .u-form-item__body__right {
                        .u-form-item__body__right__content {
                            .u-form-item__body__right__content__slot {
                                .forward-card-amount {
                                    display: flex;
                                    justify-content: space-between;
                                    align-items: flex-end;
                                    .forward-card-amount-input {
                                        width: vww(245);
                                    }
                                }
                                .u-input {
                                    border: 1px solid #dddddd;
                                }
                            }
                        }
                    }
                }
            }
        }
        .forward-card-amount {
            display: flex;
        }
    }
 
    .forwardBtn {
        width: 100%;
        // position: fixed;
        bottom: vww(50);
    }
 
    .selectHuoDaiOrFleet-container {
        .u-popup {
            .u-transition {
                height: 95%;
 
                .u-popup__content {
                    overflow: scroll !important;
                    .selectHuoDaiOrFleet-container-box {
                        width: 90%;
                        margin: 0 auto;
                    }
                }
            }
        }
    }
}
</style>