<template>
  <div class="detail-container">
    <!-- 主图LOGO部分 -->
    <div class="logo-section flex left top">
      <div class="fw-600">主图LOGO：</div>
      <upload v-model="queryParams.logoImage"></upload>
    </div>
    <el-divider />
    <!-- 选择详情模板部分 -->
    <div class="template-section ">
      <div class="flex between">
        <span>选择详情模版</span>
        <div class="template-pagination">
          <el-pagination background layout="prev, pager, next" v-model:current-page="queryParams.current"
            v-model:page-size.sync="queryParams.size" :total="totalPage" @current-change="onCurrentChange"
            @size-change="onSizeChange" />
        </div>
      </div>

      <div class="template-list">
        <div v-for="(template, index) in visibleTemplates" :key="index" class="template-item"
          @click="queryParams.templateId = template.id">
          <div class="select-warp" :class="queryParams.templateId == template.id ? 'active' : ''">
            <el-icon color="#FFFFFF">
              <Select />
            </el-icon>
          </div>
          <div class="template-info">
            <span class="mar-left-10">{{ template.templateId }}</span>
            <div class="template-view" @click="viewTemplate(template)">查看</div>
          </div>
        </div>
      </div>
    </div>

    <!-- 详情资料准备部分 -->
    <div class="data-prep-section">

      <div class="flex-item left">详情资料准备 (2选1)</div>
      <div class="flex-item left">
        <el-radio-group v-model="queryParams.radio1" class="ml-4">
          <el-radio label="1" size="large">EXCEL文件选择</el-radio>
          <el-radio label="2" size="large">系统对接（和业务员联系）</el-radio>
        </el-radio-group>
      </div>
      <div v-if="dataPrepOption === 'excel'" class="excel-upload">
        <el-row :gutter="20">
          <el-col :span="1"></el-col>
          <el-col :span="4">商品基础资料EXCEL文件选择：</el-col>
          <el-col :span="18">
            <el-input type="textarea" v-model="excelFilePath" />
          </el-col>
          <el-col :span="1"></el-col>

        </el-row>
      </div>
    </div>

    <!-- 开始生成按钮 -->
    <button class="generate-button button--primary1" @click="generate">开始生成</button>
  </div>
</template>

<script lang="ts" setup>


import { ref, computed, reactive } from 'vue';
import { Select } from '@element-plus/icons-vue'


import upload from '@/components/upload'

// 模拟数据
const templates = [
  { id: 1101, templateId: '某某模版编号1', preview: '...' },
  { id: 1102, templateId: '某某模版编号2', preview: '...' },
  { id: 1103, templateId: '某某模版编号3', preview: '...' },
  { id: 1104, templateId: '某某模版编号4', preview: '...' },
  { id: 1105, templateId: '某某模版编号5', preview: '...' },
  { id: 1106, templateId: '某某模版编号6', preview: '...' },
  { id: 1107, templateId: '某某模版编号7', preview: '...' },
  { id: 1108, templateId: '某某模版编号8', preview: '...' },
  { id: 1109, templateId: '某某模版编号9', preview: '...' },
  { id: 1110, templateId: '某某模版编号10', preview: '...' },
  { id: 1111, templateId: '某某模版编号11', preview: '...' },
  { id: 1112, templateId: '某某模版编号12', preview: '...' },
  // 更多模板...
];
const itemsPerPage = 4; // 每页显示的模板数量
// 状态变量
const currentPage = ref(1);
const selectedTemplateIndex = ref(0);
const dataPrepOption = ref('excel');
const excelFilePath = ref('D:\\MyDocuments\\PythonCode\\MyPython\\red_dragonfly\\deal_pics\\auto_capture_V2\\auto_photo');
const totalPage = ref(3);

const queryParams = reactive({
  logoImage: '',
  size: 1,
  current: 1,
  templateId: 1101,
  radio1: 1
})

// 计算属性，获取当前页可见的模板
const visibleTemplates = computed(() => {
  const startIndex = (queryParams.current - 1) * itemsPerPage;
  const data = templates.slice(startIndex, startIndex + itemsPerPage);
  return data
});
// 查看模板详情
const viewTemplate = (template) => {
  console.log('查看模板详情', template);
};
const onCurrentChange = (page) => {
  queryParams.current = page;
};
const onSizeChange = (data) => {

};

// 开始生成操作
const generate = () => {
  console.log('开始生成');
  // 这里添加实际生成主图和详情的逻辑
};
</script>

<style lang="scss" scoped>
.detail-container {
  padding: 20px 0 20px 20px;
  max-width: 1200px;
  background-color: #EAECED;
  width: 100%;

}

.logo-section,
.template-section,
.data-prep-section {
  margin-bottom: 20px;
}

.logo-upload {
  border: 1px dashed #ccc;
  border-radius: 5px;
  padding: 50px 0;
  text-align: center;
  cursor: pointer;
}

.template-pagination button {
  margin-right: 5px;
}

.template-pagination span {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 20px;
  text-align: center;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-right: 5px;
  cursor: pointer;
}


.template-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;


  .template-item {
    width: calc(25% - 34px);
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 10px;
    height: 320px;
    cursor: pointer;
    background: #f0f0f0;
    position: relative;
    overflow: hidden;

    .template-info {
      position: absolute;
      bottom: 0;
      left: 0;
      background: rgba($color: #000000, $alpha: .3);
      width: 100%;
      height: 36px;
      line-height: 36px;
      color: #eee;
      display: flex;
      align-items: center;
      justify-content: space-between;

      .template-view {
        background: #DFE2E3;
        color: #3366FF;
        height: 30px;
        line-height: 30px;
        padding: 0 10px;
        border-radius: 4px;
        margin-right: 10px;
        font-size: 14px;
      }
    }
  }
}



.excel-upload {
  width: 100%;
  background: #F7F7F7;
  padding: 20px 0;
}

.generate-button {
  padding: 10px 20px;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
}

.select-warp {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background-color: #fff;

  &.active {
    background-color: #1677FF;
  }
}
</style>