evaluateList.js 3.96 KB
//evaluateList.js
import { API_HOST } from '../../../libs/config';
import { GET } from '../../../libs/request';
import { getChannelCode, getGenderCode } from '../../../utils/home';
import { parseEvaluateListData } from '../../../utils/evaluateList';
import {
  logEvent,
  YB_PAGE_OPEN_L,
} from '../../../libs/analytics.js'

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

const windowWidth = app.globalData.systemInfo.windowWidth;
const screenHeight = app.globalData.systemInfo.screenHeight;
let imageWidth = windowWidth;
let PV_ID = new Date().getTime() + '';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    isFetching: false,
    gender: '',
    yh_channel: 1,
    productId: '',
    page: 1,
    totalPage: 1,
    fileterList: null,
    evaluateList: null,
    currentFilterId: '7',
    current_page_name: 'evaluateList',
    screenHeight,
    scrollTop: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let gender = getGenderCode(getApp().globalData.selectedChannel);
    let yh_channel = getChannelCode(getApp().globalData.selectedChannel);
    var res = tt.getSystemInfoSync()
    let screenHeight = res.windowHeight;
    this.setData({
      screenHeight,
      gender: gender,
      yh_channel: yh_channel,
      productId : options.productId
    });
    this.fetchEvaluateList();

    let from_page_name = options.page_name ? options.page_name : '';
    let from_page_param = options.page_param ? options.page_param : '';
    let current_page_param = options.productId ? options.productId:'';


    let params = {
      PAGE_NAME: this.data.current_page_name,
      PAGE_PARAM: current_page_param,
      FROM_PAGE_NAME: from_page_name,
      FROM_PAGE_PARAM: from_page_param,
      PV_ID: PV_ID,
    };
    logEvent(YB_PAGE_OPEN_L, params);
  },

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

  //下拉加载更多
  loadMore: function () {
    if (this.data.page >= this.data.totalPage) {
      return;
    }
    this.setData({
      page: this.data.page + 1,
    });
    this.fetchEvaluateList();
  },

  //获取晒单数据
  fetchEvaluateList: function () {
    let param = {
      method: 'show.productShareOrderList',
      gender: this.data.gender,
      yh_channel: this.data.yh_channel,
      productId: this.data.productId,
      filterId: this.data.currentFilterId,
      limit: '10',
      page: this.data.page,
      fromPage: this.data.current_page_name,
    }
    this.setData({
      isFetching: true,
    });
    GET(API_HOST, param)
      .then(result => {
        if (!result || !result.code || result.code != 200) {
          this.setData({
            isFetching: false,
          });
          return;
        }

        let pageResponse = result.data.pageResponse;
        let evaluateList = parseEvaluateListData(pageResponse.list, 200, 200, 80, 80, imageWidth);
        if (this.data.page == 1) {
          this.data.evaluateList = evaluateList;
        } else { // 当page>1 时,数据累加,分页数据
          evaluateList.map((item) => {
            this.data.evaluateList.push(item);
          });
        }
        this.setData({
          isFetching: false,
          page: pageResponse.pageNo,
          totalPage: pageResponse.totalPage,
          fileterList: result.data.fileter,
          evaluateList: this.data.evaluateList
        });
      })
      .catch(error => {
        this.setData({
          isFetching: false,
        });
      });
  },

  //选中顶部分类
  onFilterIdSelected: function (e) {
    let id = e.currentTarget.dataset.id;
    if (id == this.data.currentFilterId) { //点的同一个不做处理
        return;
    }
    this.setData({
      scrollTop: 0
    })
    this.setData({
      currentFilterId: id,
      page:1
    });
    this.fetchEvaluateList();
  },

  //预览图片
  previewImage: function (event) {
    var src = event.currentTarget.dataset.src;
    tt.previewImage({
      urls: [src] // 需要预览的图片http链接列表
    })
  },

})