activity.vue 9.7 KB

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