user-answer-list.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. <text class="fw-b">{{item.name}}</text>
  8. <text class="fr cr-base">{{item.add_time_time}}</text>
  9. </view>
  10. <view class="cr-gray margin-top-lg">{{item.content}}</view>
  11. <view v-if="(item.reply || null) != null" class="br-t margin-top-main padding-top-main">
  12. <text class="bg-main cr-white padding-top-xs padding-bottom-xs padding-left padding-right round margin-right-sm">答</text>
  13. <text class="cr-gray">{{item.reply}}</text>
  14. </view>
  15. </view>
  16. </view>
  17. <view v-else>
  18. <!-- 提示信息 -->
  19. <component-no-data :propStatus="data_list_loding_status"></component-no-data>
  20. </view>
  21. <!-- 结尾 -->
  22. <component-bottom-line :propStatus="data_bottom_line_status"></component-bottom-line>
  23. </scroll-view>
  24. <!-- 新增入口 -->
  25. <navigator url="/pages/answer-form/answer-form" hover-class="none">
  26. <view class="answer-add-submit bg-main cr-white round tc">+</view>
  27. </navigator>
  28. </view>
  29. </template>
  30. <script>
  31. const app = getApp();
  32. import componentNoData from "../../components/no-data/no-data";
  33. import componentBottomLine from "../../components/bottom-line/bottom-line";
  34. export default {
  35. data() {
  36. return {
  37. data_list: [],
  38. data_total: 0,
  39. data_page_total: 0,
  40. data_page: 1,
  41. data_list_loding_status: 1,
  42. data_bottom_line_status: false
  43. };
  44. },
  45. components: {
  46. componentNoData,
  47. componentBottomLine
  48. },
  49. props: {},
  50. onLoad() {},
  51. onShow() {
  52. this.init();
  53. // 分享菜单处理
  54. app.globalData.page_share_handle();
  55. },
  56. // 下拉刷新
  57. onPullDownRefresh() {
  58. this.setData({
  59. data_page: 1
  60. });
  61. this.get_data_list(1);
  62. },
  63. methods: {
  64. init() {
  65. var user = app.globalData.get_user_info(this, "init");
  66. if (user != false) {
  67. // 用户未绑定用户则转到登录页面
  68. if (app.globalData.user_is_need_login(user)) {
  69. uni.redirectTo({
  70. url: "/pages/login/login?event_callback=init"
  71. });
  72. return false;
  73. } else {
  74. // 获取数据
  75. this.get_data_list();
  76. }
  77. } else {
  78. this.setData({
  79. data_list_loding_status: 0,
  80. data_bottom_line_status: false
  81. });
  82. }
  83. },
  84. get_data_list(is_mandatory) {
  85. // 分页是否还有数据
  86. if ((is_mandatory || 0) == 0) {
  87. if (this.data_bottom_line_status == true) {
  88. uni.stopPullDownRefresh();
  89. return false;
  90. }
  91. }
  92. // 加载loding
  93. uni.showLoading({
  94. title: '加载中...'
  95. });
  96. this.setData({
  97. data_list_loding_status: 1
  98. });
  99. // 获取数据
  100. uni.request({
  101. url: app.globalData.get_request_url("index", "answer"),
  102. method: 'POST',
  103. data: {
  104. page: this.data_page
  105. },
  106. dataType: 'json',
  107. success: res => {
  108. uni.hideLoading();
  109. uni.stopPullDownRefresh();
  110. if (res.data.code == 0) {
  111. if (res.data.data.data.length > 0) {
  112. if (this.data_page <= 1) {
  113. var temp_data_list = res.data.data.data;
  114. } else {
  115. var temp_data_list = this.data_list || [];
  116. var temp_data = res.data.data.data;
  117. for (var i in temp_data) {
  118. temp_data_list.push(temp_data[i]);
  119. }
  120. }
  121. this.setData({
  122. data_list: temp_data_list,
  123. data_total: res.data.data.total,
  124. data_page_total: res.data.data.page_total,
  125. data_list_loding_status: 3,
  126. data_page: this.data_page + 1
  127. });
  128. // 是否还有数据
  129. this.setData({
  130. data_bottom_line_status: (this.data_page > 1 && this.data_page > this.data_page_total)
  131. });
  132. } else {
  133. this.setData({
  134. data_list_loding_status: 0
  135. });
  136. }
  137. } else {
  138. this.setData({
  139. data_list_loding_status: 0
  140. });
  141. if (app.globalData.is_login_check(res.data, this, 'get_data_list')) {
  142. app.globalData.showToast(res.data.msg);
  143. }
  144. }
  145. },
  146. fail: () => {
  147. uni.hideLoading();
  148. uni.stopPullDownRefresh();
  149. this.setData({
  150. data_list_loding_status: 2
  151. });
  152. app.globalData.showToast('服务器请求出错');
  153. }
  154. });
  155. },
  156. // 滚动加载
  157. scroll_lower(e) {
  158. this.get_data_list();
  159. }
  160. }
  161. };
  162. </script>
  163. <style>
  164. @import './user-answer-list.css';
  165. </style>