index.js 4.0 KB

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