rules-for-sellbooks.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view class="rules-page">
  3. <!-- 头部选项卡 -->
  4. <view class="sticky-header">
  5. <view class="type-tabs-wrapper">
  6. <view class="type-tab" :class="{ active: currentTab === 0 }" @click="handleTabChange(0)">卖书答疑</view>
  7. <view class="type-tab" :class="{ active: currentTab === 1 }" @click="handleTabChange(1)">买书答疑</view>
  8. </view>
  9. </view>
  10. <!-- 折叠面板 -->
  11. <view class="collapse-container" v-if="!loading && faqList.length > 0">
  12. <u-collapse :accordion="true" @change="changeHandler" ref="collapse">
  13. <u-collapse-item
  14. v-for="(item, index) in faqList"
  15. :key="index"
  16. :title="item.subTitle"
  17. :index="index"
  18. :arrow="true"
  19. :name="index"
  20. :class="{ 'active-item': selectedIndex == index }"
  21. >
  22. <template #title>
  23. <view class="custom-title">
  24. <text class="title-text">{{ item.subTitle }}</text>
  25. </view>
  26. </template>
  27. <view class="collapse-content">
  28. <u-parse :html="item.subContent" class="rich-text-style"></u-parse>
  29. </view>
  30. </u-collapse-item>
  31. </u-collapse>
  32. </view>
  33. <!-- 空状态 -->
  34. <view v-if="!loading && faqList.length === 0" class="empty-state">
  35. <u-empty mode="data" text="暂无数据"></u-empty>
  36. </view>
  37. <!-- 客服按钮 -->
  38. <view class="customer-service">
  39. <!-- #ifdef MP-ALIPAY -->
  40. <button class="service-btn" @click="navigateToCustomerService">
  41. <view class="service-title">在线客服</view>
  42. <view class="service-time">需要帮助?联系在线客服,每日8:00-24:00在线</view>
  43. </button>
  44. <!-- #endif -->
  45. <!-- #ifndef MP-ALIPAY -->
  46. <button class="service-btn" open-type="contact">
  47. <view class="service-title">在线客服</view>
  48. <view class="service-time">需要帮助?联系在线客服,每日8:00-24:00在线</view>
  49. </button>
  50. <!-- #endif -->
  51. </view>
  52. <!-- 加载中 -->
  53. <u-loading-page :loading="loading"></u-loading-page>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. currentTab: 0,
  61. faqList: [], // FAQ列表数据
  62. loading: false,
  63. selectedIndex: -1,
  64. };
  65. },
  66. onLoad() {
  67. uni.setNavigationBarTitle({
  68. title: "买卖答疑"
  69. });
  70. this.getFaqData();
  71. },
  72. methods: {
  73. handleTabChange(index) {
  74. if (this.currentTab === index) return;
  75. this.currentTab = index;
  76. this.selectedIndex = -1;
  77. this.getFaqData();
  78. },
  79. navigateToCustomerService() {
  80. uni.navigateTo({
  81. url: '/pages-mine/pages/customer-service'
  82. });
  83. },
  84. // 获取FAQ数据
  85. getFaqData() {
  86. this.loading = true;
  87. const code = this.currentTab === 0 ? 'faq' : 'faqShop';
  88. this.$u.http
  89. .get("/token/getArticleTwo?code=" + code)
  90. .then((res) => {
  91. if (res.code === 200) {
  92. if (res.data && res.data.subArticleList && res.data.subArticleList.length > 0) {
  93. this.faqList = res.data.subArticleList;
  94. } else {
  95. this.faqList = [];
  96. }
  97. } else {
  98. this.$u.toast(res.msg || "获取数据失败");
  99. }
  100. })
  101. .catch((err) => {
  102. console.error("获取FAQ数据失败", err);
  103. this.$u.toast("获取数据失败");
  104. })
  105. .finally(() => {
  106. this.loading = false;
  107. });
  108. },
  109. // 折叠面板变化事件
  110. changeHandler(index) {
  111. console.log("当前打开的是第" + index + "个");
  112. this.selectedIndex = index;
  113. },
  114. },
  115. };
  116. </script>
  117. <style lang="scss" scoped>
  118. .rules-page {
  119. min-height: 100vh;
  120. background-color: #f5f5f5;
  121. padding-bottom: 120rpx;
  122. }
  123. .sticky-header {
  124. position: sticky;
  125. top: 0;
  126. z-index: 99;
  127. background: #f5f5f5;
  128. }
  129. .type-tabs-wrapper {
  130. display: flex;
  131. justify-content: space-around;
  132. align-items: center;
  133. height: 88rpx;
  134. background-color: #f5f5f5;
  135. }
  136. .type-tab {
  137. flex: 1;
  138. text-align: center;
  139. font-size: 30rpx;
  140. color: #666;
  141. line-height: 88rpx;
  142. position: relative;
  143. background-color: transparent;
  144. }
  145. .type-tab.active {
  146. color: #38c148;
  147. font-weight: bold;
  148. }
  149. .type-tab.active::after {
  150. content: '';
  151. position: absolute;
  152. bottom: 0;
  153. left: 50%;
  154. transform: translateX(-50%);
  155. width: 60rpx;
  156. height: 4rpx;
  157. background-color: #38c148;
  158. border-radius: 4rpx;
  159. }
  160. .collapse-container {
  161. background-color: #ffffff;
  162. overflow: hidden;
  163. }
  164. .custom-title {
  165. display: flex;
  166. align-items: center;
  167. flex: 1;
  168. }
  169. .title-text {
  170. font-size: 28rpx;
  171. color: #333;
  172. flex: 1;
  173. }
  174. .collapse-content {
  175. color: #444444;
  176. font-size: 28rpx;
  177. padding: 20rpx 0;
  178. height: auto;
  179. overflow: visible;
  180. }
  181. .empty-state {
  182. margin-top: 100rpx;
  183. }
  184. .customer-service {
  185. position: fixed;
  186. bottom: 0;
  187. left: 0;
  188. right: 0;
  189. padding: 24rpx;
  190. background-color: #fff;
  191. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  192. z-index: 10;
  193. padding-bottom: calc(env(safe-area-inset-bottom) + 20rpx);
  194. }
  195. .service-btn {
  196. width: 100%;
  197. height: 90rpx;
  198. line-height: 32rpx;
  199. background-color: #4caf50;
  200. color: white;
  201. font-size: 36rpx;
  202. border-radius: 10rpx;
  203. text-align: center;
  204. margin-bottom: 15rpx;
  205. padding-top: 16rpx;
  206. }
  207. .service-time {
  208. font-size: 22rpx;
  209. color: #ffffff;
  210. text-align: center;
  211. }
  212. ::v-deep .u-collapse-item {
  213. border-bottom: 1px solid #f0f0f0;
  214. overflow: visible;
  215. background-color: #ffffff;
  216. padding: 0 30rpx;
  217. }
  218. ::v-deep .u-collapse-item:last-child {
  219. border-bottom: none;
  220. }
  221. ::v-deep .active-item .u-collapse-body {
  222. height: fit-content !important;
  223. }
  224. ::v-deep .rich-text-style {
  225. width: 100%;
  226. }
  227. ::v-deep .rich-text-style img {
  228. max-width: 100%;
  229. height: auto !important;
  230. border-radius: 10rpx;
  231. margin-top: 10rpx;
  232. display: block;
  233. }
  234. </style>