CountDate.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <div class="count-content">
  3. <div class="countDown" v-if="dateColor == 0">
  4. <div>{{ dayString }}</div>
  5. <p>天</p>
  6. <div>{{ hourString1 }}</div>
  7. <p>:</p>
  8. <div>{{ minuteString }}</div>
  9. <p>:</p>
  10. <div>{{ secondString }}</div>
  11. </div>
  12. <div class="countDowns" v-if="dateColor == 1">
  13. <div>距离秒杀结束:</div>
  14. <div>{{ dayString }}</div>
  15. <p>天</p>
  16. <div>{{ hourString1 }}</div>
  17. <p>:</p>
  18. <div>{{ minuteString }}</div>
  19. <p>:</p>
  20. <div>{{ secondString }}</div>
  21. </div>
  22. <div class="countDown-s" v-if="dateColor == 2">
  23. <p style="font-size: 20px">限时秒杀</p>
  24. <p>距离结束</p>
  25. <div>{{ dayString }}</div>
  26. <p>天</p>
  27. <div>{{ hourString1 }}</div>
  28. <p>:</p>
  29. <div>{{ minuteString }}</div>
  30. <p>:</p>
  31. <div>{{ secondString }}</div>
  32. <div class="rights" @click="toMore">
  33. <span>更多抢购</span>
  34. <span class="right-icon">
  35. <img
  36. src="http://screen.zhousi.hdlkeji.com/aksdbn/img/goods/goods-icon5.png"
  37. />
  38. </span>
  39. </div>
  40. </div>
  41. <!-- <span>{{ hourString }}</span>小时<span>{{ minuteString }}</span>分钟<span>{{ secondString }}</span>秒-->
  42. </div>
  43. </template>
  44. <script>
  45. export default {
  46. props: {
  47. remainTime: {
  48. // 倒计时间总秒数
  49. type: Number,
  50. default: 0,
  51. },
  52. dateColor: {
  53. type: Number,
  54. default: 0,
  55. },
  56. },
  57. data() {
  58. return {
  59. day: "",
  60. hour: "",
  61. minute: "",
  62. second: "",
  63. promiseTimer: "",
  64. time: "",
  65. };
  66. },
  67. computed: {
  68. hourString() {
  69. let num;
  70. if (this.day > 1) {
  71. num = this.day * 24 + this.hour;
  72. } else if (this.day == "") {
  73. num = this.hour;
  74. }
  75. return this.formatNum(num);
  76. },
  77. hourString1() {
  78. return this.formatNum(this.hour);
  79. },
  80. minuteString() {
  81. return this.formatNum(this.minute);
  82. },
  83. secondString() {
  84. return this.formatNum(this.second);
  85. },
  86. dayString() {
  87. return this.formatNum(this.day);
  88. },
  89. },
  90. mounted() {
  91. if (this.remainTime > 0) {
  92. this.day = Math.floor(this.remainTime / 3600 / 24);
  93. this.hour = Math.floor((this.remainTime / 3600) % 24);
  94. this.minute = Math.floor((this.remainTime / 60) % 60);
  95. this.second = Math.floor(this.remainTime % 60);
  96. this.countDowm();
  97. }
  98. },
  99. // watch:{
  100. // remainTime(oldValue,newValue){
  101. // if(oldValue){
  102. // this.remainTime=1
  103. // }
  104. // },
  105. // deep: true,
  106. // immediate: true,
  107. // },
  108. methods: {
  109. countDowm() {
  110. let self = this;
  111. clearInterval(this.promiseTimer);
  112. this.promiseTimer = setInterval(function () {
  113. // console.log("打印---day---",self.day)
  114. if (self.hour === 0) {
  115. if (self.minute !== 0 && self.second === 0) {
  116. self.second = 59;
  117. self.minute -= 1;
  118. } else if (self.minute === 0 && self.second === 0) {
  119. self.second = 0;
  120. self.$emit("countDowmEnd", true);
  121. clearInterval(self.promiseTimer);
  122. } else {
  123. self.second -= 1;
  124. }
  125. } else {
  126. if (self.minute !== 0 && self.second === 0) {
  127. self.second = 59;
  128. self.minute -= 1;
  129. } else if (self.minute === 0 && self.second === 0) {
  130. self.hour -= 1;
  131. self.minute = 59;
  132. self.second = 59;
  133. } else {
  134. self.second -= 1;
  135. }
  136. }
  137. }, 1000);
  138. },
  139. formatNum(num) {
  140. return num < 10 ? "0" + num : "" + num;
  141. },
  142. toMore() {
  143. this.$router.push({
  144. name: "seckillRank",
  145. });
  146. },
  147. },
  148. };
  149. </script>
  150. <style scoped lang="less">
  151. .countDowns {
  152. display: flex;
  153. }
  154. .countDown-s {
  155. display: flex;
  156. position: relative;
  157. z-index: 1;
  158. padding: 10px 10px 0 10px;
  159. justify-content: space-between;
  160. .rights {
  161. background: none !important;
  162. width: 240px;
  163. .right-icon {
  164. position: absolute;
  165. right: 0;
  166. top: 10px;
  167. img {
  168. width: 16px;
  169. height: 16px;
  170. }
  171. }
  172. span {
  173. display: block;
  174. }
  175. }
  176. p {
  177. color: #fff;
  178. margin: 0 10px;
  179. font-size: 18px;
  180. line-height: 45px;
  181. }
  182. div {
  183. color: #fff;
  184. font-size: 22px;
  185. //width: 38px;
  186. padding: 0 3px;
  187. height: 42px;
  188. background: #000000;
  189. text-align: center;
  190. line-height: 42px;
  191. }
  192. }
  193. .countDown {
  194. display: flex;
  195. justify-content: center;
  196. position: relative;
  197. z-index: 1;
  198. p {
  199. color: #fff;
  200. margin: 10px;
  201. }
  202. div {
  203. color: #fff;
  204. font-size: 22px;
  205. width: 38px;
  206. height: 42px;
  207. background: #000000;
  208. text-align: center;
  209. line-height: 42px;
  210. }
  211. }
  212. </style>