index.js 2.9 KB

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