<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">
            <view class="u-line-1">{{ item.HIDDENDESCR || "暂无" }}</view>
            <view :class="HIDDEN_LEVEL_COlOR[item.HIDDENLEVEL]">
              {{ item.HIDDENLEVELNAME }}
            </view>
          </view>
          <view class="flex-between mt-10 subtitle">
            <view>来源：{{ HIDDEN_SOURCE[item.SOURCE] }}</view>
          </view>
          <view class="flex-between subtitle mt-5">
            <view>隐患发现人：{{ item.findUserNames || "暂无" }}</view>
            <view>
              隐患发现时间：{{ item.DISCOVERYTIME ? formatDate(item.DISCOVERYTIME) : "暂无" }}
            </view>
          </view>
          <view class="flex-between subtitle mt-5">
            <view>隐患确认人：{{ item.confirmUserName || "暂无" }}</view>
            <view>
              隐患确认时间：{{ item.CONFIRM_TIME ? formatDate(item.CONFIRM_TIME) : "暂无" }}
            </view>
          </view>
          <view class="flex-between mt-10 subtitle">
            <view></view>
            <view class="flex-between">
              <u-button type="primary" text="整改" size="mini" @click="fnRectification(item.HIDDEN_ID)"></u-button>
            </view>
          </view>
        </view>
      </u-list-item>
    </u-list>
    <empty v-else></empty>
  </view>
</template>

<script>
import {getHiddenList} from "../../api/api";
import dayjs from 'dayjs'

export default {
  data() {
    return {
      pageSize: 10,
      currentPage: 1,
      totalPage: 0,
      list: [],
      HIDDEN_LEVEL_COlOR: {
        hiddenLevel1001: "yellow-bg",
        hiddenLevel1002: "yellow-bg",
        hiddenLevel1004: "yellow-bg",
        hiddenLevel2001: "red-bg",
        hiddenLevel2002: "red-bg",
      },
      HIDDEN_SOURCE: {
        1: "隐患快报",
        2: "清单排查",
        3: "清单排查",
        4: "安全环保检查（监管端）",
        5: "安全环保检查（企业端）",
        6: "消防检查",
      }
    }
  },
  onShow() {
    this.resetList()
  },
  methods: {
    async getData() {
      let resData = await getHiddenList({
        DISPOSESTATE: 2,
        isIndex: 0,
        USERDEPT: this.$store.getters.getUserInfo.DEPARTMENT_ID,
        SELFUSERID: this.$store.getters.getUserInfo.USER_ID,
        currentPage: this.currentPage,
        showCount: this.pageSize,
        totalResult: 0,
        postMethod: 'application/json',
        XGF_CORPINFO_ID: this.$store.getters.getUserInfo.CORPINFO_ID,
        CORPINFO_ID: ''
      });
      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();
    },
    formatDate(date) {
      return dayjs(date).format("YYYY-MM-DD")
    },
    fnRectification(HIDDEN_ID) {
      uni.$u.route({
        url: '/pages/hidden_rectification/rectification',
        params: {HIDDEN_ID,}
      })
    },
  }
}
</script>

<style scoped lang="scss">
.yellow-bg {
  color: #fbbd08;
  background-color: #fef2ce;
  padding: 10rpx 20rpx;
  font-size: 24rpx;
  border-radius: 10rpx;
}

.red-bg {
  color: #e54d42;
  background-color: #fadbd9;
  padding: 10rpx 20rpx;
  font-size: 24rpx;
  border-radius: 10rpx;
}
</style>
