activity-detail.vue 9.9 KB

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