seat.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: true, name: '位置信息登记', leftArrow: true, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. // 查询
  13. form: {},
  14. // 地图
  15. key: 'AFMBZ-7LJC6-TKWSZ-E232O-TUK7K-TIBPU',
  16. markers: [],
  17. positionInfo: { longitude: 126.414274, latitude: 41.944132 }
  18. },
  19. initValidate() {
  20. const rules = { boundary: { required: true, }, keyword: { required: true } }
  21. // 验证字段的提示信息,若不传则调用默认的信息
  22. const messages = { boundary: { required: '请输入城市名称', }, keyword: { required: '请输入关键词', } };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. back: function () {
  26. wx.navigateBack({ url: '/pages/merchant/index' })
  27. },
  28. // 查询数据
  29. onSubmit: function (e) {
  30. const params = e.detail.value;
  31. if (!this.WxValidate.checkForm(params)) {
  32. const error = this.WxValidate.errorList[0];
  33. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  34. return false
  35. } else {
  36. wx.serviceMarket.invokeService({
  37. service: 'wxc1c68623b7bdea7b',
  38. api: 'poiSearch',
  39. data: { "boundary": `region(${params.boundary})`, "keyword": params.keyword, page_size: 20 },
  40. }).then(res => {
  41. const markers = res.data.data.map((i) => ({ title: i.title, longitude: i.location.lng, latitude: i.location.lat }))
  42. if (markers) this.setData({ markers: markers })
  43. if (markers) this.setData({ positionInfo: markers[0] })
  44. }).catch(err => {
  45. console.log(err);
  46. })
  47. }
  48. },
  49. // 选点
  50. toOne: function (e) {
  51. const data = e.detail;
  52. this.setData({ positionInfo: data })
  53. this.setData({ markers: [data] })
  54. },
  55. // 确认选点
  56. toCheck: function () {
  57. let data = this.data.positionInfo;
  58. console.log(data);
  59. },
  60. /**
  61. * 生命周期函数--监听页面加载
  62. */
  63. onLoad: function (options) {
  64. //验证规则函数
  65. this.initValidate()
  66. // 计算高度
  67. this.searchHeight();
  68. },
  69. // 计算高度
  70. searchHeight: function () {
  71. let frameStyle = this.data.frameStyle;
  72. let client = app.globalData.client;
  73. // 减去状态栏
  74. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  75. // 是否减去底部菜单
  76. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  77. if (infoHeight) this.setData({ infoHeight: infoHeight })
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady: function () {
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function () {
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function () {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function () {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function () {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function () {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function () {
  113. }
  114. })