<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>
      <view class="mt-10">
        <u-button type="primary" text="提交" @click="$u.debounce(fnSubmit, 1000,true)"></u-button>
      </view>
    </view>
  </view>
</template>

<script>
import {setResignationApplication,resign} from "../../api";
import {resignV1} from "../../api/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 resignV1({
        leaveReason: this.form.LEAVE_REASON,
        operatorId: this.userInfo.USER_ID,
        userId: this.userInfo.USER_ID,
        id: this.userInfo.USER_ID,
        postMethod: 'application/json'
      })
      uni.$u.toast('离职成功')
      setTimeout(() => {
        uni.navigateBack()
      }, 2000)
    }
  },
}
</script>

<style scoped>

</style>
