index.vue 6.2 KB

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