鸿宇研学生前端代码
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
1.9 KiB

  1. <template>
  2. <view class="calendar">
  3. <uv-calendar
  4. ref="calendar"
  5. title="出行日期"
  6. mode="single"
  7. rowHeight="110"
  8. :defaultDate="defaultDate"
  9. @confirm="confirm"
  10. ></uv-calendar>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. props: {
  16. value: {
  17. type: String,
  18. default: null
  19. },
  20. options: {
  21. type: Array,
  22. default() {
  23. return []
  24. }
  25. },
  26. },
  27. data() {
  28. return {
  29. defaultDate: null,
  30. }
  31. },
  32. computed: {
  33. selected: {
  34. set(val) {
  35. this.$emit('input', val)
  36. },
  37. get() {
  38. return this.value
  39. }
  40. },
  41. startDateList() {
  42. return this.options.map(item => {
  43. const { startDate } = item
  44. return this.$dayjs(`2025/${startDate}`).format('YYYY-MM-DD')
  45. })
  46. },
  47. },
  48. onReady() {
  49. this.$refs.calendar.setFormatter(this.formatter);
  50. },
  51. methods: {
  52. formatter(day) {
  53. const dateStr = this.$dayjs(day.date).format('YYYY-MM-DD')
  54. const index = this.startDateList.findIndex(startDate => startDate === dateStr)
  55. if (index === -1) {
  56. day.disabled = true
  57. return day;
  58. }
  59. const { startDate, endDate, currentPrice } = this.options[index]
  60. // day.topInfo = `${startDate}-${endDate}`
  61. day.topInfo = `~${endDate}`
  62. day.bottomInfo = `¥${currentPrice}`
  63. return day
  64. },
  65. open() {
  66. if (this.selected) {
  67. const index = this.options.findIndex(option => option.id === this.selected)
  68. this.defaultDate = this.startDateList[index]
  69. }
  70. this.$refs.calendar.open();
  71. },
  72. confirm(e) {
  73. const dateStr = e[0]
  74. const index = this.startDateList.findIndex(startDate => startDate === dateStr)
  75. this.selected = this.options[index].id
  76. },
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. </style>