zhaoxiaoqiang
2021-05-18 fb9591ea38b263afe9d051168e34aa03028494eb
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
<!--
 * @Author: 小明丶
 * @Date: 2019-08-15 16:25:46
 * @LastEditors: 小明丶
 * @LastEditTime: 2020-11-17 09:38:26
 * @Description: 新增渠道页面
 -->
<template>
    <div class="channel-detail-box h-100-g">
        <v-navbar :title="isAdd ? '新增渠道':'渠道详情'" fixed>
            <div slot='right' v-if="!isAdd" @click="updateChannel">
                保存
            </div>
        </v-navbar>
        <div class="cell-group">
            <v-cell :readonly="!isAdd" v-model.trim="form.chanName" max='20' label='渠道名称' icon='iconyonghu' placeholder='请输入渠道名称'></v-cell>
            <v-cell :readonly="!isAdd" v-model.trim="form.licenseNo"  max='20' label='营业执照号' icon='iconmobanguanliliebiao' placeholder='请输入营业执照号'></v-cell>
            <v-cell :readonly="!isAdd" v-model.trim="form.priIdNo"  max='18' label='身份证号' icon='iconyinhangka' placeholder='请输入身份证号'></v-cell>
            <v-cell :value="form.areaText" label='所在地区' icon='icondingwei' isLink readonly  placeholder='请选择' @click.native="isShowArea = true;"></v-cell>
            <v-cell v-model.trim="form.dtlAddr"  max='30' label='详细地址' icon='icontishi' placeholder='请输入详细地址'></v-cell>
        </div>
 
        <div class="cell-group">
            <v-cell :readonly="!isAdd" v-model.trim="form.priName"  max='6' label='负责人姓名' placeholder='请输入姓名'></v-cell>
            <v-cell :readonly="!isAdd" v-model.trim="form.priMblNo" type='tel' max='11' label='负责人手机号' placeholder='请输入手机号'></v-cell>
        </div>
        <p class="tip" v-if="isAdd">*该手机号将作为登录用户名,密码将通过短信发至手机</p>
 
        <div class="cell-group" v-if="isAdd">
            <v-cell v-model.trim="form.priEmail"  max='50' label='联系邮箱' placeholder='请输入邮箱地址'></v-cell>
        </div>
 
        <footer class="flex-center-g footer" v-if="isAdd">
            <van-button class="btn-submit" :color="$store.state.backColor" @click="addChannel">新增渠道</van-button>
        </footer>
 
         <footer class="flex-center-g footer" v-else>
            <van-button class="btn left" @click="openDialog">{{form.freezeStatus?'冻结':'启用'}}渠道</van-button>
            <van-button class="btn right" :color="$store.state.backColor" @click="go">商户查询</van-button>
        </footer>
 
        <van-popup v-model="isShowArea" position="bottom" :close-on-click-overlay="false">
            <van-area ref='Area' :area-list='areaList' @cancel="closeAreaModal" @confirm="setAreaValue"></van-area>
        </van-popup>
 
    </div>
</template>
 
