1
0

app-surplus_time.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <text>{{html}}</text>
  3. </template>
  4. <script>
  5. export default {
  6. name: "app-surplus_time",
  7. data() {
  8. return {
  9. html: '',
  10. time: null,
  11. countDown: this.surplus_time
  12. }
  13. },
  14. destroyed() {
  15. clearInterval(this.time);
  16. },
  17. props: {
  18. surplus_time: {
  19. type: Number,
  20. default() {
  21. return 0;
  22. }
  23. },
  24. surplus_date_time: String,
  25. },
  26. methods: {
  27. setTime(data) {
  28. let timelog = new Date(data.replace(/-/g, '/'));
  29. clearInterval(this.time);
  30. this.time = setInterval(() =>{
  31. let time = timelog.getTime() - new Date().getTime();
  32. if (time < 0) {
  33. clearInterval(this.time);
  34. }
  35. let day = parseInt((time/1000/60/60/24)%30);
  36. let hou = parseInt((time/1000/60/60)%24);
  37. let min = parseInt((time/1000/60)%60);
  38. let sec = parseInt((time/1000)%60);
  39. if (day > 0) {
  40. this.html = day+"天"+hou+":"+(min<10?"0"+min:min) + ":"+(sec<10?"0"+sec:sec);
  41. } else {
  42. this.html = hou+":"+(min<10?"0"+min:min) + ":"+(sec<10?"0"+sec:sec);
  43. }
  44. },1000);
  45. }
  46. },
  47. watch: {
  48. surplus_date_time: {
  49. handler(time) {
  50. if (time) {
  51. this.setTime(time);
  52. }
  53. },
  54. immediate: true
  55. }
  56. }
  57. }
  58. </script>
  59. <style scoped>
  60. </style>