index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const QQMapWX = require('../../utils/qqmap-wx-jssdk.js');
  5. const qqmapsdk = new QQMapWX({
  6. key: '36IBZ-VI53O-FJHW2-SV2NP-USSAE-GFBUS'
  7. })
  8. Page({
  9. data: {
  10. userInfo: {},
  11. list: []
  12. },
  13. onLoad: function () {
  14. if (app.globalData.userInfo) {
  15. this.setData({
  16. userInfo: app.globalData.userInfo
  17. });
  18. this.getList();
  19. } else {
  20. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  21. // 所以此处加入 callback 以防止这种情况
  22. app.userInfoReadyCallback = res => {
  23. this.setData({
  24. userInfo: res
  25. })
  26. this.getList();
  27. };
  28. }
  29. },
  30. goDetail(e) {
  31. let id = e.currentTarget.dataset.id;
  32. let currentActivity = this.data.list.filter(v => {
  33. return v.id == id;
  34. });
  35. app.globalData.currentActivity = currentActivity[0];
  36. wx.navigateTo({
  37. url: '/pages/detail/index',
  38. })
  39. },
  40. async getList() {
  41. try {
  42. let result = await app.globalData.api.activity_list_mine(app.globalData.userInfo.phone || '');
  43. const lngArr = [];
  44. result.data.forEach(v => {
  45. v.shareMember = 0;
  46. if (v.images) {
  47. v.imgList = v.images.split(';').filter(v=>{
  48. return v != '';
  49. })
  50. }
  51. if(v.members){
  52. v.membersList = v.members.split(';').filter(v=>{
  53. return v != '';
  54. })
  55. if(v.membersList.indexOf(app.globalData.userInfo.phone || '0') > -1){
  56. v.shareMember = 1;
  57. }
  58. }
  59. if (v.lat && v.lng) {
  60. lngArr.push({
  61. latitude: v.lat,
  62. longitude: v.lng
  63. })
  64. }
  65. });
  66. this.setData({
  67. list: result.data
  68. })
  69. if (lngArr.length) {
  70. this.getDistance(lngArr);
  71. }
  72. } catch (error) {
  73. console.log(error)
  74. }
  75. },
  76. getDistance(localresult) {
  77. qqmapsdk.calculateDistance({
  78. to: localresult, //终点坐标
  79. success: function (res) { //成功后的回调
  80. console.log(res,8888)
  81. //判断经纬度,获取具体门店,付值 distance
  82. // resolve(res.result.elements[0].distance);
  83. },
  84. fail: function (error) {
  85. console.error(error);
  86. },
  87. complete: function (res) {}
  88. });
  89. },
  90. goEdit() {
  91. console.log('edit')
  92. },
  93. userInfoHandler(e) {
  94. const that = this;
  95. if (e.detail.errMsg == "getUserInfo:ok") {
  96. let userInfo = e.detail.userInfo;
  97. let params = Object.assign({}, {
  98. openid: app.globalData.userInfo.openid,
  99. nickName: userInfo.nickName,
  100. gender: userInfo.gender,
  101. avatarUrl: userInfo.avatarUrl
  102. });
  103. app.globalData.api.binduserinfo(params).then(res => {
  104. console.log(res);
  105. let newUserInfo = Object.assign({}, app.globalData.userInfo, {
  106. nickName: userInfo.nickName,
  107. gender: userInfo.gender,
  108. avatarUrl: userInfo.avatarUrl
  109. });
  110. app.globalData.userInfo = newUserInfo;
  111. that.setData({
  112. userInfo: newUserInfo
  113. })
  114. })
  115. }
  116. },
  117. })