reportInfo.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. if(!data.acceptTime || !data.finishTime){
  71. return data;
  72. }
  73. let arr1 = data.acceptTime.split(' ')
  74. let arr2 = data.finishTime.split(' ')
  75. if (arr1.length == 2 && !arr1[1]) {
  76. data.acceptTime = data.acceptTime + '00:00:00'
  77. }
  78. if (arr2.length == 2 && !arr2[1]) {
  79. data.finishTime = data.finishTime + '00:00:00'
  80. }
  81. return data;
  82. },
  83. // 开始时间
  84. starTimeChange(e) {
  85. this.starTime = e;
  86. this.reportForm.acceptTime = e;
  87. this.calculateTimeDifference()
  88. },
  89. // 结束时间
  90. endTimeChange(e) {
  91. this.finishTime = e;
  92. this.reportForm.finishTime = e;
  93. this.calculateTimeDifference();
  94. },
  95. calculateTimeDifference() {
  96. if (!this.reportForm.acceptTime || !this.reportForm.finishTime) {
  97. this.days = '';
  98. this.hours = '';
  99. this.minutes = '';
  100. this.reportForm.inFactDuration = '';
  101. return
  102. }
  103. // 计算时间差
  104. const acceptTime = new Date(this.reportForm.acceptTime);
  105. const finishTime = new Date(this.reportForm.finishTime);
  106. const timeDiff = finishTime - acceptTime; // 毫秒数
  107. // 转换为天、小时、分钟
  108. const minutes = timeDiff / (1000 * 60);
  109. const hours = minutes / 60;
  110. const days = hours / 24;
  111. this.reportForm.inFactDuration = minutes;
  112. this.minutes = minutes.toFixed(0) + ' 分钟';
  113. this.hours = hours.toFixed(1) + ' 小时';
  114. this.days = days.toFixed(1) + ' 天';
  115. },
  116. }
  117. }
  118. </script>
  119. <style>
  120. </style>