HotProduct.vue 8.4 KB

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