index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. var t = getApp();
  2. Component({
  3. externalClasses: ["i-class"],
  4. properties: {
  5. height: {
  6. type: String,
  7. value: "300",
  8. observer: function (val) {
  9. if (val) {
  10. var sHeight = this.setScrollStyle(val);
  11. this.setData({
  12. scrollHeight: sHeight
  13. });
  14. }
  15. }
  16. },
  17. itemHeight: {
  18. type: Number,
  19. value: 18
  20. },
  21. localCity: {
  22. type: Object,
  23. }
  24. },
  25. relations: {
  26. "../index-item/index": {
  27. type: "child",
  28. linked: function () {
  29. this._updateDataChange();
  30. },
  31. linkChanged: function () {
  32. this._updateDataChange();
  33. },
  34. unlinked: function () {
  35. this._updateDataChange();
  36. }
  37. }
  38. },
  39. data: {
  40. scrollTop: 0,
  41. fixedData: [],
  42. current: 0,
  43. timer: null,
  44. startTop: 0,
  45. itemLength: 0,
  46. currentName: "",
  47. isTouches: false,
  48. localCity: {},
  49. scrollHeight: ""
  50. },
  51. attached: function () {
  52. // let city = wx.getStorageSync('city');
  53. // this.setData({
  54. // localCity: city
  55. // });
  56. },
  57. methods: {
  58. changeGPSCommunity: function () {
  59. wx.setStorage({
  60. key: "city_id",
  61. data: 0
  62. })
  63. var e = getCurrentPages(), a = 1;
  64. e[e.length - 2].route.indexOf("/position/search") > -1 && (a = 2), t.globalData.changeCity = this.data.localCity,
  65. wx.navigateBack({
  66. delta: a
  67. });
  68. },
  69. setScrollStyle: function (t) {
  70. for (var e = ["%", "px", "rem", "rpx", "em", "rem"], a = !1, i = 0; i < e.length; i++) {
  71. var n = e[i];
  72. if (t.indexOf(n) > -1) {
  73. a = !0;
  74. break;
  75. }
  76. }
  77. return "height:" + (a ? t : t + "px");
  78. },
  79. loop: function () { },
  80. _updateDataChange: function () {
  81. var t = this, e = this.getRelationNodes("../index-item/index"), a = e.length, i = this.data.fixedData;
  82. a > 0 && (this.data.timer && (clearTimeout(this.data.timer), this.setData({
  83. timer: null
  84. })), this.data.timer = setTimeout(function () {
  85. var a = [];
  86. e.forEach(function (t) {
  87. t.data.name && -1 === i.indexOf(t.data.name) && (a.push(t.data.name), t.updateDataChange());
  88. }), t.setData({
  89. fixedData: a,
  90. itemLength: e.length
  91. }), t.setTouchStartVal();
  92. }, 0), this.setData({
  93. timer: this.data.timer
  94. }));
  95. },
  96. handlerScroll: function (t) {
  97. var e = this, a = t.detail.scrollTop;
  98. this.getRelationNodes("../index-item/index").forEach(function (t, i) {
  99. var n = t.data, r = n.top + n.height;
  100. a < r && a >= n.top && e.setData({
  101. current: i,
  102. currentName: n.currentName
  103. });
  104. });
  105. },
  106. getCurrentItem: function (t) {
  107. var e = this.getRelationNodes("../index-item/index"), a = {};
  108. return t < 0 && (t = 0), a = e[t].data, a.total = e.length, a;
  109. },
  110. triggerCallback: function (t) {
  111. this.triggerEvent("change", t);
  112. },
  113. handlerFixedTap: function (t) {
  114. var e = t.currentTarget.dataset.index, a = this.getCurrentItem(e);
  115. this.setData({
  116. scrollTop: a.top,
  117. currentName: a.currentName,
  118. isTouches: !0
  119. }), this.triggerCallback({
  120. index: e,
  121. current: a.currentName
  122. });
  123. },
  124. handlerTouchMove: function (t) {
  125. var e = this.data, a = (t.touches[0] || {}).pageY - e.startTop, i = Math.ceil(a / e.itemHeight);
  126. i = i >= e.itemLength ? e.itemLength - 1 : i;
  127. var n = this.getCurrentItem(i);
  128. n.name !== this.data.currentName && wx.vibrateShort(), this.setData({
  129. scrollTop: n.top,
  130. currentName: n.name,
  131. isTouches: !0
  132. }), this.triggerCallback({
  133. index: i,
  134. current: n.name
  135. });
  136. },
  137. handlerTouchEnd: function () {
  138. this.setData({
  139. isTouches: !1
  140. });
  141. },
  142. setTouchStartVal: function () {
  143. var t = this;
  144. wx.createSelectorQuery().in(this).select(".i-index-fixed").boundingClientRect(function (e) {
  145. t.setData({
  146. startTop: e.top
  147. });
  148. }).exec();
  149. }
  150. }
  151. });