search.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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.submitsearchword=="function"){
  21. this.submitsearchword(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. }
  57. }
  58. export const linkToSearch = function (word) {
  59. wx.navigateTo({ url: `../buy/buy?keys=${word}` });
  60. if(typeof this.submitsearchword=="function"){
  61. this.submitsearchbrand(word);
  62. }
  63. this.cancelSearch();
  64. }
  65. export default bindSearch