<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="设备编号" prop="deviceId">
        <el-input v-model="queryParams.deviceId" placeholder="请输入设备编号关键词" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="设备名称" prop="deviceName">
        <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称关键词" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="告警等级" prop="alertLevel">
        <el-select v-model="queryParams.alertLevel" placeholder="所有告警等级" clearable>
          <el-option v-for="dict in dict.type.alert_level" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="设备类型" prop="deviceType">
        <el-select v-model="queryParams.deviceType" placeholder="所有设备类型" clearable>
          <el-option v-for="dict in dict.type.alert_device_type" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="所属地块" prop="fieldId">
        <el-select v-model="queryParams.fieldId" placeholder="所有地块" clearable>
          <el-option
            v-for="dict in dict.type.field_list"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->

      <el-form-item label="所属地块" prop="fieldIdList">
        <el-select v-model="queryParams.fieldIdList" placeholder="请选择地块" multiple collapse-tags filterable clearable>
          <el-option v-for="dict in fieldIdList" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <!-- <el-form-item label="所属农场" prop="farmId">
        <el-select v-model="queryParams.farmId" placeholder="所有农场" clearable>
          <el-option
            v-for="dict in dict.type.farm_list"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->


      <el-form-item label="所属农场" prop="deptIdList">
        <treeselect v-model="queryParams.deptIdList" :options="deptOptions" multiple :flat="true" :limit="1"
          :limitText="count => `+${count}`" style="width:200px" :show-count="true" placeholder="请选所属农场" />
      </el-form-item>


      <el-form-item label="告警时间">
        <el-date-picker v-model="daterangeAlertTime" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="至" start-placeholder="年/月/日" end-placeholder="年/月/日"></el-date-picker>
      </el-form-item>
      <el-form-item label="处理状态" prop="processStatus">
        <el-select v-model="queryParams.processStatus" placeholder="所有状态" clearable>
          <el-option v-for="dict in dict.type.alert_process_status" :key="dict.value" :label="dict.label"
            :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 告警统计面板 -->
    <div class="statistics-panel">
      <el-row :gutter="20">
        <el-col :span="6">
          <div class="stat-card total">
            <div class="stat-header">
              <span class="stat-title">今日告警总数</span>
            </div>
            <div class="stat-content">
              <div class="stat-number">{{ todayStatistics.total }}</div>
              <div class="stat-change" :class="todayStatistics.change >= 0 ? 'increase' : 'decrease'">
                <span>较昨日 {{ todayStatistics.change >= 0 ? '+' : '' }}{{ todayStatistics.change }}</span>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="stat-card emergency">
            <div class="stat-header">
              <span class="stat-title">紧急告警</span>
            </div>
            <div class="stat-content">
              <div class="stat-number">{{ levelStatistics.emergency.total }}</div>
              <div class="stat-detail">
                <span>未处理: {{ levelStatistics.emergency.unprocessed }}</span>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="stat-card warning">
            <div class="stat-header">
              <span class="stat-title">警告</span>
            </div>
            <div class="stat-content">
              <div class="stat-number">{{ levelStatistics.warning.total }}</div>
              <div class="stat-detail">
                <span>未处理: {{ levelStatistics.warning.unprocessed }}</span>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="6">
          <div class="stat-card info">
            <div class="stat-header">
              <span class="stat-title">提示信息</span>
            </div>
            <div class="stat-content">
              <div class="stat-number">{{ levelStatistics.info.total }}</div>
              <div class="stat-detail">
                <span>未处理: {{ levelStatistics.info.unprocessed }}</span>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['base:record:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordList">
      <el-table-column label="告警ID" align="center" prop="alertId" />
      <el-table-column label="告警等级" align="center" prop="alertLevel">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.alert_level" :value="scope.row.alertLevel" />
        </template>
      </el-table-column>
      <el-table-column label="设备名称" align="center" prop="deviceName" />
      <el-table-column label="设备编号" align="center" prop="deviceId" />
      <el-table-column label="设备类型" align="center" prop="deviceType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.alert_device_type" :value="scope.row.deviceType" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="所属地块" align="center" prop="fieldId" />
      <el-table-column label="所属农场" align="center" prop="farmId" /> -->
      <el-table-column label="所属地块" align="center" key="fieldName" prop="fieldName" />
      <el-table-column label="所属农场" align="center" key="deptName" prop="deptName" />

      <el-table-column label="告警内容" align="center" prop="alertContent" />
      <el-table-column label="告警时间" align="center" prop="alertTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.alertTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理状态" align="center" prop="processStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.alert_process_status" :value="scope.row.processStatus" />
        </template>
      </el-table-column>
      <el-table-column label="处理人" align="center" prop="processor" />
      <el-table-column label="处理时间" align="center" prop="processTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.processTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)">查看</el-button>
          <el-button v-if="scope.row.processStatus == 0 || scope.row.processStatus == '0'" size="mini" type="text"
            icon="el-icon-edit" @click="handleProcess(scope.row)" v-hasPermi="['base:record:edit']">处理</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 告警详情对话框 -->
    <el-dialog title="告警详情" :visible.sync="detailOpen" width="600px" append-to-body>
      <div class="alert-detail">
        <!-- 主要告警信息卡片 -->
        <div class="alert-card">
          <!-- 头部信息 -->
          <div class="alert-header">
            <div class="alert-level-tag">
              <dict-tag :options="dict.type.alert_level" :value="currentRecord.alertLevel" />
            </div>
            <div class="alert-time">{{ parseTime(currentRecord.alertTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</div>
          </div>

          <!-- 告警内容 -->
          <div class="alert-content">
            {{ getAlertContent(currentRecord) }}
          </div>
        </div>

        <!-- 设备信息 -->
        <div class="section">
          <div class="section-title">设备信息</div>
          <div class="device-info">
            <div class="info-grid">
              <div class="info-item">
                <span class="label">设备名称</span>
                <span class="value">{{ currentRecord.deviceName }}</span>
              </div>
              <div class="info-item">
                <span class="label">设备编号</span>
                <span class="value">{{ currentRecord.deviceId }}</span>
              </div>
              <div class="info-item">
                <span class="label">设备类型</span>
                <span class="value">
                  <dict-tag :options="dict.type.alert_device_type" :value="currentRecord.deviceType" />
                </span>
              </div>
              <div class="info-item">
                <span class="label">所属地块</span>
                <span class="value">{{ currentRecord.fieldName }}</span>
              </div>
              <div class="info-item">
                <span class="label">所属农场</span>
                <span class="value">{{ currentRecord.deptName }}</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 处理状态 -->
        <div class="section">
          <div class="section-title">处理状态</div>
          <div class="status-info">
            <div class="status-item">
              <span class="label">当前状态</span>
              <span class="value status">
                <dict-tag :options="dict.type.alert_process_status" :value="currentRecord.processStatus" />
              </span>
            </div>
            <div class="status-item">
              <span class="label">处理人</span>
              <span class="value">{{ currentRecord.processor || '-' }}</span>
            </div>
            <div class="status-item">
              <span class="label">处理时间</span>
              <span class="value">{{ currentRecord.processTime || '-' }}</span>
            </div>
            <div class="status-item full-width">
              <span class="label">处理记录</span>
              <div class="process-record">
                {{ currentRecord.processComment || '暂无处理记录' }}
              </div>
            </div>
          </div>
        </div>

        <!-- 附件信息 -->
        <div class="section">
          <div class="section-title">附件信息</div>
          <div class="attachment-info">
            <div v-if="currentRecord.attachments && currentRecord.attachments.length > 0" class="attachment-list">
              <div v-for="(attachment, index) in getAttachmentList(currentRecord.attachments)" :key="index"
                class="attachment-item">
                <div class="attachment-preview">
                  <i v-if="isImage(attachment.name)" class="el-icon-picture-outline"></i>
                  <i v-else class="el-icon-document"></i>
                </div>
                <div class="attachment-details">
                  <div class="attachment-name" :title="attachment.name">{{ attachment.name }}</div>
                  <div class="attachment-size">{{ formatFileSize(attachment.size) }}</div>
                </div>
                <div class="attachment-actions">
                  <el-button size="mini" type="text" @click="downloadAttachment(attachment)">下载</el-button>
                  <el-button v-if="isImage(attachment.name)" size="mini" type="text"
                    @click="previewImage(attachment)">预览</el-button>
                </div>
              </div>
            </div>
            <div v-else class="no-attachment">
              <i class="el-icon-folder-opened"></i>
              <span>暂无附件</span>
            </div>
          </div>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button @click="detailOpen = false">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 处理告警对话框 -->
    <el-dialog title="处理告警" :visible.sync="processOpen" width="500px" append-to-body>
      <el-form ref="processForm" :model="processForm" :rules="processRules" label-width="80px">
        <el-form-item label="告警信息">
          <div class="process-alert-info">
            <div class="info-item">
              <span class="label">设备编号:</span>
              <span class="value">{{ processForm.deviceId }}</span>
            </div>
            <div class="info-item">
              <span class="label">设备名称:</span>
              <span class="value">{{ processForm.deviceName }}</span>
            </div>
            <div class="alert-content-preview">
              {{ getAlertContent(processForm) }}
            </div>
          </div>
        </el-form-item>
        <el-form-item label="处理结果" prop="processStatus">
          <el-select v-model="processForm.processStatus" placeholder="请选择处理结果">
            <el-option label="未处理" :value="0"></el-option>
            <el-option label="已确认" :value="1"></el-option>
            <el-option label="已处理" :value="2"></el-option>
            <el-option label="忽略" :value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理备注" prop="processComment">
          <el-input v-model="processForm.processComment" type="textarea" :rows="4" placeholder="请输入处理备注..."
            maxlength="500" show-word-limit />
        </el-form-item>
        <el-form-item label="附件上传">
          <file-upload v-model="processForm.attachments" :limit="5" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitProcess" :loading="processLoading">确 定</el-button>
        <el-button @click="cancelProcess">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listRecord, getRecord, updateRecord } from "@/api/base/record"
import { deptTreeSelect } from "@/api/system/user";
import { listFieldName } from "@/api/base/field";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
  name: "Record",
  components: { Treeselect },
  dicts: ['alert_process_status', 'alert_level', 'alert_device_type', 'field_list', 'farm_list'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 告警记录表格数据
      recordList: [],
      // 告警时间范围
      daterangeAlertTime: [],


      // 部门树选项
      deptOptions: undefined,

      // 所属地块
      fieldIdList: [],

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deviceId: null,
        deviceName: null,
        deviceType: null,
        alertLevel: null,
        alertTime: null,
        processStatus: null,
        farmId: null,
        fieldId: null,

        deptIdList: [],
      },
      // 告警详情对话框
      detailOpen: false,
      // 当前记录
      currentRecord: {},
      // 处理告警对话框
      processOpen: false,
      // 处理表单
      processForm: {},
      // 处理规则
      processRules: {
        processStatus: [{ required: true, message: '请选择处理结果', trigger: 'change' }],
        processComment: [{ required: true, message: '请输入处理备注', trigger: 'blur' }],
      },
      // 处理按钮加载中
      processLoading: false,
      // 今日统计数据
      todayStatistics: {
        total: 0,
        change: 0
      },
      // 各等级统计数据
      levelStatistics: {
        emergency: {
          total: 0,
          unprocessed: 0
        },
        warning: {
          total: 0,
          unprocessed: 0
        },
        info: {
          total: 0,
          unprocessed: 0
        }
      }
    }
  },
  created() {
    this.getList()
    this.getStatistics()
    this.getDeptTree();
    this.getFieldNameList();
  },
  methods: {


    /** 查询地块名称 **/
    getFieldNameList() {
      listFieldName().then(res => {
        this.fieldIdList = res;
        this.fieldIdList.forEach(x => {
          x.value = x.id;
          x.label = x.fieldName;
        })
      });
    },


    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
      });
    },
    /** 查询告警记录列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (null != this.daterangeAlertTime && '' != this.daterangeAlertTime) {
        this.queryParams.params["beginAlertTime"] = this.daterangeAlertTime[0]
        this.queryParams.params["endAlertTime"] = this.daterangeAlertTime[1]
      }
      listRecord(this.queryParams).then(response => {
        this.recordList = response.rows
        this.total = response.total
        this.loading = false
        // 获取列表后更新统计数据
        this.updateStatisticsFromList()
      })
    },
    /** 获取统计数据 */
    getStatistics() {
      // 这里可以调用专门的统计API
      // 暂时使用模拟数据
      this.todayStatistics = {
        total: 0,
        change: 0
      }
      this.levelStatistics = {
        emergency: {
          total: 0,
          unprocessed: 0
        },
        warning: {
          total: 0,
          unprocessed: 0
        },
        info: {
          total: 0,
          unprocessed: 0
        }
      }
    },
    /** 从列表数据更新统计 */
    updateStatisticsFromList() {
      if (!this.recordList || this.recordList.length === 0) {
        return
      }

      // 重置统计数据
      this.levelStatistics = {
        emergency: { total: 0, unprocessed: 0 },
        warning: { total: 0, unprocessed: 0 },
        info: { total: 0, unprocessed: 0 }
      }

      // 今日日期
      const toDateStr = (dateLike) =>
        new Date(dateLike).toISOString().slice(0, 10);

      const today = toDateStr(new Date());
      const yesterday = toDateStr(Date.now() - 86400000);

      let todayCount = 0;
      let yesterdayCount = 0;

      this.recordList.forEach(record => {
        if (!record.alertTime) return;          // 空值跳过
        const alertDay = toDateStr(record.alertTime);

        if (alertDay === today) todayCount++;
        if (alertDay === yesterday) yesterdayCount++;
        // 统计各等级告警
        const level = record.alertLevel
        const isUnprocessed = record.processStatus == 0 || record.processStatus == '0'


        if (level == 1 || level == '1') {
          this.levelStatistics.info.total++
          if (isUnprocessed) this.levelStatistics.info.unprocessed++
        } else if (level == 2 || level == '2') {
          this.levelStatistics.warning.total++
          if (isUnprocessed) this.levelStatistics.warning.unprocessed++
        } else if (level == 3 || level == '3') {
          this.levelStatistics.emergency.total++
          if (isUnprocessed) this.levelStatistics.emergency.unprocessed++
        }

      })

      this.todayStatistics.change = todayCount - yesterdayCount;
      // 更新今日统计
      if (todayCount > 0) {
        this.todayStatistics.total = todayCount
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeAlertTime = []
      this.resetForm("queryForm")
      this.handleQuery()
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('base/record/export', {
        ...this.queryParams
      }, `record_${new Date().getTime()}.xlsx`)
    },
    /** 查看告警详情 */
    handleDetail(record) {
      // 可以根据需要调用API获取更详细的信息
      // getRecord(record.alertId).then(response => {
      //   this.currentRecord = response.data
      //   this.detailOpen = true
      // })

      // 当前直接使用列表数据显示
      this.currentRecord = { ...record }
      this.detailOpen = true
    },
    /** 获取告警标题 */
    getAlertTitle(record) {
      // 优先显示设备名称
      if (record.deviceName) {
        return record.deviceName
      }
      // 如果没有设备名称，显示设备编号
      if (record.deviceId) {
        return record.deviceId
      }
      // 最后的默认标题
      return '未知设备'
    },
    /** 获取告警内容 */
    getAlertContent(record) {
      if (!record.alertContent) {
        return '暂无告警内容'
      }

      let content = record.alertContent

      // 尝试去掉设备名称前缀
      // 匹配模式：设备XXX + 告警内容
      const devicePatterns = [
        // 匹配"设备D1001温度异常"格式
        /^设备[A-Za-z0-9]+(.+)$/,
        // 匹配"D1001温度异常"格式
        /^[A-Za-z0-9]+(.+)$/,
        // 匹配设备名称开头的格式
        /^.+?号(.+)$/,
        /^.+?站(.+)$/
      ]

      // 如果告警内容包含设备信息，尝试去掉设备前缀
      if (record.deviceId && content.includes(record.deviceId)) {
        // 去掉设备编号前缀
        content = content.replace(new RegExp(`^.*?${record.deviceId}`, ''), '')
      } else if (record.deviceName && content.includes(record.deviceName)) {
        // 去掉设备名称前缀
        content = content.replace(new RegExp(`^.*?${record.deviceName}`, ''), '')
      } else {
        // 使用通用模式尝试去掉设备前缀
        for (let pattern of devicePatterns) {
          const match = content.match(pattern)
          if (match && match[1]) {
            content = match[1]
            break
          }
        }
      }

      // 清理开头的标点符号
      content = content.replace(/^[：:，,\s]+/, '')

      return content || record.alertContent
    },
    /** 获取附件列表 */
    getAttachmentList(attachments) {
      if (!attachments) return []
      // 如果attachments是字符串，尝试解析为JSON
      if (typeof attachments === 'string') {
        try {
          return JSON.parse(attachments)
        } catch (e) {
          // 如果解析失败，按逗号分割处理
          return attachments.split(',').map(url => ({
            name: this.getFileNameFromUrl(url),
            url: url,
            size: 0
          }))
        }
      }
      // 如果是数组直接返回
      return Array.isArray(attachments) ? attachments : []
    },
    /** 从URL中提取文件名 */
    getFileNameFromUrl(url) {
      if (!url) return '未知文件'
      const parts = url.split('/')
      return parts[parts.length - 1] || '未知文件'
    },
    /** 判断是否为图片 */
    isImage(fileName) {
      if (!fileName) return false
      const imageExts = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp']
      const ext = fileName.toLowerCase().substring(fileName.lastIndexOf('.'))
      return imageExts.includes(ext)
    },
    /** 格式化文件大小 */
    formatFileSize(size) {
      if (!size || size === 0) return '未知大小'
      if (size < 1024) return size + ' B'
      if (size < 1024 * 1024) return (size / 1024).toFixed(1) + ' KB'
      return (size / (1024 * 1024)).toFixed(1) + ' MB'
    },
    /** 下载附件 */
    downloadAttachment(attachment) {
      if (attachment.url) {
        window.open(attachment.url, '_blank')
      } else {
        this.$modal.msgError('附件链接无效')
      }
    },
    /** 预览图片 */
    previewImage(attachment) {
      if (attachment.url) {
        this.$modal.msgInfo('图片预览功能暂未实现，请点击下载查看')
        // 这里可以集成图片预览组件
        // this.$imagePreview([attachment.url])
      }
    },
    /** 处理告警 */
    handleProcess(record) {
      this.resetProcessForm()
      this.currentRecord = { ...record }
      this.processForm = {
        alertId: record.alertId,
        deviceId: record.deviceId,
        deviceName: record.deviceName,
        deviceType: record.deviceType,
        fieldId: record.fieldId,
        farmId: record.farmId,
        alertContent: record.alertContent,
        alertLevel: record.alertLevel,
        alertTime: record.alertTime,
        processStatus: 0, // 默认设为未处理，用户可以修改
        processComment: '',
        attachments: ''
      }
      this.processOpen = true
    },
    /** 提交处理 */
    submitProcess() {
      this.$refs.processForm.validate((valid) => {
        if (valid) {
          this.processLoading = true

          // 准备要更新的数据
          const updateData = {
            alertId: this.processForm.alertId,
            processStatus: this.processForm.processStatus,
            processComment: this.processForm.processComment,
            attachments: this.processForm.attachments
          }

          updateRecord(updateData).then(response => {
            this.$modal.msgSuccess("处理成功")
            this.processOpen = false
            this.processLoading = false
            this.resetProcessForm()
            // 刷新列表
            this.getList()
          }).catch(() => {
            this.processLoading = false
          })
        }
      })
    },
    /** 取消处理 */
    cancelProcess() {
      this.processOpen = false
      this.resetProcessForm()
    },
    /** 重置处理表单 */
    resetProcessForm() {
      this.processForm = {
        alertId: null,
        deviceId: null,
        deviceName: null,
        deviceType: null,
        fieldId: null,
        farmId: null,
        alertContent: null,
        alertLevel: null,
        alertTime: null,
        processStatus: 0,
        processComment: null,
        attachments: null
      }
      if (this.$refs.processForm) {
        this.$refs.processForm.resetFields()
      }
    }
  }
}
</script>

