activity-detail.vue 11 KB

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