methods.js 4 KB
import {
  getSceneMarketMaterialMenu,
  getSceneMarketMaterialList,
  enterPageTrack,
  getAiagent
} from '../request'
import dayjs from 'dayjs'
export default {
  enterPageTrack(e) {
    const userInfo = wx.$util.getUserInfo()
    const params = {
      goodsId: e.detail,
      goodsType: 0,
      merchantId: userInfo.default4SStoreInfo.merchantId,
      merchantName: userInfo.default4SStoreInfo.merchantName
    }
    enterPageTrack(params).then(({
      data
    }) => {
      this.trackId = data
    })
  },
  jumpClueIndex() {
    wx.navigateTo({
      url: '/packageStudy/pages/sceneMarket/clue/clue',
    })
  },
  /**获取tab高度 */
  getTabHeight() {
    wx.$util.getViewInfo('#scene-market-tab', res => {
      if (res?.height) this.setData({
        tabHeight: res.height
      })
    })
  },
  async getSceneMarketMaterialMenu() {
    try {
      const {
        code,
        message,
        data
      } = await getSceneMarketMaterialMenu()
      if (code == 0) {
        this.setData({
          tab: data
        })
        this.tabBarClick({
          detail: 0
        })
      } else throw message
    } catch (error) {
      wx.$util.showToast(error)
    }
  },
  tabBarClick(e) {
    if (this.data.tabIndex == e.detail) return
    const tabIndex = e.detail,
      {
        tab
      } = this.data
    this.setData({
      tabIndex,
      tagIndex: 0
    })
    let detail = tab[tabIndex].code
    if (tab[tabIndex]?.sceneMarketLevelTwoList.length) detail = tab[tabIndex].sceneMarketLevelTwoList[0]
    this.tabClick({
      detail
    })
  },
  tabClick({
    detail: {
      code: businessCode
    }
  }) {
    if (this.data.requestParams.businessCode == businessCode) return
    this.setData({
      requestParams: {
        businessCode,
      },
      requestComplete: false,
      isFiltrate: 0
    })
    this.selectComponent('#filtrate-box').reset()
    this.getSceneMarketMaterialList()
  },
  async getSceneMarketMaterialList() {
    try {
      wx.$util.showLoading('加载中')
      const {
        requestParams
      } = this.data, {
        code,
        message,
        data
      } = await getSceneMarketMaterialList(requestParams)
      if (code == 0) {
        wx.hideLoading()
        data?.map(e => {
          e.date = dayjs(e.createdDate).format('YYYY-MM-DD')
        })
        this.setData({
          materialList: data,
          requestComplete: true
        }, () => {
          setTimeout(() => {
            wx.hideLoading()
          }, 200)
        })
      } else throw message
    } catch (error) {
      wx.hideLoading()
      wx.$util.showToast(error)
    }

  },
  filtrate(e) {
    let {
      detail
    } = e, {
      requestParams
    } = this.data,
      filtrateList = ['materialType', 'readStatus', 'tag'],
      isFiltrate = 0

    requestParams = {
      ...requestParams,
      ...detail
    }
    filtrateList.map(key => {
      if (requestParams[key] != null) isFiltrate += 1
    })
    this.setData({
      requestParams,
      isFiltrate
    })

    this.getSceneMarketMaterialList()
  },
  refreshPage() {
    this.refreshPageStatus = true
  },
  viewScroll(e) {
    this.setData({
      showBtn: false
    })
  },
  showBtnFun() {
    if (this.data.showBtn) return
    this.setData({
      showBtn: true
    })
  },
  jumpAI() {
    if (this.aiUrl) wx.navigateTo({
      url: `/pages/webView/webView?url=${encodeURIComponent(this.aiUrl)}`
    })
    else {
      wx.$util.showToast('暂无权限')
      this.getAIUrl()
    }
  },
  async getAIUrl() {
    const {
      phone,
      uuid
    } = this.data.userInfo, {
      code,
      data
    } = await getAiagent({
      accountPhone: phone,
      ownerShipType: 0,
      agentCode: 'AI6'
    })
    if (code == 0 && data && data.length) {
      let [item] = data, {
        ownerPost,
        agentUrl,
        domainName,
        presuppositionProblem,
        accountPhone
      } = item
      this.aiUrl = `${agentUrl}?one_id=${uuid}&platformType=0&phone=${accountPhone}&position=${ownerPost}&domain=${domainName}&presuppositionProblem=`
    }
  }
}