filtrate.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. Component({
  2. options: {
  3. addGlobalClass: true
  4. },
  5. properties: {
  6. iconName: {
  7. type: String,
  8. value: "icon-feiyongleixing"
  9. },
  10. title: {
  11. type: String,
  12. },
  13. type: {
  14. type: String,
  15. value: "全部"
  16. },
  17. list: {
  18. type: Array,
  19. },
  20. onChange: {
  21. type: Function,
  22. },
  23. clickOpen: {
  24. type: Function,
  25. },
  26. isEmpty: {
  27. type: Boolean,
  28. value: false
  29. }
  30. },
  31. lifetimes: {
  32. attached: function () {
  33. getApp().globalData.Language.getLanguagePackage(this)
  34. this.setData({
  35. actions: this.data.list.map(item => {
  36. return {
  37. name: getApp().globalData.Language.getMapText(item.remarks || item.value),
  38. value: item.value,
  39. color: item.value == this.data.type ? "#3874F6" : ""
  40. }
  41. })
  42. })
  43. this.setShowText();
  44. }
  45. },
  46. data: {
  47. actionShow: false,
  48. },
  49. methods: {
  50. setShowText() {
  51. try {
  52. this.setData({
  53. showText: this.data.actions.find(item => item.value == this.data.type).name
  54. })
  55. } catch (error) {
  56. this.setData({
  57. showText: '全部'
  58. })
  59. }
  60. },
  61. setShowArrText(arr) {
  62. if (arr.length) {
  63. this.setData({
  64. showText: arr.map(v => getApp().globalData.Language.getMapText(v))
  65. })
  66. } else {
  67. this.setData({
  68. showText: '全部'
  69. })
  70. }
  71. },
  72. openActionSheet() {
  73. if (this.data.actions.length) this.setData({
  74. actionShow: true
  75. })
  76. this.triggerEvent("clickOpen")
  77. },
  78. onSelect(event) {
  79. const {
  80. value
  81. } = event.detail;
  82. if (this.data.type == value) return this.onCancel();
  83. this.setData({
  84. actions: this.data.actions.map(item => {
  85. item.color = item.value == value ? "#3874F6" : "";
  86. item.loading = item.value == value ? true : false;
  87. return item
  88. })
  89. })
  90. this.triggerEvent("onChange", value)
  91. },
  92. onCancel() {
  93. this.setData({
  94. actionShow: false,
  95. actions: this.data.actions.map(item => {
  96. item.loading = false;
  97. return item
  98. })
  99. })
  100. this.setShowText();
  101. },
  102. clearResults() {
  103. this.setData({
  104. showText: '全部'
  105. })
  106. this.triggerEvent("clickOpen", "clear")
  107. }
  108. }
  109. })