indexes.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const app = getApp();
  2. Page({
  3. data: {
  4. StatusBar: app.globalData.StatusBar,
  5. CustomBar: app.globalData.CustomBar,
  6. hidden: true
  7. },
  8. onLoad() {
  9. let list = [];
  10. for (let i = 0; i < 26; i++) {
  11. list[i] = String.fromCharCode(65 + i)
  12. }
  13. this.setData({
  14. list: list,
  15. listCur: list[0]
  16. })
  17. },
  18. onReady() {
  19. let that = this;
  20. wx.createSelectorQuery().select('.indexBar-box').boundingClientRect(function(res) {
  21. that.setData({
  22. boxTop: res.top
  23. })
  24. }).exec();
  25. wx.createSelectorQuery().select('.indexes').boundingClientRect(function(res) {
  26. that.setData({
  27. barTop: res.top
  28. })
  29. }).exec()
  30. },
  31. //获取文字信息
  32. getCur(e) {
  33. this.setData({
  34. hidden: false,
  35. listCur: this.data.list[e.target.id],
  36. })
  37. },
  38. setCur(e) {
  39. this.setData({
  40. hidden: true,
  41. listCur: this.data.listCur
  42. })
  43. },
  44. //滑动选择Item
  45. tMove(e) {
  46. let y = e.touches[0].clientY,
  47. offsettop = this.data.boxTop,
  48. that = this;
  49. //判断选择区域,只有在选择区才会生效
  50. if (y > offsettop) {
  51. let num = parseInt((y - offsettop) / 20);
  52. this.setData({
  53. listCur: that.data.list[num]
  54. })
  55. };
  56. },
  57. //触发全部开始选择
  58. tStart() {
  59. this.setData({
  60. hidden: false
  61. })
  62. },
  63. //触发结束选择
  64. tEnd() {
  65. this.setData({
  66. hidden: true,
  67. listCurID: this.data.listCur
  68. })
  69. },
  70. indexSelect(e) {
  71. let that = this;
  72. let barHeight = this.data.barHeight;
  73. let list = this.data.list;
  74. let scrollY = Math.ceil(list.length * e.detail.y / barHeight);
  75. for (let i = 0; i < list.length; i++) {
  76. if (scrollY < i + 1) {
  77. that.setData({
  78. listCur: list[i],
  79. movableY: i * 20
  80. })
  81. return false
  82. }
  83. }
  84. }
  85. });