index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. Component({
  2. options: {
  3. addGlobalClass: true
  4. },
  5. lifetimes: {
  6. attached() {
  7. if (wx.getStorageSync('SearchHistory')) this.setData({
  8. history: wx.getStorageSync('SearchHistory')
  9. })
  10. getApp().globalData.Language.getLanguagePackage(this)
  11. }
  12. },
  13. properties: {
  14. active: {
  15. type: [Number, String],
  16. value: 0
  17. },
  18. tabs: {
  19. type: Array,
  20. value: [{
  21. title: "中止"
  22. }]
  23. },
  24. onChangeTab: {
  25. type: Function
  26. },
  27. onSearch: {
  28. type: Function
  29. },
  30. threshold: {
  31. type: [String, Number],
  32. value: 4
  33. }
  34. },
  35. data: {
  36. },
  37. methods: {
  38. onChange({
  39. detail
  40. }) {
  41. this.triggerEvent("onChangeTab", detail)
  42. },
  43. /* 开启关闭搜索 */
  44. clickSearch() {
  45. this.setData({
  46. startUsing: !this.data.startUsing
  47. });
  48. setTimeout(this.setListHeight, 400)
  49. },
  50. /* 搜索 */
  51. confirmSearch(e) {
  52. if (this.data.condition == e.detail.value) return;
  53. this.setData({
  54. condition: e.detail.value
  55. })
  56. this.triggerEvent("onSearch", e.detail.value)
  57. },
  58. /* 开始搜索 */
  59. startSearch({
  60. detail
  61. }) {
  62. if (this.data.condition == detail) return;
  63. this.setData({
  64. condition: detail
  65. })
  66. this.triggerEvent("onSearch", detail)
  67. if (this.data.record || detail == '') {
  68. let list = this.data.history;
  69. if (list.findIndex(v => v == detail) == -1) {
  70. list.push(detail)
  71. this.setData({
  72. history: list
  73. });
  74. wx.setStorageSync("SearchHistory", list)
  75. }
  76. }
  77. },
  78. /* 取消搜索 */
  79. endSearch() {
  80. this.setData({
  81. condition: ""
  82. })
  83. this.triggerEvent("onSearch", "")
  84. },
  85. /* 删除搜索历史 */
  86. deleteHistory(e) {
  87. let that = this;
  88. wx.showModal({
  89. cancelText: getApp().globalData.Language.getMapText('取消'),
  90. confirmText: getApp().globalData.Language.getMapText('确定'),
  91. title: getApp().globalData.Language.getMapText('提示'),
  92. content: getApp().globalData.Language.getMapText('是否删除所有搜索历史'),
  93. complete: ({
  94. confirm
  95. }) => {
  96. if (confirm) {
  97. wx.setStorageSync("SearchHistory", [])
  98. that.setData({
  99. history: []
  100. });
  101. this.setListHeight();
  102. }
  103. }
  104. })
  105. },
  106. /* 快速搜索 */
  107. clickTag(e) {
  108. const {
  109. name
  110. } = e.currentTarget.dataset;
  111. this.setData({
  112. condition: name
  113. });
  114. this.triggerEvent("onSearch", name)
  115. },
  116. /* 单独删除 */
  117. delteTag(e) {
  118. const {
  119. name
  120. } = e.currentTarget.dataset;
  121. this.setData({
  122. history: this.data.history.filter(v => v != name)
  123. });
  124. wx.setStorageSync('SearchHistory', this.data.history);
  125. this.setListHeight();
  126. },
  127. /* 设置列表高度 */
  128. setListHeight() {
  129. let pages = getCurrentPages()[getCurrentPages().length - 1].selectComponent("#ListBox");
  130. if (pages) pages.automaticSetHei();
  131. },
  132. /* 搜索框焦点 */
  133. onFocus() {
  134. this.setData({
  135. showHistory: true
  136. });
  137. setTimeout(this.setListHeight, 50);
  138. },
  139. /* 搜索框失焦 */
  140. onBlur() {
  141. this.setData({
  142. showHistory: false
  143. })
  144. setTimeout(this.setListHeight, 50);
  145. },
  146. clickFiltration() {
  147. let page = getCurrentPages()[getCurrentPages().length - 1].selectComponent("#Filtrate");
  148. if (page) {
  149. page.setData({
  150. show: true
  151. })
  152. } else {
  153. this.triggerEvent("onClick", item)
  154. }
  155. }
  156. }
  157. })