message.vue 6.2 KB

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