search.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. 搜索确定时事件
  16. */
  17. inputConfirm : function(e) {
  18. var word = e.detail.value;
  19. if (word) {
  20. if(typeof this.submitsearchword=="function"){
  21. this.submitsearchword(word);
  22. }
  23. } else {
  24. this.setData({
  25. searchshow: false,
  26. searchfocus: false
  27. })
  28. if (this.focusani){
  29. clearTimeout(this.focusani);
  30. }
  31. }
  32. },
  33. /*
  34. 搜索聚焦事件
  35. */
  36. searchFocus:function(e) {
  37. var _self = this;
  38. this.setData({
  39. searchshow: true
  40. })
  41. this.focusani = setTimeout(function () {
  42. _self.setData({
  43. searchfocus: true
  44. })
  45. }, 500)
  46. },
  47. cancelSearch:function(e){
  48. var _self = this;
  49. this.setData({
  50. searchshow: false
  51. })
  52. }
  53. }
  54. export const linkToSearch = function (word) {
  55. wx.navigateTo({ url: `../searchresult/searchresult?value=${word}` });
  56. }
  57. export default bindSearch