HotProduct.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <view class="group-goods" v-if="detail.length>0">
  3. <view class="title-box x-bc" >
  4. <text class="title">热门榜单</text>
  5. <view class="group-people x-f" @tap="navTo('/pages/home/productList')">
  6. <text class="tip">更多</text>
  7. <text class="cuIcon-right"></text>
  8. </view>
  9. </view>
  10. <view class="goods-box swiper-box x-f">
  11. <swiper class="carousel" circular @change="swiperChange" :autoplay="true" interval="10000" duration="2000">
  12. <swiper-item v-for="(goods, index) in goodsList" :key="index" class="carousel-item">
  13. <view class="goods-list-box x-f">
  14. <block v-for="mgoods in goods" :key="mgoods.productId" >
  15. <view class="min-goods" @tap="showProduct(mgoods)" >
  16. <view class="img-box">
  17. <view class="tag">hot</view>
  18. <image class="img" :src="mgoods.image" mode="widthFix"></image>
  19. </view>
  20. <view class="price-box">
  21. <view class="y-f">
  22. <text class="seckill-current" v-if="user.isShow==1">¥{{ mgoods.price.toFixed(2) }}</text>
  23. <text class="seckill-current" v-else>¥{{ mgoods.otPrice.toFixed(2) }}</text>
  24. <text class="original" v-if="user.isShow==1">销量{{ mgoods.sales }}{{mgoods.unitName}}</text>
  25. </view>
  26. </view>
  27. <view class="title">
  28. <slot name="titleText"></slot>
  29. </view>
  30. </view>
  31. </block>
  32. </view>
  33. </swiper-item>
  34. </swiper>
  35. <view class="swiper-dots" v-if="goodsList.length > 1">
  36. <text :class="swiperCurrent === index ? 'dot-active' : 'dot'" v-for="(dot, index) in goodsList.length"
  37. :key="index"></text>
  38. </view>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {getUserInfo} from '@/api/user'
  44. export default {
  45. name: "HotProduct",
  46. data() {
  47. return {
  48. goodsList: [],
  49. swiperCurrent: 0,
  50. UserInfo:uni.getStorageSync('AppToken'),
  51. user:{}
  52. };
  53. },
  54. props: {
  55. detail: Array
  56. },
  57. computed: {},
  58. created() {},
  59. watch: {
  60. detail(next) {
  61. this.goodsList = this.sortData(next, 4)
  62. },
  63. UserInfo() {
  64. return uni.getStorageSync('AppToken')
  65. }
  66. },
  67. mounted() {
  68. this.UserInfo = uni.getStorageSync('AppToken') // 强制更新登录状态
  69. if(this.UserInfo) {
  70. this.getUserInfo()
  71. }
  72. console.log(this.detail)
  73. },
  74. methods: {
  75. getUserInfo(){
  76. getUserInfo().then(
  77. res => {
  78. if(res.code==200){
  79. if(res.user!=null){
  80. this.user=res.user;
  81. }
  82. else{
  83. // this.utils.loginOut();
  84. }
  85. }else{
  86. uni.showToast({
  87. icon:'none',
  88. title: "请求失败",
  89. });
  90. }
  91. },
  92. rej => {}
  93. );
  94. },
  95. swiperChange(e) {
  96. this.swiperCurrent = e.detail.current;
  97. },
  98. // 数据分层
  99. sortData(oArr, length) {
  100. let arr = [];
  101. let minArr = [];
  102. oArr.forEach(c => {
  103. if (minArr.length === length) {
  104. minArr = [];
  105. }
  106. if (minArr.length === 0) {
  107. arr.push(minArr);
  108. }
  109. minArr.push(c);
  110. });
  111. return arr;
  112. },
  113. navTo(url){
  114. uni.navigateTo({
  115. url: url
  116. })
  117. },
  118. showProduct(item){
  119. uni.navigateTo({
  120. url: '/pages/shopping/productDetails?productId='+item.productId
  121. })
  122. },
  123. }
  124. }
  125. </script>
  126. <style lang="scss" scoped>
  127. .group-goods {
  128. position: relative;
  129. z-index: 1;
  130. background: #FFFFFF;
  131. border-radius: 16upx;
  132. margin-bottom: 20upx;
  133. margin-top: 20upx;
  134. padding: 20upx;
  135. }
  136. .swiper-box,
  137. .carousel {
  138. width: 700rpx;
  139. height: 240upx;
  140. position: relative;
  141. border-radius: 20rpx;
  142. .carousel-item {
  143. width: 100%;
  144. height: 100%;
  145. // padding: 0 28upx;
  146. overflow: hidden;
  147. }
  148. .swiper-image {
  149. width: 100%;
  150. height: 100%;
  151. // border-radius: 10upx;
  152. background: #ccc;
  153. }
  154. }
  155. .swiper-dots {
  156. display: flex;
  157. position: absolute;
  158. left: 50%;
  159. transform: translateX(-50%);
  160. bottom: 0rpx;
  161. z-index: 66;
  162. .dot {
  163. width: 45rpx;
  164. height: 3rpx;
  165. background: #eee;
  166. border-radius: 50%;
  167. margin-right: 10rpx;
  168. }
  169. .dot-active {
  170. width: 45rpx;
  171. height: 3rpx;
  172. background: #a8700d;
  173. border-radius: 50%;
  174. margin-right: 10rpx;
  175. }
  176. }
  177. // 今日必拼+限时抢购
  178. .group-goods {
  179. background: #fff;
  180. border-radius: 20rpx;
  181. overflow: hidden;
  182. .title-box {
  183. padding-bottom: 20rpx;
  184. .title {
  185. font-size: 32rpx;
  186. font-weight: bold;
  187. }
  188. .group-people {
  189. .time-box {
  190. font-size: 26rpx;
  191. color: #edbf62;
  192. .count-text-box {
  193. width: 30rpx;
  194. height: 34rpx;
  195. background: #edbf62;
  196. text-align: center;
  197. line-height: 34rpx;
  198. font-size: 24rpx;
  199. border-radius: 6rpx;
  200. color: rgba(#fff, 0.9);
  201. margin: 0 8rpx;
  202. }
  203. }
  204. .head-box {
  205. .head-img {
  206. width: 40rpx;
  207. height: 40rpx;
  208. border-radius: 50%;
  209. background: #ccc;
  210. }
  211. }
  212. .tip {
  213. font-size: 24rpx;
  214. padding-left: 30rpx;
  215. color: #999999;
  216. }
  217. .cuIcon-right {
  218. font-size: 30rpx;
  219. line-height: 28rpx;
  220. color: #666;
  221. }
  222. }
  223. }
  224. .goods-box {
  225. .goods-item {
  226. margin-right: 22rpx;
  227. &:nth-child(4n) {
  228. margin-right: 0;
  229. }
  230. }
  231. }
  232. .min-goods{
  233. margin-right: 22rpx;
  234. }
  235. }
  236. .min-goods {
  237. width: 152rpx;
  238. background: #fff;
  239. .img-box {
  240. width: 152rpx;
  241. height: 152rpx;
  242. overflow: hidden;
  243. position: relative;
  244. .tag {
  245. position: absolute;
  246. left: 0;
  247. bottom: 0rpx;
  248. z-index: 2;
  249. line-height: 35rpx;
  250. background: linear-gradient(132deg, rgba(243, 223, 177, 1), rgba(243, 223, 177, 1), rgba(236, 190, 96, 1));
  251. border-radius: 0px 18rpx 18rpx 0px;
  252. padding: 0 10rpx;
  253. font-size: 24rpx;
  254. font-family: PingFang SC;
  255. font-weight: bold;
  256. color: rgba(120, 79, 6, 1);
  257. }
  258. .img {
  259. width: 100%;
  260. background-color: #ccc;
  261. }
  262. }
  263. .price-box {
  264. width: 100%;
  265. margin-top: 10rpx;
  266. .seckill-current {
  267. font-size: 30rpx;
  268. font-weight: 500;
  269. color: rgba(225, 33, 43, 1);
  270. }
  271. .original {
  272. font-size: 20rpx;
  273. font-weight: 400;
  274. // text-decoration: line-through;
  275. color: rgba(153, 153, 153, 1);
  276. margin-left: 14rpx;
  277. }
  278. }
  279. .title {
  280. font-size: 26rpx;
  281. }
  282. }
  283. </style>