<template>
  <view class="content">
    <u-list @scrolltolower="scrolltolower" v-if="list.length > 0">
      <u-list-item v-for="(item, index) in list" :key="index">
        <view>
          <view class="flex-between main-title">
            <text>单位名称:{{ item.relevantUnitName }}</text>
          </view>
          <view class="flex-between mt-10 subtitle" v-show="item.startDate">
            <text>就职时间:{{ item.startDate }}-{{ item.endDate || '至今' }}</text>
          </view>
          <view class="flex-between mt-10 subtitle" v-show="item.departState">
            <text>就职状态:
              <template v-if="item.departState === '0'">在职</template>
              <template v-if="item.departState === '1'">离职</template>
              <template v-if="item.departState === '-1'">离职申请中</template>
              <template v-if="item.departState === '2'">待审核</template>
              <template v-if="item.departState === '3'">已审核</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>单位在职申请审核状态:
              <template v-if="item.auditState === '0'">已打回</template>
              <template v-if="item.auditState === '1'">待审核</template>
              <template v-if="item.auditState === '2'">审核通过</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle" v-show="item.departState !== '0' && item.reviewState">
            <text>单位离职申请审核状态:
              <template v-if="item.reviewState === '0'">已打回</template>
              <template v-if="item.reviewState === '1'">待审核</template>
              <template v-if="item.reviewState === '2'">审核通过</template>
            </text>
          </view>

          <view class="flex-between mt-10 subtitle" v-if="item.auditRemarks">
            <text>审核意见:{{ item.auditRemarks }}
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <view></view>
            <view class="flex-between">
              <u-button type="primary" text="查看" size="mini"
                        @click="fnView(item.employmentApplyManagementId, item.corpinfoId, item.departState)"></u-button>
              <view class="ml-10">
                <u-button type="primary" text="离职" size="mini"
                          v-if="item.departState === '0'"
                          @click="fnResignationApplication(item.employmentApplyManagementId,item.relevantUnitName)">
                </u-button>
              </view>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

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

export default {
  data() {
    return {
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getEmpLog({
        id: this.$store.getters.getUserInfo.USER_ID,
        limit: this.pageSize,
        curPage: this.currentPage,
        postMethod: 'application/json'
      });
      this.list = [...this.list, ...resData.page.list];
      this.totalPage = resData.page.totalPage;
    },
    resetList() {
      this.pageSize = 10
      this.currentPage = 1
      this.list = []
      this.getData()
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.getData();
    },
    fnResignationApplication(EMPLOYMENT_APPLY_MANAGEMENT_ID, RELEVANT_UNIT_NAME) {
      uni.$u.route({
        url: '/pages/employed_by/resignation_application',
        params: {
          EMPLOYMENT_APPLY_MANAGEMENT_ID,
          RELEVANT_UNIT_NAME
        }
      })
    },
    fnView(EMPLOYMENT_APPLY_MANAGEMENT_ID, CORPINFO_ID, DEPART_STATE) {
      uni.$u.route({
        url: '/pages/related_party_units/view',
        params: {
          EMPLOYMENT_APPLY_MANAGEMENT_ID,
          CORPINFO_ID,
          DEPART_STATE
        }
      })
    }
  }
}
</script>

<style scoped>

</style>