index.vue 5.86 KB
Newer Older
程智春 committed
1
<template>
程默 committed
2 3
  <div class="contact">
    <div class="contact-img">
李嘉林 committed
4
      <img src="https://cdn.mayi888.com/product/HCe2iRXHsP.png" alt="" />
程默 committed
5
    </div>
柳士祥 committed
6
    <div class="btn-wrap" v-if="defaultContact == true">
7
      <button open-type="contact" @contact="handleContact" show-message-card :send-message-title="wxConcatGoods.title" :send-message-img="wxConcatGoods.img"
8 9
      :send-message-path="wxConcatGoods.pathLink"
       :session-from="sessionFrom">
程默 committed
10 11
        <div class="btn-main">
          <div class="main-img">
李嘉林 committed
12
            <img src="http://cdn.mayi888.com/public/png/8782e194-b208-44d6-99c1-10935ce36e2f.png" alt="" />
程默 committed
13 14
          </div>
          <div class="main-text">官方微信客服</div>
程智春 committed
15
        </div>
李嘉林 committed
16
        <img class="btn-next" src="http://cdn.mayi888.com/public/png/a054b29e-8929-415e-9017-dda875e25968.png" alt="" />
程默 committed
17
      </button>
程智春 committed
18
    </div>
柳士祥 committed
19 20 21 22
    <div class="btn-wrap" v-else-if="defaultContact == false" @click="myOpeChat">
      <button>
        <div class="btn-main">
          <div class="main-img">
李嘉林 committed
23
            <img src="http://cdn.mayi888.com/public/png/8782e194-b208-44d6-99c1-10935ce36e2f.png" alt="" />
柳士祥 committed
24 25 26
          </div>
          <div class="main-text">官方微信客服</div>
        </div>
李嘉林 committed
27
        <img class="btn-next" src="http://cdn.mayi888.com/public/png/a054b29e-8929-415e-9017-dda875e25968.png" alt="" />
柳士祥 committed
28 29
      </button>
    </div>
程默 committed
30
  </div>
程智春 committed
31 32 33
</template>

<script>
程默 committed
34
import { getUserLocation } from "../../utils/wxIndex.js";
柳士祥 committed
35
import { getWxContact } from "@/api/wxContact.js";
36
import pathToNavigation from '@/utils/pathToNavigation'
37 38
const app = getApp();
const { log } = app;
柳士祥 committed
39

程智春 committed
40
export default {
程默 committed
41 42 43
  data() {
    return {
      sessionFrom: "",
柳士祥 committed
44
      defaultContact: null,
45 46
      result: null,
      wxConcatGoods:{}
程默 committed
47 48 49
    };
  },
  onLoad(options) {
50 51 52 53 54 55
    if(options.wxConcatGoods){
      let wxConcatGoods = JSON.parse(options.wxConcatGoods)
      wxConcatGoods['pathLink'] = pathToNavigation.toPageUrl(pathToNavigation.getUrlofLink(wxConcatGoods), pathToNavigation.getUrlofQuery(wxConcatGoods));
     console.log(wxConcatGoods,'wxConcatGoods');
     this.wxConcatGoods = wxConcatGoods
    }
程默 committed
56 57 58 59
    getUserLocation().then((res) => {
      options.longitude = res.longitude;
      options.latitude = res.latitude;
      this.sessionFrom = JSON.stringify(options);
60
      log.info('sessionFrom', this.sessionFrom)
程默 committed
61 62
    });
  },
柳士祥 committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76
  onShow() {
    getWxContact().then(res => {
      if (res.data.code == 200) {
        const result = res.data.data
        if (result.whetherOpenCustomerChannel == 0) {
          this.defaultContact = true
        } else if (result.whetherOpenCustomerChannel == 1) {
          this.defaultContact = false
          this.result = result
        }
      }
    })
  },
  methods: {
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
    handleContact(e) {
      //TODO 商品详情页进入客服页面-进入客服聊天框-点击聊天页面的商品详情卡片进入小程序结果只是返回到了客户详情页面
      console.log(e,'handleContact-e')
      log.info(e,'handleContact-e')
      let errMsg = e.target.errMsg;
      if(errMsg && errMsg == 'enterContact:ok'){
        let backPath = e.target.query.backpath;
        let backParams = e.target.query.params;
        let url = `${e.target.path}?from=${e.target.query.from}&backpath=${encodeURIComponent(
          backPath
        )}&params=${encodeURIComponent(backParams)}}`;
        wx.reLaunch({
          url,
        })
      }
    },
柳士祥 committed
93
    myOpeChat() {
94
      log.info('okokok', this.result.whetherOpenCustomerUrl, this.result.whetherOpenCustomerSuiteId);
柳士祥 committed
95 96 97 98 99 100 101 102 103
      if (this.result.whetherOpenCustomerService == 0) {
        wx.showModal({
          title: '提示',
          content: '您未开通企业微信客服,请开通后重试'
        })
      } else if (this.result.whetherOpenCustomerService == 1) {
        if (wx.openCustomerServiceChat) {
          wx.openCustomerServiceChat({
            extInfo: {
104
              // url: this.result.whetherOpenCustomerUrl.replace(/\s*/g,"").toString()
柳士祥 committed
105 106
              url: this.result.whetherOpenCustomerUrl
            },
107
            // corpId: this.result.whetherOpenCustomerSuiteId.replace(/\s*/g,"").toString(),
柳士祥 committed
108 109
            corpId: this.result.whetherOpenCustomerSuiteId,
            success(res) {
110
              log.info(res);
柳士祥 committed
111 112
            },
            fail(res) {
113 114 115 116 117 118 119 120 121 122 123 124
              log.info(res);
              if (res.errCode == 6 && res.errMsg == 'openCustomerServiceChat:fail not bind') {
                wx.showModal({
                  title: '提示',
                  content: '您未在小程序管理后台的「功能-客服-微信客服」处,绑定对应的企业ID'
                })
              } else {
                wx.showModal({
                  title: '提示',
                  content: '系统繁忙,请稍后重试'
                })
              }
柳士祥 committed
125 126 127 128 129 130 131 132 133 134 135 136 137
            }
          })
        } else {
          wx.showModal({
            title: '提示',
            content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
          })
        }
      }

    }
  }

程默 committed
138
};
程智春 committed
139 140 141
</script>

<style scoped>
程默 committed
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
.contact {
  padding: 10px 22px 0 22px;
}
.contact-img {
  width: 100%;
  height: 154px;
  margin-bottom: 24px;
  background-color: #ccc;
  border-radius: 8px;
}
.contact-img img {
  width: 100%;
  height: 100%;
}
.btn-wrap {
  width: 100%;
  height: 80px;
  box-sizing: border-box;
}
button {
  width: 100%;
  height: 80px;
  border: none;
  padding: 20px 10px 20px 10px;
  background-color: white;
  box-shadow: #eee 0px 0px 5px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn-main {
  display: flex;
  height: 40px;
}
.main-img {
  width: 54px;
  height: 40px;
  border-right: 1px solid #d7d4d4;
  padding-top: 3px;
}
.main-img img {
  width: 42px;
  height: 34px;
}
.main-text {
  color: #1c1b1b;
  font-size: 17px;
  margin-left: 10px;
}
.btn-next {
  width: 9px;
  height: 14px;
}
.btn-next img {
  width: 100%;
  height: 100%;
}
button::after {
  border: none;
}
程智春 committed
202
</style>