index.js 3.4 KB

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