storeDetail.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { storeDetail } from '../../api/other';
  2. import { MAKE_PHONE_CALL,REPORT_BEHAVIOR } from '../../utils/util.js';
  3. // import amapFile from '../../utils/amap-wx.130.js';
  4. Page({
  5. data: {
  6. dataInfo:{},
  7. latitude:0,
  8. longitude:0,
  9. id:'',//门店id
  10. },
  11. onLoad(options) {
  12. this.setData({
  13. id:options.id
  14. })
  15. wx.getLocation({
  16. type: 'wgs84',
  17. success: (res) => {
  18. this.setData({
  19. latitude: res.latitude,
  20. longitude: res.longitude
  21. })
  22. this.loadData(options.id)
  23. },
  24. fail: (err) => {
  25. wx.showModal({
  26. title: '提示',
  27. content: '获取定位失败,请检查是否开启定位权限',
  28. showCancel: false,
  29. confirmText: '我知道了'
  30. })
  31. this.loadData(options.id)
  32. }
  33. })
  34. },
  35. async loadData(id){
  36. const res = await storeDetail(id,{longitude:this.data.longitude,latitude:this.data.latitude});
  37. if(res.code == 200){
  38. this.setData({
  39. dataInfo:res.data
  40. })
  41. }else{
  42. wx.showToast({ title: res.message || '加载失败', icon: 'none' });
  43. }
  44. },
  45. onAddress(){
  46. REPORT_BEHAVIOR('门店导航', { link_id: this.data.id })
  47. wx.openLocation({
  48. latitude: this.data.dataInfo.latitude * 1, // 纬度
  49. longitude: this.data.dataInfo.longitude * 1, // 经度
  50. name:this.data.dataInfo.name,
  51. address: this.data.dataInfo.address,
  52. })
  53. },
  54. onPhone(){
  55. MAKE_PHONE_CALL(this.data.dataInfo.phone);
  56. },
  57. })