chooseTime.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <van-popup
  3. :show="show"
  4. @close="onClose"
  5. position="bottom"
  6. round
  7. closeable
  8. :close-on-click-overlay="false"
  9. >
  10. <van-datetime-picker
  11. type="date"
  12. :value="currentDate"
  13. bind:change="onInput"
  14. @confirm="confirm1"
  15. @cancel="cancel"
  16. :min-date="minDate"
  17. :formatter="formatter"
  18. />
  19. </van-popup>
  20. </template>
  21. <script>
  22. import vanPopup from "../../../wxcomponents/weapp/dist/popup/index";
  23. import vanDatetimePicker from "../../../wxcomponents/weapp/dist/datetime-picker/index";
  24. export default {
  25. components: {
  26. vanPopup,
  27. vanDatetimePicker,
  28. },
  29. data() {
  30. return {
  31. show: false,
  32. chooseIndex: null,
  33. currentDate: new Date().getTime(),
  34. minDate: new Date().getTime(),
  35. type: null,
  36. formatter(type, value) {
  37. if (type === "year") {
  38. return `${value}年`;
  39. }
  40. if (type === "month") {
  41. return `${value}月`;
  42. }
  43. return value;
  44. },
  45. };
  46. },
  47. methods: {
  48. cancel() {
  49. this.show = false;
  50. },
  51. onOpen(i, type) {
  52. this.chooseIndex = i;
  53. this.type = type;
  54. this.show = true;
  55. },
  56. formatTime(date) {
  57. date = new Date(date);
  58. var year = date.getFullYear();
  59. var month = date.getMonth() + 1;
  60. var day = date.getDate();
  61. return [year, month, day].map(this.formatNumber).join("/");
  62. },
  63. onClose() {
  64. this.$emit(
  65. "getEndTime",
  66. this.chooseIndex,
  67. this.$common.transDate(this.currentDate),
  68. this.type
  69. );
  70. this.show = false;
  71. },
  72. confirm1(value) {
  73. // this.currentDate = event.detail;
  74. },
  75. },
  76. };
  77. </script>
  78. <style>
  79. </style>