index.js 5.3 KB

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