<template>
  <div class="container" style="max-height: 750px; overflow-y: auto; padding: 10px">
    <img
      src="@/assets/file/no_data.png"
      alt="暂无数据"
      v-if="approvalItems.length === 0"
      style="position: absolute; top: 30%; left: 43%"
    />
    <bns-timeline-tabs
      :is-examine="false"
      :btn-show="false"
      :show-type="1"
      :show-position="2"
      :items="approvalItems"
      audit-type="审核记录"
      :audit-record-type="paramsData.auditRecordType ? '全部' : '部分'"
      v-else
    ></bns-timeline-tabs>
    <div class="footer" style="position: absolute; top: 90%; left: 95%">
      <el-button type="primary" :plain="true" @click="close">关闭</el-button>
    </div>
  </div>
</template>
<script>
import BnsTimelineTabs from '@/components/pro-tabs/bns-timeline-tabs.vue'
import { approvalHistoryOld } from '@/api/terminalEquipment/deviceInformation'
import { decryptCBC } from '@/utils/aescbc'

export default {
  components: {
    BnsTimelineTabs,
  },
  data() {
    return {
      // 遮罩层
      loading: false,
      paramsData: {},
      type: 0,
      approvalItems: [],
    }
  },
  created() {
    const params = this.$route.params && this.$route.params.data
    this.paramsData = JSON.parse(decryptCBC(params))
    this.approvalHistory()
  },
  methods: {
    approvalHistory() {
      let checkType = '2' //1最新   2全部
      approvalHistoryOld({ taskId: this.paramsData.taskId, checkType: checkType }).then(res => {
        if (this.paramsData.hasOwnProperty('taskType')) {
          const hasDoubleAt = res.data.some(item => item.reason.includes('@@'))
          if (hasDoubleAt) {
            this.approvalItems = res.data.map(item => ({
              ...item,
              // reason: item.reason.split('@@')[4] || '',
              reason: item.reason.replaceAll('@', ''),
            }))
          } else {
            this.approvalItems = res.data
          }
        } else {
          this.approvalItems = res.data.map(item => ({
            ...item,
            // reason: item.reason ? item.reason.replaceAll(/@@/g, ' ') : '',
            reason: item.reason ? item.reason.replaceAll('@', '') : '',
          }))
        }
      })
    },
    close() {
      this.$tab.closePage()
    },
  },
}
</script>
<style scoped></style>
