<template>
  <view class="faq-page">
    <!-- 顶部导航栏 -->
    <view class="nav-bar">
      <view class="back" @tap="navigateBack">
        <uni-icons type="left" size="20"></uni-icons>
      </view>
      <text class="nav-title">联系客服</text>
    </view>
    <view class="main-content">
      <view class="content-card">
        <view class="qa-list">
          <view class="qa-item" 
		  @click="$utils.navigateTo('/pages/mine/questionDetail?id=' + item.id)"
		  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>
    <!-- 底部按钮 -->
    <view class="bottom-btns">
      <button class="btn-outline" @tap="callService">客服电话</button>
      <button class="btn-gradient" open-type="contact">联系在线客服</button>
    </view>
    <!-- 客服电话底部弹窗 -->
    <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">
          <text class="popup-phone">{{phone}}</text>
          <view class="popup-phone-icon">
            <uni-icons type="phone-filled" size="28" color="#222"  @tap="makePhoneCall"/>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import pullRefreshMixin from '@/pages/mixins/pullRefreshMixin.js'

export default {
  mixins: [pullRefreshMixin],
  data() {
    return {
      statusBarHeight: 0,
      navBarHeight: 0, // px
      navBarHeightRpx: 0, // rpx
      showPhonePopup: false,
      faqList: []
    }
  },
  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)
    this.getQuestionList()
  },
  computed: {
    phone() {
			console.log(getApp().globalData.configData,'getApp().globalData.configData')
      const item =  getApp().globalData.configData.find(i => i.keyName === 'phone')
      return item ? item.keyContent : ''
    },
  },
  methods: {
    async onRefresh() {
      // 模拟刷新数据
      await new Promise(resolve => setTimeout(resolve, 1000))
      uni.stopPullRefresh()
    },
    navigateBack() { uni.navigateBack() },
    callService() {
      // 打开客服电话弹窗
      this.showPhonePopup = true
    },
    closePhonePopup() {
      this.showPhonePopup = false
    },
    makePhoneCall() {
      // uni.makePhoneCall({ phoneNumber: '0731-599327-8899' })
      if (this.phone) {
        uni.makePhoneCall({
          phoneNumber: this.phone //仅为示例
        });
      }else{
        uni.showToast({ title: '暂无客服电话', icon: 'none' });
      }
    },
    getQuestionList() {
      this.$api('getQuestionList', {}, res => {
        if (res && res.success && res.result && res.result.records) {
          this.faqList = res.result.records.map(item => ({
            q: item.title,
            a: item.titleText,
			id : item.id
          }))
        }
      })
    }
  }
}
</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 {
  display: flex;
  align-items: center;
  height: calc(150rpx + var(--status-bar-height));
  padding: 0 32rpx;
  padding-top: var(--status-bar-height);
  background: linear-gradient(180deg, #fff3db 100%, #ffffff 0%);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 999;
  box-sizing: border-box;
  box-shadow: 0 2rpx 8rpx rgba(0,0,0,0.03);
  .back {
    padding: 20rpx;
    margin-left: -20rpx;
  }
  .nav-title {
    flex: 1;
    text-align: center;
    font-size: 32rpx;
    font-weight: 500;
    color: #222;
  }
}

.main-content {
  margin-top: calc(150rpx + var(--status-bar-height));
  margin-bottom: 40rpx;
  padding-bottom: calc(88rpx + env(safe-area-inset-bottom));
}

.content-card {
  margin: 0 32rpx;
  padding: 32rpx;
  background: #fff;
  border-radius: 32rpx;
  box-shadow: 0 8rpx 32rpx rgba(60, 167, 250, 0.08);
}

.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: #fff0d2;
  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> 