var t = function(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}(require("../../../../utils/LoadMore.js")), e = getApp(),oo=e.globalData,os=oo.setting,
 r = e.request,rq=r, s = new t.default(), o = require("../../../../utils/util.js");

Page({
    data: {
        url: e.globalData.setting.url,
        resourceUrl: e.globalData.setting.imghost,
        iurl: e.globalData.setting.imghost,
        list: null,
        currentPage: 1
    },
    onLoad: function() {
      var th=this,ts=s;
      //确保有登录
      e.getUserInfo(function(){
        ts.init(th, "", "list"), th.requestReturnGoods();
      })
      
    },
    onShow: function() {
        wx.getStorageSync("user:return_goods_list:update") && (wx.setStorageSync("user:return_goods_list:update", !1), 
        this.resetData(), this.requestReturnGoods());
    },
    onPullDownRefresh: function() {
        this.resetData(), this.requestReturnGoods();
    },
    onReachBottom: function() {
        s.canloadMore() && this.requestReturnGoods();
    },
    //----------读取退款退货------------
    requestReturnGoods: function() {
      var t = this, th=t,er = t.data.url + "/api/weshop/order/returngoods/page?page=" + t.data.currentPage;
          s.request(er, function(e) {
              t.data.currentPage++, th.data.list.forEach(function(t, ind, r) {
                     t.addTimeFommat = o.formatTime(t.addtime);
                     //-----判断是商品列表是否已经装载------
                     if(t.goodslist==undefined){
                          var arr=new Array();
                          if (t.goods_id==0){
                               var gidlist = t.goods_id_list.split(",");
                               for (var i = 0; i < gidlist.length;i++){
                                 //------读取商品---------
                                 rq.get("/api/weshop/goods/get/" + os.stoid + "/" + gidlist[i], {
                                   success: function (ed) {
                                     if (th.data.list[ind].goodslist != undefined){
                                         th.data.list[ind].goodslist.push(ed.data.data);
                                     }else{
                                          arr.push(ed.data.data);
                                          th.data.list[ind].goodslist = arr;
                                     }
                                     th.setData({ list: th.data.list });
                                   }
                                 })
                               }
                          }else{
                               //------读取商品---------
                               rq.get("/api/weshop/goods/get/" + os.stoid + "/" + t.goods_id,{
                                  success:function(ed){
                                     arr.push(ed.data.data);
                                     th.data.list[ind].goodslist=arr;
                                     th.setData({ list: th.data.list});                                    
                                  }
                              })
                          }
                     }
                }
              ), wx.stopPullDownRefresh();
          }, null, { store_id: os.stoid, user_id: oo.user_id}
        );
    },
    resetData: function() {
        this.data.currentPage = 1, this.data.list = null, s.resetConfig();
    },
    receiveOrder: function(t) {
        var e = this, s = t.currentTarget.dataset.id;
        wx.showModal({
            title: "确定已收货？",
            success: function(t) {
                t.confirm && r.post("/api/order/receiveConfirm", {
                    data: {
                        return_id: s
                    },
                    success: function(t) {
                        e.resetData(), e.requestReturnGoods();
                    }
                });
            }
        });
    },
    cancelReturn: function(t) {
        var e = this, 
		s = t.currentTarget.dataset.id;
        wx.showModal({
            title: "确定取消售后服务？",
            success: function(t) {
                t.confirm && r.put("/api/weshop/order/returngoods/update", {
                    data: {
                        id: s,
						store_id:os.stoid,
						status:3,
						remark:'客户取消'
                    },
                    success: function(t) {
						if(t.data.code==0){
							
							getApp().showWarning('取消成功');
							setTimeout(function(){
							   e.resetData(), e.requestReturnGoods();
							 },1000);
						}
						
                        
                    }
                });
            }
        });
    }
});