index.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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, overlay = _a.overlay, duration = _a.duration, activeColor = _a.activeColor, closeOnClickOverlay = _a.closeOnClickOverlay, direction = _a.direction;
  51. this.setData({
  52. overlay: overlay,
  53. duration: duration,
  54. activeColor: activeColor,
  55. closeOnClickOverlay: closeOnClickOverlay,
  56. direction: direction
  57. });
  58. }
  59. },
  60. onOpen: function () {
  61. this.$emit('open');
  62. },
  63. onOpened: function () {
  64. this.$emit('opened');
  65. },
  66. onClose: function () {
  67. this.$emit('close');
  68. },
  69. onClosed: function () {
  70. this.$emit('closed');
  71. this.setData({ showWrapper: false });
  72. },
  73. onOptionTap: function (event) {
  74. var option = event.currentTarget.dataset.option;
  75. var value = option.value;
  76. var shouldEmitChange = this.data.value !== value;
  77. this.setData({ showPopup: false, value: value });
  78. this.$emit('close');
  79. this.rerender();
  80. if (shouldEmitChange) {
  81. this.$emit('change', value);
  82. }
  83. },
  84. toggle: function (show, options) {
  85. var _this = this;
  86. if (options === void 0) { options = {}; }
  87. var showPopup = this.data.showPopup;
  88. if (typeof show !== 'boolean') {
  89. show = !showPopup;
  90. }
  91. if (show === showPopup) {
  92. return;
  93. }
  94. this.setData({
  95. transition: !options.immediate,
  96. showPopup: show,
  97. });
  98. if (show) {
  99. this.parent.getChildWrapperStyle().then(function (wrapperStyle) {
  100. _this.setData({ wrapperStyle: wrapperStyle, showWrapper: true });
  101. _this.rerender();
  102. });
  103. }
  104. else {
  105. this.rerender();
  106. }
  107. }
  108. }
  109. });