Seckill.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view
  3. class="seckill u-skeleton-fillet"
  4. v-if="(currSeckill && currSeckill.length > 0) || skeletonShow"
  5. >
  6. <view class="seckill-item">
  7. <view
  8. class="seckill-top"
  9. @click="goDetail('/pages/seckill/list')"
  10. >
  11. <view class="left">限时秒杀</view>
  12. <view class="line" v-if="currTime"></view>
  13. <view class="time" v-if="currTime">{{ currTime }}点场 剩余</view>
  14. <view class="reciprocal" v-if="currTime">
  15. <!-- <uni-countdown
  16. :time="finishTime"
  17. :backgroundColor="'none'"
  18. :color="'#fff'"
  19. :splitorColor="'#fff'"
  20. :show-day="time2[0] > 0"
  21. :day="time2[0]"
  22. :hour="time2[1]"
  23. :minute="time2[2]"
  24. :second="time2[3]"
  25. >
  26. </uni-countdown> -->
  27. <uv-count-down :time="finishTime" format="HH:mm:ss"></uv-count-down>
  28. </view>
  29. </view>
  30. <view
  31. class="option"
  32. v-if="(currSeckill && currSeckill.length > 0) || skeletonShow"
  33. >
  34. <swiper
  35. :indicator-dots="false"
  36. :autoplay="false"
  37. :display-multiple-items="itemsDis2"
  38. @change="imgActiveFun2"
  39. style="height: 220rpx"
  40. circular="true"
  41. >
  42. <swiper-item v-for="(item, key) in currSeckill" :key="key">
  43. <div class="fa-item">
  44. <view
  45. class="option-item"
  46. v-for="itemSon in item"
  47. @click="
  48. goProductDetails(
  49. '/pages/seckill/seckillGoods?id=' + itemSon.id
  50. )
  51. "
  52. :key="itemSon.id"
  53. >
  54. <!-- ?x-oss-process=style/w_350 -->
  55. <image
  56. v-if="itemSon && itemSon.coverImage"
  57. :src="`${itemSon.coverImage}`"
  58. mode="aspectFill"
  59. >
  60. </image>
  61. <view class="number">
  62. <rich-text
  63. :nodes="$mUtil.priceBigSmall(itemSon.minPrice)"
  64. ></rich-text>
  65. </view>
  66. </view>
  67. </div>
  68. </swiper-item>
  69. </swiper>
  70. <view class="slide-box">
  71. <view class="dotBox" v-if="currSeckill.length > 1">
  72. <view
  73. class="dotBox_item"
  74. v-for="(v, i) in currSeckill"
  75. :key="i"
  76. :class="{ active_dotBox: activeBannerIndex2 == i }"
  77. ></view>
  78. </view>
  79. </view>
  80. </view>
  81. <noData v-else :config="{ top: 1, content: '暂无商品~' }"></noData>
  82. </view>
  83. </view>
  84. </template>
  85. <script setup>
  86. import { ref } from "vue";
  87. import { seckillActivityProductFlash_Api } from "@/api/seckill.js";
  88. const props = defineProps({
  89. skeletonShow: {
  90. type: Boolean,
  91. default: false
  92. }
  93. });
  94. const emit = defineEmits(['goDetail', 'overDown2', 'imgActiveFun2', 'goProductDetails']);
  95. const currSeckill = ref([]); //秒杀
  96. const currTime = ref(null);
  97. const finishTime = ref(null);
  98. const itemsDis2 = ref(1);
  99. const activeBannerIndex2 = ref(0);
  100. const goDetail = (url) => {
  101. emit('goDetail', url);
  102. };
  103. const imgActiveFun2 = (e) => {
  104. activeBannerIndex2.value = e.detail.current;
  105. };
  106. const goProductDetails = (url) => {
  107. emit('goProductDetails', url);
  108. };
  109. const oneArrToTwoArr = (data) => {
  110. let newData = [];
  111. let zyf = 4; //一维数组转二维数组长度(此处是二维数组每一个长度控制)
  112. for (var i = 0; i < Math.ceil(data.length / zyf); i++) {
  113. newData[i] = [];
  114. newData[i].push(data[i * zyf]);
  115. for (var j = 1; j < zyf; j++) {
  116. if (data[i * zyf + j] == undefined) {
  117. //超出长度控住
  118. return newData;
  119. } else {
  120. newData[i].push(data[i * zyf + j]);
  121. }
  122. }
  123. }
  124. return newData;
  125. };
  126. /**限时秒杀 */
  127. const getSeckillList = () => {
  128. seckillActivityProductFlash_Api({ limit: 10 }).then((res) => {
  129. if (res && res.code == 200) {
  130. currTime.value = res.data.startHour;
  131. if (res.data.list) {
  132. currSeckill.value = oneArrToTwoArr(res.data.list);
  133. }
  134. if (res.data.finishTime) {
  135. finishTime.value = res.data.finishTime - new Date().getTime();
  136. }
  137. }
  138. });
  139. };
  140. getSeckillList();
  141. defineExpose({
  142. getSeckillList
  143. });
  144. </script>
  145. <style scoped lang="scss">
  146. .seckill {
  147. margin: 30rpx 30rpx 50rpx;
  148. border-radius: 10rpx;
  149. overflow: hidden;
  150. .seckill-item {
  151. border-radius: 16rpx;
  152. background-color: #ffffff;
  153. padding-bottom: 26rpx;
  154. .option {
  155. position: relative;
  156. margin-top: 20rpx;
  157. padding: 0 29rpx;
  158. .fa-item {
  159. display: flex;
  160. }
  161. .option-item:first-child {
  162. margin-left: 0;
  163. }
  164. .option-item {
  165. margin-left: 24rpx;
  166. image {
  167. width: 140rpx;
  168. height: 140rpx;
  169. }
  170. .number {
  171. margin-top: 4rpx;
  172. text-align: center;
  173. font-size: 36rpx;
  174. font-weight: Bold;
  175. line-height: 24rpx;
  176. color: #333333;
  177. width: 140rpx;
  178. }
  179. }
  180. }
  181. .seckill-top {
  182. padding: 24rpx 26rpx;
  183. display: flex;
  184. align-items: center;
  185. border-bottom: 1rpx solid #f7f7f7;
  186. background: linear-gradient(180deg, #d4ecdf, rgba(204, 235, 217, 0));
  187. .left {
  188. font-size: 36rpx;
  189. font-weight: Bold;
  190. color: #1a1a1a;
  191. margin-right: 14rpx;
  192. }
  193. .line {
  194. width: 1rpx;
  195. height: 32rpx;
  196. background-color: #707070;
  197. }
  198. .time {
  199. margin-left: 16rpx;
  200. color: #666666;
  201. font-size: 24rpx;
  202. font-weight: Regular;
  203. }
  204. .reciprocal {
  205. color: #ffffff;
  206. padding: 0rpx 14rpx;
  207. background-color: #ff0000;
  208. font-size: 24rpx;
  209. font-weight: Bold;
  210. border-radius: 30rpx;
  211. margin-left: 30rpx;
  212. &:deep(.uv-count-down__text) {
  213. color: #ffffff;
  214. font-size: 24rpx;
  215. }
  216. }
  217. }
  218. }
  219. }
  220. .slide-box {
  221. display: flex;
  222. justify-content: center;
  223. }
  224. .dotBox {
  225. height: 14rpx;
  226. overflow: hidden;
  227. border-radius: 14rpx;
  228. background-color: #ededed;
  229. display: flex;
  230. justify-content: center;
  231. .dotBox_item {
  232. width: 45rpx;
  233. height: 14rpx;
  234. border-radius: 2rpx;
  235. background-color: #ededed;
  236. transition: all 0.5s;
  237. }
  238. .active_dotBox {
  239. width: 45rpx;
  240. background: linear-gradient(109deg, #fb6b3e 20%, #feaf6b 85%);
  241. transition: all 0.5s;
  242. }
  243. }
  244. </style>