k94314517
2024-07-25 a75b18a4157ab486e0b51c438ac165ab3a08e3e0
wechat_jiaxuan/pages/index/index.js
@@ -1,4 +1,15 @@
// pages/index/index.js
import {
  getDictData,
  getMemberInfo,
  getZSZXCatalogs,
  getCustomizedNewsList,
  getHomeBanner,
  actionDo,
  getZhongTaiVideoPage,
  getZhongTaiProductNewsPage
} from '../../api/index'
const { HYEventBus } = require('hy-event-store')
const eventBus = new HYEventBus()
Page({
  /**
@@ -7,16 +18,20 @@
  data: {
    // 顶部nav
    topHeadStyle: 1,
    showWhiteHead: true,
    topHeadBorder: false,
    bannerList: [
      {imgurl: ''},
      {imgurl: 'adsa.png'},
      {imgurl: 'adsa.png'},
      {imgurl: 'adsa.png'},
    ],
    top: 0,
    font_color: '#ffffff',
    ZSZXCata: {},
    showWhiteHead: false,
    topHeadBorder: false,
    member: {},
    bannerList: [],
    bannerImgHeight: 0,
    consultList: [],
    consultImgHeight: 0,
    productVideo: {},
    bannerSwiperOption: {
      indicatorDots: true,
      vertical: false,
@@ -24,23 +39,51 @@
      interval: 3000,
      duration: 500
    },
    serviceList: [],
    testUrl: '',
    HOME_CLASS_A: '',
    HOME_CLASS_B: '',
    HOME_CLASS_B2: '',
    HOME_CLASS_C: '',
  },
  toSearch() {},
  onShow() {
    let that = this
    const member = wx.getStorageSync('member')
    if (member && (member.authStatus == '1' || member.authStatus == '2')) {
      getMemberInfo().then(res => {
        this.setData({
          member: res.data
        })
      })
    } else {
      this.setData({
        member
      })
    }
    eventBus.on("reloadHome", () => {
      console.log('reloadHome');
      this.onLoad()
    })
  },
  onLoad(options) {
    const member = wx.getStorageSync('member')
    this.initDictData()
    setTimeout(() => {
      this.initData()
    }, 1200)
  },
  changePath(e) {
    let index = e.currentTarget.dataset.type
    console.log(index);
    let that = this
    switch (index) {
      case '0':
        wx.navigateTo({
          url: '/pages/webView/index',
          success: function (res) {
            // 通过eventChannel向被打开页面传送数据
            res.eventChannel.emit('acceptDataFromOpenerPage', { link: 'https://m.zbom.com/mobile/styleTest.html?type=1' })
            saveBehavior({ type: 1 })
            res.eventChannel.emit('acceptDataFromOpenerPage', {
              link: that.data.testUrl
            })
          }
        })
        break;
@@ -69,20 +112,258 @@
        break;
    }
  },
  changeStrategy(e) {
    let item = e.currentTarget.dataset.item
    wx.navigateTo({
      url: `/pages/homeId/index?code=${item.code}&name=${item.name}`,
    })
  },
  initData() {
    // 轮播
    getHomeBanner().then(res => {
      this.setData({
        bannerList: res.data
      })
    })
    // 产品视频
    getZhongTaiVideoPage({
      pageSize: 1,
      pageNum: 1
    }).then(res => {
      if (res.data.records && res.data.records.length > 0) {
        this.setData({
          productVideo: res.data.records
        })
      }
    })
    getZSZXCatalogs().then(res => { //志说装修
      this.setData({
        ZSZXCata: res.data || {}
      })
    })
    // 资讯
    getZhongTaiProductNewsPage({
      catalogCode: 'product_info',
      pageSize: 6,
      pageNum: 1
    }).then(res => {
      if (res.data) {
        this.setData({
          consultList: res.data.records
        })
      }
    })
    getCustomizedNewsList().then(res => { // 定制服务
      this.setData({
        serviceList: res.data || []
      })
    })
  },
  initDictData() {
    // 风格测试
    getDictData({
      code: 'WX_MINI_CONFIG',
      label: 'ZBOM_STYLE_TEST_URL'
    }).then(res => {
      this.setData({
        testUrl: res.data.code
      })
    })
    getDictData({
      code: 'WEIXIN_DEFAULT_IMGS',
      label: 'HOME_CLASS_A'
    }).then(res => {
      this.setData({
        HOME_CLASS_A: res.data.code
      })
    })
    getDictData({
      code: 'WEIXIN_DEFAULT_IMGS',
      label: 'HOME_CLASS_B'
    }).then(res => {
      this.setData({
        HOME_CLASS_B: res.data.code
      })
    })
    getDictData({
      code: 'WEIXIN_DEFAULT_IMGS',
      label: 'HOME_CLASS_B2'
    }).then(res => {
      this.setData({
        HOME_CLASS_B2: res.data.code
      })
    })
    getDictData({
      code: 'WEIXIN_DEFAULT_IMGS',
      label: 'HOME_CLASS_C'
    }).then(res => {
      this.setData({
        HOME_CLASS_C: res.data.code
      })
    })
  },
  jumpProVideo() {
    wx.navigateTo({
      url: '/pages/productVideo/index',
    })
  },
  videoClick(e) {
    const {
      videourl
    } = e.currentTarget.dataset
    wx.previewMedia({
      sources: [{
        url: videourl,
        type: 'video'
      }]
    })
  },
  goserHeight: function (e) {
    const serviceHeight = e.detail.height
    this.setData({
      serviceHeight: serviceHeight
    })
  },
  bannerbindload(e) {
    const height = e.detail.height
    this.setData({
      bannerImgHeight: height
    })
  },
  consultbindload(e) {
    const {
      height,
      width
    } = e.detail
    let activeHeight = height * 670 / width
    this.setData({
      consultImgHeight: activeHeight
    })
  },
  consultClick(e) {
    const id = e.currentTarget.dataset.id
    actionDo({
      actionType: 'view',
      id: id
    })
    wx.navigateTo({
      url: '/pages/consult/detail?id=' + id
    })
  },
  bannerClick(e) {
    const {
      id
    } = e.currentTarget.dataset
    const item = e.currentTarget.dataset.item
    console.log('item', item);
    if(item.openType){
      actionDo({
        actionType: 'view',
        id: item.id
      })
    }
    if (item.openType == 'video') {
      wx.previewMedia({
        sources: [{
          url: item.openContent,
          type: 'video'
        }]
      })
    }
    if (item.openType == 'link') {
      wx.navigateTo({
        url: '/pages/webView/index?link=' + item.openContent,
      })
    }
    if (item.openType == 'page') {
      getApp().globalData.catalogCode = item.openContent
      wx.switchTab({
        url: '/pages/discover/discover'
      })
    }
    // getHomeBannerDetail({id})
  },
  seriveClick(e) {
    const {
      id,
      title
    } = e.currentTarget.dataset
    if (title === '专属客服') {
      wx.navigateTo({
        url: `/pages/kefu/index?title=${title}&id=${id}`,
      })
    } else {
      wx.navigateTo({
        url: `/pages/kefu/service?title=${title}&id=${id}`,
      })
    }
  },
  jumpProConsult() {
    wx.switchTab({
      url: '/pages/consult/consult',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  onPageScroll(e) {
    let scrollTop = e.scrollTop / 100
    if (scrollTop <= 0.1) {
      this.setData({
        font_color: '#ffffff'
      })
    } else if (scrollTop >= 0.1 && scrollTop < 0.2) {
      this.setData({
        font_color: '#d0d0d0'
      })
    } else if (scrollTop >= 0.2 && scrollTop < 0.3) {
      this.setData({
        font_color: '#bdbdbd'
      })
    } else if (scrollTop >= 0.3 && scrollTop < 0.4) {
      this.setData({
        font_color: '#a1a1a1'
      })
    } else if (scrollTop >= 0.4 && scrollTop < 0.5) {
      this.setData({
        font_color: '#878787'
      })
    } else if (scrollTop >= 0.5 && scrollTop < 0.6) {
      this.setData({
        font_color: '#6d6d6d'
      })
    } else if (scrollTop >= 0.6 && scrollTop < 0.7) {
      this.setData({
        font_color: '#535353'
      })
    } else if (scrollTop >= 0.7 && scrollTop < 0.8) {
      this.setData({
        font_color: '#3b3b3b'
      })
    } else if (scrollTop >= 0.8 && scrollTop < 0.9) {
      this.setData({
        font_color: '#282828'
      })
    } else if (scrollTop >= 0.9) {
      this.setData({
        font_color: '#000000'
      })
    }
    if (scrollTop > 0) {
      this.setData({
        showWhiteHead: true
      })
    } else {
      this.setData({
        showWhiteHead: false
      })
    }
    this.setData({
      topHeadStyle: scrollTop,
      top: scrollTop
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },
  /**
   * 生命周期函数--监听页面隐藏
   */