index.vue 5.8 KB

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