giftpacklist.js 8.8 KB
var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData;
var ut = require("../../../utils/util.js");
    
Page({
  data: {
    url: a.url, //接口网址
    iurl: a.imghost, //图片前缀网址
    isBuy: 0,
    getGiftID: '', //礼包id
    giftImage: '',
    giftTitle: '',
    giftDate: '',
    giftPrice: '',
    giftIntegral: '',
    giftPosPrice: '',
    giftQty: '',
    giftRemark: '',
    giftType: '',
    actTitle: '',
    getUrl: '',
    wareCard: [],
    orderSn: "", //订单编号
    lbId: "",
    code: "",    //核销码
	c_state:"0",  //判断是否已经使用, 0正常  1已使用  2已过期
  },
  onLoad: function(options) {
    var th = this;
    th.setData({
      isBuy: options.isBuy,
      getStorageID: a.stoid,
      getUserID: d.user_id,
      getGiftID: options.lbId,
      orderSn: options.orderSn
    })
    if (options.isBuy == 0) {
      th.GetMyGiftList();
    } else {
      th.GetBuyGiftList();
    }
    th.setData({
      giftRemark: th.data.giftRemark.replace(/<p><img/gi, "<p class='img'><img")
    })
    th.close();
  },
  onShow: function() {

  },
  GetBuyPrice: function(e) {
    var that = this.data;
    var th = this;
    // var id = e.currentTarget.dataset.id;//活动id
    var my_confirm = th.selectComponent("#my_confirm"); //组件的id
    my_confirm.open(
      "是否确定购买该礼包",
      "取消",
      "确定",
      function() {
        my_confirm.open_cancel(0);
      },
      function() {
        my_confirm.open_cancel(0);
        var json = {
          "actId": '', //活动Id
          "actType": '', //活动类型 1:新人礼、2:评价有礼、3:节日营销、4:生日营销
          "buyType": '2', //1=积分兑换 2=余额购买
          "lbId": that.getGiftID, //礼包Id
          "storeId": that.getStorageID, //商家Id
          "userId": that.getUserID, //用户ID
          "buyFrom": 2
        };
        var data = JSON.stringify(json);
        var url = that.url + "/api/weshop/marketing/buy/receive/gift/record/insert";
        wx.request({
          url: url,
          data: data,
          method: 'post',
          header: {
            'content-type': 'application/json'
          }, // 设置请求的 header
          success: function(res) {
            if (res.data.code == 0) {
              res = res.data.data;
              wx.requestPayment({
                timeStamp: String(res.timeStamp),
                nonceStr: res.nonceStr,
                package: res.packageValue,
                signType: res.signType,
                paySign: res.paySign,
                success: function(n) {

                },
                fail: function(n) {

                }
              });
            } else {
              getApp().my_warnning(res.data.msg, 0, th);
            }
          }
        })

      }


    )


  },
  GetBuyIntegral: function(e) {
    var that = this.data;
    var th = this;
    // var id = e.currentTarget.dataset.id;//活动id
    var my_confirm = th.selectComponent("#my_confirm"); //组件的id
    my_confirm.open(
      "是否确定兑换该礼包",
      "取消",
      "确定",
      function() {
        my_confirm.open_cancel(0);
      },
      function() {
        my_confirm.open_cancel(0);
        var json = {
          "actId": '', //活动Id
          "actType": '', //活动类型 1:新人礼、2:评价有礼、3:节日营销、4:生日营销
          "buyType": '1', //1=积分兑换 2=余额购买
          "lbId": that.getGiftID, //礼包Id
          "storeId": that.getStorageID, //商家Id
          "userId": that.getUserID //用户ID
        };
        var data = JSON.stringify(json);
        var url = that.url + "/api/weshop/marketing/buy/receive/gift/record/insert";
        wx.request({
          url: url,
          data: data,
          method: 'post',
          header: {
            'content-type': 'application/json'
          }, // 设置请求的 header
          success: function(res) {
            if (res.data.code == 0) {
              getApp().my_warnning("兑换成功!", 1, th);
            } else {
              getApp().my_warnning(res.data.msg, 0, th);
            }
          }
        })

      })


  },
  GetMyGiftList: function() {
    var _this = this;
    var th = this;
    getApp().request.get('/api/weshop/marketing/my/giftbag/detail/get', {
      data: {
        "storeId": th.data.getStorageID, //商家ID
        "userId": th.data.getUserID, //用户ID
        "orderSn": th.data.orderSn
      },
      success: function success(res) {
        if (res.data.code == 0) {
          th.setData({
            giftImage: th.data.iurl + res.data.data.lbUrl,
            giftTitle: res.data.data.giftTitle
          })
          if (res.data.data.giftRemark == '') {
            th.setData({
              giftRemark: '暂无详情......'
            })
          } else {
            th.setData({
              giftRemark: res.data.data.giftRemark
            })
          }
		  
		  //---获取日期的时间戳---
		  var t_endtime=res.data.data.endTime;
		  t_endtime = t_endtime.replace(/-/g,'/');
		  var t_date = new Date(t_endtime)/1000;
		  var t_now=ut.gettimestamp();
		  
		  if(res.data.data.goodsUseState) th.setData({c_state:1})
		  else if(t_date<=t_now)
		     th.setData({c_state:2})

          th.setData({
            giftDate: res.data.data.endTime,
            giftPosPrice: res.data.data.giftPosPrice,
            giftQty: res.data.data.giftQty,
            giftIntegral: res.data.data.payIntegral,
            giftPrice: res.data.data.payMoney,
            giftType: res.data.data.actType,
            actTitle: res.data.data.actTitle,
            wareCard: res.data.data.wareCard,
            lbId: res.data.data.lbId
          })
        } else {
          getApp().my_warnning("系统繁忙,请稍后再试", 0, th);
          return false;
        }
      }
    });

  },
  GetBuyGiftList: function() {
    var _this2 = this;
    var th = this.data;
    getApp().request.get('/api/weshop/marketing/giftbag/detail/get', {
      data: {
        "storeId": th.getStorageID, //商家ID
        "userId": th.getUserID, //用户ID
        "giftBagId": th.getGiftID
      },
      success: function success(res) {
        if (res.data.code == 0) {
          _this2.setData({
            giftImage: th.iurl + res.data.data.lbUrl,
            giftTitle: res.data.data.giftTitle
          })
          if (res.data.data.giftRemark == '') {

            _this2.setData({
              giftRemark: '暂无详情......'
            })
          } else {
            _this2.setData({
              giftRemark: res.data.data.giftRemark
            })
          }

          _this2.setData({
            giftDate: res.data.data.endTime,
            giftPosPrice: res.data.data.giftPosPrice,
            giftQty: res.data.data.giftQty,
            giftIntegral: res.data.data.payIntegral,
            giftPrice: res.data.data.payMoney,
            giftType: res.data.data.actType,
            actTitle: res.data.data.actTitle,
            wareCard: res.data.data.wareCard
          })
        } else {
          getApp().my_warnning("系统繁忙,请稍后再试", 0, _this2);
          return false;
        }
      }
    });

  },
  //显示核销码
  code_show: function(e) {
    var th = this;
    //--获取成功的时候--
    var no = th.data.code;
    var qc_com = th.selectComponent("#qc_com"); //组件的id
    var obj = {
      val: no,
      content: "请将二维码展示给核销员,收货更快捷"
    };
    qc_com.open(obj)
  },
  //获取核销码
  getcode: function() {
    var th = this;
    var orderSn = th.data.orderSn; //订单号
    var json = {
      "storeId": a.stoid,
      "orderSn": orderSn
    };
    var data = JSON.stringify(json);
    var url = th.data.url + "/api/weshop/marketing/gift/goods/verify/code/get"; //预约接口地址
    wx.request({
      url: url,
      data: data,
      method: 'put',
      header: {
        'content-type': 'application/json'
      }, // 设置请求的 header
      success: function(res) {
        if (res.data.code == 0) {
          th.setData({
            code: res.data.data
          })
          th.code_show();
        } else {
          getApp().my_warnning(res.data.msg, 0, th);
        }
      }
    })
  },
  //界面跳转
  goto: function(e) {
    var th = this;
    var url = e.currentTarget.dataset.url;
    getApp().goto(url);
  },
  //图片失败,默认图片
  bind_bnerr2: function (e) {
    var _errImg = e.target.dataset.errorimg;
    var _errObj = {};
    _errObj[_errImg] = "/public/images/empty.jpg";
    this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; 

  },
  //关闭导航
  close: function () {
    var th = this;
    var nav_b = th.selectComponent("#nav_b"); //组件的id
    nav_b.close_box();
    nav_b.set_name("礼包", "/pages/giftpack/buygiftpack/giftpackbuy");
  }
});