<template>
  <view class="staff-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">{{ staff.name }}</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">电话</text>
          <text class="value">{{ staff.phone }}</text>
        </view>
        <view class="divider"></view>
        <view class="info-row">
          <text class="label">角色</text>
          <text class="value">{{ staff.role }}</text>
        </view>
      </view>
    </view>
    <view class="bottom-bar">
      <button class="action-btn danger" @tap="removeStaff">解除员工</button>
    </view>
  </view>
</template>

<script>
import pullRefreshMixin from '../mixins/pullRefreshMixin.js'
export default {
  mixins: [pullRefreshMixin],
  data() {
    return {
      staff: {
        name: '冯启彬',
        phone: '18899102278',
        role: '质检员',
      },
      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('staffDetail', (staff) => {
        this.staff = Object.assign({}, this.staff, staff);
      });
    }
  },
  methods: {
    goBack() {
      uni.navigateBack();
    },
    removeStaff() {
      if (!this.staff.id) {
        uni.showToast({ title: '缺少员工ID', icon: 'none' });
        return;
      }
      this.$api && this.$api('removeMember', { id: this.staff.id }, res => {
        if (res && res.code === 200) {
      uni.showToast({ title: '已解除员工', icon: 'none' });
          setTimeout(() => {
            uni.$emit('refreshStaffList');
            uni.navigateBack();
          }, 500);
        } else {
          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>
.staff-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: calc(120rpx + var(--status-bar-height));
  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: 110rpx;
    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> 