图书馆小程序
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.

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