methods.js 2.71 KB
import {
  getSceneClueList,
  getSceneMarketMaterialMenu
} from '../request'
import dayjs from 'dayjs'
export default {
  inputSearch(e) {
    let {
      value
    } = e.detail
    this.setData({
      currentPage: 1,
      list: [],
      flag: false,
      nothing: false,
      storeName: value
    })
    this.getSceneClueList()
  },
  search() {
    this.setData({
      currentPage: 1,
      list: [],
      flag: false,
      nothing: false,
      storeName: ''
    })
    this.getSceneClueList()
  },
  tabBarClick(e) {
    if (this.data.tabIndex == e.detail) return
    const tabIndex = e.detail
    this.setData({
      tabIndex
    })
    this.search()
  },
  jumpClue(e) {
    let {
      id
    } = e.currentTarget.dataset,
      url = '/packageStudy/pages/sceneMarket/clueForm/clueForm'
    if (id) url += `?id=${id}`
    wx.navigateTo({
      url,
    })
  },
  /**获取tab高度 */
  getTabHeight() {
    wx.$util.getViewInfo('.search-box', res => {
      if (res?.height) this.setData({
        searchBoxHeight: 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)
    }
  },
  async getSceneClueList() {
    try {
      wx.$util.showLoading()
      const {
        tab,
        storeName,
        tabIndex,
        pageSize,
        currentPage
      } = this.data, {
        code,
        message,
        data
      } = await getSceneClueList({
        pageSize,
        currentPage,
        businessCode: tab[tabIndex].code,
        storeName
      })
      wx.hideLoading()
      if (code == 0) {
        let {
          list,
          total
        } = data
        list?.map(e => {
          e.time = dayjs(e.createdDate).format('YYYY-MM-DD')
        })
        this.setData({
          [`list[${currentPage - 1}]`]: list || [],
          total,
          flag: true
        }, () => {
          setTimeout(() => {
            wx.hideLoading()
          }, 200)
        })
      } else throw message
    } catch (error) {
      wx.hideLoading()
      this.setData({
        flag: true
      })
      wx.$util.showToast(error)
    }
  },
  viewScrollTolower() {
    let {
      currentPage,
      total,
      pageSize
    } = this.data
    if (!pageSize) pageSize = 10
    if (Math.ceil(total / pageSize) > currentPage) {
      this.setData({
        currentPage: currentPage + 1
      })
      this.getSceneClueList()
    } else {
      this.setData({
        nothing: true
      })
    }
  }

}