<template>
  <view class="tui-apply-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" :style="{marginTop: navBarRealHeight + 'px'}">
      <view class="info-card info-card-apply">
        <view class="card-title-row">
          <view class="card-title">申请信息</view>
          <view v-if="apply.status==='待审批'" class="status-tag orange">待审批</view>
          <view v-else-if="apply.status==='已驳回'" class="status-tag red">已驳回</view>
          <view v-else-if="apply.status==='已确认'" class="status-tag gray">已确认</view>
        </view>
        <view class="info-row">
          <text class="label">姓名</text>
          <text class="value">{{ apply.name }}</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">电话</text>
          <text class="value">{{ apply.phone }}</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">每日可花推广时间</text>
          <text class="value">{{ apply.time }}</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">申请时间</text>
          <text class="value">{{ apply.applyTime }}</text>
        </view>
      </view>
    </view>
    <view class="bottom-bar">
      <button class="action-btn danger" @tap="reject">驳回</button>
      <button class="action-btn primary" @tap="approve">通过</button>
    </view>
  </view>
</template>

<script>
import pullRefreshMixin from '../mixins/pullRefreshMixin.js'
export default {
  mixins: [pullRefreshMixin],
  data() {
    return {
      apply: {
        name: '周小艺',
        phone: '18899102278',
        time: '6小时',
        applyTime: '2025-03-20 11:00',
        status: '待审批',
      },
      statusBarHeight: 0,
      navBarRealHeight: 0,
    }
  },
  computed: {
    navbarStyle() {
      return `padding-top: ${this.statusBarHeight}px;`;
    }
  },
  onLoad(options) {
    uni.getSystemInfo({
      success: (res) => {
        this.statusBarHeight = res.statusBarHeight || 20;
      }
    });
    this.$nextTick(() => {
      uni.createSelectorQuery().select('.navbar').boundingClientRect(rect => {
        if (rect) {
          this.navBarRealHeight = rect.height;
        }
      }).exec();
    });
    // eventChannel 传递申请信息
    const eventChannel = this.getOpenerEventChannel && this.getOpenerEventChannel();
    if (eventChannel) {
      eventChannel.on('applyDetail', (apply) => {
        this.apply = Object.assign({}, this.apply, apply);
      });
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    reject() {
      uni.showToast({ title: '已驳回', icon: 'none' });
    },
    approve() {
      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-apply-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);
  position: relative;
}
.card-title-row {
  display: flex;
  align-items: center;
  margin-bottom: 32rpx;
}
.card-title {
  font-size: 32rpx;
  font-weight: bold;
  color: #222;
  margin-right: 18rpx;
}
.status-tag {
  font-size: 28rpx;
  border-radius: 0 20rpx 0 0;
  padding: 8rpx 32rpx;
  font-weight: 400;
  position: absolute;
  right: 0;
  top: 0;
  &.orange {
    background: #fff7e6;
    color: #ffb400;
  }
  &.red {
    background: #ffeaea;
    color: #ff4d4f;
  }
  &.gray {
    background: #f5f5f5;
    color: #999;
  }
}
.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;
  gap: 32rpx;
}
.action-btn {
  flex: 1;
  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.primary {
  color: #fff;
  border: none;
  background: linear-gradient(90deg, #FFD36D 0%, #FFA800 100%);
}
.action-btn.danger {
  color: #ffb800;
  border: 2rpx solid #ffd36d;
  background: #fffbe6;
}
</style> 