var e = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
    return typeof e;
} : function(e) {
    return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, t = getApp(), r = t.globalData.setting,oo=t.globalData,os=oo.setting,
 o = t.request,rq=o, s = require("../../../../utils/util.js");

Page({
    data: {
        url: r.url,
        resourceUrl: r.imghost,
        return_goods: null,
        goods: null,
        loading:0, //是不是在处理中，避免重复点击
    },
    onLoad: function(e) {
      if (e.order_id!=undefined){
         this.getreturn(e.order_id, e.goods_id);
      }else{
         this.requestReturnGoods(e.id);
      }
    },
    //获取--return_goods---
    getreturn(a,b){
        var th=this,data=null;
      if (b == undefined) { data = { order_id: a, store_id: os.stoid};}
      else data = { order_id: a, goods_id: b, store_id: os.stoid};
        rq.get('/api/weshop/order/returngoods/page',{
            data:data,
            success:function(dda){
                var item=dda.data.data.pageData[0];
                th.requestReturnGoods(null, item);
            }
        })
    },
    
    //获取--详细内容---
    requestReturnGoods: function(t,b) {
        var r = this, th = r;
        if(b!=undefined){
              console.log("requestReturnGoods");
              console.log(b);
              var o = b, odata = o;
              o.addTimeFormat = s.format(o.addtime), "object" == e(o.seller_delivery) && "number" == typeof o.seller_delivery.express_time && (o.seller_delivery.expressTimeFormat = s.format(o.seller_delivery.express_time)),
                r.setData({
                  return_goods: o,
                });
              var arr = new Array();
              if (odata.goods_id == 0) {
                var gidlist = odata.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 (odata.goodslist != undefined) {
                        odata.goodslist.push(ed.data.data);
                      } else {
                        arr.push(ed.data.data);
                        odata.goodslist = arr;
                      }
                      th.setData({ return_goods: odata });
                    }
                  })
                }
              } else {
                //------读取商品---------
                rq.get("/api/weshop/goods/get/" + os.stoid + "/" + odata.goods_id, {
                  success: function (ed) {
                    arr.push(ed.data.data);
                    odata.goodslist = arr;
                    th.setData({ return_goods: odata });
                  }
                })
              }
        }else{
           rq.get("/api/weshop/order/returngoods/get/"+os.stoid+"/"+t, {
                success: function(t) {
                    console.log("requestReturnGoods");
                    console.log(t);
                    var o = t.data.data,odata=o;
                    o.addTimeFormat = s.format(o.addtime), "object" == e(o.seller_delivery) && "number" == typeof o.seller_delivery.express_time && (o.seller_delivery.expressTimeFormat = s.format(o.seller_delivery.express_time)), 
                    r.setData({
                        return_goods: o,
                    });

                  var arr = new Array();
                  if (odata.goods_id == 0) {
                      var gidlist = odata.goods_id_list.split(",");
                      for (var i = 0; i < gidlist.length; i++) {
                        //------读取商品---------
                        rq.get("/api/weshop/ordergoods/list?store_id=" + os.stoid + "&goods_id=" + gidlist[i], {
                          success: function (ed) {
                            if (odata.goodslist != undefined) {
                              odata.goodslist.push(ed.data.data.pageData[0]);
                            } else {
                              arr.push(ed.data.data.pageData[0]);
                              odata.goodslist = arr;
                            }
                            th.setData({ return_goods: odata });
                          }
                        })
                      }
                    } else {
                      //------读取商品---------
                    rq.get("/api/weshop/ordergoods/list?store_id=" + os.stoid + "&goods_id=" + odata.goods_id, {
                        success: function (ed) {
                          arr.push(ed.data.data.pageData[0]);
                          odata.goodslist = arr;
                          th.setData({ return_goods: odata });
                        }
                      })
                    }
                  }
            });
        }
    },
    receiveOrder: function() {
        var e = this, t = this.data.return_goods.id;
        wx.showModal({
            title: "确定已收货？",
            success: function(r) {
                r.confirm && o.post("/api/order/receiveConfirm", {
                    data: {
                        return_id: t
                    },
                    success: function(r) {
                        wx.setStorageSync("user:return_goods_list:update", !0), e.requestReturnGoods(t);
                    }
                });
            }
        });
    },
    cancelReturn: function() {


        var e = this, 
		id = this.data.return_goods.id;

        if(this.data.loading) return false;
        this.data.loading=1;

        wx.showModal({
            title: "确定取消售后服务？",
            success: function(r) {
                r.confirm && o.put("/api/weshop/order/returngoods/update", {
                    data: {
                        id: id,
						store_id:os.stoid,
						status:3,
						remark:'客户取消'
                    },
                    success: function(r) {

						if(r.data.code==0){							
							 getApp().showWarning('取消成功');									
							 setTimeout(function(){
								  wx.setStorageSync("user:return_goods_list:update", !0), e.requestReturnGoods(id);
							 },1000)							
						}else{

                            e.data.loading=0;
                            s.m_toast(r.data.msg);
                        }

                    }
                });
            }
        });
    },
    previewImgs: function(e) {
        var t = this, r = this.data.return_goods.imgs;
        getApp().globalData.no_clear=1;
        r = r.map(function(e) {
            return t.data.url + e;
        }), wx.previewImage({
            current: r[e.currentTarget.dataset.idx],
            urls: r
        });
    },


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