activity-detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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 tags" v-if="pro.activeStatus === 1">
  13. <!-- 拼团价 活动价 限时特价 券后价 -->
  14. <view class="tag pt" v-if="pro.collageStatus > 0">拼团价</view>
  15. <view class="tag hd" v-else-if="pro.activeStatus > 0">活动价</view>
  16. <view class="tag other" v-else-if="pro.discountStatus > 0">限时特价</view>
  17. <view class="tag other" v-else-if="pro.couponStatus > 1">{{ pro.couponInfo }}</view>
  18. <view class="tag other" v-else-if="pro.couponStatus > 0">券后价</view>
  19. </view>
  20. <view class="product-list-pri">
  21. <view class="price">
  22. <text>¥{{ pro.price | priceFormat }}</text>
  23. <text class="delete">¥{{ pro.price | priceFormat }}</text>
  24. </view>
  25. <view class="carts" @click.stop="handAddCarts(pro)">
  26. <view class="carts-add"><text class="iconfont icon-gouwuche"></text></view>
  27. </view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <cm-loadmore
  33. :hasMore="hasNextPage"
  34. :isLoading="isLoading"
  35. :visiable="visiable"
  36. backgroundColor="#ff457b"
  37. ></cm-loadmore>
  38. <!-- 可拖动悬浮按钮 -->
  39. <cm-drag :cartNum="kindCount" :isDock="true" :existTabBar="true" @btnClick="btnClick"></cm-drag>
  40. <!-- 分享弹窗 -->
  41. <cm-share-popup ref="sharePopup" :data="posterData" type="activity"></cm-share-popup>
  42. <!-- 返回顶部 -->
  43. <tui-scroll-top
  44. :scrollTop="scrollTop"
  45. :isShare="true"
  46. :bottom="60"
  47. :customShare="true"
  48. @share="onShare"
  49. ></tui-scroll-top>
  50. </view>
  51. </template>
  52. <script>
  53. import { fetchProductList } from '@/services/api/goods.js'
  54. import { debounce, queryStringify } from '@/common/utils.js'
  55. import { makeQuery } from '@/pages/views/goods/config/config.js'
  56. import { mapGetters, mapActions } from 'vuex'
  57. export default {
  58. data() {
  59. return {
  60. isRefresh: true,
  61. isLoading: false, // 正在加载更多
  62. activityBanner: '',
  63. listQuery: makeQuery(),
  64. activityName: '',
  65. productList: [], //商品列表
  66. total: 0,
  67. hasNextPage: false,
  68. posterData: {},
  69. scrollTop: 0,
  70. type: 'other'
  71. }
  72. },
  73. onLoad(option) {
  74. this.listQuery.activityId = option.activityId
  75. this.listQuery.userId = this.userId
  76. if (option.type === 'share') {
  77. this.type = option.type
  78. this.listQuery.userId = option.dealerUserId
  79. }
  80. this.listQuery.listType = 6
  81. this.activityName = option.name
  82. this.fetchProductList()
  83. this.$store.dispatch('cart/fetchCartKindCount')
  84. },
  85. computed: {
  86. ...mapGetters(['userId', 'kindCount']),
  87. visiable() {
  88. return this.productList.length > this.listQuery.pageSize
  89. }
  90. },
  91. onPageScroll(e) {
  92. this.scrollTop = e.scrollTop
  93. },
  94. onShareAppMessage() {
  95. // 加密
  96. const state_str = encodeURIComponent(
  97. this.$crypto.encrypt({
  98. type: 3,
  99. activityId: this.listQuery.activityId,
  100. dealerUserId: this.userId
  101. })
  102. )
  103. return {
  104. title: this.activityName,
  105. path: `/pages/index/index?state_str=${state_str}`,
  106. imageUrl: this.activityBanner
  107. }
  108. },
  109. methods: {
  110. ...mapActions('cart', ['addToCart']),
  111. // 分享事件
  112. onShare() {
  113. this.posterData = {
  114. query: queryStringify({
  115. type: 3,
  116. activityId: this.listQuery.activityId,
  117. dealerUserId: this.userId
  118. }),
  119. productImage: this.activityBanner,
  120. porductName: this.activityName
  121. }
  122. this.$refs.sharePopup.open()
  123. },
  124. // 获取商品列表
  125. fetchProductList: debounce(async function() {
  126. try {
  127. if (this.listQuery.sortType === 1) {
  128. this.listQuery.productIds = this.productList.map(item => item.productId).join(',')
  129. } else {
  130. this.listQuery.productIds = ''
  131. }
  132. const { data } = await fetchProductList(this.listQuery)
  133. // 活动banner
  134. this.activityBanner = data.activityBanner
  135. // 产品相关
  136. this.productList = [...this.productList, ...data.pageInfo.results]
  137. this.hasNextPage = data.pageInfo.hasNextPage
  138. this.total = data.pageInfo.totalRecord
  139. // 页面状态
  140. this.listQuery.pageNum++
  141. this.isRequest = false
  142. this.isLoading = false
  143. } catch (e) {
  144. console.log('获取商品列表失败')
  145. }
  146. }, 200),
  147. // 查单详情
  148. detail(pro) {
  149. this.$router.navigateTo(`goods/goods-detail?productId=${pro.productId}&jumpState=2`)
  150. },
  151. // 加入购物车
  152. handAddCarts(pro) {
  153. this.addToCart({ skuId: pro.skuId, heUserId: this.userId })
  154. },
  155. // 跳转购物车
  156. btnClick() {
  157. console.log('购物车')
  158. this.$router.navigateTo('cart/cart')
  159. }
  160. }
  161. }
  162. </script>
  163. <style lang="scss" scoped>
  164. page {
  165. height: auto !important;
  166. background-color: #f83c6c;
  167. }
  168. .activity-banner {
  169. width: 750rpx;
  170. height: 600rpx;
  171. float: left;
  172. margin-bottom: 24rpx;
  173. .activity-banner-image {
  174. width: 100%;
  175. height: 100%;
  176. display: block;
  177. }
  178. }
  179. .share-button {
  180. @extend .cm-flex-center;
  181. position: fixed;
  182. right: 30rpx;
  183. bottom: 120rpx;
  184. flex-direction: column;
  185. z-index: 98;
  186. width: 96rpx;
  187. height: 96rpx;
  188. border-radius: 50%;
  189. background: rgba(0, 0, 0, 0.2);
  190. .label {
  191. font-size: 20rpx;
  192. color: #fff;
  193. }
  194. .iconfont {
  195. color: #fff;
  196. }
  197. }
  198. .container-section {
  199. width: 100%;
  200. height: auto;
  201. box-sizing: border-box;
  202. padding: 0 24rpx;
  203. .product-list {
  204. width: 339rpx;
  205. height: 532rpx;
  206. float: left;
  207. margin-right: 24rpx;
  208. margin-bottom: 24rpx;
  209. background-color: #ffffff;
  210. border-radius: 16rpx;
  211. &:nth-child(2n) {
  212. margin-right: 0;
  213. }
  214. .product-list-image {
  215. width: 100%;
  216. height: 339rpx;
  217. float: left;
  218. position: relative;
  219. .product-image {
  220. width: 100%;
  221. height: 100%;
  222. display: block;
  223. border-radius: 16rpx 16rpx 0 0;
  224. }
  225. .product-icon {
  226. width: 68rpx;
  227. height: 55rpx;
  228. display: block;
  229. position: absolute;
  230. top: 0;
  231. left: 34rpx;
  232. }
  233. }
  234. .product-list-msg {
  235. width: 100%;
  236. height: 193rpx;
  237. box-sizing: border-box;
  238. padding: 16rpx 24rpx;
  239. float: left;
  240. position: relative;
  241. .product-msg-name {
  242. width: 100%;
  243. height: 72rpx;
  244. line-height: 35rpx;
  245. text-overflow: ellipsis;
  246. overflow: hidden;
  247. display: -webkit-box;
  248. -webkit-line-clamp: 2;
  249. line-clamp: 2;
  250. -webkit-box-orient: vertical;
  251. font-size: 26rpx;
  252. color: #333333;
  253. text-align: justify;
  254. float: left;
  255. }
  256. .product-list-tag {
  257. position: relative;
  258. z-index: 9;
  259. width: 100%;
  260. height: 30rpx;
  261. margin-top: 8rpx;
  262. float: left;
  263. .tag {
  264. display: inline-block;
  265. height: 32rpx;
  266. font-size: 22rpx;
  267. line-height: 30rpx;
  268. text-align: center;
  269. color: #f83c6c;
  270. float: left;
  271. margin-right: 10rpx;
  272. &.tag-02 {
  273. width: 80rpx;
  274. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  275. no-repeat;
  276. background-size: contain;
  277. }
  278. &.tag-01 {
  279. width: 56rpx;
  280. color: #fff;
  281. background-color: #f83c6c;
  282. border-radius: 4rpx;
  283. }
  284. &.tag-03 {
  285. width: 80rpx;
  286. background: linear-gradient(270deg, #ff457b 0%, #b03bb8 51%, #6431f2 100%);
  287. color: #fff;
  288. border-radius: 4rpx;
  289. }
  290. }
  291. }
  292. .product-list-pri {
  293. width: 100%;
  294. height: 44rpx;
  295. position: absolute;
  296. bottom: 16rpx;
  297. left: 0;
  298. box-sizing: border-box;
  299. padding: 0 24rpx;
  300. .price {
  301. font-size: 26rpx;
  302. color: #f83c6c;
  303. font-weight: bold;
  304. line-height: 44rpx;
  305. .delete {
  306. font-size: 20rpx;
  307. color: #999999;
  308. text-decoration: line-through;
  309. font-weight: normal;
  310. margin-left: 10rpx;
  311. }
  312. }
  313. .carts {
  314. position: absolute;
  315. right: 24rpx;
  316. bottom: 0;
  317. .carts-add {
  318. width: 44rpx;
  319. height: 44rpx;
  320. text-align: center;
  321. line-height: 44rpx;
  322. background-color: #ff457b;
  323. border-radius: 50%;
  324. .iconfont {
  325. font-size: 32rpx;
  326. color: #ffffff;
  327. }
  328. }
  329. }
  330. }
  331. }
  332. }
  333. }
  334. </style>