index.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { useParent } from '../common/relation';
  2. import { VantComponent } from '../common/component';
  3. VantComponent({
  4. field: true,
  5. relation: useParent('dropdown-menu', function () {
  6. this.updateDataFromParent();
  7. }),
  8. props: {
  9. value: {
  10. type: null,
  11. observer: 'rerender',
  12. },
  13. title: {
  14. type: String,
  15. observer: 'rerender',
  16. },
  17. disabled: Boolean,
  18. titleClass: {
  19. type: String,
  20. observer: 'rerender',
  21. },
  22. options: {
  23. type: Array,
  24. value: [],
  25. observer: 'rerender',
  26. },
  27. popupStyle: String,
  28. },
  29. data: {
  30. transition: true,
  31. showPopup: false,
  32. showWrapper: false,
  33. displayTitle: '',
  34. },
  35. methods: {
  36. rerender() {
  37. wx.nextTick(() => {
  38. var _a;
  39. (_a = this.parent) === null || _a === void 0 ? void 0 : _a.updateItemListData();
  40. });
  41. },
  42. updateDataFromParent() {
  43. if (this.parent) {
  44. const { overlay, duration, activeColor, closeOnClickOverlay, direction, } = this.parent.data;
  45. this.setData({
  46. overlay,
  47. duration,
  48. activeColor,
  49. closeOnClickOverlay,
  50. direction,
  51. });
  52. }
  53. },
  54. onOpen() {
  55. this.$emit('open');
  56. },
  57. onOpened() {
  58. this.$emit('opened');
  59. },
  60. onClose() {
  61. this.$emit('close');
  62. },
  63. onClosed() {
  64. this.$emit('closed');
  65. this.setData({ showWrapper: false });
  66. },
  67. onOptionTap(event) {
  68. const { option } = event.currentTarget.dataset;
  69. const { value } = option;
  70. const shouldEmitChange = this.data.value !== value;
  71. this.setData({ showPopup: false, value });
  72. this.$emit('close');
  73. this.rerender();
  74. if (shouldEmitChange) {
  75. this.$emit('change', value);
  76. }
  77. },
  78. toggle(show, options = {}) {
  79. var _a;
  80. const { showPopup } = this.data;
  81. if (typeof show !== 'boolean') {
  82. show = !showPopup;
  83. }
  84. if (show === showPopup) {
  85. return;
  86. }
  87. this.setData({
  88. transition: !options.immediate,
  89. showPopup: show,
  90. });
  91. if (show) {
  92. (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getChildWrapperStyle().then((wrapperStyle) => {
  93. this.setData({ wrapperStyle, showWrapper: true });
  94. this.rerender();
  95. });
  96. }
  97. else {
  98. this.rerender();
  99. }
  100. },
  101. },
  102. });