// packageH/installationSever/installationSeverAfterApply/installationSeverAfterApply.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pictureList: [],
    install_order_goods_id: 0,
    order_sn: '',
    message: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      install_order_goods_id: options.install_order_goods_id,
      order_sn: options.order_sn
    });
  },

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

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  sendBtn() {
    let {
      install_order_goods_id,
      message,
      pictureList
    } = this.data;
    let urlStr = app.getNetAddresss('plugin.live-install.frontend.order.applyAfterSale');
    app._postNetWork({
      url: urlStr,
      data: {
        install_order_goods_id,
        refund_reason: message,
        refund_image: pictureList
      },
      success: (resdata) => {
        var res = resdata.data;
        app.tips(res.msg);
        if (res.result != 1) return;
        let pages = getCurrentPages();
        let page = pages[pages.length - 2];
        page.getDetails();
        wx.navigateBack();
      }
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


  onRead_2() {
    wx.chooseImage({
      count: 9,
      sizeType: ["original", "compressed"],
      sourceType: ["album", "camera"],
      success: res => {
        // var tempFilePaths = res.tempFilePaths
        console.log(res.tempFilePaths);
        this.unload({
          tempFilePaths: res.tempFilePaths,
        });
      },
    });
  },
  //多张上传方法
  unload(data) {
    if (data.tempFilePaths.length == 0) return;
    wx.showLoading({
      title: "上传中",
    });
    let urlStr = app.getNetAddresss("upload.uploadPic");

    wx.uploadFile({
      url: urlStr,
      filePath: data.tempFilePaths[0],
      name: "file",
      formData: null,
      success: (resdata) => {
        var res = JSON.parse(resdata.data);
        let pictureList = this.data.pictureList;
        pictureList.push(res.data.img_url);
        this.setData({
          pictureList
        });

      },

      complete: (e) => {
        wx.hideLoading();
        data.tempFilePaths.shift();
        this.unload(data);

      },
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
});