activity.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <view class="container activity">
  3. <view class="activity-banner">
  4. <image class="activity-banner-image" :src="activityBanner" mode=""></image>
  5. </view>
  6. <!-- 商品列表 -->
  7. <view class="container-section tui-skeleton clearfix">
  8. <view class="product-list" v-for="(pro, index) in productList" :key="index" @click.stop="Details(pro)">
  9. <view class="product-list-image">
  10. <image class="product-image" :src="pro.mainImage" mode=""></image>
  11. </view>
  12. <view class="product-list-msg">
  13. <view class="product-msg-name">{{ pro.name }}</view>
  14. <view class="product-list-tag" v-if="pro.activeStatus === 1">
  15. <text class="tag tag-01">促销</text> <text class="tag tag-02">活动价</text>
  16. </view>
  17. <view class="product-list-pri">
  18. <view class="price">¥{{ pro.price | PriceFormat }}</view>
  19. <view class="carts" @click.stop="handAddCarts(pro)">
  20. <view class="carts-add"> <text class="iconfont icon-gouwuche"></text> </view>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </view>
  26. <!-- 可拖动悬浮按钮 -->
  27. <cm-drag
  28. :cartNum="cartNum"
  29. :isDock="true"
  30. :existTabBar="true"
  31. @btnClick="btnClick"
  32. @btnTouchstart="btnTouchstart"
  33. @btnTouchend="btnTouchend"
  34. >
  35. </cm-drag>
  36. </view>
  37. </template>
  38. <script>
  39. import wxLogin from '@/services/wxLogin.js'
  40. import { mapGetters } from 'vuex'
  41. import cmDrag from '@/components/cm-module/cm-drag/cm-drag'
  42. export default {
  43. components: {
  44. cmDrag
  45. },
  46. data() {
  47. return {
  48. StaticUrl: this.$Static,
  49. activityBanner: `${this.$Static}banner.png`,
  50. cartNum: 0,
  51. listQuery: {
  52. activityId: 0,
  53. userId: 0,
  54. pageNum: 1,
  55. pageSize: 10
  56. },
  57. activityName: '',
  58. UserId: 0, //存储普通用户ID
  59. hasNextPage: false,
  60. productList: [] //商品列表
  61. }
  62. },
  63. onLoad(option) {
  64. this.listQuery.activityId = option.activityId
  65. this.listQuery.userId = option.userId
  66. this.activityName = option.name
  67. this.GetProductActivityDetails()
  68. },
  69. filters: {
  70. //处理金额
  71. PriceFormat: function(text) {
  72. return Number(text).toFixed(2)
  73. }
  74. },
  75. computed: {
  76. ...mapGetters(['hasLogin'])
  77. },
  78. methods: {
  79. GetProductActivityDetails() {
  80. //初始化活动详情
  81. this.ProductService.GetProductActivityDetails(this.listQuery)
  82. .then(response => {
  83. const data = response.data
  84. this.activityBanner = data.image
  85. this.hasNextPage = data.pageInfo.hasNextPage
  86. this.productList = data.pageInfo.list
  87. })
  88. .catch(error => {
  89. this.$util.msg(error.msg, 2000)
  90. })
  91. },
  92. GetOnReachBottomData() {
  93. //上滑加载更多
  94. this.listQuery.pageNum += 1
  95. this.ProductService.GetProductActivityDetails(this.listQuery)
  96. .then(response => {
  97. const data = response.data
  98. this.hasNextPage = data.pageInfo.hasNextPage
  99. this.productList = this.productList.concat(data.pageInfo.list)
  100. })
  101. .catch(error => {
  102. this.$util.msg(error.msg, 2000)
  103. })
  104. },
  105. Details(pro) {
  106. this.$api.navigateTo(
  107. `/pages/goods/product-activi?productId=${pro.productId}&heUserId=${this.listQuery.userId}`
  108. )
  109. },
  110. handAddCarts(pro) {
  111. if (!this.hasLogin) {
  112. this.$api.navigateTo('/pages/login/login')
  113. } else {
  114. this.ProductService.shoppingAddCart({
  115. productId: pro.productId,
  116. userId: this.UserId * 1,
  117. productCount: 1,
  118. heUserId: this.listQuery.userId * 1
  119. })
  120. .then(response => {
  121. this.$util.msg('加入购物车成功', 1500, true, 'success')
  122. this.GetCartNumber()
  123. })
  124. .catch(error => {
  125. console.log('查询购物车数量错误信息', error)
  126. })
  127. }
  128. },
  129. GetCartNumber() {
  130. //查询购物车数量
  131. this.ProductService.QueryShoppingQuantity({
  132. userId: this.listQuery.userId
  133. })
  134. .then(response => {
  135. this.$store.commit('app/updateAllNum', response.data)
  136. this.cartNum = response.data
  137. })
  138. .catch(error => {
  139. console.log('查询购物车数量错误信息', error)
  140. })
  141. },
  142. btnClick() {
  143. this.$emit('goCartPage')
  144. },
  145. btnTouchstart() {
  146. // console.log('btnTouchstart');
  147. },
  148. btnTouchend() {
  149. // console.log('btnTouchend');
  150. }
  151. },
  152. onPullDownRefresh() {
  153. //下拉刷新
  154. this.listQuery.pageNum = 1
  155. THIS.GetProductActivityDetails()
  156. uni.stopPullDownRefresh()
  157. },
  158. onReachBottom() {
  159. if (this.hasNextPage) {
  160. this.GetOnReachBottomData()
  161. }
  162. },
  163. onShow() {
  164. wxLogin.wxLoginQuick()
  165. this.$api.getStorage().then(resolve => {
  166. this.UserId = resolve.userId ? resolve.userId : ''
  167. this.GetCartNumber()
  168. })
  169. },
  170. onShareAppMessage(res) {
  171. //分享转发
  172. if (res.from === 'button') {
  173. // 来自页面内转发按钮
  174. }
  175. return {
  176. title: `${this.activityName}`,
  177. path: `/pages/user/activity/activity?activityId=${this.listQuery.activityId}&userId=${
  178. this.listQuery.userId
  179. }`,
  180. imageUrl: 'https://static.caimei365.com/app/mini-hehe/icon/icon-index-share.jpg'
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss">
  186. page {
  187. height: auto !important;
  188. background-color: $color-system;
  189. }
  190. .activity-banner {
  191. width: 100%;
  192. height: 600rpx;
  193. float: left;
  194. margin-bottom: 64rpx;
  195. .activity-banner-image {
  196. width: 100%;
  197. height: 100%;
  198. display: block;
  199. }
  200. }
  201. .container-section {
  202. width: 100%;
  203. height: auto;
  204. box-sizing: border-box;
  205. padding: 0 24rpx;
  206. .product-list {
  207. width: 339rpx;
  208. height: 532rpx;
  209. float: left;
  210. margin-right: 24rpx;
  211. margin-bottom: 24rpx;
  212. background-color: #ffffff;
  213. border-radius: 16rpx;
  214. &:nth-child(2n) {
  215. margin-right: 0;
  216. }
  217. .product-list-image {
  218. width: 100%;
  219. height: 339rpx;
  220. float: left;
  221. position: relative;
  222. .product-image {
  223. width: 100%;
  224. height: 100%;
  225. display: block;
  226. border-radius: 16rpx 16rpx 0 0;
  227. }
  228. .product-icon {
  229. width: 68rpx;
  230. height: 55rpx;
  231. display: block;
  232. position: absolute;
  233. top: 0;
  234. left: 34rpx;
  235. }
  236. }
  237. .product-list-msg {
  238. width: 100%;
  239. height: 193rpx;
  240. box-sizing: border-box;
  241. padding: 16rpx 24rpx;
  242. float: left;
  243. position: relative;
  244. .product-msg-name {
  245. width: 100%;
  246. height: 72rpx;
  247. line-height: 35rpx;
  248. text-overflow: ellipsis;
  249. overflow: hidden;
  250. display: -webkit-box;
  251. -webkit-line-clamp: 2;
  252. line-clamp: 2;
  253. -webkit-box-orient: vertical;
  254. font-size: $font-size-26;
  255. color: #333333;
  256. text-align: justify;
  257. float: left;
  258. }
  259. .product-list-tag {
  260. position: relative;
  261. z-index: 9;
  262. width: 100%;
  263. height: 30rpx;
  264. margin-top: 8rpx;
  265. float: left;
  266. .tag {
  267. display: inline-block;
  268. height: 32rpx;
  269. font-size: 22rpx;
  270. line-height: 30rpx;
  271. text-align: center;
  272. color: #f83c6c;
  273. float: left;
  274. margin-right: 10rpx;
  275. &.tag-02 {
  276. width: 80rpx;
  277. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center
  278. no-repeat;
  279. background-size: contain;
  280. }
  281. &.tag-01 {
  282. width: 56rpx;
  283. color: #fff;
  284. background-color: #f83c6c;
  285. border-radius: 4rpx;
  286. }
  287. }
  288. }
  289. .product-list-pri {
  290. width: 100%;
  291. height: 44rpx;
  292. float: left;
  293. position: absolute;
  294. bottom: 16rpx;
  295. left: 0;
  296. box-sizing: border-box;
  297. padding: 0 24rpx;
  298. .price {
  299. float: left;
  300. font-size: $font-size-26;
  301. color: #f83c6c;
  302. font-weight: bold;
  303. line-height: 44rpx;
  304. }
  305. .carts {
  306. float: right;
  307. .carts-add {
  308. width: 44rpx;
  309. height: 44rpx;
  310. text-align: center;
  311. line-height: 44rpx;
  312. background-color: #ff457b;
  313. border-radius: 50%;
  314. .iconfont {
  315. font-size: 32rpx;
  316. color: #ffffff;
  317. }
  318. }
  319. }
  320. }
  321. }
  322. }
  323. }
  324. </style>