<template>
  <view class="faq-page" :style="{paddingTop: navBarHeightRpx + 'rpx'}">
    <!-- 顶部导航栏 -->
    <view class="nav-bar" :style="{height: navBarHeightRpx + 'rpx', paddingTop: statusBarHeight + 'px'}">
      <view class="nav-bar-inner">
        <view class="back-icon" @tap="navigateBack">
          <uni-icons type="left" size="22" color="#222"></uni-icons>
        </view>
        <view class="title">联系客服</view>
        <view class="nav-bar-right"></view>
      </view>
    </view>

    <!-- 主要内容区域 -->
    <view class="content-card">
      <view class="qa-list">
        <view class="qa-item" v-for="(item, idx) in faqList" :key="idx">
          <view class="question-row">
            <text class="q-icon">Q</text>
            <text class="question">{{item.q}}</text>
          </view>
          <view class="answer">{{item.a}}</view>
        </view>
      </view>
      <view class="dashed-line"></view>
      <view class="bottom-tip">
        如有任何问题或建议，请随时与我们联系，我们将竭诚为您服务！
      </view>
    </view>

    <!-- 底部按钮 -->
    <view class="bottom-btns">
      <button class="btn-outline" @tap="callService">客服电话</button>
      <button class="btn-gradient" @tap="openEmailPopup">联系在线客服</button>
    </view>
    <email-popup 
      :show="showEmailPopup" 
      @close="handleCloseEmailPopup"
    />
    <!-- 客服电话底部弹窗 -->
    <view v-if="showPhonePopup" class="phone-popup">
      <view class="popup-mask" @tap="closePhonePopup"></view>
      <view class="popup-content">
        <view class="popup-header">
          <text class="close-btn" @tap="closePhonePopup">关闭</text>
          <text class="popup-title">客服电话</text>
        </view>
        <view class="popup-phone-row" @tap="makePhoneCall">
          <text class="popup-phone">0731-599327-8899</text>
          <view class="popup-phone-icon">
            <uni-icons type="phone-filled" size="28" color="#222" />
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'
import emailPopup from '@/wxcomponents/email-popup/email-popup.vue'

export default {
  mixins: [pullRefreshMixin],
  components: { emailPopup },
  data() {
    return {
      statusBarHeight: 0,
      navBarHeight: 0, // px
      navBarHeightRpx: 0, // rpx
      showEmailPopup: false,
      showPhonePopup: false,
      faqList: [
        {q: '如何申请成为推广官？', a: '您好！如需帮助，请优先选择以下方式联系我们。'},
        {q: '推广官的佣金如何计算？', a: '您好！如需帮助，请优先选择以下方式联系我们。'},
        {q: '为什么我的订单显示"回收失败"？', a: '您好！如需帮助，请优先选择以下方式联系我们。'},
        {q: '如果我的订单出现问题怎么办？', a: '您好！如需帮助，请优先选择以下方式联系我们。'},
        {q: '回收的旧衣如何处理？', a: '您好！如需帮助，请优先选择以下方式联系我们。'},
        {q: '哪些衣物可以回收？', a: '您好！如需帮助，请优先选择以下方式联系我们。'},
      ]
    }
  },
  onLoad() {
    const sysInfo = uni.getSystemInfoSync()
    this.statusBarHeight = sysInfo.statusBarHeight
    let navBarHeight = 24
    try {
      const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
      navBarHeight = menuButtonInfo.bottom + menuButtonInfo.top - sysInfo.statusBarHeight
    } catch (e) {}
    this.navBarHeight = navBarHeight
    // px转rpx（750设计稿）
    this.navBarHeightRpx = Math.round(navBarHeight * 750 / sysInfo.windowWidth)
  },
  methods: {
    async onRefresh() {
      // 模拟刷新数据
      await new Promise(resolve => setTimeout(resolve, 1000))
      this.stopPullRefresh()
    },
    openEmailPopup() { this.showEmailPopup = true },
    handleCloseEmailPopup() { this.showEmailPopup = false },
    navigateBack() { uni.navigateBack() },
    callService() {
      // 打开客服电话弹窗
      this.showPhonePopup = true
    },
    closePhonePopup() {
      this.showPhonePopup = false
    },
    makePhoneCall() {
      uni.makePhoneCall({ phoneNumber: '0731-599327-8899' })
    }
  }
}
</script>

