activity.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <view class="container activity">
  3. <tui-skeleton v-if="isRequest" loadingType="2"></tui-skeleton>
  4. <view class="activity-banner">
  5. <image class="activity-banner-image" :src="activityBanner" mode=""></image>
  6. </view>
  7. <!-- 商品列表 -->
  8. <view class="container-section tui-skeleton clearfix">
  9. <view class="product-list" v-for="(pro, index) in productList" :key="index" @click.stop="detail(pro)">
  10. <view class="product-list-image">
  11. <image class="product-image" :src="pro.mainImage" mode=""></image>
  12. </view>
  13. <view class="product-list-msg">
  14. <view class="product-msg-name">{{ pro.name }}</view>
  15. <view class="product-list-tag" v-if="pro.activeStatus === 1">
  16. <text class="tag tag-01">促销</text> <text class="tag tag-02">活动价</text>
  17. <text class="tag tag-02" v-if="pro.couponsLogo">优惠券</text>
  18. </view>
  19. <view class="product-list-pri">
  20. <view class="price">¥{{ pro.price | priceFormat }}</view>
  21. <view class="carts" @click.stop="handAddCarts(pro)">
  22. <view class="carts-add"> <text class="iconfont icon-gouwuche"></text> </view>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. <template v-if="productList.length >= 6">
  29. <tui-loadmore :index="3" :visible="loadmore"></tui-loadmore>
  30. <tui-nomore :text="loadingText" :visible="!loadmore" backgroundColor="#ff457b"></tui-nomore>
  31. </template>
  32. <!-- 可拖动悬浮按钮 -->
  33. <cm-drag :cartNum="kindCount" :isDock="true" :existTabBar="true" @btnClick="btnClick"> </cm-drag>
  34. </view>
  35. </template>
  36. <script>
  37. import wxLogin from '@/services/wxLogin.js'
  38. import { mapGetters, mapActions, mapMutations } from 'vuex'
  39. import cmDrag from '@/components/cm-module/cm-drag/cm-drag'
  40. export default {
  41. components: {
  42. cmDrag
  43. },
  44. data() {
  45. return {
  46. StaticUrl: this.$Static,
  47. activityBanner: `${this.$Static}banner.png`,
  48. cartNum: 0,
  49. listQuery: {
  50. activityId: 0,
  51. userId: 0,
  52. pageNum: 1,
  53. pageSize: 6
  54. },
  55. activityName: '',
  56. hasNextPage: false,
  57. productList: [], //商品列表
  58. isRefresh: false,
  59. isRequest: true,
  60. loadmore: false // 正在加载更多
  61. }
  62. },
  63. onLoad(option) {
  64. // 收集分享信息
  65. if (option.type && option.type === 'share') this.setInviteUserId(option.inviteUserId)
  66. this.listQuery.activityId = option.activityId
  67. this.listQuery.userId = this.userId
  68. this.activityName = option.name
  69. this.getProductActivityDetails()
  70. },
  71. filters: {
  72. //处理金额
  73. priceFormat: function(text) {
  74. return Number(text).toFixed(2)
  75. }
  76. },
  77. computed: {
  78. ...mapGetters(['hasLogin', 'userId', 'kindCount']),
  79. loadingText() {
  80. return this.hasNextPage ? '上拉加载更多' : '没有更多了'
  81. }
  82. },
  83. methods: {
  84. ...mapActions('cart', ['addToCart']),
  85. ...mapMutations('user', ['setInviteUserId']),
  86. // 获取活动信息
  87. getProductActivityDetails() {
  88. this.loadmore = true
  89. this.ProductService.GetProductActivityDetails(this.listQuery)
  90. .then(response => {
  91. const data = response.data
  92. this.activityBanner = data.image
  93. this.hasNextPage = data.pageInfo.hasNextPage
  94. if (this.isRefresh) {
  95. this.productList = data.pageInfo.list
  96. } else {
  97. this.productList = [...this.productList, ...data.pageInfo.list]
  98. }
  99. this.isRequest = false
  100. this.loadmore = false
  101. })
  102. .catch(error => {
  103. this.$util.msg(error.msg, 2000)
  104. })
  105. .finally(() => {
  106. if (this.isRefresh) {
  107. setTimeout(() => {
  108. uni.stopPullDownRefresh()
  109. }, 500)
  110. this.isRefresh = false
  111. }
  112. })
  113. },
  114. detail(pro) {
  115. this.$api.navigateTo(`/pages/goods/product-detail?productId=${pro.productId}&jumpState=2`)
  116. },
  117. handAddCarts(pro) {
  118. this.addToCart({ productId: pro.productId, heUserId: this.userId })
  119. },
  120. btnClick() {
  121. this.$api.navigateTo('/pages/goods/cart')
  122. }
  123. },
  124. onPullDownRefresh() {
  125. //下拉刷新
  126. this.isRefresh = true
  127. this.listQuery.pageNum = 1
  128. this.getProductActivityDetails()
  129. },
  130. onReachBottom() {
  131. if (this.hasNextPage) {
  132. this.listQuery.pageNum ++
  133. this.getProductActivityDetails()
  134. }
  135. },
  136. onShareAppMessage(res) {
  137. //分享转发
  138. if (res.from === 'button') {
  139. // 来自页面内转发按钮
  140. }
  141. return {
  142. title: `${this.activityName}`,
  143. path: `/pages/user/activity/activity?type=share&activityId=${this.listQuery.activityId}&userId=${this.userId}&inviteUserId=${this.userId}`,
  144. imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss">
  150. page {
  151. height: auto !important;
  152. background-color: $color-system;
  153. }
  154. .activity-banner {
  155. width: 100%;
  156. height: 600rpx;
  157. float: left;
  158. margin-bottom: 64rpx;
  159. .activity-banner-image {
  160. width: 100%;
  161. height: 100%;
  162. display: block;
  163. }
  164. }
  165. .container-section {
  166. width: 100%;
  167. height: auto;
  168. box-sizing: border-box;
  169. padding: 0 24rpx;
  170. .product-list {
  171. width: 339rpx;
  172. height: 532rpx;
  173. float: left;
  174. margin-right: 24rpx;
  175. margin-bottom: 24rpx;
  176. background-color: #ffffff;
  177. border-radius: 16rpx;
  178. &:nth-child(2n) {
  179. margin-right: 0;
  180. }
  181. .product-list-image {
  182. width: 100%;
  183. height: 339rpx;
  184. float: left;
  185. position: relative;
  186. .product-image {
  187. width: 100%;
  188. height: 100%;
  189. display: block;
  190. border-radius: 16rpx 16rpx 0 0;
  191. }
  192. .product-icon {
  193. width: 68rpx;
  194. height: 55rpx;
  195. display: block;
  196. position: absolute;
  197. top: 0;
  198. left: 34rpx;
  199. }
  200. }
  201. .product-list-msg {
  202. width: 100%;
  203. height: 193rpx;
  204. box-sizing: border-box;
  205. padding: 16rpx 24rpx;
  206. float: left;
  207. position: relative;
  208. .product-msg-name {
  209. width: 100%;
  210. height: 72rpx;
  211. line-height: 35rpx;
  212. text-overflow: ellipsis;
  213. overflow: hidden;
  214. display: -webkit-box;
  215. -webkit-line-clamp: 2;
  216. line-clamp: 2;
  217. -webkit-box-orient: vertical;
  218. font-size: $font-size-26;
  219. color: #333333;
  220. text-align: justify;
  221. float: left;
  222. }
  223. .product-list-tag {
  224. position: relative;
  225. z-index: 9;
  226. width: 100%;
  227. height: 30rpx;
  228. margin-top: 8rpx;
  229. float: left;
  230. .tag {
  231. display: inline-block;
  232. height: 32rpx;
  233. font-size: 22rpx;
  234. line-height: 30rpx;
  235. text-align: center;
  236. color: #f83c6c;
  237. float: left;
  238. margin-right: 10rpx;
  239. &.tag-02 {
  240. width: 80rpx;
  241. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  242. no-repeat;
  243. background-size: contain;
  244. }
  245. &.tag-01 {
  246. width: 56rpx;
  247. color: #fff;
  248. background-color: #f83c6c;
  249. border-radius: 4rpx;
  250. }
  251. }
  252. }
  253. .product-list-pri {
  254. width: 100%;
  255. height: 44rpx;
  256. float: left;
  257. position: absolute;
  258. bottom: 16rpx;
  259. left: 0;
  260. box-sizing: border-box;
  261. padding: 0 24rpx;
  262. .price {
  263. float: left;
  264. font-size: $font-size-26;
  265. color: #f83c6c;
  266. font-weight: bold;
  267. line-height: 44rpx;
  268. }
  269. .carts {
  270. float: right;
  271. .carts-add {
  272. width: 44rpx;
  273. height: 44rpx;
  274. text-align: center;
  275. line-height: 44rpx;
  276. background-color: #ff457b;
  277. border-radius: 50%;
  278. .iconfont {
  279. font-size: 32rpx;
  280. color: #ffffff;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. }
  288. </style>