<template>
  <view class="content">
    <view class="search card">
      <u--input
          prefixIcon="search"
          placeholder="请输入关键字"
          border="surround"
          v-model="KEYWORDS"
          clearable
          shape="circle"
      ></u--input>
      <view class="bth-mini ml-10">
        <u-button type="success" text="确定" @click="resetList"></u-button>
      </view>

    </view>
    <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.INSPECTION_PLACE }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>
              检查状态：{{ state[item.INSPECTION_STATUS] }}
            </text>
            <text>
              检查类型：{{ item.INSPECTION_TYPE_NAME }}
            </text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text class="u-line-1">检查人：{{ item.INSPECTION_USERS }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>被检查人：{{ item.PERSON_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>检查时间：{{ item.INSPECTION_TIME_START }}-{{ item.INSPECTION_TIME_END }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>检查隐患数：{{ item.HIDDEN_COUNT }}</text>

            <view>
              <u-button type="primary" text="查看" size="mini"
                        @click="fnNavigatorDetail(item.KEYPROJECTCHECK_ID,'view')"></u-button>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
    <fab-button @click="fnNavigatorDetail('', 'add')"/>
  </view>
</template>

<script>
import {getKeyProjectsCheckList} from "../../../api";
import FabButton from "@/components/fab_button/index.vue";

export default {
  components: {FabButton},
  data() {
    return {
      KEYWORDS: '',
      CORPINFO_ID: '',
      OUTSOURCED_ID: '',
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
      state: {
        '-1': '检查人驳回',
        '0': '待被检查人确认',
        '1': '被检查人已确认',
        '2': '已归档',
      }
    }
  },
  onLoad(e) {
    this.OUTSOURCED_ID = e.OUTSOURCED_ID,
        this.CORPINFO_ID = this.$route.query.CORPINFO_ID
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getKeyProjectsCheckList({
        KEYWORDS: this.KEYWORDS,
        OUTSOURCED_ID: this.OUTSOURCED_ID,
        CORPINFO_ID: this.CORPINFO_ID,
        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()
    },
    fnNavigatorDetail(KEYPROJECTCHECK_ID, type) {
      uni.$u.route({
        url: '/pages/key-project-management/safety-environmental-inspection/detail',
        params: {
          KEYPROJECTCHECK_ID,
          type,
          CORPINFO_ID: this.CORPINFO_ID,
          OUTSOURCED_ID: this.OUTSOURCED_ID
        }
      })
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.getData();
    },
  }
}
</script>

<style scoped lang="scss">
.see_btn {
  width: 200rpx;
  float: right;
}

</style>
