activity.vue 7.1 KB

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