index.js 4.73 KB
// packageIndex/pages/selfGoodsDetail/index.js
import homeApi from '~/api/module/home.js'
const navStyle = 'background-color: transparent;'
let navBarHeight = 38
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navStyle,
    goodsFlag: true,
    goodsInfo: {},
    addressList: [{
      id: 1,
      receiveName: '何瑶1',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 1
    }, {
      id: 2,
      receiveName: '何瑶2',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 3,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 4,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 5,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 6,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }, {
      id: 7,
      receiveName: '何瑶',
      receiveMobile: '15044526870',
      provinceName: '广东省',
      cityName: '深圳市',
      countyName: '南山区',
      address: '南山智园崇文园区1号楼14层',
      isDefault: 0
    }],
    defaultAddress: {id: 2}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    wx.p.router.getRouterParams(options).then(params => {
      this.getDetail(params)
    }).catch(err => {
      console.error('参数获取失败:', err)
    })
    // this.getPlatFormAddress()
  },

  navbarReady(e) {
    navBarHeight = e.detail.height
  },

  goodsActionReady(e) {
    this.setData({
      padding_bottom: e.detail
    })
  },

  onPageScroll(e) {
    const { curTabIndex } = this.data
    if (curTabIndex == 0) {
      this.scrollY = e.scrollTop
    }
    this.setData({
      navStyle: e.scrollTop >= navBarHeight || curTabIndex ? '' : navStyle,
      opacity: curTabIndex == 1 ? 1 : e.scrollTop / 200,
    })
  },

  // 点击添加购物车或立即兑换
  goodsActionClick(e) {
    let type = e.detail
    this.showSkuFun()
    this.setData({
      clickType: type
    })
  },
  // 显示sku弹窗
  showSkuFun() {
    this.setData({
      showSku: true
    })
    wx.setPageStyle({
      style: {
        overflow: 'hidden'
      }
    })
  },
  // 显示地址选择弹窗
  toShowAddressModal() {
    this.setData({
      showAddress: true
    })
  },
  // 地址选择确定
  getAddress(e) {
    this.setData({
      contactAddress: e.detail.contactAddress,
      defaultAddress: e.detail.defaultAddress
    })
  },

  changeBanner(e) {
    this.setData({
      bannerIndex: e.detail.current
    })
  },

  previewImage(e) {
    let {
      current,
      item
    } = e.currentTarget.dataset
    let urls = []
    item.map(i => {
      urls.push(i.content)
    })
    wx.p.wxApi.previewImage({
      current,
      urls
    })
  },

  back() {
    wx.p.router.back()
  },

  getDetail(options) {
    homeApi.getGoodsDetailInfo({id: options.id}).then(res => {
      console.log(res)
    })
    let { goodsInfo } = this.data
    let activeSku = null
    if (goodsInfo.specificationList && goodsInfo.specificationList.length) {
      activeSku = goodsInfo.specificationDetailList[0].specificationData
      goodsInfo.skuPrice = goodsInfo.specificationDetailList[0].retailPrice
    }
    this.setData({
      goodsInfo,
      activeSku
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})