<template>
  <el-dialog
    title="通知记录"
    :visible.sync="visible"
    width="70%"
    :before-close="handleClose"
    append-to-body
  >
    <div class="dialog-content">
      <div class="dialog-header">
        <div class="order-info">
          <span>订单号: {{ orderInfo ? orderInfo.orderId : '' }}</span>
          <span style="margin-left: 20px">客户: {{ orderInfo ? orderInfo.name : '' }}</span>
        </div>
        <el-button type="primary" size="mini" icon="el-icon-refresh" @click="refresh">刷新</el-button>
      </div>

      <el-table
        :max-height="400"
        :data="recordList"
        style="width: 100%"
        v-loading="loading"
        border
        stripe
      >
        <el-table-column label="主叫号码" align="left" prop="displayNumber" />
        <el-table-column label="被叫号码" align="left" prop="calleeNumber" />
        <el-table-column label="通话时长" align="left" prop="duration" />

        <el-table-column label="呼叫开始时间" align="center" width="180">
          <template slot-scope="scope">
            {{ parseTime(scope.row.startCallTime) }}
          </template>
        </el-table-column>
        
        <el-table-column label="呼叫结束时间" align="center" width="180">
          <template slot-scope="scope">
            {{ parseTime(scope.row.endTime) }}
          </template>
        </el-table-column>
      

        <el-table-column label="状态" align="center" width="100">
          <template slot-scope="scope">
            <el-tag :type="scope.row.callState === 1 ? 'success' : 'info'">
              {{ scope.row.status === 1 ? '已送达' : '未送达' }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table>

      <div v-if="!recordList || recordList.length === 0" class="empty-record">
        <i class="el-icon-document"></i>
        <p>暂无记录信息</p>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import { getNotifyRecords } from "@/api/system/Order"

export default {
  name: "NotifyRecord",
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    orderInfo: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      recordList: [],
      loading: false
    }
  },
  watch: {
    visible(val) {
      if (val && this.orderInfo) {
        this.getList()
      }
    }
  },
  mounted(){
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      getNotifyRecords(this.orderInfo.orderId).then(response => {
        this.recordList = response.data
        this.loading = false
      }).catch(() => {
        this.loading = false
        this.$message.error('获取记录失败')
      })
    },
    getNotifyTypeTag(type) {
      const typeMap = {
        1: 'success',
        2: 'warning',
        3: 'info'
      }
      return typeMap[type] || 'info'
    },
    getNotifyTypeName(type) {
      const typeMap = {
        1: '接单通知',
        2: '服务通知',
        3: '系统通知'
      }
      return typeMap[type] || '其他通知'
    },
    refresh() {
      this.getList()
    },
    handleClose() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="scss" scoped>
.dialog-content {
  min-height: 300px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.order-info {
  font-weight: bold;
  font-size: 14px;
}

.empty-record {
  padding: 40px 0;
  text-align: center;
  color: #909399;
}

.empty-record i {
  font-size: 40px;
  margin-bottom: 15px;
}
</style>
