小程序跳转企业微信客服

小程序跳转企业微信客服

下文中路径都是以完整包前端代码:view/uniapp

1、文件view/uniapp/utils/util.js

/**
     * 处理客服不同的跳转;
     * 
     */
    getCustomer(userInfo,url){
        let self = this;
        customerType().then(res=>{
            let data = res.data;
            if (data.customer_type == 1) {
                uni.makePhoneCall({
                    phoneNumber: data.customer_phone
                });
            } else if (data.customer_type == 2) {
                let href = data.customer_url;
                let hrefO = href + '?uid=' + userInfo.uid + '&nickName=' + userInfo.nickname + '&phone=' +
                    userInfo.phone + '&sex=' + userInfo.sex + '&avatar=' + userInfo.avatar +
                    '&openid=' + userInfo.openid;
                let hrefT = href + '&uid=' + userInfo.uid + '&nickName=' + userInfo.nickname + '&phone=' +
                    userInfo.phone + '&sex=' + userInfo.sex + '&avatar=' + userInfo.avatar +
                    '&openid=' + userInfo.openid;
                let urls = encodeURIComponent(href.indexOf('?') === -1 ? hrefO : hrefT);
                // #ifdef MP
                if (data.customer_url.indexOf('work.weixin.qq.com') > 0){
                    uni.openCustomerServiceChat({
                        extInfo: {
                            url: data.customer_url
                        },
                        corpId: data.wechat_work_corpid,
                        success(res) {},
                        fail(err) {
                            self.Tips({
                                title: err.errMsg
                            });
                        }
                    })
                }else{
                    uni.navigateTo({
                        url: `/pages/annex/web_view/index?url=${urls}`
                    });
                }
                // #endif
                // #ifndef MP
                uni.navigateTo({
                    url: `/pages/annex/web_view/index?url=${urls}`
                });
                // #endif
            } else {
                uni.navigateTo({
                    url: url || '/pages/extension/customer_list/chat'
                })
            }
        }).catch(err=>{
            self.Tips({
                title: err
            });
        })
    },

分别在用到的页面进行调用(路径):

2、view/uniapp/pages/user/index.vue

替换:this.kefuInfo(url); 整体为下图所示部分

3、view/uniapp/pages/users/order_details/index.vue

goGoodCall方法:替换成如下截图

4、view/uniapp/components/kefuIcon/index.vue

<template>
    <!-- #ifdef APP-PLUS || H5 -->
    <view class="acea-row row-center-wrapper cartf iconfont icon-kefu3" :style="{ top: top + 'px'}" @touchmove.stop.prevent="setTouchMove" @click="licks"></view>
    <!-- #endif -->
    <!-- #ifdef MP -->
    <view v-if="routineContact == 0">
        <view class="acea-row row-center-wrapper cartf iconfont icon-kefu3" :style="{ top: top + 'px'}" @touchmove.stop.prevent="setTouchMove" @click="licks"></view>
    </view>
    <button class="acea-row row-center-wrapper cartf iconfont icon-kefu3" open-type='contact' :style="{ top: top + 'px'}" @touchmove.stop.prevent="setTouchMove" v-else-if="routineContact==1 && !goodsCon"></button>
    <button class="acea-row row-center-wrapper cartf iconfont icon-kefu3" open-type='contact' :send-message-title="storeInfo.store_name" :send-message-img="storeInfo.image" :send-message-path="`/pages/goods_details/index?id=${storeInfo.id}`" show-message-card :style="{ top: top + 'px'}" @touchmove.stop.prevent="setTouchMove" v-else-if="routineContact==1 && goodsCon"></button>
    <!-- #endif -->
</template>

licks(){
                let userInfo = {}
                if(typeof this.userInfo === 'string'){
                    userInfo = JSON.parse(this.userInfo)
                }else{
                    userInfo = this.userInfo
                }
                let url = `/pages/extension/customer_list/chat?productId=${this.ids}`
                this.$util.getCustomer(userInfo,url)
            }

本页目录