HotProduct.vue 8.1 KB

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