<template>
  <view>
    <Navbar title="工程审批" />
    <div class="content">
      <!-- 数据列表 -->
      <div class="list-item" v-for="(item, index) in approvalList" :key="index" @click="handleItem(item)">
        <div class="item-wrapper">
          <!-- <div class="item-time">{{ item.time || '-' }}</div> -->
          <div>{{ item.label }}</div>
        </div>
        <div><u-badge type="error" max="9999" :value="item.tipValue" /></div>
      </div>
    </div>
  </view>
</template>

<script>
import { getExamineList } from '@/api/project'

export default {
  data() {
    return {
      params: {},
      approvalList: [],
      toBeReviewedList: []
    }
  },
  onLoad(opt) {
    this.params = JSON.parse(opt.params)
    console.log('工程审批', this.params)
  },
  mounted() {
    this.getExamineList()
  },
  methods: {
    handleItem(item) {
      console.log('工程审批--Item', item)
      const params = {
        supUuid: this.params.supUuid,
        proId: this.params.id,
        consUuid: this.params.consUuid
      }
      const baseUrl = `/pages/projectApproval/approvalList?id=${item.value}&title=`
      const routes = {
        1: `${item.label}&params=${JSON.stringify(params)}`,
        2: `${item.label}&isContractor=true&params=${JSON.stringify(params)}`,
        3: `${item.label}&isSubcontractor=true&params=${JSON.stringify(params)}`,
        4: `${item.label}&isContractor=true&params=${JSON.stringify(params)}`,
        5: `${item.label}&isContractor=true&isPersonnel=true&params=${JSON.stringify(params)}`,
        6: `${item.label}&isContractor=true&isPersonnel=true&params=${JSON.stringify(params)}`,
        7: `${item.label}&isContractor=true&params=${JSON.stringify(params)}`,
        8: `${item.label}&isTools=true&params=${JSON.stringify(params)}`,
        9: `${item.label}&isContractor=true&params=${JSON.stringify(params)}`,
        10: `${item.label}&isSubcontractor=true&isPersonnel=true&params=${JSON.stringify(params)}`,
        11: `${item.label}&isSubcontractor=true&isPersonnel=true&params=${JSON.stringify(params)}`,
        12: `${item.label}&isSubcontractor=true&params=${JSON.stringify(params)}`
      }

      const url = baseUrl + routes[item.value]
      if (url) {
        uni.navigateTo({ url })
      } else {
        console.log('err--无匹配')
      }
    },
    // 审批列表
    async getExamineList() {
      const params = {
        proId: this.params.id,
        personnelId: uni.getStorageSync('userInfo').userId
      }
      console.log('🚀 ~ 审批列表 ~ params:', params)
      const res = await getExamineList(params)
      console.log('审批列表', res)
      if (res.code === 200) {
        this.approvalList = res.examineList
        this.toBeReviewedList = res.toBeReviewedList
        this.toBeReviewedList.forEach(item => {
          this.approvalList.forEach(list => {
            if (item.taskType == list.value) {
              list.tipValue = item.nums
            }
          })
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  padding: 0 20px 20px;

  .list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 18px 0;
    padding: 0 10px;
    height: 55px;
    background: rgba(56, 136, 255, 0.05);
    border-radius: 3px 3px 3px 3px;
    border: 0.5px solid #3888ff;
    font-weight: 400;
    font-size: 12px;
    color: #0a2640;

    .item-wrapper {
      height: 55px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: flex-start;
      .item-time {
        color: rgba(15, 39, 75, 0.5);
      }
    }
  }
}
</style>
