<template>
  <view class="content">
    <u-cell-group>
      <u-cell v-for="(item,index) in baseList" :key="index" isLink :url="item.url">
        <view slot="title">{{ item.title }}</view>
        <view slot="value">
          <u-badge :value="item.NUM"></u-badge>
        </view>
      </u-cell>
    </u-cell-group>
  </view>
</template>

<script>
import {getSafetyenvironmentalRedPoint} from "@/api";

export default {
  data() {
    return {
      baseList: [{
        title: '安全环保检查发起',
        url: '/pages/safety-environmental-inspection/initiate/list',
        vector: '0',
        NUM: 0
      },
        {
          title: '检查人确认',
          url: '/pages/safety-environmental-inspection/inspector-confirms/list',
          vector: '1',
          NUM: 0
        },
        {
          title: '隐患指派及验收',
          url: '/pages/safety-environmental-inspection/inspector-archives/list',
          vector: '2',
          NUM: 0
        },
        {
          title: '申辩记录',
          url: '/pages/safety-environmental-inspection/defense-record/list',
          vector: '3',
        }
      ]
    }
  },
  computed: {
    userInfo() {
      return this.$store.getters.getUserInfo
    }
  },
  onShow(event) {
    this.getRedPoint()
  },
  methods: {
    fnNavigator(e) {
      uni.$u.route({
        url: this.baseList[e].url
      })
    },
    async getRedPoint() {
      let resData = await getSafetyenvironmentalRedPoint({
        CORPINFO_ID: this.userInfo.CORPINFO_ID,
        INSPECTION_USER_ID: this.userInfo.USER_ID,
        INSPECTED_SITEUSER_ID: this.userInfo.USER_ID,
        INSPECTION_ORIGINATOR_ID: this.userInfo.USER_ID
      });

      for (const baseListKey in this.baseList) {
        if(this.baseList[baseListKey].vector === '0'){
          this.baseList[baseListKey].NUM = resData.repulseCount.repulseCount?resData.repulseCount.repulseCount:0
        }
        if(this.baseList[baseListKey].vector === '1'){
          this.baseList[baseListKey].NUM = resData.confirmCount.confirmCount?resData.confirmCount.confirmCount:0
        }
        if(this.baseList[baseListKey].vector === '2'){
          this.baseList[baseListKey].NUM = resData.repulseAndCheckCount.repulseAndCheckCount?resData.repulseAndCheckCount.repulseAndCheckCount:0
        }
      }

    },
  },
}
</script>

<style scoped>

</style>
