// pages/mine/wxml/delivergoods/delivergoods.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    array: [],
    index: 0,
    news:[]
  },
  bindPickerChange: function(e) {
    //console.log(e.target.dataset.value)
    this.setData({
      index: e.detail.value
    })
  },
  formSubmit: function(e) {
    //console.log(this.data.news)
    var str = e.detail.value.courierServicesCompany;
    var array = str.split('+');
    //console.log(array);
    if (e.detail.value.couriernumber !== "") {
      var _this = this;
      wx.request({
        url: app.globalData.prodUrl + 'web-pm/wx/pm/deliver',
        header: {
          'ydw-token': wx.getStorageSync('key').ydw_token
        },
        data: {
          item_kid: _this.data.kid,
          type_code: array[0],
          logistics_number: e.detail.value.couriernumber,
          expressage:array[1],
          formId: e.detail.formId
        },
        success: function(data) {
          //console.log(data)
          wx.navigateBack({
            delta: 1,
            success: function () {
              var pages = getCurrentPages();
              var page = getCurrentPages().pop();
              //console.log(pages)
              if (page == undefined || page == null) return;
              pages[2].onLoad(pages[2].options);
            }
          })
        }
      })
    }else{
      wx.showToast({
        title: '请填写快递号！',
        icon: 'none',
        duration: 3000
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //console.log(options)
    var _this = this
    _this.setData({
      kid: options.kid
    })
    wx.request({
      url: app.globalData.prodUrl + 'web-pm/wx/pm/list_express',
      data: {
        pm_item_id: options.kid
      },
      header: {
        'ydw-token': wx.getStorageSync('key').ydw_token
      },
      success: function(data) {
        //console.log(data)
        _this.setData({
          array: data.data.data,
          news: data.data.pm_item_submit
        })
      },
    });
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})