<template>
  <div>
    <van-nav-bar title="加入组织" left-text="返回" @click-left="$route_back" left-arrow>

    </van-nav-bar>

    <div class="body_com has_header">
      <scroller>
        <div style="padding:0.3rem;" v-show="company_info.name">申请加入：{{company_info.name}}</div>
        <van-cell-group>

          <van-field required label="您的姓名" v-model="formdata.employee_name" placeholder="填写您的姓名" />

        </van-cell-group>
        <div class="submit_btn_box">
          <van-button type="info" :disabled="submit_loading" @click="company_change" :loading="submit_loading" size="large">提 交</van-button>
        </div>
      </scroller>
    </div>

  </div>
</template>

<script>
  import request from '@/utils/request'
  export default {
    name: 'join_company',
    data(){
      return {
        submit_loading: false,
        formdata: {
          employee_name: '',
          id: 0,
          dept_id: 0
        },
        company_info:{}
      }
    },
    created(){
      let id = this.$route.query.id
      let dept_id = this.$route.query.dept_id
      this.formdata.id = id
      if(dept_id){
        this.formdata.dept_id = dept_id
      }
      this.get_company_info(id)
    },
    methods:{
      get_company_info(id){
        let self = this
        request('get','/addons/ems/index/get_company_info',{id:id}).then((res) => {
          if(res.data.code == 1){
            self.company_info = res.data.data
          }else{
            if(res.data.code == 999){
              //没有组织
              self.$router.push({name: 'create_company'})
            }
          }

        }).catch((e) => {

        })
      },
      company_change(){
        let self = this
        self.submit_loading = true
        request('post','/addons/ems/index/join_company',self.formdata).then((res) => {
          self.submit_loading = false
          if(res.data.code == 1){
            self.$toast('申请成功，等待审批')
          }else{
            self.$toast(res.data.msg)
          }
        }).catch((e) => {
          self.$toast(e)
        })
      }

    }
  }
</script>

<style scoped>
  .submit_btn_box{padding:0.32rem;}
  .body_com{height: calc(100% - 1rem); position: relative;}
</style>
