<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.FIRST_PARTY_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>人员类型：{{ item.IS_FLOW === '0' ? '固定人员' : '流动人员' }}</text>
            <text>服务状态：
              <template v-if="item.STATUS === '-1'">已作废</template>
              <template v-if="item.STATUS === '0'">确认中</template>
              <template v-if="item.STATUS === '1'">生效中</template>
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <view></view>
            <u-button type="primary" text="查看" size="mini"
                      @click="fnView(item.SERVICE_COMPANY_USER_MAP_ID)"></u-button>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

<script>

import {getServiceUnitList} from "../../api";

export default {
  data() {
    return {
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  onLoad() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getServiceUnitList({
        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();
    },
    fnView(SERVICE_COMPANY_USER_MAP_ID) {
      uni.$u.route({
        url: '/pages/service_unit_management/view',
        params: {
          SERVICE_COMPANY_USER_MAP_ID
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
