<script lang="ts" setup>
// @ts-ignore
import { computed } from 'vue';

import { ElCard, ElDescriptions, ElDescriptionsItem } from 'element-plus';

// @ts-ignore
import { useVbenVxeGrid } from '#/adapter/vxe-table';

// 定义组件的Props接口
interface OperatingPlanProps {
  taskDetail: any;
}

// 接收父组件传递的任务详情数据
const props = defineProps<OperatingPlanProps>();

// 计算属性，获取经营计划数据
const operatingPlanData = computed(() => {
  return props.taskDetail || {};
});

// 计算属性，获取内在因素评估数据
const internalFactorsData = computed(() => {
  return (
    props.taskDetail?.internalFactors || [
      {
        item: '位置',
        example: '道路商圈、可见度、易进度',
        disadvantage: '-',
        advantage: '-',
      },
      {
        item: '配置',
        example: '油站形象包装、加油设备、便利店设备',
        disadvantage: '-',
        advantage: '-',
      },
      {
        item: '商品服务',
        example: '价格、型号、品类、促销、供应稳定性、质量、销售时间性特点',
        disadvantage: '-',
        advantage: '-',
      },
      {
        item: '人员',
        example: '人手、服务、执行力、销售效率',
        disadvantage: '-',
        advantage: '-',
      },
      {
        item: '其它',
        example: '流程、政策、品牌等',
        disadvantage: '-',
        advantage: '-',
      },
    ]
  );
});

// 计算属性，获取外在因素评估数据
const externalFactorsData = computed(() => {
  return (
    props.taskDetail?.externalFactors || [
      {
        item: '位置',
        example: '潜在道路商圈规划',
        threat: '-',
        opportunity: '-',
      },
      {
        item: '竞争',
        example: '新油站/商超便利店、现有对手的变化/促销',
        threat: '-',
        opportunity: '-',
      },
      {
        item: '顾客',
        example: '需求变化、对油品/非油品的质量顾虑',
        threat: '-',
        opportunity: '-',
      },
      { item: '其它', example: '', threat: '-', opportunity: '-' },
    ]
  );
});

// 内在因素评估表格列配置
const internalFactorsColumns: any = [
  {
    field: 'item',
    title: '项目',
    width: 120,
    fixed: 'left',
  },
  {
    field: 'example',
    title: '举例',
    width: 200,
  },
  {
    field: 'disadvantage',
    title: '劣势',
    width: 200,
  },
  {
    field: 'advantage',
    title: '优势',
    width: 200,
  },
];

// 外在因素评估表格列配置
const externalFactorsColumns: any = [
  {
    field: 'item',
    title: '项目',
    width: 120,
    fixed: 'left',
  },
  {
    field: 'example',
    title: '举例',
    width: 200,
  },
  {
    field: 'threat',
    title: '威胁',
    width: 200,
  },
  {
    field: 'opportunity',
    title: '机遇',
    width: 200,
  },
];

// 初始化内在因素评估表格配置
const internalFactorsGridOptions: any = {
  size: 'medium',
  toolbarConfig: {
    custom: false,
    refresh: false,
    zoom: false,
  },
  pagerConfig: {
    enabled: false,
  },
  proxyConfig: {
    ajax: {
      query: async () => {
        return {
          items: internalFactorsData.value,
        };
      },
    },
  },
  columns: internalFactorsColumns,
};

// 初始化外在因素评估表格配置
const externalFactorsGridOptions: any = {
  size: 'medium',
  toolbarConfig: {
    custom: false,
    refresh: false,
    zoom: false,
  },
  pagerConfig: {
    enabled: false,
  },
  proxyConfig: {
    ajax: {
      query: async () => {
        return {
          items: externalFactorsData.value,
        };
      },
    },
  },
  columns: externalFactorsColumns,
};

// 使用内在因素评估表格组件
const [InternalFactorsTable, internalFactorsApi] = useVbenVxeGrid({
  gridOptions: internalFactorsGridOptions,
});

// 使用外在因素评估表格组件
const [ExternalFactorsTable, externalFactorsApi] = useVbenVxeGrid({
  gridOptions: externalFactorsGridOptions,
});
</script>

<template>
  <ElCard>
    <template #header>
      <div class="flex items-center gap-4">
        <div style="width: 4px; height: 12px; background-color: #215acd"></div>
        <span
          class="text-lg font-bold text-gray-800"
          style="font-size: 14px; font-weight: 600"
        >
          经营计划详情
        </span>
      </div>
    </template>

    <div class="task-info">
      <!-- 基本信息 -->
      <div class="section-title">
        <div class="section-bar"></div>
        <span class="section-text">基本信息</span>
      </div>
      <ElDescriptions :column="2" class="mb-6">
        <ElDescriptionsItem label="本站策略:">
          {{ operatingPlanData.siteStrategy || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="本站变化:">
          {{ operatingPlanData.siteChange || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="竞对策略:">
          {{ operatingPlanData.competitorStrategy || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="竞对变化:">
          {{ operatingPlanData.competitorChange || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="商圈变化:">
          {{ operatingPlanData.businessDistrictChange || '-' }}
        </ElDescriptionsItem>
        <ElDescriptionsItem label="SWOT分析计划回顾:">
          {{ operatingPlanData.swotAnalysisReview || '-' }}
        </ElDescriptionsItem>
      </ElDescriptions>

      <!-- 内在因素评估表格 -->
      <div class="section-title">
        <div class="section-bar"></div>
        <span class="section-text">内在因素评估</span>
      </div>
      <div class="mb-6">
        <InternalFactorsTable table-title="" class="w-full" />
      </div>

      <!-- 外在因素评估表格 -->
      <div class="section-title">
        <div class="section-bar"></div>
        <span class="section-text">外在因素评估</span>
      </div>
      <div class="mb-6">
        <ExternalFactorsTable table-title="" class="w-full" />
      </div>
    </div>
  </ElCard>
</template>

<style scoped lang="scss">
.task-info {
  .section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 20px 0 12px 0;

    .section-bar {
      width: 4px;
      height: 12px;
      background-color: #215acd;
    }

    .section-text {
      font-size: 14px;
      font-weight: 600;
      color: var(--text-color-primary);
    }
  }

  :deep(.el-descriptions) {
    margin-bottom: 0 !important;
  }

  :deep(.el-descriptions__label) {
    font-size: 14px;
    font-weight: 400;
    color: var(--text-color-secondary);
  }

  :deep(.el-descriptions__content) {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-color-primary);
  }

  :deep(.el-descriptions__table) {
    background: transparent !important;
  }
}
</style>
