activity-detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. },
  84. computed: {
  85. ...mapGetters(['userId', 'kindCount']),
  86. visiable() {
  87. return this.productList.length > this.listQuery.pageSize
  88. }
  89. },
  90. onPageScroll(e) {
  91. this.scrollTop = e.scrollTop
  92. },
  93. onShareAppMessage() {
  94. // 加密
  95. const state_str = encodeURIComponent(
  96. this.$crypto.encrypt({
  97. type: 3,
  98. activityId: this.listQuery.activityId,
  99. dealerUserId: this.userId
  100. })
  101. )
  102. return {
  103. title: this.activityName,
  104. path: `/pages/index/index?state_str=${state_str}`,
  105. imageUrl: this.activityBanner
  106. }
  107. },
  108. methods: {
  109. ...mapActions('cart', ['addToCart']),
  110. // 分享事件
  111. onShare() {
  112. this.posterData = {
  113. query: queryStringify({
  114. type: 3,
  115. activityId: this.listQuery.activityId,
  116. dealerUserId: this.userId
  117. }),
  118. productImage: this.activityBanner,
  119. porductName: this.activityName
  120. }
  121. this.$refs.sharePopup.open()
  122. },
  123. // 获取商品列表
  124. fetchProductList: debounce(async function() {
  125. try {
  126. if (this.listQuery.sortType === 1) {
  127. this.listQuery.productIds = this.productList.map(item => item.productId).join(',')
  128. } else {
  129. this.listQuery.productIds = ''
  130. }
  131. const { data } = await fetchProductList(this.listQuery)
  132. // 活动banner
  133. this.activityBanner = data.activityBanner
  134. // 产品相关
  135. this.productList = [...this.productList, ...data.pageInfo.results]
  136. this.hasNextPage = data.pageInfo.hasNextPage
  137. this.total = data.pageInfo.totalRecord
  138. // 页面状态
  139. this.listQuery.pageNum++
  140. this.isRequest = false
  141. this.isLoading = false
  142. } catch (e) {
  143. console.log('获取商品列表失败')
  144. }
  145. }, 200),
  146. // 查单详情
  147. detail(pro) {
  148. this.$router.navigateTo(`goods/goods-detail?productId=${pro.productId}&jumpState=2`)
  149. },
  150. // 加入购物车
  151. handAddCarts(pro) {
  152. this.addToCart({ productId: pro.productId, heUserId: this.userId })
  153. },
  154. // 跳转购物车
  155. btnClick() {
  156. this.$router.navigateTo('cart/cart')
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. page {
  163. height: auto !important;
  164. background-color: #f83c6c;
  165. }
  166. .activity-banner {
  167. width: 750rpx;
  168. height: 600rpx;
  169. float: left;
  170. margin-bottom: 24rpx;
  171. .activity-banner-image {
  172. width: 100%;
  173. height: 100%;
  174. display: block;
  175. }
  176. }
  177. .share-button {
  178. @extend .cm-flex-center;
  179. position: fixed;
  180. right: 30rpx;
  181. bottom: 120rpx;
  182. flex-direction: column;
  183. z-index: 98;
  184. width: 96rpx;
  185. height: 96rpx;
  186. border-radius: 50%;
  187. background: rgba(0, 0, 0, 0.2);
  188. .label {
  189. font-size: 20rpx;
  190. color: #fff;
  191. }
  192. .iconfont {
  193. color: #fff;
  194. }
  195. }
  196. .container-section {
  197. width: 100%;
  198. height: auto;
  199. box-sizing: border-box;
  200. padding: 0 24rpx;
  201. .product-list {
  202. width: 339rpx;
  203. height: 532rpx;
  204. float: left;
  205. margin-right: 24rpx;
  206. margin-bottom: 24rpx;
  207. background-color: #ffffff;
  208. border-radius: 16rpx;
  209. &:nth-child(2n) {
  210. margin-right: 0;
  211. }
  212. .product-list-image {
  213. width: 100%;
  214. height: 339rpx;
  215. float: left;
  216. position: relative;
  217. .product-image {
  218. width: 100%;
  219. height: 100%;
  220. display: block;
  221. border-radius: 16rpx 16rpx 0 0;
  222. }
  223. .product-icon {
  224. width: 68rpx;
  225. height: 55rpx;
  226. display: block;
  227. position: absolute;
  228. top: 0;
  229. left: 34rpx;
  230. }
  231. }
  232. .product-list-msg {
  233. width: 100%;
  234. height: 193rpx;
  235. box-sizing: border-box;
  236. padding: 16rpx 24rpx;
  237. float: left;
  238. position: relative;
  239. .product-msg-name {
  240. width: 100%;
  241. height: 72rpx;
  242. line-height: 35rpx;
  243. text-overflow: ellipsis;
  244. overflow: hidden;
  245. display: -webkit-box;
  246. -webkit-line-clamp: 2;
  247. line-clamp: 2;
  248. -webkit-box-orient: vertical;
  249. font-size: 26rpx;
  250. color: #333333;
  251. text-align: justify;
  252. float: left;
  253. }
  254. .product-list-tag {
  255. position: relative;
  256. z-index: 9;
  257. width: 100%;
  258. height: 30rpx;
  259. margin-top: 8rpx;
  260. float: left;
  261. .tag {
  262. display: inline-block;
  263. height: 32rpx;
  264. font-size: 22rpx;
  265. line-height: 30rpx;
  266. text-align: center;
  267. color: #f83c6c;
  268. float: left;
  269. margin-right: 10rpx;
  270. &.tag-02 {
  271. width: 80rpx;
  272. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  273. no-repeat;
  274. background-size: contain;
  275. }
  276. &.tag-01 {
  277. width: 56rpx;
  278. color: #fff;
  279. background-color: #f83c6c;
  280. border-radius: 4rpx;
  281. }
  282. &.tag-03 {
  283. width: 80rpx;
  284. background: linear-gradient(270deg, #ff457b 0%, #b03bb8 51%, #6431f2 100%);
  285. color: #fff;
  286. border-radius: 4rpx;
  287. }
  288. }
  289. }
  290. .product-list-pri {
  291. width: 100%;
  292. height: 44rpx;
  293. position: absolute;
  294. bottom: 16rpx;
  295. left: 0;
  296. box-sizing: border-box;
  297. padding: 0 24rpx;
  298. .price {
  299. font-size: 26rpx;
  300. color: #f83c6c;
  301. font-weight: bold;
  302. line-height: 44rpx;
  303. .delete {
  304. font-size: 20rpx;
  305. color: #999999;
  306. text-decoration: line-through;
  307. font-weight: normal;
  308. margin-left: 10rpx;
  309. }
  310. }
  311. .carts {
  312. position: absolute;
  313. right: 24rpx;
  314. bottom: 0;
  315. .carts-add {
  316. width: 44rpx;
  317. height: 44rpx;
  318. text-align: center;
  319. line-height: 44rpx;
  320. background-color: #ff457b;
  321. border-radius: 50%;
  322. .iconfont {
  323. font-size: 32rpx;
  324. color: #ffffff;
  325. }
  326. }
  327. }
  328. }
  329. }
  330. }
  331. }
  332. </style>