index.js 2.9 KB

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