sh-price-card.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. <template>
  2. <view>
  3. <!-- 正常商品 -->
  4. <view class="normal-price-box" v-if="type !== 'score' && !detail.activity">
  5. <view class="u-felx u-col-bottom">
  6. <text class="unit font-OPPOSANS">¥</text>
  7. <text class="price font-OPPOSANS">{{ detail.price }}</text>
  8. <text class="notice">优惠价</text>
  9. </view>
  10. <view class="u-flex u-row-left price-bottom-box">
  11. <view class="u-flex">
  12. <view class="original-price font-OPPOSANS">原价:¥{{ detail.original_price }}</view>
  13. <text class="line"></text>
  14. <view class="sold font-OPPOSANS">已售:{{ detail.sales }}件</view>
  15. </view>
  16. </view>
  17. </view>
  18. <!-- 积分商品 -->
  19. <view class="score-price-card" v-if="type === 'score'">
  20. <view class="u-flex u-col-bottom">
  21. <image class="score-img" :src="$IMG_URL + '/imgs/score/score.png'" mode=""></image>
  22. <text class="price">{{ detail.price }}</text>
  23. </view>
  24. <view class="u-felx u-col-bottom price-bottom-box">
  25. <view class="u-flex">
  26. <view class="original-price font-OPPOSANS">价值:¥{{ detail.original_price }}</view>
  27. <text class="line"></text>
  28. <view class="sold font-OPPOSANS">已兑换:{{ detail.sales }}件</view>
  29. </view>
  30. </view>
  31. </view>
  32. <!-- 团购商品 -->
  33. <view class="groupon-price-box" v-if="detail.activity && detail.activity.type === 'groupon'">
  34. <view class="u-flex u-col-bottom">
  35. <text class="unit font-OPPOSANS">¥</text>
  36. <text class="price font-OPPOSANS">{{ detail.activity_type === 'groupon' ? detail.groupon_price : detail.price }}</text>
  37. <text class="notice font-OPPOSANS">{{ detail.activity.rules.team_num }}人团</text>
  38. </view>
  39. <view class="u-flex u-row-between price-bottom-box">
  40. <view class="u-flex">
  41. <view class="original-price font-OPPOSANS">原价:¥{{ detail.original_price }}</view>
  42. <text class="line"></text>
  43. <view class="sold font-OPPOSANS">已拼:{{ detail.sales }}件</view>
  44. </view>
  45. <view class="count-down font-OPPOSANS" v-show="activityRules.status !== 'end'">
  46. <text class="u-p-r-10" v-show="activityRules.status === 'waiting'">距开始</text>
  47. <text class="u-p-r-10" v-show="activityRules.status === 'ing'">距结束</text>
  48. {{ activityRules.countDownTime.h || '00' }} : {{ activityRules.countDownTime.m || '00' }} : {{ activityRules.countDownTime.s || '00' }}
  49. </view>
  50. <view class="count-down" v-show="activityRules.status === 'end'">活动已结束</view>
  51. </view>
  52. </view>
  53. <!-- 秒杀商品 -->
  54. <view class="seckill-price-box " :class="activityRules.status !== 'end' ? 'seckill-bg' : 'seckilled-bg'" v-if="detail.activity && detail.activity.type === 'seckill'">
  55. <view class="u-flex u-row-between price-top-box">
  56. <view class="u-flex">
  57. <text class="unit font-OPPOSANS">¥</text>
  58. <text class="price font-OPPOSANS">{{ detail.price }}</text>
  59. <text class="notice">秒杀价</text>
  60. </view>
  61. <view class="count-down font-OPPOSANS" v-show="activityRules.status !== 'end'">
  62. <text class="u-p-r-10" v-show="activityRules.status === 'waiting'">距开始</text>
  63. <text class="u-p-r-10" v-show="activityRules.status === 'ing'">距结束</text>
  64. {{ activityRules.countDownTime.h || '00' }} : {{ activityRules.countDownTime.m || '00' }} : {{ activityRules.countDownTime.s || '00' }}
  65. </view>
  66. <view class="count-down" v-show="activityRules.status === 'end'">活动已结束</view>
  67. </view>
  68. <view class="u-flex u-row-between price-bottom-box">
  69. <view class="u-flex">
  70. <view class="original-price font-OPPOSANS">原价:¥{{ detail.original_price }}</view>
  71. <text class="line"></text>
  72. <view class="sold font-OPPOSANS">已售:{{ detail.sales }}件</view>
  73. </view>
  74. <view class="express">
  75. <view class="u-flex">
  76. <view style="width:100rpx;" v-show="activityRules.status !== 'end'">
  77. <u-line-progress height="14" :show-percent="false" :percent="percent" inactive-color="#a1071a" active-color="#fff"></u-line-progress>
  78. </view>
  79. <view class="progress-text" v-if="detail.stock > 0">仅剩{{ detail.stock }}件</view>
  80. <view class="progress-text" v-else>已售罄</view>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </template>
  87. <script>
  88. /**
  89. * 商品详情价格卡片
  90. * @property {Object} detail - 商品详情
  91. * @property {String} type - 商品分类
  92. */
  93. let timer = null;
  94. export default {
  95. components: {},
  96. data() {
  97. return {
  98. time: {}, //倒计时
  99. activityRules: {
  100. startTime: 0,
  101. endTime: 0,
  102. status: '',
  103. countDownTime: 0
  104. }
  105. };
  106. },
  107. props: {
  108. detail: Object,
  109. type: ''
  110. },
  111. created() {
  112. if (this.detail.activity && this.detail.activity.type) {
  113. this.doActivityRules();
  114. }
  115. },
  116. beforeDestroy() {
  117. clearInterval(timer);
  118. timer = null;
  119. },
  120. computed: {
  121. // 百分比
  122. percent() {
  123. let unit = 0;
  124. if (this.detail.id) {
  125. unit = this.detail.stock + this.detail.sales > 0 ? ((this.detail.sales / (this.detail.sales + this.detail.stock)) * 100).toFixed(2) : 0;
  126. }
  127. return Number(unit);
  128. }
  129. },
  130. methods: {
  131. // 触发活动规则
  132. doActivityRules() {
  133. let that = this;
  134. switch (that.detail.activity.type) {
  135. case 'seckill':
  136. case 'groupon':
  137. that.activityRules.startTime = that.detail.activity.starttime * 1000;
  138. that.activityRules.endTime = that.detail.activity.endtime * 1000;
  139. that.countDown();
  140. break;
  141. }
  142. },
  143. // 计时器
  144. countDown() {
  145. let that = this;
  146. let t = 0;
  147. timer = setInterval(() => {
  148. let nowTime = new Date().getTime();
  149. //当前日期大于活动结束日期,活动结束
  150. if (that.activityRules.endTime < nowTime) {
  151. that.activityRules.status = 'end';
  152. that.$emit('change', JSON.stringify(that.activityRules));
  153. }
  154. // 活动未结束
  155. if (nowTime < that.activityRules.startTime) {
  156. //当前日期小于开始时间,活动未开始
  157. that.activityRules.status = 'waiting';
  158. t = that.activityRules.startTime - nowTime;
  159. } else if (nowTime > that.activityRules.endTime) {
  160. //当前日期大于结束时间,活动结束
  161. that.activityRules.status = 'end';
  162. clearInterval(timer);
  163. return;
  164. } else {
  165. // 活动进行中
  166. that.activityRules.status = 'ing';
  167. t = that.activityRules.endTime - nowTime;
  168. }
  169. that.activityRules.countDownTime = that.formatToHours(t / 1000);
  170. t--;
  171. that.$emit('change', JSON.stringify(that.activityRules));
  172. }, 1000);
  173. },
  174. //时间格式化(格式化最大为小时)
  175. formatToHours(t) {
  176. let format = {
  177. h: '00',
  178. m: '00',
  179. s: '00'
  180. };
  181. if (t > 0) {
  182. let h = Math.floor(t / 3600);
  183. let m = Math.floor((t / 60) % 60);
  184. let s = Math.floor(t % 60);
  185. format.h = h < 10 ? '0' + h : h;
  186. format.m = m < 10 ? '0' + m : m;
  187. format.s = s < 10 ? '0' + s : s;
  188. }
  189. return format;
  190. }
  191. }
  192. };
  193. </script>
  194. <style lang="scss">
  195. // 正常商品
  196. .normal-price-box {
  197. padding: 20rpx;
  198. background: url($IMG_URL+'/imgs/detail/detail_price_normal_bg.png') no-repeat;
  199. background-size: 100% 100%;
  200. .unit,
  201. .notice {
  202. font-size: 24rpx;
  203. color: #fff;
  204. }
  205. .price {
  206. font-size: 36rpx;
  207. color: #fff;
  208. font-weight: bold;
  209. margin: 0 10rpx;
  210. }
  211. .price-bottom-box {
  212. font-size: 24rpx;
  213. color: #fff;
  214. font-weight: 500;
  215. padding-top: 10rpx;
  216. .original-price {
  217. text-decoration: line-through;
  218. }
  219. .line {
  220. margin: 0 20rpx;
  221. display: inline-block;
  222. width: 3rpx;
  223. height: 24rpx;
  224. background-color: #fff;
  225. }
  226. }
  227. }
  228. // 团购商品
  229. .groupon-price-box {
  230. padding: 20rpx;
  231. background: url($IMG_URL+'/imgs/detail/detail_group_price_bg.png') no-repeat;
  232. background-size: 100% 100%;
  233. .unit,
  234. .notice {
  235. font-size: 24rpx;
  236. color: rgba(#fff, 0.9);
  237. }
  238. .notice {
  239. line-height: 40rpx;
  240. border: 1rpx solid rgba(255, 255, 255, 1);
  241. border-radius: 6rpx;
  242. padding: 0 10rpx;
  243. }
  244. .price {
  245. font-size: 36rpx;
  246. color: rgba(#fff, 0.9);
  247. font-weight: bold;
  248. margin: 0 10rpx;
  249. }
  250. .price-bottom-box {
  251. font-size: 24rpx;
  252. color: rgba(#fff, 0.9);
  253. font-weight: 500;
  254. padding-top: 10rpx;
  255. .line {
  256. margin: 0 20rpx;
  257. display: inline-block;
  258. width: 3rpx;
  259. height: 24rpx;
  260. background-color: #fff;
  261. }
  262. .count-down {
  263. font-size: 24rpx;
  264. color: rgba(#fff, 0.9);
  265. }
  266. }
  267. }
  268. // 积分商品价格卡片
  269. .score-price-card {
  270. padding: 20rpx;
  271. background: url($IMG_URL+'/imgs/detail/detail_price_score_bg.png') no-repeat;
  272. background-size: 100% 100%;
  273. width: 750rpx;
  274. .notice {
  275. font-size: 24rpx;
  276. color: #fff;
  277. }
  278. .score-img {
  279. width: 36rpx;
  280. height: 36rpx;
  281. }
  282. .price {
  283. font-size: 36rpx;
  284. color: #fff;
  285. font-weight: bold;
  286. margin: 0 10rpx;
  287. }
  288. .price-bottom-box {
  289. font-size: 24rpx;
  290. color: #fff;
  291. font-weight: 500;
  292. padding-top: 10rpx;
  293. .original-price {
  294. text-decoration: line-through;
  295. }
  296. .line {
  297. margin: 0 20rpx;
  298. display: inline-block;
  299. width: 3rpx;
  300. height: 24rpx;
  301. background-color: #fff;
  302. }
  303. }
  304. }
  305. // 秒杀商品
  306. .seckill-bg {
  307. background: url($IMG_URL+'/imgs/detail/detail_price_seckill_bg.png') no-repeat;
  308. background-size: 100% 100%;
  309. }
  310. .seckilled-bg {
  311. background: url($IMG_URL+'/imgs/detail/detail_price_seckilled_bg.png') no-repeat;
  312. background-size: 100% 100%;
  313. }
  314. .seckill-price-box {
  315. padding: 20rpx;
  316. .unit,
  317. .notice,
  318. .count-down {
  319. font-size: 24rpx;
  320. color: rgba(#fff, 0.9);
  321. }
  322. .notice {
  323. line-height: 40rpx;
  324. border: 1rpx solid rgba(255, 255, 255, 1);
  325. border-radius: 6rpx;
  326. padding: 0 10rpx;
  327. margin-left: 10rpx;
  328. }
  329. .price {
  330. font-size: 36rpx;
  331. color: rgba(#fff, 0.9);
  332. font-weight: bold;
  333. margin: 0 10rpx;
  334. }
  335. .price-bottom-box {
  336. font-size: 24rpx;
  337. color: rgba(#fff, 0.9);
  338. font-weight: 500;
  339. padding-top: 10rpx;
  340. .original-price {
  341. text-decoration: line-through;
  342. }
  343. .express {
  344. .progress-text {
  345. color: rgba(#fff, 0.9);
  346. font-size: 24rpx;
  347. margin-left: 10rpx;
  348. }
  349. }
  350. .line {
  351. margin: 0 20rpx;
  352. display: inline-block;
  353. width: 3rpx;
  354. height: 24rpx;
  355. background-color: #fff;
  356. }
  357. }
  358. }
  359. </style>