gx
queenwuli
2021-01-15 4b80c98ef5fda8d6358778f2efe8bb35cb20ccf9
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
<template>
    <view class="container">
        <form @submit="submit" id="list">
            <view class="input-group-row">
                <text class="label">会员头像</text>
                <view class="right-text flex align-center justify-end" @click="showUploadImage">
                    <image :src="formData.photo?formData.photo:'../../static/images/default-avatar.png'" class="avatar"></image>
                    <text class="iconfont iconarrow-backimg gray"></text>
                </view>
            </view>
            <view class="input-group-row">
                <text class="label">会员姓名<text class="require">*</text></text>
                <input name="vipName" v-model="formData.vipName" type="text" maxlength="20"  placeholder="请填写会员姓名" placeholder-class='placeholder'/>
            </view>
            <view class="input-group-row">
                <text class="label">会员编号<text class="require">*</text></text>
                <input name="vipNo" v-model="formData.vipNo" type="text" maxlength="10" placeholder="请填写会员编号" placeholder-class='placeholder'/>
            </view>
            <view class="input-group-row">
                <text class="label">资金密码<text class="require">*</text></text>
                <input name="password" v-model="formData.password" type="password" maxlength="6" placeholder="6位数字格式密码" placeholder-class='placeholder'/>
            </view>
            <view class="input-group-row">
                <text class="label">手机号码<text class="require">*</text></text>
                <input name="phone" v-model="formData.phone" type="number" maxlength="11" placeholder="请填写手机号码" placeholder-class='placeholder'/>
            </view>
            <view class="input-group-row">
                <text class="label">性别<text class="require">*</text></text>
                <view class="right-text">
                    <radio-group name="sex" @change="sexChange">
                        <label><radio value="男" color="#518EFF"  class="radio" :checked="formData.sex==='男'"/>男</label>
                        <label><radio value="女" color="#518EFF" class="radio" :checked="formData.sex==='女'"/>女</label>
                    </radio-group>
                </view>
            </view>
            <view class="input-group-row">
                <text class="label">生日</text>
                <view class="right-text">
                    <picker mode="date" @change="dateChange" :end="endDate">
                        <text :class="formData.birthday?'':'gray'">{{formData.birthday?formData.birthday:'请选择生日'}}</text>
                    </picker>
                </view>
            </view>
            <view class="input-group-row">
                <text class="label">省市区</text>
                <view @click="openAddres" class="right-text">
                    <text :class="formData.areas?'':'gray'">{{formData.areas?formData.areas:'请选择省市区'}}</text>
                </view>
            </view>
            <view class="input-group-row">
                <text class="label">详细地址</text>
                <input name="address" v-model="formData.address" type="text" value="" placeholder="请填写详细地址" placeholder-class='placeholder'/>
            </view>
            <view class="input-group-row">
                <text class="label">到店途径</text>
                <view class="right-text">
                    <picker mode="selector" range-key="value" :range="arrivalWayList" @change="wayChange">
                        <view>
                            <text :class="formData.arrivalWay?'':'gray'">{{formData.arrivalWay?formData.arrivalWay:'请选择到店途径'}}</text>
                            <text class="iconfont iconjiantouarrow486 gray"></text>
                        </view>
                    </picker>
                </view>
            </view>
            <view class="input-group-row">
                <text class="label">推荐人</text>
                <navigator :url="'./selectCustomer?selectId='+formData.recommendId" hover-class="none" class="right-text">
                    <text :class="recommendName?'':'gray'">{{recommendName?recommendName:'请选择推荐人'}}</text>
                    <text class="iconfont iconarrow-backimg gray"></text>
                </navigator>
            </view>
            <view class="input-group-row">
                <text class="label">备注</text>
                <input name="remark" v-model="formData.remark" maxlength="60" type="text" placeholder="请填写备注" placeholder-class='placeholder'/>
            </view>
            <navigator url="./addLabel" hover-class="none" class="input-group-row">
                <text class="label">标签</text>
                <view class="right-text">
                    <text class="tag" v-for="item in formData.labels">{{item.label}}</text>
                </view>
            </navigator>
            <view class="footer">
                <button form-type="submit" :disabled="isDisabled" class="blue-btn ">保存</button>
            </view>
        </form>
        <region ref="simpleAddress" @onConfirm="addressChange" themeColor="#518EFF" cancelColor="#8c9fad"></region>
    </view>
</template>
 
