<!--通话记录卡片组件-->
<template>
  <view class="call-record-card">
    <view class="call-header">
      <view class="call-time">{{ formatCallTime(record.communication_time) }}</view>
      <view class="call-result">{{ getCallResult(record.communication_result) }}</view>
    </view>
    
    <view class="call-info">
      <view class="info-row">
        <text class="info-label">通话类型：</text>
        <text class="info-value">{{ getCallType(record.communication_type) }}</text>
      </view>
      <view class="info-row">
        <text class="info-label">通话时间：</text>
        <text class="info-value">{{ formatCallTime(record.communication_time) }}</text>
      </view>
    </view>
    
    <view class="call-notes">
      <view class="notes-header">
        <text class="notes-label">通话备注：</text>
        <view class="edit-btn" @click="handleEdit">
          <text class="edit-text">编辑</text>
        </view>
      </view>
      <text class="notes-content" v-if="record.remarks">{{ record.remarks }}</text>
      <text class="notes-placeholder" v-else>暂无备注信息</text>
    </view>
  </view>
</template>

<script>
export default {
  name: 'CallRecordCard',
  props: {
    record: {
      type: Object,
      required: true
    }
  },
  methods: {
    formatCallTime(time) {
      if (!time) return '未知时间'
      // 如果有工具方法则使用，否则使用内置格式化
      if (this.$util && this.$util.formatToDateTime) {
        return this.$util.formatToDateTime(time, 'Y-m-d H:i')
      }
      // 内置格式化方法
      const date = new Date(time)
      const year = date.getFullYear()
      const month = String(date.getMonth() + 1).padStart(2, '0')
      const day = String(date.getDate()).padStart(2, '0')
      const hours = String(date.getHours()).padStart(2, '0')
      const minutes = String(date.getMinutes()).padStart(2, '0')
      return `${year}-${month}-${day} ${hours}:${minutes}`
    },
    
    getCallType(type) {
      const typeMap = {
        'phone': '电话',
        'message': '消息',
        'wechat': '微信',
        'qq': 'QQ'
      }
      return typeMap[type] || type || '电话'
    },
    
    getCallResult(result) {
      const resultMap = {
        'success': '成功',
        'failed': '失败',
        'busy': '忙线',
        'no_answer': '未接听'
      }
      return resultMap[result] || result || '未知'
    },
    
    handleEdit() {
      // 触发父组件的编辑事件
      this.$emit('remark', this.record)
    }
  }
}
</script>

<style lang="less" scoped>
.call-record-card {
  background-color: #1a1a1a;
  border-radius: 15rpx;
  padding: 25rpx;
  margin-bottom: 20rpx;
  border: 1rpx solid #333;
}

.call-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20rpx;
  
  .call-time {
    color: white;
    font-size: 26rpx;
    font-weight: bold;
  }
  
  .call-result {
    color: #29d3b4;
    font-size: 22rpx;
    background-color: rgba(41, 211, 180, 0.2);
    padding: 6rpx 15rpx;
    border-radius: 15rpx;
  }
}

.call-info {
  .info-row {
    display: flex;
    align-items: center;
    margin-bottom: 15rpx;
    
    .info-label {
      color: #999;
      font-size: 22rpx;
      width: 150rpx;
      flex-shrink: 0;
    }
    
    .info-value {
      color: white;
      font-size: 22rpx;
      flex: 1;
    }
  }
}

.call-notes {
  margin-top: 15rpx;
  padding-top: 15rpx;
  border-top: 1rpx solid #333;
  
  .notes-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8rpx;
    
    .notes-label {
      color: #999;
      font-size: 22rpx;
    }
    
    .edit-btn {
      background-color: #29d3b4;
      color: white;
      padding: 6rpx 15rpx;
      border-radius: 15rpx;
      font-size: 20rpx;
      
      .edit-text {
        color: white;
        font-size: 20rpx;
      }
    }
  }
  
  .notes-content {
    color: white;
    font-size: 22rpx;
    line-height: 1.5;
    word-break: break-all;
  }
  
  .notes-placeholder {
    color: #666;
    font-size: 22rpx;
    font-style: italic;
  }
}
</style>