<script>
    import {mapState, mapMutations} from 'vuex';
    export default {
        data() {
            return {
                isShowArea:false,
                form:{
                    areaText:'',//地区文字展示
                    chanName:'',
                    licenseNo:'',
                    priIdNo:'',
                    dtlAddr:'',
                    priName:'',
                    priMblNo:'',
                    priEmail:'',
                    provCode: '',
                    cityCode: '',
                    areaCode: '',
                },
                rule:[
                    {key:"chanName",message:"请输入渠道名称",type:"isEmpty"},
                    {key:"chanName",message:"请输入正确的渠道名称",rule:/^[\u4e00-\u9fa50-9a-zA-Z]{1,20}$/},
                    {key:"licenseNo",message:"请输入营业执照号",type:"isEmpty"},
                    {key:"licenseNo",message:"请输入正确的营业执照号",rule:/^[0-9a-zA-Z]{1,20}$/},
                    {key:"priIdNo",message:"请输入身份证号",type:"isEmpty"},
                    // {key:"priIdNo",message:"请输入正确的身份证号",type:"isIdCard"},
                    {key:"areaText",message:"请选择地址",type:"isEmpty"},
                    {key:"dtlAddr",message:"请输入详细地址",type:"isEmpty"},
                    {key:"dtlAddr",message:"请输入正确的详细地址",rule:/^[\u4e00-\u9fa50-9a-zA-Z]{1,30}$/},
                    {key:"priName",message:"请输入负责人姓名",type:"isEmpty"},
                    {key:"priName",message:"请输入正确的负责人姓名",rule:/^[\u4e00-\u9fa50-9a-zA-Z]{1,6}$/},
                    {key:"priMblNo",message:"请输入负责人手机号",type:"isEmpty"},
                    {key:"priMblNo",message:"请输入正确的手机号",type:"isTel"},
                    {key:"priEmail",message:"请输入联系邮箱",type:"isEmpty"},
                    {key:"priEmail",message:"请输入正确的联系邮箱",type:"isEmail"},
                ]
            }
        },
        computed:{
            ...mapState(['areaList']),
            // 判断是 添加 还是 详情
            isAdd(){
                return this.$route.query.isAdd =='1';
            }
        },
        created(){
            if(!this.isAdd){
                this.getChannelInfo()
            }
        },
        methods:{
            go(){
                 this.$router.push({
                    path: '/mine/mer-manager',
                    query: {
                        chanId: this.form.chanId
                    }
                });
            },
            //关闭地区弹窗
            closeAreaModal(){
                this.isShowArea = false;
                this.$refs.Area.reset()
            },
            setAreaValue(arr){
                this.form.areaText = arr[0].name + '-' +arr[1].name +'-'+ arr[2].name;
                this.form.provCode= arr[0].code;
                this.form.cityCode= arr[1].code;
                this.form.areaCode= arr[2].code;
                this.isShowArea = false;
                this.$refs.Area.reset()
            },
            // 冻结启用 渠道
            openDialog(){
                let {chanId,freezeStatus} = this.form;
                this.$dialog.confirm({
                    message: `请问是否确认${freezeStatus ? '冻结' : '启用'}该渠道?`
                }).then(() => {
                    let statusType = freezeStatus ? 0 : 1;
                    this.$api.channSwitchStatus({
                        orgId: chanId,
                        orgType: 2,
                        statusType
                    }).then((res) => {
                        let text = statusType ? '启用成功' : '冻结成功';
                        this.form.freezeStatus = statusType;
                        this.$notify_success(text)
                    }).catch((err) => {
 
                    });
                }).catch(() => {
                // on cancel
                });
            },
            // 获取渠道详情
            getChannelInfo(){
                this.$api.getChannelInfo(this.$route.query.chanId).then(({body}) => {
                    this.form = {...body}
                    this.form.areaText = body.provName + '-' +body.cityName +'-'+ body.areaName;
                }).catch((err) => {
 
                });
            },
            //更新渠道信息
            updateChannel(){
                if(!this.validatorForm()) return
                this.$api.updateChan(this.form).then((res) => {
                    this.$notify('保存成功')
                }).catch((err) => {
                });
            },
            // 验证form参数
            validatorForm(){
                return this.$validator(this.form,this.rule).check(item=>{
                    this.$notify(item.message)
                })
            },
            // 新增渠道
            addChannel() {
                if(!this.validatorForm()) return
                this.$api.addChan(this.form).then(() => {
                    this.$notify('新增成功')
                    setTimeout(() => this.$router.go(-1), 1000);
                });
            },
        }
    }
</script>
<style lang="less" scoped>
    .channel-detail-box {
        background-color: @c-bg-f5;
        padding-top: 44px;
        .tip {
            margin: 10px 0 15px 21px;
            font-size: @font-12;
            color: @c-text-999;
        }
    }
 
    .cell-group {
        margin: 10px 8px 0;
    }
 
    .btn-submit {
        width: 340px;
        height: 44px;
        border: none;
        font-size: @font-16;
        border-radius: 22px;
        background-color: @c-bg-default;
        color: @c-text-fff;
 
    }
 
    .footer {
        margin-top: 20px;
        padding-bottom: 30px;
        .btn{
            width: 170px;
            height: 44px;
            border: none;
            font-size: @font-16;
            &.left{
                background-color: @c-bg-eee;
                color: @c-text-666;
                border-radius:22px 0px 0px 22px;
            }
            &.right{
            background-color: @c-bg-default;
                color: @c-text-fff;
                border-radius:0px 22px 22px 0px;
            }
        }
    }
</style>