timer-tips.vue 893 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <view class="timer-tips">
  3. {{time_remaining |timeFilter}}
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: "timer-tips",
  9. data() {
  10. return {
  11. time_remaining: 0
  12. };
  13. },
  14. props: {
  15. createtime: Number
  16. },
  17. filters: {
  18. timeFilter(value) {
  19. if (value < 0) {
  20. return '该交易已关闭'
  21. } else if (parseInt(value / 60) > 0) {
  22. return '交易剩余支付时间 ' + parseInt(value / 60) + '分' + (value % 60) + '秒'
  23. } else {
  24. return '交易剩余支付时间 ' + value + '秒'
  25. }
  26. }
  27. },
  28. mounted() {
  29. let now = parseInt(new Date().getTime() / 1000);
  30. this.time_remaining = this.createtime + 1800 - now;
  31. setInterval(() => {
  32. this.time_remaining--
  33. }, 1000)
  34. }
  35. }
  36. </script>
  37. <style>
  38. .timer-tips {
  39. background-color: #ffff7f;
  40. text-align: center;
  41. font-size: 24upx;
  42. color: red;
  43. line-height: 40upx;
  44. }
  45. </style>