index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="time" :style="justifyLeft+'background-color:'+ bgColor +';color:'+ colors +';'">
  3. <text class="red" v-if="tipText">{{ tipText }}</text>
  4. <text class="styleAll" v-if="isDay === true">{{ day }}</text>
  5. <text class="timeTxt red" v-if="dayText">{{ dayText }}</text>
  6. <text class="styleAll">{{ hour }}</text>
  7. <text class="timeTxt red" v-if="hourText">{{ hourText }}</text>
  8. <text class="styleAll">{{ minute }}</text>
  9. <text class="timeTxt red" v-if="minuteText">{{ minuteText }}</text>
  10. <text class="styleAll">{{ second }}</text>
  11. <text class="timeTxt red" v-if="secondText">{{ secondText }}</text>
  12. </view>
  13. </template>
  14. <script>
  15. // +----------------------------------------------------------------------
  16. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  17. // +----------------------------------------------------------------------
  18. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  19. // +----------------------------------------------------------------------
  20. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  21. // +----------------------------------------------------------------------
  22. // | Author: CRMEB Team <admin@crmeb.com>
  23. // +----------------------------------------------------------------------
  24. export default {
  25. name: "countDown",
  26. props: {
  27. justifyLeft: {
  28. type: String,
  29. default: ""
  30. },
  31. //距离开始提示文字
  32. tipText: {
  33. type: String,
  34. default: "倒计时"
  35. },
  36. dayText: {
  37. type: String,
  38. default: "天"
  39. },
  40. hourText: {
  41. type: String,
  42. default: "时"
  43. },
  44. minuteText: {
  45. type: String,
  46. default: "分"
  47. },
  48. secondText: {
  49. type: String,
  50. default: "秒"
  51. },
  52. datatime: {
  53. type: Number,
  54. default: 0
  55. },
  56. isDay: {
  57. type: Boolean,
  58. default: true
  59. },
  60. id:{
  61. type: String | Number,
  62. default: ""
  63. },
  64. bgColor:{
  65. type: String,
  66. default: ""
  67. },
  68. colors:{
  69. type: String,
  70. default: ""
  71. }
  72. },
  73. data: function() {
  74. return {
  75. day: "00",
  76. hour: "00",
  77. minute: "00",
  78. second: "00"
  79. };
  80. },
  81. created: function() {
  82. this.show_time();
  83. },
  84. mounted: function() {},
  85. methods: {
  86. show_time: function() {
  87. let that = this;
  88. function runTime() {
  89. //时间函数
  90. let intDiff = that.datatime - Date.parse(new Date()) / 1000; //获取数据中的时间戳的时间差;
  91. let day = 0,
  92. hour = 0,
  93. minute = 0,
  94. second = 0;
  95. if (intDiff > 0) {
  96. //转换时间
  97. if (that.isDay === true) {
  98. day = Math.floor(intDiff / (60 * 60 * 24));
  99. } else {
  100. day = 0;
  101. }
  102. hour = Math.floor(intDiff / (60 * 60)) - day * 24;
  103. minute = Math.floor(intDiff / 60) - day * 24 * 60 - hour * 60;
  104. second =
  105. Math.floor(intDiff) -
  106. day * 24 * 60 * 60 -
  107. hour * 60 * 60 -
  108. minute * 60;
  109. if (hour <= 9) hour = "0" + hour;
  110. if (minute <= 9) minute = "0" + minute;
  111. if (second <= 9) second = "0" + second;
  112. that.day = day;
  113. that.hour = hour;
  114. that.minute = minute;
  115. that.second = second;
  116. } else {
  117. that.day = "00";
  118. that.hour = "00";
  119. that.minute = "00";
  120. that.second = "00";
  121. that.$emit('getProduct');
  122. clearInterval(runTime)
  123. uni.$emit('endTime',that.id)
  124. }
  125. }
  126. runTime();
  127. setInterval(runTime, 1000);
  128. }
  129. }
  130. };
  131. </script>
  132. <style>
  133. .time{
  134. display: flex;
  135. justify-content: center;
  136. }
  137. .styleAll {
  138. padding: 0 6rpx;
  139. color: var(--view-theme);
  140. border-radius: 2rpx;
  141. background-color: var(--view-minorColor);
  142. }
  143. .red{
  144. margin: 0 4rpx;
  145. }
  146. </style>