index.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // components/My_categoryListings/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. height: {
  8. type: String,
  9. value: '500'
  10. },
  11. list: {
  12. type: Array,
  13. value: []
  14. }
  15. },
  16. options: {
  17. addGlobalClass: true
  18. },
  19. lifetimes: {
  20. ready() {}
  21. },
  22. /**
  23. * 组件的初始数据
  24. */
  25. data: {
  26. systemIndex: 0, //系统index
  27. portIndex: 0, //选择端口Index
  28. moduleIndex: 0, //选择模块Index
  29. result: ['a', 'b'],
  30. portID: null, //端口ID
  31. leftIntoViewId: null,
  32. rightIntoViewId: null,
  33. heightList: [],
  34. modulesIndex: 0, //模块列表
  35. scrollTop: 0
  36. },
  37. observers: {
  38. 'list': function (list) {
  39. if (!list.length) return;
  40. let data = list[0].clients[0];
  41. console.log("list", list)
  42. console.log("data", data)
  43. let id = data.modules[0] ? "M" + data.modules[0].systemmoduleid : '';
  44. if (this.data.portID == null) this.setData({
  45. portID: 'S' + data.systemclientid,
  46. leftIntoViewId: id,
  47. rightIntoViewId: id
  48. })
  49. setTimeout(() => {
  50. this.getAppsHeight();
  51. }, 200)
  52. }
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. /* 系统分类 */
  59. changePortID(e) {
  60. const {
  61. dataset
  62. } = e.currentTarget;
  63. this.setData({
  64. portID: e.target.id,
  65. systemIndex: dataset.index,
  66. portIndex: dataset.i,
  67. modulesIndex: 0,
  68. scrollTop: 0
  69. });
  70. setTimeout(() => {
  71. this.getAppsHeight();
  72. }, 300)
  73. },
  74. /* 点击模块分类 */
  75. changeType(e) {
  76. this.setData({
  77. leftIntoViewId: e.target.id,
  78. rightIntoViewId: e.target.id
  79. })
  80. },
  81. getAppsHeight() {
  82. const list = this.data.list[this.data.systemIndex].clients[this.data.portIndex].modules,
  83. that = this;
  84. let heightList = [];
  85. let id = 'M' + list[0].systemmoduleid;
  86. for (let i = 0; i < list.length; i++) {
  87. let query = wx.createSelectorQuery().in(that).select('.' + 'M1' + list[i].systemmoduleid).boundingClientRect();
  88. query.exec(res => {
  89. if (!res[0]) return this.getAppsHeight();
  90. heightList.push(res[0])
  91. if (list.length == heightList.length) this.setData({
  92. heightList,
  93. leftIntoViewId: id,
  94. rightIntoViewId: id
  95. })
  96. })
  97. }
  98. },
  99. viewScroll({
  100. detail
  101. }) {
  102. let arr = this.data.heightList, //获取元素信息
  103. id = this.data.leftIntoViewId, //获取当前左侧栏选项
  104. i = arr.findIndex(v => v.id == id), //选项当前在数组中的索引号
  105. scrollTop = detail.scrollTop,
  106. //判断当前索引是不是数组最后一条数据,不是的话拿下一个索引的距顶距离
  107. top = (i + 1 == arr.length) ? arr[i].top - 15 - arr[i].height : arr[i + 1].top - 15 - arr[i + 1].height;
  108. if (scrollTop >= top) {
  109. if (!arr[i + 1]) return;
  110. if (id == arr[i + 1].id) return;
  111. this.setData({
  112. leftIntoViewId: arr[i + 1].id
  113. })
  114. } else if (scrollTop < top) {
  115. if (!arr[i - 1] || id == arr[0].id) return;
  116. if (scrollTop < Math.abs(arr[i - 1].top - arr[i - 1].height + 80)) this.setData({
  117. leftIntoViewId: arr[i - 1].id
  118. })
  119. } else {
  120. if (id == arr[1].id) return; //排除第一个
  121. }
  122. },
  123. }
  124. })