index.js 5.2 KB

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