map.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // pages/home/map/map.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. location:{},
  9. mapworkelist:[],
  10. inputValue:"",
  11. workelist:[],
  12. hasMarkers:true,
  13. workedesc:"",
  14. status:"",
  15. show:false
  16. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad: function (options) {
  21. var that = this
  22. that.setData({
  23. location:{
  24. 'latitude':wx.getStorageSync('latitude'),
  25. 'longitude':wx.getStorageSync('longitude')
  26. }
  27. })
  28. that.workDesc();
  29. that.setData({
  30. status:app.globalData.status
  31. })
  32. },
  33. onHide(){
  34. wx.stopLocationUpdate({
  35. success: (res) => {
  36. console.log(res);
  37. },
  38. })
  39. },
  40. /**
  41. * 生命周期函数--监听页面卸载
  42. */
  43. onUnload: function () {
  44. wx.stopLocationUpdate({
  45. success: (res) => {
  46. console.log(res);
  47. },
  48. })
  49. },
  50. //网点列表
  51. workDesc:function(e){
  52. var that=this;
  53. var keyword=that.data.inputValue;
  54. console.log(keyword);
  55. var latitude=wx.getStorageSync('latitude');
  56. var longitude=wx.getStorageSync('longitude');
  57. app.api.useApi(app.globalData.baseAppUrl + "api", {
  58. lat: latitude,
  59. lng: longitude,
  60. keyword: keyword,
  61. }, "get").then(function (res) {
  62. if (res.code != 200) {
  63. wx.showLoading({
  64. title: '网点加载失败'+res.status,
  65. })
  66. } else {
  67. var data=res.message.data.data
  68. that.setData({
  69. workelist:res.message.data.data
  70. })
  71. var maplist=[];
  72. var workelist=[];
  73. for (var i = 0; i < data.length; ++i) {
  74. maplist[i]={
  75. 'id':data[i]['id'],
  76. 'latitude':data[i]['lat'],
  77. 'longitude':data[i]['lng'],
  78. 'iconPath': '/image/address/location.png',
  79. 'width':60,
  80. 'height':60,
  81. }
  82. workelist[data[i]['id']]={
  83. 'id':data[i]['id'],
  84. 'latitude':data[i]['lat'],
  85. 'longitude':data[i]['lng'],
  86. 'title':data[i]['title'],
  87. 'address':data[i]['address'],
  88. 'name':data[i]['name'],
  89. 'signing_status':data[i]['signing_status'],
  90. 'distance':data[i]['distance']
  91. }
  92. if((keyword!='' || keyword!=null)&& i==0){
  93. that.setData({
  94. workedesc: workelist[data[i]['id']],
  95. show:true
  96. })
  97. }
  98. }
  99. console.log(data);
  100. if(data=="" || data ==null || data==[]){
  101. console.log(33333);
  102. var workedesc={
  103. 'id':0,
  104. 'latitude':0,
  105. 'longitude':0,
  106. 'title':'暂无数据',
  107. 'address':'暂无数据',
  108. 'name':'暂无数据',
  109. 'signing_status':0,
  110. 'distance':0
  111. }
  112. that.setData({
  113. workedesc: workedesc,
  114. show:true
  115. })
  116. }
  117. that.setData({
  118. mapworkelist:maplist,
  119. hasMarkers:true,
  120. workelist:workelist
  121. })
  122. console.log(that.data.mapworkelist)
  123. }
  124. wx.hideLoading();
  125. }).catch(function (err) {
  126. var workedesc={
  127. 'id':0,
  128. 'latitude':0,
  129. 'longitude':0,
  130. 'title':'暂无数据!',
  131. 'address':'暂无数据!',
  132. 'name':'暂无数据!',
  133. 'signing_status':12,
  134. 'distance':0
  135. }
  136. that.setData({
  137. workedesc: workedesc,
  138. show:true
  139. })})
  140. },
  141. bindKeyInput: function (e) {
  142. this.setData({
  143. inputValue: e.detail.value
  144. })
  145. },
  146. markertap(e) {
  147. console.log('@@@ markertap', e)
  148. var workelist=this.data.workelist;
  149. var markerId=e.detail.markerId;
  150. var workedesc=workelist[markerId];
  151. this.setData({
  152. workedesc: workedesc,
  153. show:true
  154. })
  155. },
  156. //设置网点
  157. setworke(e){
  158. const network_id=e.target.dataset.id;
  159. var that=this;
  160. app.api.useApi(app.globalData.baseAppUrl+"api/user/"+network_id+"/setNetwork",{
  161. },"post").then(function(res){
  162. if (res.code == 200) {
  163. wx.showLoading({
  164. title: '网点设置成功',
  165. })
  166. wx.setStorageSync('nid', network_id);
  167. setTimeout(function () {
  168. wx.switchTab({
  169. url: '/pages/tabber/home/index',
  170. })
  171. }, 3000)
  172. }
  173. }).catch(function(err){
  174. console.log(222);
  175. })
  176. }
  177. })