index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. var _component = require("../common/component");
  3. var _my = require("../../__antmove/api/index.js")(my);
  4. var wx = _my;
  5. (0, _component.VantComponent)({
  6. field: true,
  7. relation: {
  8. name: "dropdown-menu",
  9. type: "ancestor",
  10. current: "dropdown-item",
  11. linked: function linked() {
  12. this.updateDataFromParent();
  13. }
  14. },
  15. props: {
  16. value: {
  17. type: null,
  18. observer: "rerender"
  19. },
  20. title: {
  21. type: String,
  22. observer: "rerender"
  23. },
  24. disabled: Boolean,
  25. titleClass: {
  26. type: String,
  27. observer: "rerender"
  28. },
  29. options: {
  30. type: Array,
  31. value: [],
  32. observer: "rerender"
  33. },
  34. popupStyle: String
  35. },
  36. data: {
  37. transition: true,
  38. showPopup: false,
  39. showWrapper: false,
  40. displayTitle: ""
  41. },
  42. methods: {
  43. rerender: function rerender() {
  44. var _this = this;
  45. wx.nextTick(function () {
  46. _this.parent && _this.parent.updateItemListData();
  47. });
  48. },
  49. updateDataFromParent: function updateDataFromParent() {
  50. if (this.parent) {
  51. var _this$parent$data = this.parent.data,
  52. overlay = _this$parent$data.overlay,
  53. duration = _this$parent$data.duration,
  54. activeColor = _this$parent$data.activeColor,
  55. closeOnClickOverlay = _this$parent$data.closeOnClickOverlay,
  56. direction = _this$parent$data.direction;
  57. this.setData({
  58. overlay: overlay,
  59. duration: duration,
  60. activeColor: activeColor,
  61. closeOnClickOverlay: closeOnClickOverlay,
  62. direction: direction
  63. });
  64. }
  65. },
  66. onOpen: function onOpen() {
  67. this.$emit("open");
  68. },
  69. onOpened: function onOpened() {
  70. this.$emit("opened");
  71. },
  72. onClose: function onClose() {
  73. this.$emit("close");
  74. },
  75. onClosed: function onClosed() {
  76. this.$emit("closed");
  77. this.setData({
  78. showWrapper: false
  79. });
  80. },
  81. onOptionTap: function onOptionTap(event) {
  82. var option = event.currentTarget.dataset.option;
  83. var value = option.value;
  84. var shouldEmitChange = this.data.value !== value;
  85. this.setData({
  86. showPopup: false,
  87. value: value
  88. });
  89. this.$emit("close");
  90. this.rerender();
  91. if (shouldEmitChange) {
  92. this.$emit("change", value);
  93. }
  94. },
  95. toggle: function toggle(show) {
  96. var _this2 = this;
  97. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  98. var showPopup = this.data.showPopup;
  99. if (typeof show !== "boolean") {
  100. show = !showPopup;
  101. }
  102. if (show === showPopup) {
  103. return;
  104. }
  105. this.setData({
  106. transition: !options.immediate,
  107. showPopup: show
  108. });
  109. if (show) {
  110. this.parent.getChildWrapperStyle().then(function (wrapperStyle) {
  111. _this2.setData({
  112. wrapperStyle: wrapperStyle,
  113. showWrapper: true
  114. });
  115. _this2.rerender();
  116. });
  117. } else {
  118. this.rerender();
  119. }
  120. }
  121. }
  122. });