productListCell.js 2.94 KB
// component/productListCell.js
import { shouldDiscardTap} from '../utils/util';
import {
  logEvent,
  YB_MAIN_EVENT
} from '../libs/analytics.js'

//获取应用实例
let app = getApp();

const screenHeight = app.globalData.systemInfo.screenHeight;
const windowWidth = app.globalData.systemInfo.windowWidth;
const windowHeight = app.globalData.systemInfo.windowHeight;

const DEVICE_WIDTH_RATIO = windowWidth / 320;

let listWidth = Math.ceil(137.5 * DEVICE_WIDTH_RATIO);
let listHeight = Math.ceil(254 * DEVICE_WIDTH_RATIO);

const IMAGE_WIDTH = 145;
const IMAGE_HEIGHT = 193;
const IMAGE_RATIO = IMAGE_HEIGHT / IMAGE_WIDTH;
let listImageTop = 31;
let listImageWidth = listWidth;
let listImageHeight = Math.ceil(listWidth * IMAGE_RATIO);

let listMarginHorizontal = (windowWidth - listWidth * 2) / 3;

let PV_ID = new Date().getTime() + '';

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    item:{
      type: Object
    },
    pageName: {
      type: String,
      value: ""
    },
    animationType: {
      type: String,
      value: ""
    },
    logEvenName: {
      type: String,
      value: ""
    },
    index: {
      type: Number,
      value: 0
    },
    fIndex: {
      type: Number,
      value: 0
    },
    fName: {
      type: String,
      value: ""
    },
    pageParam: {
      type: String,
      value: ""
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    lastTapTimeStamp: 0,

    screenHeight,
    windowHeight,
    listWidth,
    listHeight,
    listImageWidth,
    listImageHeight,
    listImageTop,
    listMarginHorizontal,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    productCellTapped(event) {
      if (shouldDiscardTap(event.timeStamp, this.data.lastTapTimeStamp)) {
        return;
      }
      this.setData({ lastTapTimeStamp: event.timeStamp });
      let data = event.currentTarget.dataset;
      let productSkn = data.productSkn;
      // 以下是埋点代码,如果需要埋点请传入相应参数
      if (this.properties.logEvenName && this.properties.logEvenName != "") {
        let params = {
          F_ID: this.properties.fIndex,
          F_NAME: this.properties.fName,
          F_URL: '/pages/goodsDetail/goodsDetail?productSkn=' + productSkn,
          F_INDEX: this.properties.fIndex,
          I_INDEX: this.properties.index + 1,
          PV_ID: PV_ID,
        };
        logEvent(this.properties.logEvenName, params);
      }
      // 根据动画类型来选择动画效果
      if (this.properties.animationType && this.properties.animationType == "redirectTo") {
        wx.redirectTo({
          url: '/pages/goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + this.properties.pageName + '&page_param=' + this.properties.pageParam
        })
      } else {
        wx.navigateTo({
          url: '/pages/goodsDetail/goodsDetail?productSkn=' + productSkn + '&page_name=' + this.properties.pageName + '&page_param=' + this.properties.pageParam
        });
      }
    }
  }
})