materials.js 3.4 KB
const IMG_URL = 'https://img02.glsx.com.cn/weapp/resource/dj-car-boutique-work-wechat/'
import api from '~/utils/request/request.js'
let currentTabType = 'video'
Component({
  properties: {
    navBarHeight: Number,
    navStyle: String,
    scrollTop: Number
  },
  data: {
    IMG_URL,
    userInfo: {},
    menuList: [{
      title: '视频',
      name: 'video',
      icon: 'default_video',
      list: []
    }, {
      title: 'PDF',
      name: 'PDF',
      icon: 'default_pdf',
      list: []
    }, {
      title: '图片',
      name: 'image',
      icon: 'default_img',
      list: []
    }],
    searchKey: '',
    showPage: false,
    onResult: false
  },
  methods: {
    async onLoad() {
      this.pdfPageTrack()
      setTimeout(async () => {
        this.setData({
          showPage: true,
          userInfo: wx.$util.getUserInfo() || {}
        })
        this.getListData()
      }, 300);
      this.intaval = setInterval(() => {
        this.selectComponent('#tabID').resize();
      }, 500);
    },
    onChangeTab(e) {
      currentTabType = e.detail.name
      this.initData()
    },
    getListData() {
      const userInfo = wx.$util.getUserInfo()
      // 登录信息映射值: 0 会员权益升级 1 精品升级 3 售后众筹 ,2次新车转化
      // 0-图片;1-视频;2-pdf;
      const newType = currentTabType == 'video' ? 1 : currentTabType == 'PDF' ? 2 : 0
      let { searchKey, onResult } = this.data
      let params = {
        merchantId: userInfo.default4SStoreInfo.merchantId,
        scene: userInfo.sceneType,
        showChannel: 1,
        type: newType,
        title: searchKey,
        sortedBy: 1
      }
      let list = [], listNameMap = {
        0: 'menuList[2].list',
        1: 'menuList[0].list',
        2: 'menuList[1].list',
      }
      const target = listNameMap[newType]
      this.currentTarget = target
      this.materialListApi(params).then(res => {
        if (res && res.data) {
          res.data.forEach(el => {
            // if (el.createdDate) el.createdDate = new Date(el.createdDate).format('yyyy/MM/dd')
            if (el.createdDate) {
              let date = el.createdDate + ''
              date = date.replace(/-/g, '/').split(' ')[0] // 日期格式处理
              el.createdDate = date
            }
          })
        }
        list = res.data
        onResult = list.length ? false : true
        this.setData({
          [target]: list,
          onResult
        })
      })
    },
    onChangeSearch(e) {

    },
    onSearch(e) {
      this.setData({
        searchKey: e.detail
      }, () => {
        this.getListData()
      })
    },
    onCancel(e) {
      this.onSearch(e)
    },
    initData() {
      this.setData({
        [this.currentTarget]: [],
        searchKey: ''
      }, () => {
        this.getListData()
      })
    },
    /** 内容列表 */
    materialListApi(data) {
      let params = data || {}
      return api.post('dj.api.smartcarlife.material.list', params)
    },
    /**退出页面增埋点 */
    leavePageTrack(data) {
      let params = data || {}
      return api.post('dj.api.customer.dynamic.record.leave', params)
    },
    pdfPageTrack() {
      const id = wx.getStorageSync('pageQueryOfcontent_trackId')
      if (id) {
        this.leavePageTrack({ id }).then(res => {
          wx.removeStorageSync('pageQueryOfcontent_trackId');
        })
      }
    },
    onHide() {
      clearInterval(this.intaval)
    }

  }
})