monthgiftbag.js 10.8 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
var i = require("../../../../utils/util.js")
var e = getApp(),
  a = e.globalData.setting,
  os = a,
  t = e.request,
  d = e.globalData,ut=i;

Page({
  data: {
    url: a.url, //接口网址
    iurl: a.imghost, //图片前缀网址
    getDate: "",
    getStorageID: '',
    getUserID: '',
    wareCard: [],
    // pages: 0,
    // pageSize: 10,
    isEmpty: false,
    loadingType: 0, //定义加载方式 0---contentdown  1---contentrefresh 2---contentnomore
    contentText: {
      contentdown: '加载更多',
      contentrefresh: '加载中...',
      contentnomore: '已加载全部'
    },
    ismore: 0, //数据是否全部加载完成
    is_read: 0, //是否查询过我的礼包接口
    curpage: 1, //当前分页数
    pageSize: 10, //页大小
    total: 0, //总数量
    ad_data: null,
    first_leader: e.globalData.first_leader || 0, // 推荐人ID

    sear_key:''
  },
  onLoad: function (options) {
    this.setData({
      params: options,
    })
  },

  init() {
    let options = this.data?.params;
    var th = this;
    this.setData({
      getStorageID: a.stoid,
      getUserID: d.user_id,
      loadingType: 0,
      getDate: i.formatTime(new Date().getTime())
    });
    //-- 获取分享人的ID --
    var first_leader = options.first_leader || getApp().globalData.first_leader;
    if (first_leader) {
      this.setData({
        first_leader,
      })
      //--  user_id代过来免登录 --
      getApp().globalData.first_leader = first_leader;
      //调用接口判断是不是会员
      getApp().request.promiseGet("/api/weshop/shoppingGuide/get/" + os.stoid + "/" + first_leader, {}).then(res => {
        if (res.data.code == 0) {
          getApp().globalData.guide_id = res.data.data.id;
          getApp().globalData.guide_pick_id= res.data.data.pickup_id
        }
      })
    }

    getApp().request.promiseGet("/api/weshop/ad/page?pid=1208&store_id=" + os.stoid, {
      data: {
        enabled: 1
      }
    }).then(res => {
      if (res.data.code == 0 && res.data.data && res.data.data.pageData && res.data.data.pageData.length > 0) {
        var a = res.data.data.pageData;
        var tt = {
          'ad_code': os.imghost + a[0].ad_code,
          'media_link': '',
          'ad_weapplink': a[0].ad_weapplink,
          'bgcolor': a[0].bgcolor,
        };
        th.setData({ ad_data: tt });
      }
    })
    this.getList();
  },
  onShow: function () {
      getApp().check_can_share();
     this.setData({
      curpage:1
     })
    //--先判断会员状态--
    getApp().is_Single_page(this, function () {
      var user_info = getApp().globalData.userInfo;
      if (user_info == null || user_info.mobile == undefined || user_info.mobile == "" || user_info.mobile == null) {
        getApp().goto('/packageE/pages/togoin/togoin');
        return false;
      }
      this.data.curpage=0;
      this.data.searching=0;
      this.setData({ismore:0,is_get:0,wareCard:[]});

      this.init()
    })


  },

  getList: function () {

    if(this.data.ismore) return false;
    if(this.data.searching) return false;
    this.data.searching=1;

    wx.showLoading({
      title: '加载中.',
    })

    var th = this;
    let r_q={
      store_id: th.data.getStorageID, //商家ID
      user_id: th.data.getUserID, //用户ID
      page: th.data.curpage,
      pageSize: th.data.pageSize,
      pay_state:1,
      isdetail:1
    };

    if(this.data.sear_key){
      r_q.key_str=this.data.sear_key;
    }


    getApp().request.get('/api/weshop/marketing/marketingMonthgiftbagRecord/page', {
      isShowLoading: true,
      data:r_q ,
      success: function (res) {

        th.data.searching=0;

        if (res.data.code == 0) {
          
          var arr1 = th.data.wareCard;
          var arr2 = res.data.data.pageData;
          if (arr2.length>=th.data.pageSize) {
            th.data.curpage++;
          }
          for (let j = 0; j < arr2.length; j++) {
            // arr2[j].starTime1=Date.parse(new Date(arr2[j].begindate.replace(/-/g, "/")))/1000
            // arr2[j].starTime1=arr2[j].begindate
            // arr2[j].starTime=i.formatTime(arr2[j].begindate, "yyyy-MM-dd hh:mm:ss");
            // arr2[j].endTime=i.formatTime(arr2[j].enddate, "yyyy-MM-dd hh:mm:ss");
            arr2[j].giftPosPrice=arr2[j].oldPrice
            arr2[j].payMoney=arr2[j].pay_money
            arr2[j].payIntegral=arr2[j].pay_integral
            // arr2[j].giftQty=arr2[j].buynum
            arr2[j].cover_img=arr2[j].imageurl
            arr2[j].giftTitle=arr2[j].act_name
            arr2[j].lbId=arr2[j].cur_giftid
            arr2[j].orderSn=arr2[j].order_sn
            arr2[j].pay_time=i.formatTime(arr2[j].paytime, "yyyy-MM-dd hh:mm:ss");

            // arr2[j].virtualsales=arr2[j].virtualSales
            // arr2[j].lbnum=arr2[j].lbNum


            if(!arr2[j].receive_ordersn){
              arr2[j].is_no_rev=1;
            }

            arr2[j].is_detail=0;
            if(arr2[j].detaillist){
              arr2[j].is_detail=1;
            }else{
              continue;
            }



            arr2[j].lbType=0;
            if(arr2[j].detaillist.iswarelbtype){
              arr2[j].lbType=1;
            }
            //---获取日期的时间戳---
            var t_endtime = arr2[j].detaillist.endTime;
            t_endtime = t_endtime.replace(/-/g, '/');
            var t_date = new Date(t_endtime) / 1000;
            var t_now = ut.gettimestamp();

            var t_starttime = arr2[j].detaillist.starTime;
            t_starttime = t_starttime.replace(/-/g, '/');
            var t_sdate = new Date(t_starttime) / 1000;

            arr2[j].c_state=0
            if (arr2[j].detaillist.goodsUseState)
               arr2[j].c_state=1
            else if (t_date <= t_now)
               arr2[j].c_state=2
            else if (t_sdate > t_now)
               arr2[j].c_state=-1

        }


          var arr3 = [...arr1, ...arr2];
          var ismore = 0;
          if (arr3.length == res.data.data.total) ismore = 1
          th.setData({
            wareCard: arr3,
            total: res.data.data.total,
            ismore: ismore,
            is_read: 1,
            is_get:1,
          }), wx.stopPullDownRefresh(); //停止下拉刷新
        } else {
          th.setData({
            is_read: 1,
            ismore: 1,
            is_get:1,
          })
        }

        wx.hideLoading();

      }

    });

  },
  //销毁界面跳转
  redirectTo: function (e) {
    var th = this;
    var url = e.currentTarget.dataset.url;
    //销毁跳转
    wx.redirectTo({
      url: url
    });
  },
  //不销毁界面跳转
  navigateTo: function (e) {
    var th = this;
    var url = e.currentTarget.dataset.url;
    let index =e.currentTarget.dataset.index;
    let item=this.data.wareCard[index];

    var form_id = item.form_id;
    let is_back = e.currentTarget.dataset.is_back;
    let order_sn = item.order_sn;
    
    if (is_back==1) {
      wx.showToast({
        title: '该礼包已退款',
        icon: 'none',
        duration: 2000
      })
    }else{
      //getApp().goto(url);
      url="/packageE/pages/user/monthgiftbag/my_giftpackinfo/my_giftpackinfo?id="+form_id+"&order_sn="+order_sn;
      getApp().goto(url);

    }
  },
  //下拉事件
  onReachBottom: function () {
    var th = this;
    if (th.data.total <= th.data.pageSize) return;
    if (th.data.ismore) return;
    th.getList();
  },

  //图片失败,默认图片
  bind_bnerr2: function (e) {
    var _errImg = e.target.dataset.errorimg;
    var _errObj = {};
    _errObj[_errImg] = "/miniapp/images/default_g_img.gif";
    this.setData(_errObj) //注意这里的赋值方式,只是将数据列表中的此项图片路径值替换掉 ; 
  },


  //--- 分享设置 --
  onShareAppMessage: function (e) {
      getApp().globalData.no_clear=1;
    var curPage = this;
    var pagePath = curPage.route; //当前页面url
    if (pagePath.indexOf('/') != 0) {
      pagePath = '/' + pagePath;
    }
    pagePath += "?first_leader=" + this.data.getUserID;
    return {
      title: "每月礼包",
      path: pagePath,
    }
  },

    onShareTimeline() {
        getApp().globalData.no_clear=1;
        return {
            title: '每月礼包',
            imageUrl: this.data.ad_data.ad_code,
            query: "first_leader=" + this.data.getUserID
        }
    },

  search_lb(){
    this.data.curpage=0;
    this.data.searching=0;
    this.setData({ismore:0,is_get:0,wareCard:[]});
    this.getList();
  },

  input_sear(e){
    let value = e.detail;
    this.data.sear_key=value;
  },

  //-- 获取核销码 ---
  getcode: function (e) {
    var th = this;
    let codeId = e.currentTarget.dataset.codeid;
    let orderSn = e.currentTarget.dataset.ordersn;
    var json = {
      "storeId": a.stoid,
      "orderSn": orderSn,
    }
    if (codeId && codeId !== "") {
      json.id = codeId
    }
    var data = JSON.stringify(json);
    var url = th.data.url + "/api/weshop/marketing/gift/goods/verify/code/get"; //预约接口地址
    getApp().request.json_post(url, json,
        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);
          }
        },
        function (res) {

        },
        "put"
    )
  },

  //显示核销码
  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)
  },

  getGift(e){
    var that=this;
    if (that.data.islogin) {
      return
    }
    that.setData({
      islogin:true
    })

    var record_list_id=e.currentTarget.dataset.record_list_id;
    var index=e.currentTarget.dataset.index;

    var json = {
      "id":record_list_id,// "记录Id",
      "storeId": that.data.getStorageID, //商家Id
      "userId": that.data.getUserID, //用户ID
    };
    // var url ="/api/weshop/marketing/buy/receive/gift/record/insert";
    // var url ="/api/weshop/marketing/marketingMonthgiftbagRecord/createOrder";
    var url ="/api/weshop/marketing/marketingMonthgiftbagRecord/recordReceive";
    getApp().request.json_post(url, json,
        function (res) {
          console.log('领取礼包');
          console.log(res);
          if (res.data.code == 0 && res.data.data) {

            var txt="wareCard["+index+"]is_receive";
            that.setData({
                [txt]:1
            })
            getApp().my_warnning("领取成功!", 1, that);

          } else {
            that.setData({submit:0})
            getApp().my_warnning(res.data.msg, 0, that);
          }
          that.setData({
            islogin:false
          })
        },
        function (res) {
          that.setData({submit:0})
        }
    )
  },





});