yangan
22 小时以前 a28d0135ee42809b2c5863609da37155d3ecba5b
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
<template>
    <!-- 添加承运商或司机 -->
    <view class="addTo-freightForwarder-drvier">
        <view class="addForm">
            <u--form labelPosition="top"
                ref="form1">
                <u-form-item labelWidth="20%"
                    :label="role == 1 ?'承运商' : '姓名'" 
                    ref="item1"
                    v-if="role == 1"><u--input v-model="name"
                        :customStyle="{ border: '1px solid #dddddd' }"></u--input></u-form-item>
                <u-form-item labelWidth="25%"
                    label="手机号"
                    ref="item1"
                    v-if="role == 1"><u--input v-model="phone"
                        :customStyle="{ border: '1px solid #dddddd' }"></u--input></u-form-item>
                <u-form-item labelWidth="25%"
                    label="汽车车牌号"
                    ref="item1"
                    v-if="role == 2">
                    <xm-cell special label="车牌号" :value="carNo" @show="showKeyboard('xmKeyboard')"></xm-cell>
                    <xm-keyboard-v2 ref="xmKeyboard" @confirm="(v) => carNo = v"></xm-keyboard-v2>
                </u-form-item>
            </u--form>
        </view>
        <view class="else-invite"
            @click="elseInvite">
            +从其他车队选择
        </view>
        <view class="addBtn"><u-button text="邀请"
                type="primary"
                @click="addToHuoDaiOrDriver"
                :loading="loading"></u-button></view>
    </view>
</template>
 
<script>
    import { customerId } from '@/utils/status.js';
    export default {
        onLoad(params) {
            console.log(params,'params')
            this.role = params.role;
            if (params.fleetId) {
                this.fleetId = params.fleetId;
            }
        },
        data() {
            return {
                role: null, // 决定添加承运商司机,还是车队司机
                fleetId: null,
                name: '',
                phone: '',
                carNo: '',
                customerId,
                loading: false
            };
        },
        methods: {
            showKeyboard(ref){
                this.$refs[ref].toShow(this.carNo)
            },
            init() {},
            addToHuoDaiOrDriver() {
                switch (this.role) {
                    case '1':
                        if (this.name == '' || this.phone == '') {
                            uni.showToast({
                                title: '请规范输入!',
                                icon: 'error',
                                duration: 2000
                            });
                        } else {
                            this.bindHuoDai();
                        }
                        break;
                    case '2':
                        if (this.carNo == '') {
                            uni.showToast({
                                title: '请规范输入!',
                                icon: 'error',
                                duration: 2000
                            });
                        } else {
                            this.bindUserFleet();
                        }
                    default:
                        break;
                }
            },
            // 邀请承运商
            bindHuoDai() {
                this.loading = true
                this.$reqPost('bindHuoDai', { name: this.name, phone: this.phone }, 'params').then(res => {
                    this.loading = false
                    if (res.code == 0) {
                        this.$u.toast('添加成功');
                        setTimeout(() => {
                            uni.navigateBack()
                            uni.$emit('needRefresh')
                            // uni.switchTab({
                            //     url: '/pages/tabbar-page/myPage-tabbar/myPage-tabbar'
                            // });
                        }, 1000);
                    } else {
                        this.$u.toast(res.msg ? res.msg : '未成功添加');
                    }
                }).catch(e => {
                    this.loading = false
                })
            },
            // 邀请司机
            bindUserFleet() {
                this.loading = true
                this.$reqPost('bindUserFleet', {
                    fleetId: this.fleetId,
                    carNo: this
                        .carNo
                }, 'params').then(res => {
                    console.log('邀请司机', res);
                    this.loading = false
                    if (res.code == 0) {
                        this.$u.toast(res.msg ? res.msg : '操作成功');
                        setTimeout(() => {
                            uni.navigateBack()
                            uni.$emit('needRefresh')
                            // uni.switchTab({
                            //     url: '/pages/tabbar-page/myPage-tabbar/myPage-tabbar'
                            // });
                        }, 1000)
                    } else {
                        uni.showToast({
                            title: res.msg ? res.msg : '操作失败',
                            duration: 2000
                        });
                    }
                }).catch(e => {
                    this.loading = false
                })
            },
            elseInvite() {
                uni.navigateTo({
                    url: `/pages/public-page/selectFleet/selectFleet?fleetId=${this.fleetId}`
                })
            }
        }
    };
</script>
 
<style lang="scss"
    scoped>
    ::v-deep.addTo-freightForwarder-drvier {
        width: 90%;
        margin: 0 auto;
 
        .addForm {
            margin: 0 auto;
        }
 
        .else-invite {
            width: vww(150);
            margin: 0 auto;
            color: #3c9cff;
            margin-top: vww(40);
        }
 
        .addBtn {
            width: 90%;
            position: fixed;
            bottom: vww(48);
            margin: 0 auto;
        }
    }
</style>