FirstList.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <!-- 商城宣传页,列表页 -->
  2. <template>
  3. <view class="page-body" style="background: #f6f6f6;">
  4. {{type}}
  5. <view v-if="state.pagination.total > 0 && type == 'activityCard'">
  6. <view class="article ss-r-10" v-for="item in state.pagination.list" @click="sheep.$router.go('/pages/public/richtext', {title:item.title});">
  7. <view class="title" >
  8. {{item.title}}
  9. </view>
  10. <view class="content">
  11. <view class="image " v-if="item.picUrl.trim()">
  12. <image :src="item.picUrl" mode="aspectFit" class="image-content"></image>
  13. </view>
  14. <view class="desc" >
  15. {{item.introduction}}
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. <view v-if="state.pagination.total > 0 && type == 'articleCard'">
  21. <view class="activity ss-r-10" v-for="item in state.pagination.list" :style="{ backgroundImage: `url(${item.picUrl})` }" @click="sheep.$router.go('/pages/public/richtext', {title:item.title});">
  22. <view class="activity-bottom">
  23. <text>{{item.title}}</text>
  24. <view class=""><image src="@/static/firstIndex/youjiantou.png" mode="aspectFit" /></view>
  25. </view>
  26. </view>
  27. </view>
  28. <s-empty v-if="state.pagination.total === 0" icon="/static/data-empty.png" :text="t('common.no_data')" />
  29. <uni-load-more v-if="state.pagination.total > 0" :status="state.loadStatus" :content-text="{ contentdown: '上拉加载更多'}" @tap="loadmore" />
  30. <s-tabbar path="/pages/index/FirstIndex" :tabbar="tabbar" />
  31. </view>
  32. </template>
  33. <script setup>
  34. import {
  35. computed,
  36. ref,
  37. reactive
  38. } from 'vue';
  39. import {
  40. onLoad,
  41. onShow,
  42. onReachBottom,
  43. onPullDownRefresh
  44. } from '@dcloudio/uni-app';
  45. import sheep from '@/sheep';
  46. import $share from '@/sheep/platform/share';
  47. import _ from 'lodash';
  48. import {
  49. isAndroid,
  50. getAndroidJiGuangId
  51. } from '@/sheep/hooks/useApp'
  52. import {
  53. showWalletModal,
  54. colseWalletModal
  55. } from '@/sheep/hooks/useModal';
  56. import { t } from '@/locale'
  57. import ArticleApi from '@/sheep/api/promotion/article';
  58. // 隐藏原生tabBar
  59. uni.hideTabBar();
  60. const appInfo = computed(() => sheep.$store('app').info);
  61. const {
  62. safeArea
  63. } = sheep.$platform.device;
  64. const pageHeight = computed(() => safeArea.height - 45);
  65. const props = defineProps({
  66. // 是否显示tabbar
  67. tabbar: {
  68. type: Boolean,
  69. default: true
  70. },
  71. // 是否显示tabbar
  72. categoryId: {
  73. type: Number,
  74. default: 0
  75. },
  76. type:{
  77. type:String,
  78. default:'articleCard'
  79. }
  80. });
  81. const tabbar = ref({
  82. "theme": "red",
  83. "style": {
  84. "bgType": "color",
  85. "bgColor": "#ffffff",
  86. "color": "#3c3c3c",
  87. "activeColor": "#1fa380"
  88. },
  89. "items": [{
  90. "text": t('common.home'),
  91. "url": "/pages/index/FirstIndex",
  92. "iconUrl": sheep.$url.static('/static/firstIndex/index.svg'),
  93. "activeIconUrl": sheep.$url.static('/static/firstIndex/index-active.svg')
  94. },
  95. {
  96. "text": t('common.activities'),
  97. "url": "/pages/index/FirstActivity",
  98. "iconUrl": sheep.$url.static('/static/firstIndex/activity.svg'),
  99. "activeIconUrl": sheep.$url.static('/static/firstIndex/activity-active.svg')
  100. },
  101. // {
  102. // "text": t('common.merchant'),
  103. // "url": "/pages/index/FirstMerchant",
  104. // "iconUrl": sheep.$url.static('/static/firstIndex/merchant.svg'),
  105. // "activeIconUrl": sheep.$url.static('/static/firstIndex/merchant-active.svg')
  106. // },
  107. {
  108. "text": t('common.videos'),
  109. "url": "/pages/index/FirstVideo",
  110. "iconUrl": sheep.$url.static('/static/firstIndex/video.svg'),
  111. "activeIconUrl": sheep.$url.static('/static/firstIndex/video-active.svg')
  112. },
  113. {
  114. "text": t('common.mall'),
  115. "url": "/pages/index/index",
  116. "iconUrl": sheep.$url.static('/static/firstIndex/shop.svg'),
  117. "activeIconUrl": sheep.$url.static('/static/firstIndex/shop-active.svg')
  118. }
  119. ]
  120. });
  121. // 数据
  122. const state = reactive({
  123. categoryId: 0,
  124. pagination: {
  125. list: [],
  126. current_page: 1,
  127. total: 1,
  128. last_page: 1,
  129. },
  130. loadStatus: ''
  131. });
  132. async function getArticleList(page = 1, list_rows = 5) {
  133. state.loadStatus = 'loading';
  134. let { code, data } = await ArticleApi.getArticleByCategory({pageNo: page,pageSize: list_rows,categoryId: state.categoryId});
  135. if (code !== 0) {
  136. return;
  137. }
  138. let articleList = _.concat(state.pagination.list, data.list);
  139. state.pagination.list = articleList
  140. state.pagination.total = data.total;
  141. state.pagination.last_page = Math.ceil(data.total / 5)
  142. if (state.pagination.current_page < state.pagination.last_page) {
  143. state.loadStatus = 'more';
  144. } else {
  145. state.loadStatus = 'noMore';
  146. }
  147. console.log(state.pagination.list,state.pagination.total)
  148. }
  149. // 加载更多
  150. function loadMore() {
  151. if (state.loadStatus !== 'noMore') {
  152. state.pagination.current_page += 1
  153. getArticleList(state.pagination.current_page);
  154. }
  155. }
  156. onLoad(async (option) => {
  157. if(option && option.categoryId){
  158. state.categoryId = option.categoryId
  159. }else{
  160. state.categoryId = props.categoryId
  161. }
  162. await getArticleList();
  163. });
  164. // 上拉加载更多
  165. onReachBottom(() => {
  166. loadMore();
  167. });
  168. // 下拉刷新
  169. onPullDownRefresh(() => {
  170. state.pagination.list = []
  171. state.pagination.current_page = 1
  172. state.pagination.total = 1
  173. state.pagination.last_page = 1
  174. getArticleList();
  175. setTimeout(function() {
  176. uni.stopPullDownRefresh();
  177. }, 800);
  178. });
  179. </script>
  180. <style scoped>
  181. .page-body {
  182. width: 100%;
  183. position: relative;
  184. z-index: 1;
  185. flex: 1;
  186. padding-top:40rpx;
  187. box-sizing:border-box;
  188. .article {
  189. padding:16rpx;
  190. height: 230rpx;
  191. position: relative;
  192. width: 90%;
  193. margin: 0 auto;
  194. color:#000;
  195. margin-bottom: 40rpx;
  196. background-repeat: no-repeat;
  197. background-size: 100%;
  198. background-position: center;
  199. background-color: #fff;
  200. overflow: hidden;
  201. .title {
  202. font-size: 34rpx;
  203. /* font-weight: bold; */
  204. margin-bottom: 8px;
  205. }
  206. .content {
  207. display: flex;
  208. flex-direction: row;
  209. }
  210. .image {
  211. width: 300rpx;
  212. height: 169rpx;
  213. margin-right: 16rpx;
  214. background-color: #999;
  215. }
  216. .image-content {
  217. width: 100%;
  218. height: 100%;
  219. border-radius: 8rpx;
  220. }
  221. .desc {
  222. flex: 1;
  223. font-size: 32rpx;
  224. color: #333;
  225. line-height: 1.6;
  226. padding-top: 10rpx;
  227. overflow: hidden;
  228. display: -webkit-box;
  229. -webkit-box-orient: vertical;
  230. -webkit-line-clamp: 3;
  231. text-overflow: ellipsis;
  232. }
  233. }
  234. .activity {
  235. height: 300rpx;
  236. position: relative;
  237. width: 90%;
  238. margin: 0 auto;
  239. color:#fff;
  240. margin-bottom: 40rpx;
  241. background-repeat: no-repeat;
  242. background-size: 100%;
  243. background-position: center;
  244. background-color: #fff;
  245. overflow: hidden;
  246. .activity-bottom{
  247. position: absolute;
  248. bottom: 0;
  249. left: 0;
  250. width: 100%;
  251. height: 50rpx;
  252. background: rgba(0,0,0,0.5);
  253. padding:10rpx;
  254. box-sizing: border-box;
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. text{
  259. white-space: nowrap;
  260. overflow: hidden;
  261. text-overflow: ellipsis;
  262. };
  263. image{
  264. width: 20rpx;
  265. height: 20rpx;
  266. }
  267. }
  268. }
  269. }
  270. </style>