图书馆小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
5.7 KiB

2 months ago
1 month ago
1 month ago
2 months ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
1 month ago
2 months ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
1 month ago
  1. <template>
  2. <view class="feedback-page">
  3. <scroll-view
  4. class="feedback-list"
  5. scroll-y
  6. @scrolltolower="loadMore"
  7. :scroll-with-animation="true"
  8. >
  9. <view class="empty" v-if="feedbackList.length === 0">
  10. <uni-icons style="margin-left: 20px;" custom-prefix="iconfont" type="icon-kongshuju" size="80" color="#ccc"></uni-icons>
  11. <text style="margin-top: 20px;">暂无留言</text>
  12. </view>
  13. <view
  14. class="feedback-item"
  15. v-for="(item, index) in feedbackList"
  16. :key="index"
  17. @click="goDetail(item)"
  18. >
  19. <view class="feedback-content">
  20. <text class="subject">{{ item.title }}</text>
  21. <text class="create-time">{{ formatTimestamp(item.suggestionTime) }}</text>
  22. </view>
  23. </view>
  24. <view class="loading-more" v-if="loading">
  25. <text>加载中...</text>
  26. </view>
  27. <view class="no-more" v-if="noMore">
  28. <text>没有更多留言了~</text>
  29. </view>
  30. </scroll-view>
  31. <view class="write-btn-box">
  32. <button class="write-btn" @click="goWriteComment">去留言</button>
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import { FetchInitReaderMessage } from '@/api/user';
  38. import config from '@/utils/config';
  39. import { getOpenId } from '@/utils/storage';
  40. export default {
  41. data() {
  42. return {
  43. feedbackList: [],
  44. pageNum: 0,
  45. pageSize: 10,
  46. loading: false,
  47. noMore: false,
  48. };
  49. },
  50. onLoad() {
  51. this.getInitReaderMessage();
  52. },
  53. onShow() {
  54. // 检查是否需要刷新(从留言页面提交成功返回)
  55. const needRefresh = uni.getStorageSync('needRefreshFeedback');
  56. uni.removeStorageSync('needRefreshFeedback');
  57. if (needRefresh) {
  58. this.refreshList();
  59. }
  60. },
  61. methods: {
  62. async getInitReaderMessage(){
  63. const openId = await getOpenId();
  64. if (!openId) {
  65. uni.showToast({ title: '获取用户信息失败', icon: 'none' });
  66. return;
  67. }
  68. // const currentReaderCard = await getCurrentReaderCard();
  69. const res = await FetchInitReaderMessage({
  70. libcode: config.LIB_CODE,
  71. openId: openId,
  72. // readCardNo: currentReaderCard.readCardNo,
  73. // readName: '',
  74. page: this.pageNum,
  75. size: this.pageSize,
  76. });
  77. if (res.code === 200) {
  78. this.feedbackList = res.data.content || [];
  79. } else {
  80. uni.showToast({ title: res.message || '获取留言列表失败', icon: 'none' });
  81. }
  82. },
  83. goWriteComment() {
  84. uni.navigateTo({
  85. url: '/subpkg/pages/feedback/feedback'
  86. });
  87. },
  88. goDetail(item) {
  89. console.log(item);
  90. uni.navigateTo({
  91. url: '/subpkg/pages/feedback-detail/feedback-detail?item=' + encodeURIComponent(JSON.stringify(item))
  92. });
  93. },
  94. formatTimestamp(timestamp) {
  95. if (!timestamp || typeof timestamp !== 'number') {
  96. return '暂无时间';
  97. }
  98. const date = new Date(timestamp);
  99. const year = date.getFullYear();
  100. const month = String(date.getMonth() + 1).padStart(2, '0');
  101. const day = String(date.getDate()).padStart(2, '0');
  102. const hours = String(date.getHours()).padStart(2, '0');
  103. const minutes = String(date.getMinutes()).padStart(2, '0');
  104. return `${year}-${month}-${day} ${hours}:${minutes}`;
  105. },
  106. async loadMore() {
  107. if (this.loading || this.noMore) return;
  108. this.loading = true;
  109. this.pageNum++;
  110. try {
  111. const openId = await getOpenId();
  112. if (!openId) {
  113. uni.showToast({ title: '获取用户信息失败', icon: 'none' });
  114. return;
  115. }
  116. const res = await FetchInitReaderMessage({
  117. libcode: config.LIB_CODE,
  118. openId: openId,
  119. page: this.pageNum,
  120. size: this.pageSize,
  121. });
  122. if (res.code === 200) {
  123. const newData = res.data.content || [];
  124. if (newData.length > 0) {
  125. this.feedbackList = [...this.feedbackList, ...newData];
  126. } else {
  127. this.noMore = true;
  128. }
  129. } else {
  130. uni.showToast({ title: res.message || '获取留言列表失败', icon: 'none' });
  131. this.pageNum--;
  132. }
  133. } catch (error) {
  134. console.error('加载更多失败:', error);
  135. this.pageNum--;
  136. uni.showToast({ title: '加载更多失败', icon: 'none' });
  137. } finally {
  138. this.loading = false;
  139. }
  140. },
  141. async refreshList() {
  142. // 重置分页状态
  143. this.pageNum = 0;
  144. this.noMore = false;
  145. this.loading = false;
  146. // 重新加载第一页数据
  147. await this.getInitReaderMessage();
  148. uni.pageScrollTo({
  149. scrollTop: 0,
  150. duration: 300
  151. });
  152. uni.stopPullDownRefresh();
  153. }
  154. }
  155. };
  156. </script>
  157. <style lang="scss" scoped>
  158. .feedback-page {
  159. background-color: #f7f8fa;
  160. min-height: 100vh;
  161. }
  162. .feedback-list {
  163. height: calc(100vh - 80px);
  164. }
  165. .empty {
  166. height: calc(100vh - 200px);
  167. }
  168. .feedback-item {
  169. background-color: #fff;
  170. border-radius: 8px;
  171. padding: 15px;
  172. margin: 0 10px 10px 10px;
  173. box-shadow: 0 1px 6px rgba(0, 0, 0, 0.06);
  174. }
  175. .feedback-content {
  176. line-height: 1.6;
  177. }
  178. .subject {
  179. font-size: 15px;
  180. font-weight: bold;
  181. color: #333;
  182. display: block;
  183. margin-bottom: 8px;
  184. }
  185. .create-time {
  186. font-size: 12px;
  187. color: #999;
  188. display: block;
  189. text-align: right;
  190. }
  191. .write-btn-box {
  192. position: fixed;
  193. bottom: 20px;
  194. left: 0;
  195. right: 0;
  196. padding: 0 15px;
  197. }
  198. .write-btn {
  199. background-color: #01a4fe;
  200. color: #fff;
  201. border-radius: 25px;
  202. font-size: 14px;
  203. padding: 4px 0;
  204. }
  205. .loading-more,
  206. .no-more {
  207. text-align: center;
  208. padding: 15px 0;
  209. font-size: 12px;
  210. color: #999;
  211. }
  212. </style>