activity.vue 6.8 KB

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