Seckill.vue 6.7 KB

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