<template>
  <view class="content">
    <view class="card">
      <u-cell-group>
        <u-cell title="离职申请单位" :value="RELEVANT_UNIT_NAME"></u-cell>
        <u-cell title="离职原因">
          <template #value>
            <u--textarea v-model="form.LEAVE_REASON" placeholder="请输入离职原因" border="none"
                         autoHeight></u--textarea>
          </template>
        </u-cell>
        <u-cell title="申请时间" :value="form.APPLY_TIME"></u-cell>
        <u-cell title="申请人" :value="userInfo.NAME"></u-cell>
      </u-cell-group>
      <u-button type="primary" text="提交" class="mt-10" @click="$u.debounce(fnSubmit, 1000,true)"></u-button>
    </view>
  </view>
</template>

<script>
import {setResignationApplication} from "../../api";

export default {
  data() {
    return {
      EMPLOYMENT_APPLY_MANAGEMENT_ID:'',
      RELEVANT_UNIT_NAME:'',
      form: {
        LEAVE_REASON: '',
        APPLY_TIME: uni.$u.timeFormat(new Date(), 'yyyy-mm-dd'),
		REVIEW_STATE: '1',
		DEPART_STATE: '-1',
		EMPLOYMENT_APPLY_MANAGEMENT_ID: ''
      }
    }
  },
  onLoad(query) {
    this.EMPLOYMENT_APPLY_MANAGEMENT_ID = query.EMPLOYMENT_APPLY_MANAGEMENT_ID
    this.RELEVANT_UNIT_NAME = query.RELEVANT_UNIT_NAME
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  methods: {
    async fnSubmit() {
      if(!this.form.LEAVE_REASON){
        uni.$u.toast('请填写离职原因')
        return
      }
	this.form.EMPLOYMENT_APPLY_MANAGEMENT_ID = this.EMPLOYMENT_APPLY_MANAGEMENT_ID
      await setResignationApplication({
        ...this.form,
        OPERATOR:this.userInfo.USER_ID
      })
      uni.$u.toast('申请成功')
      setTimeout(()=>{
        uni.navigateBack()
      },2000)
    }
  },
}
</script>

<style scoped>

</style>