<template>
  <el-dialog 
    title="历史开单记录详情" 
    :visible.sync="visible" 
    :close-on-click-modal="false"
    class="NCC-dialog NCC-dialog_center" 
    width="1000px"
    @close="handleClose">
    <div class="detail-content" v-loading="loading">
      <!-- 基本信息卡片 -->
      <el-card class="info-card" shadow="hover">
        <div slot="header" class="card-header">
          <i class="el-icon-tickets"></i>
          <span class="card-title">基本信息</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="info-item"> 
              <label class="info-label">
                <i class="el-icon-document"></i>
                ID：
              </label>
              <span class="info-value highlight">{{ dataForm.id || '无' }}</span>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-tickets"></i>
                开单号：
              </label>
              <span class="info-value highlight">{{ dataForm.orderNo || '无' }}</span>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-picture"></i>
                图片名称：
              </label>
              <span class="info-value">{{ dataForm.imageName || '无' }}</span>
            </div>
          </el-col>
        </el-row>
      </el-card>

      <!-- 会员信息卡片 -->
      <el-card class="info-card" shadow="hover">
        <div slot="header" class="card-header">
          <i class="el-icon-user"></i>
          <span class="card-title">会员信息</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-user"></i>
                会员编号：
              </label>
              <span class="info-value">{{ dataForm.memberNo || '无' }}</span>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-phone"></i>
                会员手机号：
              </label>
              <span class="info-value">{{ dataForm.memberPhone || '无' }}</span>
            </div>
          </el-col>
          <el-col :span="8">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-user-solid"></i>
                会员名称：
              </label>
              <span class="info-value">{{ dataForm.memberName || '无' }}</span>
            </div>
          </el-col>
        </el-row>
      </el-card>

      <!-- 备注信息卡片 -->
      <el-card class="info-card" shadow="hover" v-if="dataForm.remarks">
        <div slot="header" class="card-header">
          <i class="el-icon-edit-outline"></i>
          <span class="card-title">备注信息</span>
        </div>
        <div class="info-item">
          <div class="remarks-content">{{ dataForm.remarks || '无' }}</div>
        </div>
      </el-card>

      <!-- 时间信息卡片 -->
      <el-card class="info-card" shadow="hover">
        <div slot="header" class="card-header">
          <i class="el-icon-time"></i>
          <span class="card-title">时间信息</span>
        </div>
        <el-row :gutter="20">
          <el-col :span="12">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-time"></i>
                创建时间：
              </label>
              <span class="info-value">{{ formatDateTime(dataForm.createdAt) || '无' }}</span>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="info-item">
              <label class="info-label">
                <i class="el-icon-time"></i>
                更新时间：
              </label>
              <span class="info-value">{{ formatDateTime(dataForm.updatedAt) || '无' }}</span>
            </div>
          </el-col>
        </el-row>
      </el-card>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleClose">关闭</el-button>
    </div>
  </el-dialog>
</template>

<script>
import request from '@/utils/request'

export default {
  name: 'DetailDialog',
  data() {
    return {
      visible: false,
      loading: false,
      dataForm: {
        id: null,
        orderNo: '',
        imageName: '',
        memberNo: '',
        memberPhone: '',
        memberName: '',
        remarks: '',
        createdAt: null,
        updatedAt: null
      }
    }
  },
  methods: {
    // 初始化
    init(id) {
      this.visible = true
      if (id) {
        this.getInfo(id)
      }
    },
    // 获取详情
    getInfo(id) {
      this.loading = true
      request({
        url: `/api/Extend/LqOrderRecords/${id}`,
        method: 'GET'
      }).then(res => {
        if (res.code === 200) {
          this.dataForm = res.data || {}
        } else {
          this.$message.error(res.msg || '获取详情失败')
        }
        this.loading = false
      }).catch(error => {
        console.error('获取历史开单记录详情失败:', error)
        this.$message.error('获取详情失败')
        this.loading = false
      })
    },
    // 关闭
    handleClose() {
      this.visible = false
      this.dataForm = {
        id: null,
        orderNo: '',
        imageName: '',
        memberNo: '',
        memberPhone: '',
        memberName: '',
        remarks: '',
        createdAt: null,
        updatedAt: null
      }
    },
    // 格式化日期时间
    formatDateTime(dateTime) {
      if (!dateTime) return '无'
      const date = new Date(dateTime)
      if (isNaN(date.getTime())) return '无'
      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')
      const seconds = String(date.getSeconds()).padStart(2, '0')
      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
    }
  }
}
</script>

<style lang="scss" scoped>
.detail-content {
  padding: 10px 0;
//   max-height: 70vh;
//   overflow-y: auto;
}

.info-card {
  margin-bottom: 20px;
  border-radius: 8px;
  transition: all 0.3s;
  
  &:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  }
  
  &:last-child {
    margin-bottom: 0;
  }
  
  ::v-deep .el-card__header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #f5f7fa 0%, #ffffff 100%);
    border-bottom: 1px solid #e4e7ed;
  }
  
  ::v-deep .el-card__body {
    padding: 20px;
  }
}

.card-header {
  display: flex;
  align-items: center;
  
  i {
    margin-right: 8px;
    color: #409EFF;
    font-size: 18px;
  }
  
  .card-title {
    font-size: 16px;
    font-weight: 600;
    color: #303133;
  }
}

.info-item {
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  padding: 8px 0;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  .info-label {
    min-width: 120px;
    color: #606266;
    font-weight: 500;
    display: flex;
    align-items: center;
    margin-right: 12px;
    
    i {
      margin-right: 6px;
      color: #909399;
      font-size: 14px;
    }
  }
  
  .info-value {
    flex: 1;
    color: #303133;
    word-break: break-all;
    font-size: 14px;
    
    &.highlight {
      color: #409EFF;
      font-weight: 600;
    }
  }
}

.remarks-content {
  padding: 12px 16px;
  background: #f5f7fa;
  border-radius: 6px;
  color: #303133;
  line-height: 1.6;
  word-break: break-all;
  white-space: pre-wrap;
  border-left: 3px solid #409EFF;
}

.dialog-footer {
  text-align: right;
  padding: 20px 0 0;
  border-top: 1px solid #e4e7ed;
  margin-top: 10px;
}

.dialog-footer .el-button {
  margin-left: 10px;
}

// 滚动条样式优化
.detail-content::-webkit-scrollbar {
  width: 6px;
}

.detail-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.detail-content::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
  
  &:hover {
    background: #a8a8a8;
  }
}
</style>

