// pages/qiyemore/qiyemore.js
import http from '../../base/httputil'
Page({

  onLoad() {
    this.getLocation()
  },

  /**
   * 页面的初始数据
   */
  data: {
    longitude: Number,
    form: {
      longitude: Number,
      latitude: Number,
      businessName: null,
      orgCode: null,
      officeAddress: null,
      businessAddress: null,
      supervisor: null,
      tradeDept: null,
      deptId: null,
      mainPerson: null,
      mainPersonPhone: null,
      headSecurity: null,
      headSecurityPhone: null
    }
  },
  //-------------------------------表单数据绑定方法---------------------------------------
  get_businessName(e) {
    this.data.form.businessName = e.detail.value
  },
  get_orgCode(e) {
    this.data.form.orgCode = e.detail.value
  },
  get_officeAddress(e) {
    this.data.form.officeAddress = e.detail.value
  },
  get_businessAddress(e) {
    this.data.form.businessAddress = e.detail.value
  },
  get_supervisor(e) {
    this.data.form.supervisor = e.detail.value
  },
  get_tradeDept(e) {
    this.data.form.tradeDept = e.detail.value
  },
  get_mainPerson(e) {
    this.data.form.mainPerson = e.detail.value
  },
  get_mainPersonPhone(e) {
    this.data.form.mainPersonPhone = e.detail.value
  },
  get_headSecurity(e) {
    this.data.form.headSecurity = e.detail.value
  },
  headSecurityPhone(e) {
    this.data.form.headSecurityPhone = e.detail.value
  },
  //----------------------------------------------------------------------------




  addEnterprise(e) {
    let obj = new Object()
    obj.latitude = this.data.form.latitude
    obj.longitude = this.data.form.longitude
    obj.businessName = this.data.form.businessName
    obj.orgCode = this.data.form.orgCode
    obj.officeAddress = this.data.form.officeAddress
    obj.businessAddress = this.data.form.businessAddress
    obj.supervisor = this.data.form.supervisor
    obj.tradeDept = this.data.form.tradeDept
    obj.mainPerson = this.data.form.mainPerson
    obj.mainPersonPhone = this.data.form.mainPersonPhone
    obj.headSecurity = this.data.form.headSecurity
    obj.headSecurityPhone = this.data.form.headSecurityPhone

    http.post("/system/AppEnterpriseController/addEnterprise", obj, this.addEnterpriseSuccess)
  },
  addEnterpriseSuccess(e) {
    wx.showToast({
      title: e.msg,
      icon: "none" 
    })
    if(e.code == 200){
      wx.navigateTo({
        url: '../qiye/qiye',
      })
    }
  },



  getLocation() {
    let that = this
    wx.getLocation({
      type: 'wgs84', //返回可以用于wx.openLocation的经纬度
      success: function (res) {
        that.setData({
          form: {
            longitude: res.longitude,
            latitude: res.latitude
          }
        })
      },
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})