''
liukangdong
2024-07-19 73c3507d82c06066d592d626ccd1a9a0961e0c5f
wechat_jiaxuan/pages/consult/consult.js
@@ -1,4 +1,4 @@
import { getZhongTaiProductNewsPage, getCatalogList } from '../../api/index'
import { getZhongTaiProductNewsPage, getCatalogList, getCataLogTagList } from '../../api/index'
Page({
  /**
@@ -6,10 +6,11 @@
   */
  data: {
    category: [],
    secondCategory: ['级分类','级分类','级分类','级分类','级分类','级分类'],
    activeCate: '',
    seActiveCate: '',
    secondCategory: [],
    catalogCode: '',
    tagCode: '',
    search: '',
    dataList: [],
    total: 0,
    pageNum: 1,
@@ -17,23 +18,47 @@
  },
  onLoad(options) {
    this.getCate()
    this.getList()
  },
  getCate() {
    getCatalogList({catalogCode: 'product_info'}).then(res => {
      this.setData({ category: res.data })
      if(res.data && res.data.length > 0){
        this.setData({catalogCode: res.data[0].code})
        this.gettag()
        this.getList()
      }
    })
  },
  gettag() {
    const { catalogCode } = this.data
    getCatalogList({
      catalogCode
    }).then(res => {
      if(res.data && res.data.length > 0){
        this.setData({ secondCategory: res.data })
      }
    })
  },
  itemClick(e) {
    const { id } = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/consult/detail?id='+id,
    })
    const item = e.currentTarget.dataset.item
    if(item.contentType == 'link'){
      wx.navigateTo({
        url: '/pages/webView/index?link=' + item.content,
        success: function(res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('acceptDataFromOpenerPage', { link: item.openContent, title: item.title })
        }
      })
    }else{
      wx.navigateTo({
        url: '/pages/consult/detail?id='+item.id,
      })
    }
  },
  getList() {
    const { pageNum, pageSize, activeCate } = this.data
    const { pageNum, pageSize, catalogCode, tagCode, search } = this.data
    getZhongTaiProductNewsPage({
      pageNum, pageSize, catalogCode: activeCate
      pageNum, pageSize, search, catalogCode: tagCode || catalogCode
    }).then(res => {
      if(res.data){
        this.setData({ dataList: res.data.records,total: res.data.records.total })
@@ -43,13 +68,26 @@
  },
  cateClick(e) {
    const { code } = e.currentTarget.dataset
    this.setData({ activeCate: code })
    this.setData({ catalogCode: code,secondCategory: [], tagCode: ''  })
    this.gettag()
    this.getList()
    console.log('e', e.currentTarget.dataset);
    console.log('catalogCode', this.data.catalogCode);
  },
  seCateClick(e) {
    const { index } = e.currentTarget.dataset
    console.log(index);
    const { code } = e.currentTarget.dataset
    if(this.data.tagCode == code){
      this.setData({ tagCode: '' })
    }else{
      this.setData({ tagCode: code })
    }
    this.getList()
  },
  priviewFull(e){
      const item = e.currentTarget.dataset.item
      console.log('item', item);
    },
  onReady() {
  },