index.js 3.3 KB

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