const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address: '',
    region: [],
    content: '',
    name: '',
    phone: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getshareGui()
  },
  //提交
  getTijiao() {
    let t = this;
    let u = 'index/makeMeng';
    let d = {
      name: t.data.name,
      phone: t.data.phone,
      area: t.data.address
    }
    if (d.name == '') {
      wx.showToast({
        title: '姓名不能为空',
        icon: "none"
      })
    } else if (d.phone == '') {
      wx.showToast({
        title: '电话号不能为空',
        icon: "none"
      })
    } else if (!(/^1[3456789]\d{9}$/.test(d.phone))) {
      wx.showToast({
        title: '手机号错误',
        icon: "none"
      })
    } else if (d.area == '') {
      wx.showToast({
        title: '地址不能为空',
        icon: "none"
      })
    } else {

      app.post(u, d).then(r => {
        if (r.code == 1) {
          wx.showToast({
            title: r.msg
          })
          setTimeout(function () {
            wx.navigateBack({
              delta: 1,
            })
          }, 3000)
        } else {
          wx.showToast({
            title: r.msg,
            icon: "none"
          })
        }
      })
    }


  },
  //头部
  getshareGui() {
    let t = this;
    let u = 'index/jiameng'
    app.post(u, '').then(r => {
      console.log(r)
      let content = r.data.content
      content = content.replace(/\<img/gi, '<img style="width:100%;height:auto" ')
      t.setData({
        content: content
      })
    })
  },
  //电话
  getPhone(e) {
    this.setData({
      phone: e.detail.value
    })
  },
  //收货人
  getName(e) {
    this.setData({
      name: e.detail.value
    })
  },
  //选择城市
  bindRegionChange(e) {
    console.log(e)
    let address = this.data.address
    address = e.detail.value[0] + "-" + e.detail.value[1] + "-" + e.detail.value[2]
    this.setData({
      address: address
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})