search.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. const events = ["inputBlur", "inputConfirm","searchFocus"];
  2. const bindSearch = function (_self){
  3. Object.assign(_self, searchmodule);
  4. }
  5. /*
  6. 搜索失去聚焦事件
  7. */
  8. export const searchmodule = {
  9. inputBlur: function(e) {
  10. this.setData({
  11. searchfocus: false
  12. })
  13. },
  14. /*
  15. 搜索input确定时事件
  16. */
  17. inputConfirm : function(e) {
  18. var word = e.detail.value;
  19. //if (word) {
  20. if(typeof this.submitsearchinfo=="function"){
  21. this.submitsearchinfo({keys:word});
  22. }
  23. this.cancelSearch();
  24. // } else {
  25. // this.setData({
  26. // searchshow: false,
  27. // searchfocus: false
  28. // })
  29. if (this.focusani){
  30. clearTimeout(this.focusani);
  31. }
  32. //}
  33. },
  34. /*
  35. 搜索聚焦事件
  36. */
  37. searchFocus:function(e) {
  38. var _self = this;
  39. this.setData({
  40. searchshow: true
  41. })
  42. this.focusani = setTimeout(function () {
  43. _self.setData({
  44. searchfocus: true
  45. })
  46. }, 500)
  47. },
  48. cancelSearch:function(e){
  49. var _self = this;
  50. this.setData({
  51. searchshow: false
  52. })
  53. },
  54. tapHot:function(e){
  55. var brand = e.currentTarget.dataset.val;
  56. if(typeof this.submitsearchinfo=="function"){
  57. this.submitsearchinfo({keys:brand});
  58. }
  59. }
  60. }
  61. export default bindSearch