GaodeInputTips.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. var amapFile = require('../../libs/amap-wx.130.js');
  2. var config = require('../../libs/config');
  3. var lonlat;
  4. var city;
  5. Component({
  6. /**
  7. * 组件的属性列表
  8. */
  9. properties: {
  10. city: {
  11. type: String,
  12. value: ''
  13. },
  14. longitude: {
  15. type: String,
  16. value: ''
  17. },
  18. latitude: {
  19. type: String,
  20. value: ''
  21. },
  22. inputType: {
  23. type: String,
  24. value: ''
  25. },
  26. defaultValue: {
  27. type: String,
  28. value: '请输入'
  29. }
  30. },
  31. /**
  32. * 组件的初始数据
  33. */
  34. data: {
  35. tips: {},
  36. tipsShow: false
  37. },
  38. lifetimes: {
  39. attached: function() {
  40. // 在组件实例进入页面节点树时执行
  41. },
  42. ready: function(e) {
  43. // 在组件布局完成后执行
  44. console.log('搜索框', e)
  45. },
  46. detached: function() {
  47. // 在组件实例被从页面节点树移除时执行
  48. }
  49. },
  50. /**
  51. * 组件的方法列表
  52. */
  53. methods: {
  54. bindInput: function(e){
  55. console.log('输入内容', e)
  56. var that = this;
  57. var keywords = e.detail.value;
  58. if (keywords === '') {
  59. that.setData({
  60. tips: []
  61. });
  62. return false
  63. }
  64. var key = config.Config.key;
  65. var myAmapFun = new amapFile.AMapWX({key: key});
  66. myAmapFun.getInputtips({
  67. keywords: keywords,
  68. location: lonlat,
  69. city: city,
  70. success: function(data){
  71. if(data && data.tips){
  72. that.setData({
  73. tips: data.tips
  74. });
  75. }
  76. }
  77. })
  78. },
  79. bindSearch: function(e){
  80. console.log('点击搜索', e.target.dataset.info)
  81. console.log('点击搜索', e.target.dataset)
  82. this.triggerEvent('customEvent', {
  83. info: e.target.dataset.info,
  84. inputType: this.properties.inputType
  85. });
  86. },
  87. handleFocus: function(e) {
  88. this.setData({
  89. tipsShow: true
  90. });
  91. },
  92. handleBlur: function(e) {
  93. this.setData({
  94. tipsShow: false
  95. });
  96. }
  97. }
  98. })