index.js 4.16 KB
// pages/reception/index.js
import dayjs from 'dayjs'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    tips: '今日无待处理复盘,请继续保持!'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {},
  async getAiagent(params) {
    let {
      bussinessType,
      staffUuid,
      phone,
      channelType,
      modelType
    } = params, {
      reviewDate
    } = this.options
    const [data] = await wx.p.api.receptionApi.getAiagent({
      ownerShipType: 1,
      accountPhone: phone,
      agentCode: 'AI8'
    })
    if (data) {
      let {
        agentUrl,
        domainName,
        taskStatus
      } = data,
      brand = {
          1: '问界',
          2: '比亚迪',
          3: '其他'
        } [channelType],
        AIAvatar = 'https://img01.glsx.com.cn/weapp/resource/miniprogram/common/avatar_ai.png', //左侧头像
        AIUrl = `${agentUrl}?avatar_ai=${AIAvatar}&no_header=1&businessType=${bussinessType}&one_id=${staffUuid}&platformType=1&domain=${domainName}&brandType=${modelType || 1001}`
      if(!reviewDate) reviewDate = dayjs().subtract(1, 'day')
      AIUrl += `&phone=${phone}&brand=${brand}&date=${dayjs(reviewDate).format('YYYY-MM-DD')}`
      if (taskStatus) AIUrl += `&practice_status=${taskStatus}`
      this.setData({
        AIUrl
      })
    } else wx.p.wxApi.showToast('获取智能体失败')
  },
  async getReceptionList(params) {
    try {
      wx.showLoading({
        mask: true
      })
      console.log()
      if (!params.userId) throw '缺少必要参数:userId'
      const data = await wx.p.api.receptionApi.getReceptionList(params)
      if(!data) throw '获取复盘失败,请稍后再试!'
      let total = data.reduce((sum, e) => {
        const length = e?.sopTaskDetailTagList?.length || 0
        return sum + Number(length)
      }, 0)
      data.map(e => {
        e?.sopTaskDetailTagList?.map(i => {
          let {
            weakness,
            suggestion
          } = i
          i.weakness = weakness ? weakness.replace(/\n/g, '<br>') : '-'
          i.suggestion = suggestion ? suggestion.replace(/\n/g, '<br>') : '-'
        })
      })
      this.setData({
        total,
        list: data,
        loadComplete: true,
        tips: total ? `今日有 ${total} 条待复盘记录,请尽快处理哦~` : '今日无待处理复盘,请继续保持!'
      })
      if (data && data.length && !this.data.AIUrl) this.getAiagent(data[0])
      wx.hideLoading()
      console.log(data)
    } catch (error) {
      console.log(error)
      wx.hideLoading()
      if (error) wx.p.wxApi.showToast(error)
      this.setData({
        loadComplete: true,
      })
    }
  },
  toDetail() {
    const {
      openId
    } = this.data.userInfo
    wx.p.api.receptionApi.addCustomerDynamicRecord({
      customerOpenId: openId,
      goodsId: 1,
      goodsType: 3
    })
    wx.p.router.go('/packageReception/pages/detail/detail', this.options)
  },
  jumpAI(e) {
    const {
      openId
    } = this.data.userInfo
    wx.p.api.receptionApi.addCustomerDynamicRecord({
      customerOpenId: openId,
      goodsId: 1,
      goodsType: 2
    })
    let {
      item
    } = e.currentTarget.dataset, {
      AIUrl
    } = this.data
    AIUrl += `&presuppositionProblem=${item.tagName}`
    wx.p.router.jumpH5(AIUrl, true)
    console.log(e)
  },
  navbarReady(e) {
    let {
      height
    } = e.detail
    this.setData({
      layoutStyle: `padding-top:${height}px`
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getReceptionList(this.options)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  }
})