<template>
  <view class="admin-main">
    <view class="main-content">
      <!-- 左侧分类 -->
      <view class="category-sidebar">
        <view class="add-cat-btn">
          <text class="plus">+</text>
          <text>添加分类</text>
        </view>
        <scroll-view class="cat-list" scroll-y="true">
          <view v-for="group in linkGroups" :key="group.title" class="group-wrap">
            <view class="group-title">
               <text class="arrow">▼</text>
               <text class="folder">📁</text>
               <text>{{ group.title }}</text>
               <text class="more">...</text>
            </view>
            <view 
              v-for="sub in group.children" 
              :key="sub.id" 
              class="sub-item"
              :class="{ active: selectedSubId === sub.id }"
              @click="selectedSubId = sub.id"
            >
              <text>{{ sub.name }}</text>
              <text class="more">...</text>
            </view>
          </view>
        </scroll-view>
      </view>

      <!-- 右侧列表 -->
      <view class="list-area">
        <view class="toolbar">
           <button class="add-btn" type="primary" size="mini">添加链接</button>
        </view>

        <view class="table-container">
           <view class="table-header">
              <text class="col id">ID</text>
              <text class="col name">名称</text>
              <text class="col url">H5链接</text>
              <text class="col mini">小程序链接</text>
              <text class="col time">添加时间</text>
              <text class="col op">操作</text>
           </view>
           <scroll-view class="table-body" scroll-y="true">
              <view v-for="link in links" :key="link.id" class="table-row">
                 <text class="col id">{{ link.id }}</text>
                 <text class="col name">{{ link.name }}</text>
                 <text class="col url">{{ link.h5 }}</text>
                 <text class="col mini">{{ link.mini }}</text>
                 <text class="col time">{{ link.time }}</text>
                 <view class="col op">
                    <text class="btn-text">编辑</text>
                    <text class="btn-text del">删除</text>
                 </view>
              </view>
           </scroll-view>
        </view>

        <!-- 分页 -->
        <view class="pagination">
           <text class="total">共 4 条</text>
           <view class="page-size-wrap">
              <text>15条/页</text>
              <text class="arrow">▼</text>
           </view>
           <text class="page-btn"><</text>
           <text class="page-num active">1</text>
           <text class="page-btn">></text>
           <view class="jump">
              <text>前往</text>
              <input type="number" value="1" />
              <text>页</text>
           </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="uts">
import { ref } from 'vue'

const selectedSubId = ref(1)

const linkGroups = ref([
  {
    title: '商城链接',
    children: [
      { id: 1, name: '基础链接' },
      { id: 2, name: '个人中心链接' }
    ]
  },
  {
    title: '营销链接',
    children: [
      { id: 3, name: '秒杀链接' },
      { id: 4, name: '砍价链接' },
      { id: 5, name: '积分链接' },
      { id: 6, name: '抽奖链接' },
      { id: 7, name: '优惠券链接' }
    ]
  }
])

const links = ref([
  { id: 5, name: '商品列表', h5: 'https://v5.crmeb.net/pages/goods/goods_list/index', mini: '/pages/goods/goods_list/index', time: '2024-12-25 15:45:26' },
  { id: 6, name: '我的订单', h5: 'https://v5.crmeb.net/pages/order_list/index', mini: '/pages/order_list/index', time: '2024-12-25 15:45:48' },
  { id: 7, name: '文章列表', h5: 'https://v5.crmeb.net/pages/extension/news_list/index', mini: '/pages/extension/news_list/index', time: '2024-12-25 15:46:07' },
  { id: 8, name: '退款订单', h5: 'https://v5.crmeb.net/pages/users/user_return_list/index', mini: '/pages/users/user_return_list/index', time: '2024-12-25 15:46:30' }
])
</script>

<style scoped>
.admin-main {
  height: 100vh;
  background-color: #f5f7f9;
}

.main-content {
  display: flex;
  flex-direction: row;
  height: 100%;
}

.category-sidebar {
  width: 220px;
  background-color: #fff;
  border-right: 1px solid #f0f0f0;
  display: flex;
  flex-direction: column;
}

.add-cat-btn {
  padding: 15px;
  display: flex;
  flex-direction: row;
  align-items: center;
  color: #1890ff;
  font-size: 14px;
}
.plus { font-size: 20px; margin-right: 8px; }

.cat-list { flex: 1; }
.group-wrap { margin-bottom: 5px; }
.group-title {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 10px 15px;
  background-color: #fafafa;
  font-size: 13px;
  color: #333;
}
.group-title .arrow { font-size: 10px; margin-right: 8px; color: #999; }
.group-title .folder { margin-right: 8px; color: #fadb14; }
.group-title .more { flex: 1; text-align: right; color: #ccc; }

.sub-item {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  padding: 10px 15px 10px 45px;
  font-size: 13px;
  color: #606266;
  cursor: pointer;
}
.sub-item.active { background-color: #e6f7ff; color: #1890ff; }
.sub-item .more { color: #ccc; }

.list-area { flex: 1; display: flex; flex-direction: column; background-color: #fff; margin: 15px; border-radius: 4px; overflow: hidden; }

.toolbar { padding: 15px; border-bottom: 1px solid #f0f0f0; }

.table-container { flex: 1; display: flex; flex-direction: column; }
.table-header { display: flex; flex-direction: row; background-color: #fafafa; border-bottom: 1px solid #f0f0f0; padding: 10px 0; }
.col { padding: 0 10px; font-size: 13px; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.id { width: 60px; text-align: center; }
.name { width: 120px; }
.url { flex: 1; }
.mini { flex: 1; }
.time { width: 160px; }
.op { width: 100px; text-align: center; }

.table-row { display: flex; flex-direction: row; border-bottom: 1px solid #f0f0f0; padding: 12px 0; align-items: center; }
.table-row .col { color: #606266; }

.btn-text { color: #1890ff; cursor: pointer; margin: 0 5px; }
.btn-text.del { color: #ff4d4f; }

.pagination {
  padding: 15px;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: #606266;
}

.page-size-wrap { border: 1px solid #dcdfe6; padding: 4px 8px; border-radius: 4px; display: flex; align-items: center; gap: 5px; }
.page-btn { border: 1px solid #dcdfe6; padding: 4px 10px; border-radius: 4px; }
.page-num { border: 1px solid #dcdfe6; padding: 4px 10px; border-radius: 4px; }
.page-num.active { background-color: #1890ff; color: #fff; border-color: #1890ff; }

.jump { display: flex; flex-direction: row; align-items: center; gap: 5px; }
.jump input { width: 30px; border: 1px solid #dcdfe6; border-radius: 4px; padding: 2px; text-align: center; }

</style>
