<template>
  <view class="admin-page">
      <view class="admin-sections">
        <!-- 搜索栏 -->
        <view class="admin-card filter-card">
          <view class="filter-row">
            <view class="filter-item">
              <text class="label">规则状态：</text>
              <view class="filter-select">
                <text class="select-placeholder">请选择</text>
                <text class="arrow">▼</text>
              </view>
            </view>
            <view class="filter-item">
              <text class="label">按钮名称：</text>
              <input class="filter-input" placeholder="请输入按钮名称" />
            </view>
            <button class="btn primary" @click="onSearch">查询</button>
          </view>
        </view>

      <!-- 内容区 -->
      <view class="admin-card content-card">
        <!-- 操作按钮行 -->
        <view class="action-bar">
          <button class="btn primary small" @click="onAdd">添加规则</button>
        </view>

        <!-- 表格 -->
        <view class="table-container list-table">
          <view class="table-header">
            <view class="col col-name"><text>按钮名称</text></view>
            <view class="col col-auth"><text>前项权限</text></view>
            <view class="col col-route"><text>路由</text></view>
            <view class="col col-status"><text>规则状态</text></view>
            <view class="col col-memo"><text>备注</text></view>
            <view class="col col-ops"><text>操作</text></view>
          </view>

          <view class="table-body">
            <view v-for="item in dataList" :key="item.id" class="table-row">
              <view class="col col-name">
                <text class="expand-icon">▶</text>
                <text>{{ item.name }}</text>
              </view>
              <view class="col col-auth"><text>{{ item.auth }}</text></view>
              <view class="col col-route"><text>{{ item.route }}</text></view>
              <view class="col col-status">
                <switch :checked="item.status" color="#1890ff" scale="0.8" />
              </view>
              <view class="col col-memo"><text>{{ item.memo }}</text></view>
              <view class="col col-ops">
                <text class="op-link" @click="onSelectAuth(item)">选择权限</text>
                <view class="op-divider">|</view>
                <text class="op-link" @click="onAddSub(item)">添加下级</text>
                <view class="op-divider">|</view>
                <text class="op-link" @click="onEdit(item)">编辑</text>
                <view class="op-divider">|</view>
                <text class="op-link op-danger" @click="onDelete(item)">删除</text>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

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

const dataList = ref([
  { id: 1, name: '主页', auth: 'admin-home', route: '菜单: /admin/index', status: true, memo: '主页' },
  { id: 2, name: '用户', auth: 'admin-user', route: '菜单: /admin/user', status: true, memo: '用户' },
  { id: 3, name: '订单', auth: 'admin-order', route: '菜单: /admin/order', status: true, memo: '订单' },
  { id: 4, name: '商品', auth: 'admin-product', route: '菜单: /admin/product', status: true, memo: '商品' },
  { id: 5, name: '营销', auth: 'admin-marketing', route: '菜单: /admin/marketing', status: true, memo: '营销' },
  { id: 6, name: '分销', auth: 'admin-agent', route: '菜单: /admin/agent', status: true, memo: '分销' },
  { id: 7, name: '客服', auth: 'setting-store-service', route: '菜单: /admin/kefu', status: true, memo: '客服' },
  { id: 8, name: '财务', auth: 'admin-finance', route: '菜单: /admin/finance', status: true, memo: '财务' },
  { id: 9, name: '内容', auth: 'admin-cms', route: '菜单: /admin/cms', status: true, memo: '内容' },
  { id: 10, name: '装修', auth: 'admin-setting-pages', route: '菜单: /admin/setting/pages', status: true, memo: '装修' },
  { id: 11, name: '应用', auth: 'admin-app', route: '菜单: /admin/app', status: true, memo: '应用' },
  { id: 12, name: '设置', auth: 'admin-setting', route: '菜单: /admin/setting', status: true, memo: '设置' },
  { id: 13, name: '维护', auth: 'admin-system', route: '菜单: /admin/system', status: true, memo: '维护' }
])

function onSearch() {
  uni.showToast({ title: '查询中...', icon: 'none' })
}

function onAdd() {
  uni.showToast({ title: '添加规则', icon: 'none' })
}

function onSelectAuth(item: any) {
  uni.showToast({ title: '选择权限: ' + item.name, icon: 'none' })
}

function onAddSub(item: any) {
  uni.showToast({ title: '添加下级: ' + item.name, icon: 'none' })
}

function onEdit(item: any) {
  uni.showToast({ title: '编辑: ' + item.name, icon: 'none' })
}

function onDelete(item: any) {
  uni.showModal({
    title: '提示',
    content: '确定要删除该规则吗？',
    success: (res) => {
      if (res.confirm) {
        uni.showToast({ title: '已删除', icon: 'none' })
      }
    }
  })
}
</script>

<style scoped lang="scss">
.admin-page {
  /* 使用 Layout 的背景和内边距 */
  padding: 0;
  background-color: transparent;
  min-height: auto;
}

.admin-card {
  background-color: #fff;
  border-radius: 4px;
  padding: 20px;
  margin-bottom: 20px;
}

.filter-row {
  display: flex;
  flex-direction: row;
  align-items: center;
}

.filter-item {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-right: 24px;
}

.label {
  font-size: 14px;
  color: #333;
}

.filter-select {
  width: 150px;
  height: 32px;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
}

.select-placeholder {
  color: #bfbfbf;
  font-size: 14px;
}

.filter-input {
  width: 200px;
  height: 32px;
  border: 1px solid #d9d9d9;
  border-radius: 2px;
  padding: 0 10px;
  font-size: 14px;
}

.btn {
  height: 32px;
  padding: 0 20px;
  border-radius: 2px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 1px solid #d9d9d9;
  background-color: #fff;
}

.btn.primary {
  background-color: #1890ff;
  border-color: #1890ff;
  color: #fff;
}

.btn.small {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

.action-bar {
  margin-bottom: 16px;
}

.table-container {
  width: 100%;
  border: 1px solid #f0f0f0;
}

.table-header {
  display: flex;
  flex-direction: row;
  background-color: #fafafa;
  border-bottom: 1px solid #f0f0f0;
}

.table-row {
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid #f0f0f0;
}

.col {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: #333;
}

.col-name { flex: 1.5; }
.col-auth { flex: 2; }
.col-route { flex: 3; }
.col-status { width: 100px; justify-content: center; }
.col-memo { flex: 1; }
.col-ops { flex: 3; justify-content: flex-end; display: flex; flex-direction: row; }

.expand-icon {
  margin-right: 8px;
  font-size: 10px;
  color: #999;
}

.op-link {
  color: #1890ff;
  cursor: pointer;
  margin: 0 4px;
}

.op-danger {
  color: #ff4d4f;
}

.op-divider {
  color: #f0f0f0;
  margin: 0 4px;
}
</style>


