<template>
  <view class="tui-detail-container">
    <!-- 顶部导航栏 -->
    <view class="navbar" :style="navbarStyle">
      <view class="nav-left" @tap="goBack">
        <uni-icons type="back" size="24" color="#222" />
      </view>
      <view class="nav-title">推广官管理详情</view>
      <view class="nav-right">
        <!-- <uni-icons type="more-filled" size="24" color="#222" style="margin-right: 16rpx;" />
        <uni-icons type="scan" size="24" color="#222" /> -->
      </view>
    </view>
    <view class="main-content">
      <!-- 个人信息卡片 -->
      <view class="info-card">
        <view class="card-title">个人信息</view>
        <view class="info-row">
          <text class="label">姓名</text>
          <text class="value">{{ tui.name }}</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">电话</text>
          <text class="value">{{ tui.phone }}</text>
        </view>
      </view>
      <!-- 推广信息卡片 -->
      <view class="info-card">
        <view class="card-title">推广信息</view>
        <view class="info-row">
          <text class="label">一级推广数</text>
          <text class="value">{{ tui.level1 }}人</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">二级推广数</text>
          <text class="value">{{ tui.level2 }}人</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">回收总额</text>
          <text class="value">{{ tui.totalAmount }}元</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">佣金总额</text>
          <text class="value">{{ tui.commission }}元</text>
        </view>
      </view>
    </view>
    <view class="bottom-bar">
      <button class="action-btn danger" @tap="removeTui">解除推广官</button>
    </view>
  </view>
</template>

<script>
import pullRefreshMixin from '../mixins/pullRefreshMixin.js'
export default {
  mixins: [pullRefreshMixin],
  data() {
    return {
      tui: {
        name: '周小艺',
        phone: '18899102278',
        level1: 67,
        level2: 67,
        totalAmount: '8273.99',
        commission: '278.99',
      },
      statusBarHeight: 0,
    }
  },
  computed: {
    navbarStyle() {
      return `padding-top: ${this.statusBarHeight}px;`;
    }
  },
  onLoad(options) {
    uni.getSystemInfo({
      success: (res) => {
        this.statusBarHeight = res.statusBarHeight || 20;
      }
    });
    // eventChannel 传递推广官信息
    const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel();
    if (eventChannel) {
      eventChannel.on('tuiDetail', (tui) => {
        this.tui = Object.assign({}, this.tui, tui);
      });
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    removeTui() {
      uni.showToast({ title: '已解除推广官', icon: 'none' });
    },
    refreshData() {
      // TODO: 实现推广官详情刷新逻辑，如重新请求接口
    },
    async onRefresh() {
      await this.refreshData && this.refreshData()
    }
  },
  onPullDownRefresh() {
    this.refreshData && this.refreshData()
    uni.stopPullDownRefresh()
  }
}
</script>

<style lang="scss" scoped>
.tui-detail-container {
  min-height: 100vh;
  background: #f7f7f7;
  padding-bottom: 160rpx;
}
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100rpx;
  background: #fff;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.03);
  padding: 0 32rpx;
  .nav-left {
    flex: 0 0 48rpx;
    display: flex;
    align-items: center;
    height: 100%;
  }
  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 36rpx;
    font-weight: bold;
    color: #222;
    line-height: 100rpx;
  }
  .nav-right {
    flex: 0 0 80rpx;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
  }
}
.main-content {
  margin-top: 120rpx;
  margin-bottom: 40rpx;
}
.info-card {
  background: #fff;
  border-radius: 40rpx;
  margin: 0 32rpx 32rpx 32rpx;
  padding: 40rpx 36rpx 36rpx 36rpx;
  box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.03);
}
.card-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #222;
  margin-bottom: 32rpx;
}
.info-row {
  display: flex;
  align-items: center;
  min-height: 60rpx;
  margin-bottom: 0;
  .label {
    font-size: 26rpx;
    color: #b3b3b3;
    width: 180rpx;
    font-weight: 400;
  }
  .value {
    font-size: 30rpx;
    color: #222;
    font-weight: 500;
    flex: 1;
    word-break: break-all;
  }
}
.divider {
  height: 2rpx;
  background: #f3f3f3;
  margin: 18rpx 0 18rpx 0;
  border: none;
}
.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f7f7f7;
  padding-bottom: env(safe-area-inset-bottom);
  padding-top: 24rpx;
  padding-bottom: 24rpx;
  z-index: 20;
}
.action-btn {
  flex: 1;
  margin: 0 32rpx;
  height: 80rpx;
  border-radius: 40rpx;
  font-size: 30rpx;
  font-weight: 500;
  border: 2rpx solid #ffd36d;
  background: #fffbe6;
  color: #ffb800;
  box-shadow: 0 2rpx 8rpx rgba(255, 156, 0, 0.03);
}
.action-btn.danger {
  color: #ffb800;
  border: 2rpx solid #ffd36d;
  background: #fffbe6;
}
</style> 