<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.RELEVANT_UNIT_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle" v-show="item.START_DATE">
            <text>就职时间：{{ item.START_DATE }}-{{ item.END_DATE || '至今' }}</text>
          </view>
          <view class="flex-between mt-10 subtitle" v-show="item.DEPART_STATE">
            <text>就职状态：
              <template v-if="item.DEPART_STATE === '0'">在职</template>
              <template v-if="item.DEPART_STATE === '1'">离职</template>
              <template v-if="item.DEPART_STATE === '-1'">离职申请中</template>
              <template v-if="item.DEPART_STATE === '2'">待审核</template>
              <template v-if="item.DEPART_STATE === '3'">已审核</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>单位在职申请审核状态：
              <template v-if="item.AUDIT_STATE === '0'">已打回</template>
              <template v-if="item.AUDIT_STATE === '1'">待审核</template>
              <template v-if="item.AUDIT_STATE === '2'">审核通过</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle" v-show="item.DEPART_STATE !== '0' && item.REVIEW_STATE">
            <text>单位离职申请审核状态：
              <template v-if="item.REVIEW_STATE === '0'">已打回</template>
              <template v-if="item.REVIEW_STATE === '1'">待审核</template>
              <template v-if="item.REVIEW_STATE === '2'">审核通过</template>
            </text>
          </view>

          <view class="flex-between mt-10 subtitle" v-if="item.AUDIT_REMARKS">
            <text>审核意见：{{ item.AUDIT_REMARKS }}
            </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.EMPLOYMENT_APPLY_MANAGEMENT_ID, item.CORPINFO_ID, item.DEPART_STATE)"></u-button>
              <view class="ml-10">
                <u-button type="primary" text="离职" size="mini"
                          v-if="item.DEPART_STATE === '0'"
                          @click="fnResignationApplication(item.EMPLOYMENT_APPLY_MANAGEMENT_ID,item.RELEVANT_UNIT_NAME)">
                </u-button>
              </view>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

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

export default {
  data() {
    return {
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getEmployedBy({
        showCount: this.pageSize,
        currentPage: this.currentPage,
      });
      this.list = [...this.list, ...resData.varList];
      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>
