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
<template>
    <view class="activity-container" :data-theme='theme()' :class="theme() || ''">
        <form @submit="formSubmit" @reset="formReset">
            <view class="activity-form p20 pb150">
                <view class="form-section bg-white radius24">
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">绑定用户</view>
                        <view class="d-s-c" @click="openUser">
                            <view class="make-item input-box flex-1" v-if="formData.user_id">
                                <text>{{user_info.name}}</text>
                            </view>
                            <view class="make-item input-box flex-1 gray9" v-else>请选择</view>
                            <view class="icon iconfont icon-jiantou f24"></view>
                        </view>
                    </view>
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">上传头像</view>
                        <view class="upload-btn tr flex-1 pr" @click="openUpload()">
                            <template v-if="formData.avatarUrl!=''">
                                <image :src="formData.avatarUrl" mode="aspectFit"></image>
                                <view class="delete-img tc" @click.stop="deleteImg()">
                                    <text class="iconfont icon-guanbi"></text>
                                </view>
                            </template>
                            <template v-else>
                                <view class="icon iconfont icon-zhanghumingcheng f60"></view>
                            </template>
                        </view>
                    </view>
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">姓名</view>
                        <input type="text" v-model="formData.real_name" class="tr flex-1" placeholder='请输入真实姓名' />
                    </view>
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">手机号</view>
                        <input type="text" v-model="formData.mobile" class="tr flex-1" placeholder='请输入手机号' />
                    </view>
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">成员身份</view>
                        <picker class="" value="" @change="changePosition" :range="positionList" range-key='name' :value="position_index">
                            <view class="d-s-c">
                                <view class="make-item input-box flex-1">{{positionList[position_index].name|| '请选择'}}</view>
                                <view class="icon iconfont icon-jiantou f24"></view>
                            </view>
                        </picker>
                    </view>
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">所属企业</view>
                        <view class="d-s-c" @click="selectSupplier()">
                            <view class="make-item input-box flex-1">{{supplier_name||'请选择'}}</view>
                            <view class="icon iconfont icon-jiantou f24"></view>
                        </view>
                    </view>
                    <view class="form-item d-b-c border-b-e">
                        <view class="item-title">籍贯</view>
                        <view class="d-s-c flex-1" @click="showMulLinkageThreePicker">
                            <input class="tr flex-1" type="text" placeholder="请选择籍贯" placeholder-class="gray9" v-model="selectCity"
                             disabled="true" />
                            <view class="icon iconfont icon-jiantou f24"></view>
                        </view>
                    </view>
                    <view class="form-item d-b-c">
                        <textarea class="ww100 lh150 p20 radius12 box-s-b" placeholder-class="grary9" style=" background-color: #f7f7f7;
                        height: 150rpx;" v-model="formData.describe" placeholder="请输入个人简介(选填)"></textarea>
                    </view>
                    
                </view>
            </view>
            <view class="footer-btn p20 bg-white">
                <button class="theme-btn" form-type="submit" type="default">提交</button>
            </view>
        </form>
        <!-- 区域选择 -->
        <mpvue-city-picker v-if="is_loaded" ref="mpvueCityPicker" :province="province" :city="city" :area="area" :pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker>
        <!-- 上传图片 -->
        <Upload v-if="isupload" @getImgs="returnImgsFunc"></Upload>
        <!-- 企业弹窗 -->
        <Supplier :isOpenSupplier="open_supplier" @close="closeSupplierFunc"></Supplier>
        <!-- 用户弹窗 -->
        <User :isOpenUser="open_user" @close="closeUserFunc"></User>
    </view>
</template>
 