<script>
    import imageUploadUtils from '../../common/jssdk/uploadImg.js'
    import region from '../../components/simple-address/simple-address.vue';
    export default{
        components:{
            region
        },
        data(){
            return {
                formData: {
                    vipName: '',
                    vipNo: '',
                    phone: '',
                    sex: '女',
                    birthday: '',
                    areas: '',
                    address: '',
                    arrivalWay: '',
                    recommendId: '',
                    remark: '',
                    labels: [],
                    photo: '',
                    password: ''
                },
                id: '',
                isDisabled: false,
                arrivalWayList: [],
                recommendName: ''
            }
        },
        onLoad(options) {
            if(options.id){
                this.id = options.id;
                uni.setNavigationBarTitle({
                    title: '编辑会员'
                });
                this.getMemberInfo()
            }
            this.loadArrivalWayList();
            this.loadReferrerList();
        },
        computed: {
            endDate() {
                return this.getDate('end');
            }
        },
        methods:{
            // 加载到店途径列表
            loadArrivalWayList(){
                this.$httpUtils.request('/api/vip/findArrivalWayList').then((res) => {
                    if(res.status == 200){
                        this.arrivalWayList = res.rows;
                    }
                })
            },
            // 加载推荐人列表
            loadReferrerList(){
                this.$httpUtils.request('/api/vip/findAllVipInfo').then((res) => {
                    if(res.status == 200){
                        let result = res.rows;
                        if(this.id){
                            for(var i in result){
                                if(result[i].id === this.formData.recommendId){
                                    this.recommendName = result[i].vipName;
                                    break;
                                }
                            }
                        }
                    }
                })
            },
            // 查询会员详情
            getMemberInfo(){
                this.$httpUtils.request('/api/vip/findVipInfoDetailById/'+this.id).then((res) => {
                    if(res.status == 200){
                        const result = res.mapInfo.vipInfo;
                        const {province, city, area} = result;
                        for(var key in this.formData){
                            this.formData[key] = result[key];
                        }
                        let arr = [province, city, area].filter((item) => {
                            return item
                        })
                        this.formData.areas = arr.join('-')
                    }
                })
            },
            showUploadImage(){
                imageUploadUtils.show((res) => {
                    this.formData.photo = res;
                })
            },
            sexChange(e){
                this.formData.sex = e.detail.value;
            },
            dateChange(e){
                this.formData.birthday = e.detail.value;
            },
            getDate(type) {
                const date = new Date();
                let year = date.getFullYear();
                let month = date.getMonth() + 1;
                let day = date.getDate();
    
                if (type === 'start') {
                    year = year - 70;
                }
                month = month > 9 ? month : '0' + month;;
                day = day > 9 ? day : '0' + day;
                return `${year}-${month}-${day}`;
            },
            openAddres(){
                this.$refs.simpleAddress.open();
            },
            addressChange(e){
                this.formData.areas = e.labelArr.join('-');
            },
            wayChange(e){
                this.formData.arrivalWay = this.arrivalWayList[e.detail.value].value;
            },
            valid(){
                const {vipName, vipNo,password, phone, sex} = this.formData;
                if(!vipName){
                    this.$toast.info('请填写会员姓名');
                    return false;
                }
                if(!vipNo){
                    this.$toast.info('请填写会员编号');
                    return false;
                }
                if(!/^\d{6}$/.test(password)){
                    this.$toast.info('请填写6位数字格式的密码');
                    return false;
                }
                if(!this.$utils.checkPhone(phone)){
                    this.$toast.info('请填写正确的手机号码');
                    return false;
                }
                if(!sex){
                    this.$toast.info('请选择性别');
                    return false;
                }
            },
            submit(e){
                let url = '';
                if(this.valid() === false){
                    return;
                }
                this.isDisabled = true;
                if(this.id){
                    url = '/api/vip/modifyVip';
                    Object.assign(this.formData, {vipId: this.id})
                } else {
                    url = '/api/vip/addVip';
                }
                let labels = this.formData.labels.map((item) => {
                    return item.label
                });
                this.formData.labels = labels;
                this.$httpUtils.request(url, this.formData, 'POST').then((res) => {
                    if(res.status == 200){
                        uni.navigateBack()
                    }
                    this.$toast.info(res.info);
                    this.isDisabled = false;
                }).catch(() => {
                    this.isDisabled = false;
                })
            },
            setData(selectItem){
                selectItem.forEach((item) => {
                    this.recommendName = item.vipName;
                    this.formData.recommendId = item.id;
                });
            }
        }
    }
</script>
 
<style>
    .container{
        padding: 10px 10px;
    }
    .avatar{
        width: 44px;
        height: 44px;
        border-radius: 50%;
    }
    .footer{
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #FFFFFF;
        padding: 0 10px 20px;
    }
</style>