<template>
  <view class="marketing-member-type">
    <view class="table-card border-shadow">
      <view class="table-container">
        <view class="table-head">
          <view class="th cell-id">ID</view>
          <view class="th cell-name">会员名</view>
          <view class="th cell-days">有效期（天）</view>
          <view class="th cell-price">原价</view>
          <view class="th cell-discount">优惠价</view>
          <view class="th cell-status">是否开启</view>
          <view class="th cell-sort">排序</view>
          <view class="th cell-op">操作</view>
        </view>

        <view class="table-body">
          <view v-for="item in memberTypes" :key="item.id" class="table-row">
            <view class="td cell-id"><text class="td-txt">{{ item.id }}</text></view>
            <view class="td cell-name"><text class="td-txt">{{ item.name }}</text></view>
            <view class="td cell-days"><text class="td-txt">{{ item.days }}</text></view>
            <view class="td cell-price"><text class="td-txt">￥{{ item.price.toFixed(2) }}</text></view>
            <view class="td cell-discount"><text class="td-txt">￥{{ item.discount.toFixed(2) }}</text></view>
            <view class="td cell-status">
              <view class="switch-mock" :class="{ active: item.is_open }" @click="toggleStatus(item)">
                <view class="switch-dot"></view>
                <text class="switch-txt">{{ item.is_open ? '开启' : '关闭' }}</text>
              </view>
            </view>
            <view class="td cell-sort"><text class="td-txt">{{ item.sort }}</text></view>
            <view class="td cell-op">
              <text class="op-link" @click="handleEdit(item)">编辑</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

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

const memberTypes = ref([
  { id: 5, name: '44555', days: '12', price: 69.00, discount: 0.00, is_open: true, sort: 55 },
  { id: 4, name: '5566', days: '永久', price: 1080.00, discount: 1080.00, is_open: true, sort: 5 },
  { id: 3, name: '年卡', days: '365', price: 99.00, discount: 0.01, is_open: true, sort: 5 },
  { id: 2, name: '55', days: '90', price: 699.00, discount: 499.00, is_open: true, sort: 5 },
  { id: 1, name: '55', days: '30', price: 699.00, discount: 499.00, is_open: true, sort: 5 }
])

const toggleStatus = (item: any) => {
  item.is_open = !item.is_open
  uni.showToast({ title: '修改成功', icon: 'success' })
}

const handleEdit = (item: any) => {
  uni.showToast({ title: '编辑功能开发中', icon: 'none' })
}
</script>

<style scoped lang="scss">
.marketing-member-type {
  padding: 16px;
  background: #f0f2f5;
  min-height: 100vh;
}

.border-shadow {
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.table-card {
  padding: 24px;
}

.table-head {
  display: flex;
  flex-direction: row;
  background-color: #f8f8f9;
  border-bottom: 1px solid #e8eaec;
}

.th {
  padding: 12px 8px;
  font-size: 13px;
  color: #515a6e;
  font-weight: bold;
}

.table-row {
  display: flex;
  flex-direction: row;
  border-bottom: 1px solid #e8eaec;
  align-items: center;
}

.td {
  padding: 16px 8px;
}

.td-txt { font-size: 13px; color: #515a6e; }

/* 各列宽度 */
.cell-id { width: 80px; }
.cell-name { flex: 1; min-width: 150px; }
.cell-days { width: 120px; }
.cell-price { width: 120px; }
.cell-discount { width: 120px; }
.cell-status { width: 120px; text-align: center; }
.cell-sort { width: 100px; text-align: center; }
.cell-op { width: 80px; text-align: right; }

.switch-mock {
  width: 50px;
  height: 24px;
  background-color: #bfbfbf;
  border-radius: 12px;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 0 4px;
  position: relative;
  transition: background-color 0.3s;
  cursor: pointer;
}
.switch-mock.active { background-color: #1890ff; }
.switch-dot {
  width: 16px;
  height: 16px;
  background-color: #fff;
  border-radius: 50%;
  position: absolute;
  left: 4px;
  transition: left 0.3s;
}
.switch-mock.active .switch-dot { left: 30px; }
.switch-txt { font-size: 11px; color: #fff; margin-left: 20px; }
.switch-mock.active .switch-txt { margin-left: 4px; }

.op-link { color: #1890ff; font-size: 13px; cursor: pointer; }

</style>



