index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. <template>
  2. <view class="regulations">
  3. <view class="regulations-content">
  4. <scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="handleScrolltolower">
  5. <view class="regulations-listbody">
  6. <!-- 列表无数据 -->
  7. <template v-if="list_empty">
  8. <view class="regulations-listbody-nodata">
  9. <text class="regulations-listbody-nodata-text">暂无数据</text>
  10. </view>
  11. </template>
  12. <!-- 列表有数据 -->
  13. <template v-else>
  14. <view
  15. class="listbody-item"
  16. v-for="regulationsItem in regulationsList"
  17. :key="regulationsItem.id"
  18. @click="handleRegulationsDetails(regulationsItem)"
  19. >
  20. <view class="item-container">
  21. <view class="container-left">
  22. <view class="left-title">{{ regulationsItem.artTitle }}</view>
  23. <view class="left-releasetime">发布时间:{{ regulationsItem.artInTime }}</view>
  24. </view>
  25. <view class="container-right">
  26. <view class="right-content">
  27. <template v-if="regulationsItem.artImage">
  28. <image
  29. :src="baseApiUrl + regulationsItem.artImage"
  30. mode="scaleToFill"
  31. class="right-content-image"
  32. />
  33. </template>
  34. <template v-else>
  35. <image
  36. src="@/static/agrcloud-images/agrcloud-empty-img.png"
  37. mode="scaleToFill"
  38. class="right-content-image"
  39. />
  40. </template>
  41. </view>
  42. </view>
  43. <view style="clear: both;"></view>
  44. </view>
  45. </view>
  46. </template>
  47. <!-- 加载更多组件 -->
  48. <uni-load-more :status="loadStatus" v-if="!list_empty"></uni-load-more>
  49. </view>
  50. </scroll-view>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. regulationsListData
  57. } from '@/agrcloud-api/regulations';
  58. import uniLoadMore from "@/agrcloud-components/uni-load-more/uni-load-more.vue"
  59. export default {
  60. name: 'regulations',
  61. components: {
  62. uniLoadMore
  63. },
  64. data() {
  65. return {
  66. loadStatus: 'more',
  67. list_empty: false,
  68. pageTotal: 0,
  69. pageCount: 0,
  70. pagination: {
  71. artCategoryId: '0',
  72. pageNum: 1,
  73. pageSize: 10
  74. },
  75. regulationsList: []
  76. };
  77. },
  78. onLoad() {
  79. this.initData();
  80. },
  81. methods: {
  82. /** 初始化数据 */
  83. initData() {
  84. this.getRegulationsListData();
  85. },
  86. /** 获取政策法规之列表数据 */
  87. getRegulationsListData() {
  88. this.list_empty = false;
  89. this.loadStatus = 'loading';
  90. regulationsListData(this.pagination).then(res => {
  91. debugger
  92. // 数据总条数
  93. this.pageTotal = res.total || 0;
  94. // 如果列表为第一页,返回列表数据清空
  95. if (this.pagination.pageNum == 1) {
  96. this.regulationsList = [];
  97. };
  98. // 处理返回结果
  99. if ((res.rows || []).length <= 0) { // 返回结果没有数据
  100. if ((this.regulationsList || []).length <= 0) {
  101. this.loadStatus = 'noMores';
  102. this.list_empty = true;
  103. } else {
  104. this.loadStatus = 'noMores';
  105. }
  106. } else { //返回结果有数据
  107. this.list_empty = false;
  108. // 获取列表数据分页数量
  109. this.pageCount = Math.ceil((res.total || 0) / this.pagination.pageSize);
  110. if ((res.total || 0) % this.pagination.pageSize == 0) {
  111. this.pageCount = Math.ceil((res.total || 0) / this.pagination.pageSize);
  112. if (this.pageCount == 1) {
  113. this.pageCount--;
  114. }
  115. } else {
  116. this.pageCount--;
  117. };
  118. // 处理页面状态
  119. if (this.pageCount === 0) {
  120. this.loadStatus = 'noMores'
  121. } else {
  122. this.loadStatus = 'more'
  123. }
  124. // 组装返回数据
  125. this.regulationsList.push.apply(this.regulationsList, res.rows || []);
  126. uni.stopPullDownRefresh();
  127. }
  128. }).catch(err => {
  129. this.loadStatus = 'noMores';
  130. });
  131. },
  132. handleScrolltolower() {
  133. debugger;
  134. this.loadStatus = 'loading';
  135. if (this.pagination.pageNum - 1 >= this.pageCount) {
  136. this.loadStatus = 'noMores';
  137. return;
  138. } else {
  139. this.pagination.pageNum++;
  140. this.getRegulationsListData();
  141. }
  142. },
  143. /** 政策法规之详情数据操作 */
  144. handleRegulationsDetails(param) {
  145. this.$store.dispatch("SetRegulationsDetails", param).then(() => {
  146. uni.navigateTo({
  147. url: '/pages/regulations/details/index'
  148. });
  149. }).catch(() => {
  150. this.$msgbox('访问数据异常!', 'none');
  151. });
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss"
  157. scoped>
  158. .regulations {
  159. padding-top: 25rpx;
  160. width: 100%;
  161. .regulations-content {
  162. width: 100%;
  163. .scroll-Y {
  164. height: calc(
  165. 100vh - 88rpx - 100rpx - env(safe-area-inset-bottom) -
  166. var(--status-bar-height)
  167. );
  168. }
  169. .regulations-listbody {
  170. width: 100%;
  171. .listbody-item {
  172. width: 750rpx;
  173. height: 208rpx;
  174. background: #ffffff;
  175. margin-bottom: 24rpx;
  176. .item-container {
  177. padding: 24rpx;
  178. .container-left {
  179. float: left;
  180. width: 478rpx;
  181. .left-title {
  182. height: 84rpx;
  183. font-size: 30rpx;
  184. font-family: PingFangSC-Medium, PingFang SC;
  185. font-weight: 500;
  186. color: #333333;
  187. line-height: 42rpx;
  188. }
  189. .left-releasetime {
  190. margin-top: 16rpx;
  191. }
  192. }
  193. .container-right {
  194. float: left;
  195. margin-left: 24rpx;
  196. .right-content {
  197. width: 200rpx;
  198. height: 160rpx;
  199. border-radius: 8rpx;
  200. .right-content-image {
  201. width: 200rpx;
  202. height: 160rpx;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. &-nodata {
  209. text-align: center;
  210. margin-top: 20rpx;
  211. &-text {
  212. font-size: 30rpx;
  213. color: #777777;
  214. }
  215. }
  216. }
  217. }
  218. }
  219. </style>