view_comment.js 3 KB
var i = require("../../../utils/util.js"),
  ut = i;
var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: a.url,
    iurl: a.imghost,
    comment: [], //用户单个评价的内容
    goods_id: "", //商品id
    order_id: "", //订单id
    is_act: 0, //是否开启活动
    actId: "", //活动id
    giftBagId: "", //礼包id
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var th = this;
    th.setData({
      goods_id: options.goods_id,
      order_id: options.order_id
    })
    th.query_comment();
  },

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

  },
  query_comment: function() {
    var th = this;
    wx.showLoading({
      title: '加载中'
    })
    var url = "/api/weshop/comment/list";
    getApp().request.promiseGet(url, {
      data: {
        store_id: a.stoid,
        userId: d.user_id,
        goods_id: th.data.goods_id,
        order_id: th.data.order_id
      }
    }).then(res => {
      wx.hideLoading();
      if (res.data.code == 0) {
        var data = res.data.data.pageData;
        if (data[0].img) data[0].img = ut.unserialize(data[0].img);
        if (data[0].weapp_img) data[0].weapp_img = JSON.parse(data[0].weapp_img);
        th.setData({
          comment: data
        })
        th.judge_act(); //判断是否开启评价有礼
      } else {
        getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
      }
    })
  },
  //评价有礼判断
  judge_act: function() {
    var th = this;
    var url = "/api/weshop/marketing/comment/act/judge";
    getApp().request.promiseGet(url, {
      data: {
        orderGoodsId: th.data.goods_id,
        orderNumber: th.data.order_id,
        orderType: 1,
        storeId: a.stoid,
        userId: d.user_id
      }
    }).then(res => {
      if (res.data.code == 0) {
        var id = res.data.data.id;
        var giftbagid = res.data.data.giftbagid;
        th.setData({
          is_act: 1,
          actId: id,
          giftBagId: giftbagid
        })
      } else {

      }
    })
  },
  //预览图片
  previewImg: function(e) {
    var th = this;
    var index = e.currentTarget.dataset.index;
    var sindex = e.currentTarget.dataset.sindex;
    var imgArr = th.data.comment;
    var image = imgArr[0].weapp_img;
    var imagename = "";
    var iurl = th.data.iurl;
    if (image != "") {
      image = imgArr[0].weapp_img[index];
      wx.previewImage({
        current: iurl + image,
        //当前图片地址
        urls: imgArr[0].weapp_img, //所有要预览的图片的地址集合 数组形式
      })
    } else {
      image = imgArr[0].img[index];
      wx.previewImage({
        current: iurl + image,
        //当前图片地址
        urls: imgArr[0].img, //所有要预览的图片的地址集合 数组形式
      })
    }
  },
  goto: function(e) {
    var th = this;
    var url = e.currentTarget.dataset.url;
    getApp().goto(url);
  }

})