<template>
  <view class="trading-alert">
    <!-- 标题 -->
    <view class="section-title">交易预警</view>

    <!-- 预警统计卡片 -->
    <view class="alert-stats">
      <view class="stat-card total">
        <text class="stat-value">{{ alertData.total }}</text>
        <text class="stat-label">预警总数</text>
      </view>
      <view class="stat-card required">
        <text class="stat-value">{{ alertData.required }}</text>
        <text class="stat-label">必查项</text>
      </view>
      <view class="stat-card spot">
        <text class="stat-value">{{ alertData.spot }}</text>
        <text class="stat-label">抽查项</text>
      </view>
    </view>

    <!-- 预警详情列表 -->
    <view class="alert-list">
      <view class="list-header">
        <text class="header-item service">服务区</text>
        <text class="header-item shop">门店</text>
        <text class="header-item type">类型</text>
      </view>

      <view class="list-content">
        <view class="alert-item" v-for="(item, index) in alertList" :key="index">
          <text class="item-service service">{{ item.serviceArea }}</text>
          <text class="item-shop shop">{{ item.shop }}</text>
          <text class="item-type type">{{ item.type }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import QiunDataCharts from './qiun-data-charts/components/qiun-data-charts/qiun-data-charts.vue'
import request from "@/util/index.js";

export default {
  components: {
    QiunDataCharts
  },

  data() {
    return {
      alertData: {
        total: 0,
        required: 0,
        spot: 0
      },
      alertList: []
    }
  },
  onReady() {
    this.handleGetData()
  },

  methods: {
    // 获取交易预警数据
    async handleGetData() {
      const req = {
        ProvinceCode: "530000",
        ServerpartId: "",
        type: 'encryption'
      }

      let data = await request.$webPost('CommercialApi/AbnormalAudit/GetCurrentEarlyWarning', req)
      data = data.Result_Data

      if (data && data.OtherData) {
        this.alertData = {
          total: (Number(data.OtherData.value) || 0) + (Number(data.OtherData.data) || 0),
          required: Number(data.OtherData.value) || 0,
          spot: Number(data.OtherData.data) || 0
        }
      }

      if (data && data.List && data.List.length > 0) {
        this.alertList = data.List.slice(0, 7).map(item => ({
          serviceArea: item.serverpartName || '',
          shop: item.serverpartShopName || '',
          type: item.exceptionTypeName || ''
        }))
      }
    },
  }
}
</script>

<style scoped>
.trading-alert {}

.section-title {
  font-size: 30rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 12rpx;
}

.alert-stats {
  display: flex;
  gap: 24rpx;
  margin-bottom: 32rpx;
}

.stat-card {
  flex: 1;
  background: #fff;
  border-radius: 16rpx;
  padding: 16rpx;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  text-align: center;
}

.stat-card.total {
  background: linear-gradient(135deg, #576EFF, #7C8FFF);
  color: #fff;
}

.stat-card.required {
  background: linear-gradient(135deg, #FF4D4F, #FF7875);
  color: #fff;
}

.stat-card.spot {
  background: linear-gradient(135deg, #75F8EE, #A0F9ED);
  color: #fff;
}

.stat-value {
  font-size: 28rpx;
  font-weight: 600;
  display: block;
  margin-bottom: 8rpx;
}

.stat-label {
  font-size: 24rpx;
  opacity: 0.9;
}

.chart-section {
  background: #fff;
  border-radius: 16rpx;
  padding: 24rpx;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  margin-bottom: 24rpx;
}

.chart-title {
  font-size: 28rpx;
  font-weight: 600;
  color: #333;
  margin-bottom: 20rpx;
}

.chart-container {
  width: 100%;
  height: 400rpx;
}

.alert-list {
  background: #fff;
  border-radius: 16rpx;
  padding: 24rpx;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.list-header {
  display: flex;
  border-bottom: 1rpx solid #f0f0f0;
  margin-bottom: 16rpx;
}

.header-item {
  font-size: 26rpx;
  font-weight: 600;
  color: #333;
}

.header-item.service {
  width: 40%;
}

.header-item.shop {
  width: 30%;
}

.header-item.type {
  width: 30%;
}

.list-content {
  max-height: 600rpx;
  overflow-y: auto;
}

.alert-item {
  display: flex;
  align-items: center;
  padding: 12rpx 0;
  border-bottom: 1rpx solid #f8f8f8;
}

.alert-item:last-child {
  border-bottom: none;
}

.item-service {
  width: 40%;
  font-size: 24rpx;
  color: #333;
}

.item-shop {
  width: 30%;
  font-size: 24rpx;
  color: #666;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.item-type {
  width: 30%;
  font-size: 24rpx;
  color: #666;
}

.item-status {
  flex: 1;
  font-size: 22rpx;
  padding: 6rpx 12rpx;
  border-radius: 12rpx;
  text-align: center;
}

.item-status.pending {
  background: #FFF2F0;
  color: #FF4D4F;
}

.item-status.processing {
  background: #FFF7E6;
  color: #FAAD14;
}

.item-status.resolved {
  background: #F6FFED;
  color: #52C41A;
}
</style>