dateSelectDl.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <uni-popup ref="commonPopup" :animation="false" :is-mask-click="false"
  3. mask-background-color="rgba(0, 0, 0, 0.4)">
  4. <view class="phone-common-dialog">
  5. <view class="common-body-box">
  6. <view class="common-title">请选择日期</view>
  7. <view class="common-content" :class="dialogContentClass">
  8. <uni-datetime-picker v-model="infoDate.selected" type="daterange" @change="dateConfirm" />
  9. </view>
  10. <view class="common-btn-box">
  11. <view class="confirm-btn" @click="confirmBtn">确认</view>
  12. </view>
  13. </view>
  14. </view>
  15. </uni-popup>
  16. </template>
  17. <script setup>
  18. import { ref,reactive } from 'vue';
  19. import uniDatetimePicker from "@/subpack/uni-datetime-picker/components/uni-datetime-picker/time-picker.vue"
  20. const props = defineProps({
  21. title: {
  22. type: String,
  23. default: ''
  24. },
  25. content: {
  26. type: String,
  27. require: true,
  28. default: ''
  29. },
  30. dialogContentClass: {
  31. type: String,
  32. require: true,
  33. default: 'content-center-class'
  34. },
  35. notBtn: {
  36. type: String,
  37. require: true,
  38. default: '取消'
  39. },
  40. okBtn: {
  41. type: String,
  42. require: true,
  43. default: '确认'
  44. },
  45. });
  46. const commonPopup = ref(null); // 索引
  47. const $emit = defineEmits(['confirm-btn', 'date-reset'])
  48. /**
  49. * 获取任意时间
  50. */
  51. function getDate(date, AddDayCount = 0) {
  52. if (!date) {
  53. date = new Date()
  54. }
  55. if (typeof date !== 'object') {
  56. date = date.replace(/-/g, '/')
  57. }
  58. const dd = new Date(date)
  59. dd.setDate(dd.getDate() + AddDayCount) // 获取AddDayCount天后的日期
  60. const y = dd.getFullYear()
  61. const m = dd.getMonth() + 1 < 10 ? '0' + (dd.getMonth() + 1) : dd.getMonth() + 1 // 获取当前月份的日期,不足10补0
  62. const d = dd.getDate() < 10 ? '0' + dd.getDate() : dd.getDate() // 获取当前几号,不足10补0
  63. return {
  64. fullDate: y + '-' + m + '-' + d,
  65. year: y,
  66. month: m,
  67. date: d,
  68. day: dd.getDay()
  69. }
  70. }
  71. const infoDate = reactive({
  72. lunar: true,
  73. range: true,
  74. insert: false,
  75. selected: [],
  76. valueData: null
  77. })
  78. function dateConfirm(data) {
  79. infoDate.selected = data;
  80. }
  81. // 打开弹窗
  82. function handleShow(data) {
  83. if (data) {
  84. infoDate.selected = data;
  85. }
  86. commonPopup.value.open();
  87. }
  88. // 取消
  89. function handleClose() {
  90. commonPopup.value.close();
  91. }
  92. // 确认
  93. function confirmBtn(){
  94. if (!infoDate.selected.lenth||infoDate.selected.length>1) {
  95. $emit('confirm-btn',infoDate.selected);
  96. commonPopup.value.close();
  97. } else {
  98. uni.showToast({
  99. title: '请选择日期',
  100. icon: 'none'
  101. })
  102. }
  103. }
  104. function handleReset() {
  105. $emit('date-reset')
  106. infoDate.selected = []
  107. handleClose();
  108. }
  109. defineExpose({
  110. handleShow,
  111. handleClose
  112. })
  113. </script>
  114. <style>
  115. </style>