<style scoped>
.alert-detail {
  padding: 10px;
}

.alert-card {
  background-color: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid #e9ecef;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  border-left: 4px solid #f56c6c;
}

.alert-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 12px;
  border-bottom: 1px solid #e9ecef;
}

.alert-level-tag {
  font-weight: bold;
}

.alert-time {
  color: #909399;
  font-size: 14px;
}

.alert-content {
  color: #606266;
  line-height: 1.6;
  font-size: 14px;
}

.section {
  margin-bottom: 20px;
}

.section-title {
  font-size: 16px;
  font-weight: bold;
  color: #303133;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ebeef5;
}

.device-info .info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 15px;
}

.info-item {
  display: flex;
  flex-direction: column;
}

.info-item .label {
  color: #909399;
  font-size: 14px;
  margin-bottom: 5px;
}

.info-item .value {
  color: #303133;
  font-weight: 500;
  font-size: 15px;
}

.status-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-item.full-width {
  grid-column: 1 / -1;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.status-item .label {
  color: #606266;
  font-size: 14px;
  font-weight: 500;
  min-width: 80px;
  flex-shrink: 0;
}

.status-item .value {
  color: #303133;
  font-weight: 600;
  flex: 1;
}

.status-item .value.status {
  display: flex;
  align-items: center;
}

.process-record {
  color: #606266;
  font-size: 14px;
  padding: 12px;
  background-color: #f8f9fa;
  border-radius: 4px;
  border: 1px solid #e9ecef;
  width: 100%;
  min-height: 50px;
  display: flex;
  align-items: center;
}

.dialog-footer {
  text-align: right;
}

.process-alert-info {
  background-color: #f8f9fa;
  border-radius: 4px;
  padding: 15px;
  margin-bottom: 10px;
  border: 1px solid #e9ecef;
}

.process-alert-info .info-item {
  display: inline-block;
  margin-right: 20px;
  margin-bottom: 8px;
}

.process-alert-info .label {
  color: #606266;
  font-size: 14px;
  margin-right: 5px;
}

.process-alert-info .value {
  color: #303133;
  font-weight: 500;
}

.alert-content-preview {
  color: #606266;
  font-size: 14px;
  line-height: 1.5;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e9ecef;
}

.attachment-info {
  margin-top: 10px;
}

.attachment-list {
  background-color: #f8f9fa;
  border-radius: 4px;
  padding: 10px;
  border: 1px solid #e9ecef;
}

.attachment-item {
  display: flex;
  align-items: center;
  padding: 8px;
  background-color: #fff;
  border-radius: 4px;
  margin-bottom: 8px;
  border: 1px solid #e9ecef;
  transition: all 0.3s;
}

.attachment-item:hover {
  background-color: #f5f7fa;
  border-color: #409eff;
}

.attachment-item:last-child {
  margin-bottom: 0;
}

.attachment-preview {
  width: 32px;
  height: 32px;
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f0f2f5;
  border-radius: 4px;
  color: #606266;
  font-size: 16px;
}

.attachment-details {
  flex: 1;
  min-width: 0;
}

.attachment-name {
  font-size: 14px;
  font-weight: 500;
  color: #303133;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.attachment-size {
  font-size: 12px;
  color: #909399;
}

.attachment-actions {
  margin-left: 12px;
  flex-shrink: 0;
}

.no-attachment {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #909399;
  font-size: 14px;
  padding: 40px 20px;
  background-color: #f8f9fa;
  border-radius: 4px;
  border: 1px dashed #e9ecef;
}

.no-attachment i {
  font-size: 32px;
  margin-bottom: 8px;
  color: #c0c4cc;
}

/* 统计面板样式 */
.statistics-panel {
  margin-bottom: 16px;
  padding: 20px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* 统一各部分间距 */
.app-container .el-form {
  margin-bottom: 16px;
}

.app-container .mb8 {
  margin-bottom: 16px !important;
}

.app-container .el-table {
  margin-top: 0;
}

.stat-card {
  border-radius: 12px;
  padding: 20px;
  height: 140px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.3s ease;
  cursor: pointer;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.05);
  position: relative;
  overflow: hidden;
  color: #fff;
}

.stat-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15), 0 4px 10px rgba(0, 0, 0, 0.1);
}

.stat-card.total {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
}

.stat-card.emergency {
  background: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
}

.stat-card.warning {
  background: linear-gradient(135deg, #f59e0b 0%, #eab308 100%);
}

.stat-card.info {
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
}

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

.stat-title {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 0;
  line-height: 1.2;
}

.stat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
}

.stat-number {
  font-size: 36px;
  font-weight: 700;
  line-height: 1.0;
  margin: 8px 0;
  color: #fff;
}

.stat-change {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  line-height: 1.2;
  margin: 0;
}

.stat-change.increase {
  color: rgba(255, 255, 255, 0.9);
}

.stat-change.decrease {
  color: rgba(255, 255, 255, 0.9);
}

.stat-detail {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.85);
  line-height: 1.2;
  margin: 0;
}
</style>
