<template>
  <div>
    <uni-section title="审核记录" type="line"></uni-section>
    <div class="cont">
      <div class="list" v-for="(list, listIndex) in tableList" :key="listIndex">
        <div v-if="opt.current == 1" style="margin-bottom: 10px">批次{{ listIndex + 1 }}</div>
        <div class="list-cont" v-for="(item, index) in list.recordVoList" :key="index">
          <div class="top-item">
            <div class="left-item">
              <div class="circle"></div>
              <div class="date">{{ formatDate(item.createTime) }}</div>
            </div>

            <div class="time">
              <u-icon name="clock" style="margin-right: 5px"></u-icon>
              {{ item.createTime }}
            </div>
          </div>
          <div class="item-cont">
            <div><u-icon name="/static/images/user.png" size="36" style="margin-right: 5px"></u-icon></div>
            <div>
              <div style="margin-bottom: 15px">
                <span>{{ item.userName }}</span>
                <span style="margin-right: 10px">（{{ item.phone }}）</span>
                <span style="color: #bbb">{{ item.type == 2 ? '供应商' : '机具分公司' }}</span>
              </div>
              <div style="margin-bottom: 6px">
                <span v-if="item.type == 2">提交派车</span>
                <span v-else>
                  <span v-if="item.auditStatus == 1">完结-审核确认通过, 共耗时: {{ item.times }}</span>
                  <span v-else>驳回-给发起人{{ list.recordVoList[index - 1].userName }}, 共间隔: {{ item.times }}</span>
                </span>
              </div>
              <div>备注：{{ item.remark || '无' }}</div>
            </div>
          </div>
        </div>
      </div>

      <!-- 空状态 -->
      <u-empty v-if="tableList.length == 0" mode="data"></u-empty>
    </div>
  </div>
</template>

<script>
import { getAuditDetails } from '@/api/carManage'

export default {
  props: {
    opt: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      tableList: []
    }
  },
  mounted() {
    console.log('🚀 ~ 详情 ~ this.opt', this.opt)
    this.getAuditDetails()
  },
  methods: {
    // 获取审核记录
    async getAuditDetails() {
      try {
        let params = {}
        if (this.opt.current == 1) {
          params = {
            encryptedData: JSON.stringify({ planId: this.opt.planId })
          }
        } else {
          params = {
            encryptedData: JSON.stringify({ outId: this.opt.outId })
          }
        }
        const res = await getAuditDetails(params)
        console.log('🚀 ~ 审核记录 ~ res', res)
        this.tableList = res.data
      } catch (error) {
        console.log('🚀 ~ 审核记录 ~ error', error)
      }
    },
    formatDate(dateString) {
      const date = new Date(dateString)
      const month = String(date.getMonth() + 1).padStart(2, '0')
      const day = String(date.getDate()).padStart(2, '0')
      return `${month}-${day}`
    }
  }
}
</script>

<style lang="scss" scoped>
.cont {
  padding: 15px;
  .top-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #666;

    .left-item {
      display: flex;
      align-items: center;
    }
    .circle {
      width: 8px;
      height: 8px;
      border: 3px solid #409eff;
      border-radius: 50%;
      margin-right: 15px;
    }

    .time {
      margin-right: 15px;
      display: flex;
      align-items: center;
    }
  }
  .item-cont {
    margin: 20px 0 20px 50px;
    padding: 10px;
    background-color: #fff;
    color: #666;
    border-radius: 8px;
    box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: flex-start;
  }
}
</style>
