金诚优选前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
2.1 KiB

  1. <template>
  2. <view class="Countdown">
  3. <view class="time">
  4. <span class="item">{{day}}</span> <span class="item">{{hour}}</span> <span class="item">{{minute}}</span> <span class="item">{{second}}</span>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. data() {
  11. return {
  12. day: 0,
  13. hour: 0,
  14. minute: 0,
  15. second: 0
  16. };
  17. },
  18. props: {
  19. value: {
  20. type: String,
  21. value: null
  22. }
  23. },
  24. methods: {
  25. countTime() {
  26. var d = 86400000,
  27. h = 3600000,
  28. n = 60000,
  29. end = this.value,
  30. arr = String(end).split(/\D/);
  31. arr = arr.map(Number);
  32. var nowTime = new Date().getTime();
  33. var endTime = new Date(arr[0], arr[1] - 1, arr[2], arr[3], arr[4], arr[5]).getTime();
  34. var interval = endTime - nowTime;
  35. if (interval < 0) {
  36. this.setData({
  37. }); // this.show = false;
  38. /*this.$emit("over");*/
  39. this.end = false;
  40. } else {
  41. var day = Math.floor(interval / d);
  42. Math.floor(interval -= day * d);
  43. var hour = Math.floor(interval / h);
  44. Math.floor(interval -= hour * h);
  45. var minute = Math.floor(interval / n);
  46. var second = Math.floor(interval % n / 1000);
  47. this.day = day;
  48. this.hour = hour;
  49. this.minute = minute;
  50. this.second = second;
  51. }
  52. },
  53. setData: function (obj) {
  54. let that = this;
  55. let keys = [];
  56. let val, data;
  57. Object.keys(obj).forEach(function (key) {
  58. keys = key.split('.');
  59. val = obj[key];
  60. data = that.$data;
  61. keys.forEach(function (key2, index) {
  62. if (index + 1 == keys.length) {
  63. that.$set(data, key2, val);
  64. } else {
  65. if (!data[key2]) {
  66. that.$set(data, key2, {});
  67. }
  68. }
  69. data = data[key2];
  70. });
  71. });
  72. }
  73. },
  74. mounted() {
  75. setInterval(() => {
  76. this.countTime();
  77. }, 1000);
  78. },
  79. };
  80. </script>
  81. <style>
  82. .Countdown{width:145px;font-size:12px}.Countdown .time .item{display:inline-block}
  83. </style>