index.js 2.8 KB

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