answer-list.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <view>
  3. <scroll-view :scroll-y="true" class="scroll-box" @scrolltolower="scroll_lower" lower-threshold="60">
  4. <view v-if="data_list.length > 0" class="padding-horizontal-main padding-top-main">
  5. <view v-for="(item, index) in data_list" :key="index" class="padding-main border-radius-main bg-white oh spacing-mb">
  6. <view class="br-b-dashed oh padding-bottom-main">
  7. <image class="avatar fl br bg-white round" :src="item.user.avatar" mode="widthFix" :data-index="index" @error="user_avatar_error"></image>
  8. <text class="fl margin-left-sm cr-base">{{item.user.user_name_view}}</text>
  9. <text class="fr cr-base">{{item.add_time_time}}</text>
  10. </view>
  11. <view class="cr-gray margin-top-lg">{{item.content}}</view>
  12. <view v-if="(item.reply || null) != null" class="br-t margin-top-main padding-top-main">
  13. <text class="bg-main cr-white padding-top-xs padding-bottom-xs padding-left padding-right round margin-right-sm">答</text>
  14. <text class="cr-gray">{{item.reply}}</text>
  15. </view>
  16. </view>
  17. </view>
  18. <view v-else>
  19. <!-- 提示信息 -->
  20. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  21. </view>
  22. <!-- 结尾 -->
  23. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  24. </scroll-view>
  25. </view>
  26. </template>
  27. <script>
  28. const app = getApp();
  29. import componentNoData from "../../components/no-data/no-data";
  30. import componentBottomLine from "../../components/bottom-line/bottom-line";
  31. export default {
  32. data() {
  33. return {
  34. data_list: [],
  35. data_total: 0,
  36. data_page_total: 0,
  37. data_page: 1,
  38. data_list_loding_status: 1,
  39. data_bottom_line_status: false
  40. };
  41. },
  42. components: {
  43. componentNoData,
  44. componentBottomLine
  45. },
  46. props: {},
  47. onLoad() {},
  48. onShow() {
  49. this.get_data_list();
  50. // 分享菜单处理
  51. app.globalData.page_share_handle();
  52. },
  53. // 下拉刷新
  54. onPullDownRefresh() {
  55. this.setData({
  56. data_page: 1
  57. });
  58. this.get_data_list(1);
  59. },
  60. methods: {
  61. get_data_list(is_mandatory) {
  62. // 分页是否还有数据
  63. if ((is_mandatory || 0) == 0) {
  64. if (this.data_bottom_line_status == true) {
  65. uni.stopPullDownRefresh();
  66. return false;
  67. }
  68. }
  69. // 加载loding
  70. this.setData({
  71. data_list_loding_status: 1
  72. });
  73. // 获取数据
  74. uni.request({
  75. url: app.globalData.get_request_url("square", "answer"),
  76. method: 'POST',
  77. data: {
  78. page: this.data_page
  79. },
  80. dataType: 'json',
  81. success: res => {
  82. uni.stopPullDownRefresh();
  83. if (res.data.code == 0) {
  84. if (res.data.data.data.length > 0) {
  85. if (this.data_page <= 1) {
  86. var temp_data_list = res.data.data.data;
  87. } else {
  88. var temp_data_list = this.data_list || [];
  89. var temp_data = res.data.data.data;
  90. for (var i in temp_data) {
  91. temp_data_list.push(temp_data[i]);
  92. }
  93. }
  94. this.setData({
  95. data_list: temp_data_list,
  96. data_total: res.data.data.total,
  97. data_page_total: res.data.data.page_total,
  98. data_list_loding_status: 3,
  99. data_page: this.data_page + 1
  100. });
  101. // 是否还有数据
  102. this.setData({
  103. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  104. });
  105. } else {
  106. this.setData({
  107. data_list_loding_status: 0
  108. });
  109. }
  110. } else {
  111. this.setData({
  112. data_list_loding_status: 0
  113. });
  114. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  115. app.globalData.showToast(res.data.msg);
  116. }
  117. }
  118. },
  119. fail: () => {
  120. uni.stopPullDownRefresh();
  121. this.setData({
  122. data_list_loding_status: 2
  123. });
  124. app.globalData.showToast('服务器请求出错');
  125. }
  126. });
  127. },
  128. // 滚动加载
  129. scroll_lower(e) {
  130. this.get_data_list();
  131. },
  132. // 头像加载错误
  133. user_avatar_error(e) {
  134. var index = e.currentTarget.dataset.index || 0;
  135. var temp_data_list = this.data_list;
  136. for (var i in temp_data_list) {
  137. if (i == index) {
  138. temp_data_list[i]['user']['avatar'] = app.globalData.data.default_user_head_src;
  139. break;
  140. }
  141. }
  142. this.setData({
  143. data_list: temp_data_list
  144. });
  145. }
  146. }
  147. };
  148. </script>
  149. <style>
  150. @import './answer-list.css';
  151. </style>