C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.2 KiB

  1. // component/FMScrollGroupsControl/FMScrollGroupsControl.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. //楼层数组
  8. groupIDs: {
  9. type: Array,
  10. value: null
  11. },
  12. //视野内显示多少个按钮,可手触上下滚动
  13. showBtnCount: {
  14. type: Number,
  15. value: 0,
  16. observer: function (newVal, oldVal) {
  17. console.log('height----', this.properties.showBtnCount * 84);
  18. if (this.properties.showBtnCount < this.properties.groupIDs.length) {
  19. this.setData({
  20. needArrow: true,
  21. scrollHeight: this.properties.showBtnCount * 84
  22. })
  23. }
  24. }
  25. },
  26. //当前的聚焦楼层id
  27. focusGroupID: {
  28. type: Number,
  29. value: 1,
  30. observer: function (newVal, oldVal) {
  31. console.log("focusGroupID", this.properties.focusGroupID)
  32. this._setFocusGroupName(this.properties.focusGroupID);
  33. }
  34. },
  35. // 展开控件
  36. expand: {
  37. type: Boolean,
  38. value: true,
  39. observer: function (newVal, oldVal) {
  40. this.setData({
  41. isShowList: newVal,
  42. })
  43. }
  44. },
  45. // 是否允许展开控件操作
  46. enableExpand: {
  47. type: Boolean,
  48. value: true,
  49. },
  50. },
  51. /**
  52. * 组件的初始数据
  53. */
  54. data: {
  55. scrollHeight: 250,
  56. focusGroupName: "F1",
  57. isShowList: true,
  58. },
  59. /**
  60. * 组件的方法列表
  61. */
  62. methods: {
  63. /**
  64. * 切换聚焦楼层
  65. * @param {*} e
  66. */
  67. switchGroup: function (e) {
  68. let focusId = e.currentTarget.dataset.gid;
  69. this.triggerEvent('switchGroup', focusId);
  70. this._setFocusGroupName(focusId);
  71. },
  72. /**
  73. * 收起下拉压缩
  74. */
  75. folderGroupBtns: function () {
  76. if (!this.properties.enableExpand) return;
  77. this.setData({
  78. isShowList: !this.data.isShowList
  79. })
  80. },
  81. /**
  82. * 设置聚焦楼层的楼层名称
  83. * @param {*} gid 聚焦楼层id
  84. */
  85. _setFocusGroupName: function (gid) {
  86. let group = this.properties.groupIDs.find((gd) => gd.gid === gid);
  87. if (group) {
  88. this.setData({
  89. focusGroupName: group.gname
  90. })
  91. console.log(group.gname);
  92. }
  93. }
  94. }
  95. })