kfMixin.js 1.15 KB
module.exports = Behavior({
  data: {},
  methods: {
    filterKfList(data) {
      let showKF = false,
        customerlist = [],
        kfUrl = ''
      if (data.customerServerType) {
        if (data.customerServerType == 1)
          customerlist[0] = {
            thumbAvatar: data.customerServerAvatar,
            staffName: data.customerServerName,
            qrCode: data.customerServerOrCode
          }
        else kfUrl = data.customerServerUrl
        showKF = true
      }

      this.setData({
        showKF,
        kfUrl,
        customerlist
      })
    },
    async openKF(e) {
      let {
        kfUrl,
        widgetStatus
      } = this.data, {
        corpId
      } = await wx.p.api.systemApi.getMockData()
      if (kfUrl)
        wx.openCustomerServiceChat({
          extInfo: {
            url: kfUrl
          },
          corpId,
          success(res) {
            console.log(res)
          },
          fail({
            errMsg
          }) {
            console.log(errMsg)
            wx.p.wxApi.showToast(errMsg)
          }
        })
      else
        this.setData({
          widgetStatus: !widgetStatus
        })
    }
  }
})