reportInfo.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <u-cell-group>
  3. <u-cell title="开始时间" arrow-direction="down">
  4. <uni-datetime-picker :end="finishTime" type="datetime" slot="value" v-model="reportForm.acceptTime"
  5. @change="starTimeChange">
  6. </uni-datetime-picker>
  7. </u-cell>
  8. <u-cell title="结束时间" arrow-direction="down">
  9. <uni-datetime-picker :start="starTime" type="datetime" slot="value" v-model="reportForm.finishTime"
  10. @change="endTimeChange">
  11. </uni-datetime-picker>
  12. </u-cell>
  13. <u-cell title="时间售后时长(天)" arrow-direction="down">
  14. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  15. <u--input readonly style="flex:1" border="surround" v-model="days">
  16. </u--input>
  17. </view>
  18. </u-cell>
  19. <u-cell title="时间售后时长(小时)" arrow-direction="down">
  20. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  21. <u--input readonly style="flex:1" border="surround" v-model="hours">
  22. </u--input>
  23. </view>
  24. </u-cell>
  25. <u-cell title="时间售后时长(分钟)" arrow-direction="down">
  26. <view slot="value" style="display: flex;align-items: center;width: 100%;">
  27. <u--input readonly style="flex:1" border="surround" v-model="minutes">
  28. </u--input>
  29. </view>
  30. </u-cell>
  31. </u-cell-group>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. reportForm: {
  38. acceptTime: '',
  39. finishTime: '',
  40. inFactDuration: ''
  41. },
  42. finishTime: '',
  43. starTime: '',
  44. minutes: '',
  45. hours: '',
  46. days: ''
  47. }
  48. },
  49. props: {
  50. form: {
  51. type: Object,
  52. default: () => {}
  53. }
  54. },
  55. watch: {
  56. form: {
  57. handler(newVal) {
  58. this.reportForm = {
  59. ...newVal
  60. }
  61. this.calculateTimeDifference();
  62. },
  63. deep: true,
  64. immediate: true
  65. }
  66. },
  67. methods: {
  68. getReportForm() {
  69. let data = JSON.parse(JSON.stringify(this.reportForm));
  70. let arr1 = data.acceptTime.split(' ')
  71. let arr2 = data.finishTime.split(' ')
  72. if (arr1.length == 2 && !arr1[1]) {
  73. data.acceptTime = data.acceptTime + '00:00:00'
  74. }
  75. if (arr2.length == 2 && !arr2[1]) {
  76. data.finishTime = data.finishTime + '00:00:00'
  77. }
  78. return data;
  79. },
  80. // 开始时间
  81. starTimeChange(e) {
  82. this.starTime = e;
  83. this.reportForm.acceptTime = e;
  84. this.calculateTimeDifference()
  85. },
  86. // 结束时间
  87. endTimeChange(e) {
  88. this.finishTime = e;
  89. this.reportForm.finishTime = e;
  90. this.calculateTimeDifference();
  91. },
  92. calculateTimeDifference() {
  93. if (!this.reportForm.acceptTime || !this.reportForm.finishTime) {
  94. this.days = '';
  95. this.hours = '';
  96. this.minutes = '';
  97. this.reportForm.inFactDuration = '';
  98. return
  99. }
  100. // 计算时间差
  101. const acceptTime = new Date(this.reportForm.acceptTime);
  102. const finishTime = new Date(this.reportForm.finishTime);
  103. const timeDiff = finishTime - acceptTime; // 毫秒数
  104. // 转换为天、小时、分钟
  105. const minutes = timeDiff / (1000 * 60);
  106. const hours = minutes / 60;
  107. const days = hours / 24;
  108. this.reportForm.inFactDuration = minutes;
  109. this.minutes = minutes.toFixed(0) + ' 分钟';
  110. this.hours = hours.toFixed(1) + ' 小时';
  111. this.days = days.toFixed(1) + ' 天';
  112. },
  113. }
  114. }
  115. </script>
  116. <style>
  117. </style>