activity.vue 7.6 KB

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