<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.INSPECTED_DEPARTMENT_NAME }}</text>
          </view>
          <view class="flex-between mt-10 subtitle">
            <text>
              状态：
              <template v-if="item.HIDDEN_STATUS == '101'">待指派确认人</template>
              <template v-else-if="item.HIDDEN_STATUS == '1'">待整改</template>
              <template v-else-if="item.HIDDEN_STATUS == '2'">待验收</template>
              <template v-else-if="item.HIDDEN_STATUS == '10'">验收打回</template>
              <template v-else-if="item.HIDDEN_STATUS == '4'">已验收</template>
              <template v-else-if="item.HIDDEN_STATUS == '-2'">已指派确认人</template>
              <template v-else-if="item.HIDDEN_STATUS == '8'">特殊处置通过</template>
              <template v-else-if="item.HIDDEN_STATUS == '16'">确认打回</template>
              <template v-else-if="item.HIDDEN_STATUS == '7'">待处理的特殊隐患</template>
            </text>
            <view class="flex-end">
              <u-button type="primary" text="查看" size="mini"
                        @click="fnNavigatorAcceptance(item.INSPECTION_ID, item.HIDDEN_ID, 'view')"></u-button>
              <view class="ml-10"
                    v-show="item.CREATOR === userInfo.USER_ID && (item.HIDDEN_STATUS === '4' || item.HIDDEN_STATUS === '8') && (!item.FINAL_CHECK || item.FINAL_CHECK === '2')">
                <u-button
                    type="primary" text="验收" size="mini"
                    @click="fnNavigatorAcceptance(item.INSPECTION_ID, item.HIDDEN_ID, 'acceptance')"></u-button>
              </view>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

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

export default {
  data() {
    return {
      INSPECTION_ID: '',
      pageSize: 100,
      currentPage: 1,
      totalPage: 0,
      list: [],
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onLoad(event) {
    this.INSPECTION_ID = event.INSPECTION_ID
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getListForSafetyEnvironmental({
        INSPECTION_ID: this.INSPECTION_ID,
        INSPECTION_STATUS: '3-7',
        showCount: this.pageSize,
        currentPage: this.currentPage,
      });
      this.list = [...this.list, ...resData.varList];
      this.totalPage = resData.page.totalPage;
    },
    resetList() {
      this.pageSize = 100
      this.currentPage = 1
      this.list = []
      this.getData()
    },
    fnNavigatorAcceptance(INSPECTION_ID, HIDDEN_ID, type) {
      uni.$u.route({
        url: '/pages/safety-environmental-inspection/inspector-archives/acceptance',
        params: {
          INSPECTION_ID,
          HIDDEN_ID,
          type
        }
      })
    },
    scrolltolower() {
      this.currentPage++;
      if (this.totalPage >= this.currentPage) this.getData();
    },
  }
}
</script>

<style scoped>

</style>