<script>
    import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker.vue';
    import Upload from '@/components/upload/upload.vue';
    import Supplier from './popup/supplier';
    import User from './popup/user';
    export default {
        components: {
            mpvueCityPicker,
            User,
            Upload,
            Supplier
        },
        data() {
            return {
                loading: false,
                cityPickerValueDefault: [0, 0, 0],
                selectCity: '选择省,市,区',
                formData: {
                    user_id: 0,
                    real_name: '',
                    mobile: '',
                    position_id: '',
                    shop_supplier_id: '', // 所属企业
                    describe: '',
                    province_id: '',
                    city_id: '',
                    region_id: '',
                    avatarUrl: '',
                },
                open_supplier: false,
                supplier_name: '', // 所属企业
                open_user: false,
                user_info: {}, // 选择的用户
                is_loaded: false,
                province: [],
                city: [],
                area: [],
                positionList: [], // 职务列表
                isupload: false,
                position_index: '',
            };
        },
        created() {
            this.getData();
        },
        methods: {
            // 获取省市区
            getData(){
                let self = this;
                self._get('branch.admin.member/add', {}, function(res) {
                    self.province = res.data.regionData[0];
                    self.city = res.data.regionData[1];
                    self.area = res.data.regionData[2];
                    self.positionList = res.data.positionList;
                    self.is_loaded = true;
                });
            },
            getRegistrationInformation(user_id) {
                let self = this;
                self._get('branch.activity/getRegistrationInformation', {user_id}, function(res) {
                    if (res.data.registrationInformation) {
                        let data=res.data.registrationInformation;
                        self.formData.province_id = data.province_id;
                        self.formData.city_id = data.city_id;
                        self.formData.region_id = data.region_id;
                        self.formData.real_name = data.real_name;
                        self.formData.mobile = data.mobile;
                        self.formData.shop_supplier_id = data.shop_supplier_id;
                        self.supplier_name = data.supplier_name;
                        self.selectCity = res.data.registrationInformation.region;
                        if (res.data.registrationInformation.branch_name) {
                            self.branch_name = res.data.registrationInformation.branch_name;
                        }
                    }
                });
            },
            
            // 提交
            formSubmit() {
                let self = this;
                let formData = this.formData;
                if (!formData.user_id) {
                    uni.showToast({
                        title: '请绑定用户',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                if (formData.avatarUrl == '') {
                    uni.showToast({
                        title: '请上传头像',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                if (formData.real_name == '') {
                    uni.showToast({
                        title: '请输入姓名',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                if (formData.mobile == '') {
                    uni.showToast({
                        title: '请输入手机号',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                let reg = /^((0\d{2,3}-\d{7,8})|(1[3456789]\d{9}))$/;
                if (!reg.test(formData.mobile)) {
                    uni.showToast({
                        title: '手机号格式不正确',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                if (!formData.position_id) {
                    uni.showToast({
                        title: '请选择成员身份',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                if (formData.province_id == '' || formData.city_id == '') {
                    uni.showToast({
                        title: '请选择籍贯',
                        duration: 1000,
                        icon: 'none'
                    });
                    return false;
                }
                
                uni.showLoading({
                    title: '正在提交',
                    mask: true
                });
                self._post('branch.admin.member/add', {formData: JSON.stringify(formData)}, function(res) {
                    self.showSuccess(res.msg, function() {
                        self.gotoPage('/pages/branch/admin/member/index')
                    }, null, function(){
                        uni.hideLoading();
                    });
                });
            },
            
            /*三级联动选择*/
            showMulLinkageThreePicker() {
                this.$refs.mpvueCityPicker.show();
            },
            
            /*确定选择的省市区*/
            onConfirm(e) {
                this.selectCity = e.label;
                this.formData.province_id = e.cityCode[0];
                this.formData.city_id = e.cityCode[1];
                this.formData.region_id = e.cityCode[2];
            },
            
            openUser() {
                this.open_user = true;
            },
            
            closeUserFunc(e) {
                if (e != null) {
                    this.formData.user_id = e.user_id;
                    this.getRegistrationInformation(this.formData.user_id )
                    this.user_info.name = e.real_name ? e.real_name : e.nickName;
                    this.user_info.avatarUrl = e.avatarUrl;
                    if (!this.formData.avatarUrl) {
                        this.formData.avatarUrl = e.avatarUrl;
                    }
                }
                this.open_user = false;
            },
            
            /*上传*/
            openUpload() {
              this.isupload = true;
            },
                    
            /*获取图片*/
            returnImgsFunc(e) {
              let self = this;
              if (e != null) {
                this.formData.avatarUrl = e[0].file_path;
              }
              this.isupload = false;
            },
            
            /*删除图片*/
            deleteImg(){
                this.formData.avatarUrl = this.user_info.avatarUrl != this.formData.avatarUrl ? this.user_info.avatarUrl : '';
            },
            
            // 选择职务
            changePosition(e) {
                this.position_index = e.target.value;
                this.formData.position_id = this.positionList[this.position_index].position_id;
            },
            
            // 打开企业选择弹窗
            selectSupplier() {
                this.open_supplier = true;
            },
            
            // 关闭企业选择弹窗
            closeSupplierFunc(e) {
                if (e != null) {
                    this.formData.shop_supplier_id = e.shop_supplier_id;
                    this.supplier_name = e.name;
                }
                this.open_supplier = false;
            },
        }
    }
</script>
 
<style lang="scss" scoped>
.activity-form {
        
    .form-section {
        padding: 0 20rpx;
        
        + .form-section {
            margin-top: 20rpx;
        }
        
        .form-item {
            padding: 30rpx 0;
            font-size: 26rpx;
            
            .upload-btn {
                
                image {
                    width: 90rpx;
                    height: 90rpx;
                    border-radius: 90rpx;
                    display: inline-block;
                }
                
                >.iconfont {
                    font-size: 90rpx;
                }
                
                .delete-img {
                    position: absolute;
                    width: 40rpx;
                    height: 40rpx;
                    background: rgba(0,0,0,.5);
                    border-radius: 40rpx;
                    line-height: 40rpx;
                    right: -10rpx;
                    top: 0;
                    
                    .iconfont {
                        font-size: 24rpx;
                    }
                }
            }
        }
    }
    
}
.footer-btn {
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    box-sizing: border-box;
    z-index: 9;
    border-top: 1rpx solid #eeeeee;
}
</style>