<style lang="scss" scoped>
.faq-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #fff3db 0%, #ffffff 100%);
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  width: 100vw;
  background: #fef4df;
  box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.03);
  .nav-bar-inner {
    display: flex;
    align-items: center;
    height: 44px;
    width: 100vw;
    position: relative;
  }
  .back-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 0;
    top: 0;
  }
  .title {
    flex: 1;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    color: #222;
    letter-spacing: 0.5px;
    line-height: 44px;
  }
  .nav-bar-right {
    width: 44px;
    height: 44px;
    position: absolute;
    right: 0;
    top: 0;
  }
}

.content-card {
  margin: 88px 0 0 0;
  padding: 0 0 32rpx 0;
  width: 92vw;
  max-width: 700rpx;
  background: #fff;
  border-radius: 32rpx;
  box-shadow: 0 8rpx 32rpx rgba(60, 167, 250, 0.08);
  margin-left: auto;
  margin-right: auto;
  padding-top: 32rpx;
  padding-bottom: 0;
}

.qa-list {
  padding: 0 36rpx;
}
.qa-item {
  margin-bottom: 36rpx;
}
.question-row {
  display: flex;
  align-items: center;
  margin-bottom: 8rpx;
}
.q-icon {
  color: #ffb300;
  font-size: 32rpx;
  font-weight: bold;
  margin-right: 12rpx;
}
.question {
  font-size: 32rpx;
  font-weight: bold;
  color: #222;
}
.answer {
  font-size: 26rpx;
  color: #999;
  line-height: 1.7;
  padding-left: 44rpx;
}
.dashed-line {
  border-bottom: 2rpx dashed #e5e5e5;
  margin: 24rpx 36rpx 0 36rpx;
}
.bottom-tip {
  font-size: 24rpx;
  color: #999;
  text-align: left;
  line-height: 1.6;
  padding: 32rpx 36rpx 0 36rpx;
}

.bottom-btns {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 101;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 32rpx;
  padding: 24rpx 36rpx calc(24rpx + env(safe-area-inset-bottom)) 36rpx;
  background: #fff;
  box-shadow: 0 -2rpx 12rpx rgba(0,0,0,0.03);
}
.btn-outline {
  flex: 1;
  height: 88rpx;
  line-height: 88rpx;
  background: #fff;
  color: #ffb300;
  font-size: 32rpx;
  border-radius: 44rpx;
  border: 2rpx solid #ffb300;
  margin-right: 0;
}
.btn-gradient {
  flex: 1;
  height: 88rpx;
  line-height: 88rpx;
  background: linear-gradient(90deg, #ffdf8c 0%, #ffb300 100%);
  color: #fff;
  font-size: 32rpx;
  border-radius: 44rpx;
  border: none;
  margin-left: 0;
}
.phone-popup {
  position: fixed;
  left: 0; right: 0; bottom: 0; top: 0;
  z-index: 9999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  .popup-mask {
    position: absolute;
    left: 0; right: 0; top: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 0;
  }
  .popup-content {
    position: relative;
    width: 100vw;
    background: #fff;
    border-radius: 24rpx 24rpx 0 0;
    box-shadow: 0 -4rpx 32rpx rgba(0,0,0,0.08);
    padding-bottom: env(safe-area-inset-bottom);
    animation: popupUp 0.2s;
  }
  @keyframes popupUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .popup-header {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 56px;
    border-bottom: 1px solid #f2f2f2;
    position: relative;
    .close-btn {
      position: absolute;
      left: 24px;
      font-size: 17px;
      color: #999;
    }
    .popup-title {
      font-size: 18px;
      color: #222;
      font-weight: 600;
      letter-spacing: 1px;
    }
  }
  .popup-phone-row {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 0 32px 0;
    .popup-phone {
      font-size: 24px;
      color: #222;
      font-weight: 400;
      letter-spacing: 1px;
      margin-right: 18px;
    }
    .popup-phone-icon {
      width: 44px;
      height: 44px;
      background: #f5f5f5;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}
</style> 