sh-seckill.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <!-- 活动商品 -->
  3. <view class="activity-wrap u-p-x-20 u-p-b-20 u-m-b-10 seckill-card" v-if="showActivity">
  4. <!-- 标题栏 -->
  5. <view class="title-box u-flex u-row-between u-p-y-20 seckill-title">
  6. <view class="u-flex u-col-center">
  7. <view class="title-text u-m-r-20 u-ellipsis-1">{{ detail.name }}</view>
  8. <u-count-down
  9. class="count-down-demo"
  10. :timestamp="timestamp"
  11. separator-color="#ffbbbb "
  12. bg-color="#ffbbbb "
  13. ref="uCountDown"
  14. color="#fff"
  15. @end="seckillEnd"
  16. autoplay
  17. ></u-count-down>
  18. </view>
  19. <view class="more-box u-flex" @tap="$Router.push('/pages/activity/seckill/list')">
  20. <text class="more-text u-m-r-10">更多抢购</text>
  21. <text class="iconfont icon-youjiantou-tianchong more-icon"></text>
  22. </view>
  23. </view>
  24. <!-- 活动商品 -->
  25. <!-- m -->
  26. <scroll-view v-if="seckillType === 1" class="scroll-box" scroll-x scroll-anchoring>
  27. <view class="goods-box u-flex">
  28. <view class="min-goods u-m-r-14" v-for="mgoods in goodsList" :key="mgoods.id" @tap="jump('/pages/goods/detail', { id: mgoods.id })">
  29. <view class="img-box"><image class="img" :src="mgoods.image" mode=""></image></view>
  30. <view class="mgoods-card-bottom u-p-20">
  31. <view class="goods-title u-m-b-10 u-ellipsis-1">{{ mgoods.title }}</view>
  32. <view class="price-box font-OPPOSANS">
  33. <view class="price u-m-b-10">{{ mgoods.price }}</view>
  34. <view class="original-price">¥{{ mgoods.original_price }}</view>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. </scroll-view>
  40. <!--b-->
  41. <view
  42. v-if="seckillType === 2"
  43. class="big-goods u-flex u-p-20 u-col-top u-m-b-16"
  44. v-for="item in goodsList"
  45. :key="item.id"
  46. @tap="jump('/pages/goods/detail', { id: item.id })"
  47. >
  48. <image class="goods-img" :src="item.image" mode="aspectFill"></u-image>
  49. <view class=" card-right u-m-l-20 u-flex-col u-row-between">
  50. <view class="">
  51. <view class="goods-title u-ellipsis-1 u-m-t-10 u-m-b-10">
  52. <view class=" sm cu-tag bg-red radius title-tag u-m-r-10" >秒杀</view>
  53. {{ item.title }}
  54. </view>
  55. <view v-show="item.subtitle" class="subtitle-text u-m-b-10 u-ellipsis-1">{{ item.subtitle }}</view>
  56. </view>
  57. <view class="u-flex u-m-y-20">
  58. <u-line-progress
  59. style="width:210rpx;"
  60. height="18"
  61. :show-percent="false"
  62. :percent="Number(item.percent)"
  63. inactive-color=" #e7e7e7"
  64. active-color="#ffbbbb "
  65. ></u-line-progress>
  66. <view class="progress-text">已售出{{ item.sales }}件</view>
  67. </view>
  68. <view class=" u-flex u-row-between u-col-center">
  69. <view class="u-flex u-col-bottom">
  70. <view class="price u-m-r-10">{{ item.price }}</view>
  71. <view class="origin-price">{{ item.original_price }}</view>
  72. </view>
  73. <button class="u-reset-button buy-btn">去抢购</button>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. /**
  81. * 自定义之秒杀样式组件
  82. * @property {Object} detail - 秒杀商品信息
  83. */
  84. export default {
  85. components: {},
  86. data() {
  87. return {
  88. timestamp: 0, //倒计时
  89. goodsList: [],
  90. showActivity: true, //是否显示活动。
  91. seckillType: this.detail.style
  92. };
  93. },
  94. props: {
  95. detail: {
  96. type: Object,
  97. default: () => {
  98. return {};
  99. }
  100. }
  101. },
  102. watch: {},
  103. computed: {},
  104. created() {
  105. this.getActivityGoodsList();
  106. },
  107. methods: {
  108. // 路由跳转
  109. jump(path, parmas) {
  110. this.$Router.push({
  111. path: path,
  112. query: parmas
  113. });
  114. },
  115. // 秒杀计时结束
  116. seckillEnd() {
  117. this.showActivity = false;
  118. },
  119. // 获取秒杀商品
  120. getActivityGoodsList() {
  121. let that = this;
  122. that.$http('goods.activity', {
  123. activity_id: that.detail.id
  124. }).then(res => {
  125. if (res.code === 1) {
  126. that.goodsList = res.data.goods.data;
  127. that.goodsList.map(item => {
  128. item.percent = item.stock + item.sales > 0 ? ((item.sales / (item.sales + item.stock)) * 100).toFixed(2) : 0;
  129. });
  130. let nowTime = new Date().getTime();
  131. let endTime = res.data.endtime * 1000;
  132. that.timestamp = (endTime - nowTime) / 1000;
  133. that.timestamp > 0 ? that.$refs.uCountDown.start() : (that.showActivity = false);
  134. } else {
  135. that.showActivity = false;
  136. console.log(`%cerr:秒杀活动已结束`, 'color:green;background:yellow');
  137. }
  138. });
  139. }
  140. }
  141. };
  142. </script>
  143. <style lang="scss" scoped>
  144. .seckill-card {
  145. background: linear-gradient(#ffebec 20%, #fff 30%, #fff 100%);
  146. }
  147. .seckill-title {
  148. background: url($IMG_URL+'/imgs/tag/seckill_title_bg.png') no-repeat;
  149. background-position: center top;
  150. background-size: 100% auto;
  151. }
  152. .activity-wrap {
  153. background-color: #fff;
  154. min-height: 300rpx;
  155. .title-box {
  156. .title-text {
  157. font-size: 32rpx;
  158. font-weight: bold;
  159. color: #333333;
  160. }
  161. .more-box {
  162. .more-text {
  163. font-size: 22rpx;
  164. font-weight: 500;
  165. color: #333333;
  166. }
  167. .more-icon {
  168. font-size: 24rpx;
  169. color: #333333;
  170. }
  171. }
  172. }
  173. .scroll-box,
  174. .goods-box {
  175. height: 380rpx;
  176. width: 100%;
  177. }
  178. }
  179. // 小商品卡片
  180. .min-goods {
  181. width: 220rpx;
  182. height: 380rpx;
  183. background: #fff7f7;
  184. box-shadow: 0px 7rpx 7rpx 0px rgba(255, 80, 94, 0.32);
  185. border-radius: 10rpx;
  186. .img-box {
  187. width: 220rpx;
  188. height: 220rpx;
  189. overflow: hidden;
  190. position: relative;
  191. border-radius: 10rpx 10rpx 0 0;
  192. .img {
  193. width: 220rpx;
  194. height: 220rpx;
  195. background-color: #ccc;
  196. }
  197. }
  198. .mgoods-card-bottom {
  199. height: 160rpx;
  200. background: url($IMG_URL+'/imgs/tag/seckill_goods_bg.png') no-repeat;
  201. background-position: bottom center;
  202. background-size: 100% 100%;
  203. }
  204. .goods-title {
  205. font-size: 26rpx;
  206. font-weight: 500;
  207. color: #000000;
  208. line-height: 26rpx;
  209. }
  210. .price-box {
  211. .price {
  212. font-size: 30rpx;
  213. font-weight: 500;
  214. color: #ff0000;
  215. &::before {
  216. content: '¥';
  217. font-size: 24rpx;
  218. }
  219. }
  220. .original-price {
  221. font-size: 20rpx;
  222. font-weight: 500;
  223. text-decoration: line-through;
  224. color: #c4c4c4;
  225. }
  226. }
  227. }
  228. // 大商品卡片
  229. .big-goods {
  230. width: 710rpx;
  231. min-height: 260rpx;
  232. background: #ffffff;
  233. box-shadow: 0px 7rpx 8rpx 1rpx rgba(254, 76, 29, 0.05);
  234. border-radius: 20rpx;
  235. .goods-img{
  236. width: 220rpx;
  237. height: 220rpx;
  238. border-radius: 6rpx;
  239. }
  240. .card-right {
  241. width: 430rpx;
  242. height: 100%;
  243. }
  244. .goods-title {
  245. font-size: 26rpx;
  246. font-weight: 600;
  247. width: 400rpx;
  248. color: #000000;
  249. }
  250. .subtitle-text {
  251. font-size: 22rpx;
  252. width: 400rpx;
  253. font-weight: 500;
  254. color: #666666;
  255. }
  256. .buy-btn {
  257. width: 120rpx;
  258. line-height: 50rpx;
  259. background: linear-gradient(90deg, #d01325, #ed3c30);
  260. border-radius: 25rpx;
  261. font-size: 24rpx;
  262. font-weight: 500;
  263. color: #ffffff;
  264. }
  265. .progress-text {
  266. color: #c4c4c4;
  267. font-size: 20rpx;
  268. margin-left: 25rpx;
  269. }
  270. // 价格
  271. .price {
  272. color: #ff0000;
  273. font-weight: 600;
  274. &::before {
  275. content: '¥';
  276. font-size: 20rpx;
  277. }
  278. }
  279. .origin-price {
  280. color: #c4c4c4;
  281. font-size: 24rpx;
  282. text-decoration: line-through;
  283. &::before {
  284. content: '¥';
  285. font-size: 20rpx;
  286. }
  287. }
  288. }
  289. </style>