import http from '../../base/httputil'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    busEnterpriseId: null,
    enterpriseDetails: {
      busEnterpriseId: null,
      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
    },


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.busEnterpriseId = options.busEnterpriseId
    this.getEnterpriseDetails()
  },

  getEnterpriseDetails() {
    let obj = new Object();
    obj.busEnterpriseId = this.busEnterpriseId
    http.post("/system/AppEnterpriseController/getEnterpriseDetails", obj, this.getEnterpriseDetailsSuccess)
  },
  getEnterpriseDetailsSuccess(res) {
    this.setData({
      enterpriseDetails: res.enterpriseDetails,
    })
  },
  //-----------------------------------------
  get_businessName(e) {
    this.data.enterpriseDetails.businessName = e.detail.value
  },
  get_officeAddress(e) {
    this.data.enterpriseDetails.officeAddress = e.detail.value
  },
  get_businessAddress(e) {
    this.data.enterpriseDetails.businessAddress = e.detail.value
  },
  get_supervisor(e) {
    this.data.enterpriseDetails.supervisor = e.detail.value
  },
  get_tradeDept(e) {
    this.data.enterpriseDetails.tradeDept = e.detail.value
  },
  get_mainPerson(e) {
    this.data.enterpriseDetails.mainPerson = e.detail.value
  },
  get_mainPersonPhone(e) {
    this.data.enterpriseDetails.mainPersonPhone = e.detail.value
  },
  get_headSecurity(e) {
    this.data.enterpriseDetails.headSecurity = e.detail.value
  },
  headSecurityPhone(e) {
    this.data.enterpriseDetails.headSecurityPhone = e.detail.value
  },

  //------------------------------------------

  updateEnterprise() {
    let obj = new Object();
    obj.busEnterpriseId = this.data.enterpriseDetails.busEnterpriseId
    obj.businessName = this.data.enterpriseDetails.businessName
    obj.officeAddress = this.data.enterpriseDetails.officeAddress
    obj.businessAddress = this.data.enterpriseDetails.businessAddress
    obj.supervisor = this.data.enterpriseDetails.supervisor
    obj.tradeDept = this.data.enterpriseDetails.tradeDept
    obj.mainPerson = this.data.enterpriseDetails.mainPerson
    obj.mainPersonPhone = this.data.enterpriseDetails.mainPersonPhone
    obj.headSecurity = this.data.enterpriseDetails.headSecurity
    obj.headSecurityPhone = this.data.enterpriseDetails.headSecurityPhone
    http.post("/system/AppEnterpriseController/updateEnterprise", obj, this.updateEnterpriseSuccess)
  },
  updateEnterpriseSuccess(res) {
    wx.showToast({
      title: res.msg,
    })
    if(res.code == 200){
      wx.navigateTo({
        url: '../details/details?busEnterpriseId=' + this.busEnterpriseId,
      })
    }
  },
  deleteEnterprise() {
    let obj = new Object();
    obj.busEnterpriseId = this.data.enterpriseDetails.busEnterpriseId
    http.post("/system/AppEnterpriseController/deleteEnterprise", obj, this.deleteEnterpriseSuccess)
  },
  deleteEnterpriseSuccess(res) {
    wx.showToast({
      title: res.msg,
    })
    if(res.code == 200){
      wx.navigateTo({
        url: '../qiye/qiye'
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  }
})