HotProduct.vue 8.4 KB

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