activity.vue 7.2 KB

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