index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. classes: ["title-class", "content-class"],
  7. relation: {
  8. name: "collapse",
  9. type: "ancestor",
  10. current: "collapse-item"
  11. },
  12. props: {
  13. name: null,
  14. title: null,
  15. value: null,
  16. icon: String,
  17. label: String,
  18. disabled: Boolean,
  19. clickable: Boolean,
  20. border: {
  21. type: Boolean,
  22. value: true
  23. },
  24. isLink: {
  25. type: Boolean,
  26. value: true
  27. }
  28. },
  29. data: {
  30. expanded: false
  31. },
  32. created: function created() {
  33. this.animation = wx.createAnimation({
  34. duration: 0,
  35. timingFunction: "ease-in-out"
  36. });
  37. },
  38. mounted: function mounted() {
  39. var _this = this;
  40. wx.nextTick(function () {
  41. _this.updateExpanded();
  42. _this.inited = true;
  43. }, 260);
  44. },
  45. methods: {
  46. updateExpanded: function updateExpanded() {
  47. if (!this.parent) {
  48. return Promise.resolve();
  49. }
  50. var _this$parent$data = this.parent.data,
  51. value = _this$parent$data.value,
  52. accordion = _this$parent$data.accordion;
  53. var _this$parent$children = this.parent.children,
  54. children = _this$parent$children === void 0 ? [] : _this$parent$children;
  55. var name = this.data.name;
  56. var index = children.indexOf(this);
  57. var currentName = name == null ? index : name;
  58. var expanded = accordion ? value === currentName : (value || []).some(function (name) {
  59. return name === currentName;
  60. });
  61. if (expanded !== this.data.expanded) {
  62. this.updateStyle(expanded);
  63. }
  64. this.setData({
  65. index: index,
  66. expanded: expanded
  67. });
  68. },
  69. updateStyle: function updateStyle(expanded) {
  70. var _this2 = this;
  71. var inited = this.inited;
  72. this.getRect(".van-collapse-item__content").then(function (rect) {
  73. return rect.height;
  74. }).then(function (height) {
  75. var animation = _this2.animation;
  76. if (expanded) {
  77. if (height === 0) {
  78. animation.height("auto").top(1).step();
  79. } else {
  80. animation.height(height).top(1).step({
  81. duration: inited ? 300 : 1
  82. }).height("auto").step();
  83. }
  84. _this2.setData({
  85. animation: animation["export"]()
  86. });
  87. return;
  88. }
  89. animation.height(height).top(0).step({
  90. duration: 1
  91. }).height(0).step({
  92. duration: 300
  93. });
  94. _this2.setData({
  95. animation: animation["export"]()
  96. });
  97. });
  98. },
  99. onClick: function onClick() {
  100. if (this.data.disabled) {
  101. return;
  102. }
  103. var _this$data = this.data,
  104. name = _this$data.name,
  105. expanded = _this$data.expanded;
  106. var index = this.parent.children.indexOf(this);
  107. var currentName = name == null ? index : name;
  108. this.parent["switch"](currentName, !expanded);
  109. }
  110. }
  111. });