index.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. Component({
  2. properties: {
  3. list: {
  4. type: Array
  5. },
  6. callback: {
  7. type: Function
  8. }
  9. },
  10. data: {
  11. safeAreaBot: 0,
  12. show: false,
  13. showList: [],
  14. extend: []
  15. },
  16. lifetimes: {
  17. attached: function () {
  18. wx.getSystemInfo({
  19. success: res => {
  20. this.setData({
  21. safeAreaBot: res.screenHeight - res.safeArea.bottom
  22. })
  23. }
  24. })
  25. getApp().globalData.Language.getLanguagePackage(this)
  26. },
  27. },
  28. observers: {
  29. 'list': function (numberA, numberB) {
  30. numberA = numberA.map(v => {
  31. v.classnames = (v.icon.split("-")[0] == 'color' ? 't-icon ' : 'iconfont ') + v.icon
  32. console.log(v.classnames)
  33. return v
  34. })
  35. if (numberA.length >= 5) {
  36. let showList = numberA.splice(0, 3);
  37. showList.push({
  38. classnames: "t-icon color-gengduo",
  39. icon: "color-gengduo",
  40. label: "更多"
  41. })
  42. this.setData({
  43. showList,
  44. extend: numberA
  45. })
  46. } else {
  47. this.setData({
  48. showList: numberA
  49. })
  50. }
  51. }
  52. },
  53. options: {
  54. addGlobalClass: true
  55. },
  56. methods: {
  57. onClose() {
  58. this.setData({
  59. show: false
  60. })
  61. },
  62. callback(e) {
  63. const {
  64. item
  65. } = e.currentTarget.dataset;
  66. if (item.label == '更多') return this.setData({
  67. show: true
  68. })
  69. if (this.data.show) this.setData({
  70. show: false
  71. })
  72. if (!item) return;
  73. this.triggerEvent("callback", item)
  74. }
  75. }
  76. })