//获取应用实例
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dingdan_msg:false,
    order_id:0,
    goods_id:'',
    type:'',
    fileListtwo: [],
    refund_remark:'',
    voucher_img:[]
  },
 
  afterReadtwo(event) {
    var that = this;
    const { file } = event.detail;
    // 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
   
    wx.uploadFile({
      url: app.buildUrl("/app/Agentwechat/uploadImg"),
      filePath: file.url,
      name: 'file',
      formData: {
        uid:app.getCache('uid'),
        token:app.getCache('token'),
        file:file.url
         },

        success: (res)=>  {
        var resp = res.data;
        var rstObj = JSON.parse(resp); //字符串转为对象
        if(rstObj.erro==0){
        app.console(rstObj.file_path+'cccccccc')
    
          // 上传完成需要更新 fileList
          const { fileListtwo = [] } = that.data;
          fileListtwo.push({ ...file, url: rstObj.file_path});
          that.setData({ fileListtwo });
        }else{
            wx.showToast({ title: rstObj.msg, icon: 'none' });
            return;
        }
      },
    });
  },
  deletetwo(event){
    app.console(event.detail.index+"================="+222),
    this.data.fileListtwo.splice([event.detail.index],1)
    this.setData({fileListtwo:this.data.fileListtwo});
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.type)
    console.log(options.id)
    if(options.type==2){
      this.setData({
        order_id:options.id,
        type:2
      })
    }
    if(options.type==3){
      this.setData({
        order_id:options.id,
        type:3
      })
    }
  },



  onClickLeft() {
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getRefundOrderDetail();
  },
 
 //退款订单详情
 getRefundOrderDetail: function () {
  var that = this;
  wx.request({
      url: app.buildUrl("/app/Goddesswechat/getOrderDetail"),
      header: app.getRequestHeader(),
      method:'POST',
      data: {
        version_number: this.data.version_number,
        uid:wx.getStorageSync('uid'),
        token:wx.getStorageSync('token'),
        order_id:this.data.order_id
      },
      success: function (res) {
          var resp = res.data;
          if(resp.erro==0){
            that.setData({
              detail:resp.detail,
              order:resp.order,
              goods_id:resp.detail.goods_id,
              id:resp.detail.id,
              refund:resp.detail.refund,
              charge_phone:resp.detail.charge_phone
             
           });
     
           console.log("上传的图片路径================="+that.data.voucher_img)
           if(that.data.voucher_img.length>0){
            that.data.voucher_img.forEach(item => {
              app.console('长度=item================'+item)
              const { fileListtwo = [] } = that.data;
              fileListtwo.push({ url: item });
              that.setData({ fileListtwo });
            })
          }         
          }
      }
  });
},

tongyi(){
this.handleRefundOrder()
},
jujue(){
  this.handleRefundOrderr()
},
 //退款审核
 handleRefundOrder: function () {
  var that = this;
  wx.request({
      url: app.buildUrl("/app/Agentwechat/handleRefundOrder"),
      header: app.getRequestHeader(),
      method:'POST',
      data: {
        version_number: app.globalData.version_number,
        uid:wx.getStorageSync('uid'),
        token:wx.getStorageSync('token'),
        id:this.data.order_id,
        status:1,
        reject:''
      },
      success: function (res) {
          var resp = res.data;
          if(resp.erro==0){
            wx.showToast({ title: resp.msg, icon: 'none' });
            setTimeout(function () {
              //要延时执行的代码
              wx.navigateBack()
            }, 2000) //延迟时间 这里是2秒          
          }
      }
  });
},
 //退款审核
 handleRefundOrderr: function () {
  var that = this;
  wx.request({
      url: app.buildUrl("/app/Agentwechat/handleRefundOrder"),
      header: app.getRequestHeader(),
      method:'POST',
      data: {
        version_number: this.data.version_number,
        uid:wx.getStorageSync('uid'),
        token:wx.getStorageSync('token'),
        id:this.data.order_id,
        status:2,
        reject:''
      },
      success: function (res) {
          var resp = res.data;
          if(resp.erro==0){
            wx.showToast({ title: resp.msg, icon: 'none' });
          }
      }
  });
},
})