index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. // lionfish_comshop/moduleB/rider/index.js
  2. var app = getApp();
  3. var location = require("../../utils/Location")
  4. Page({
  5. data: {
  6. orderdistribution_info: {},
  7. waite_get_count: 0,
  8. sending_count: 0,
  9. sended_count: 0,
  10. waite_send_list: [],
  11. sending_send_list: [],
  12. scale:'15',
  13. controls:'40',
  14. latitude:'',
  15. longitude:'',
  16. markers: [],
  17. },
  18. onLoad: function (options) {
  19. this.getMyLocal();
  20. },
  21. onReady: function (e) {
  22. this.mapCtx = wx.createMapContext('myMap')
  23. },
  24. getMyLocal: function() {
  25. let that = this;
  26. location.getGps().then(ret=>{
  27. that.setData({
  28. scale: 12,
  29. longitude: ret.longitude,
  30. latitude: ret.latitude
  31. })
  32. // wx.getLocation({
  33. // type: 'wgs84',
  34. // success: (res) => {
  35. // console.log("getMyLocal",res)
  36. // that.setData({
  37. // scale: 12,
  38. // longitude: res.longitude,
  39. // latitude: res.latitude
  40. // })
  41. // }
  42. // });
  43. }).catch(()=>{
  44. app.util.message('地图功能开启失败', '', 'error');
  45. })
  46. },
  47. getMemberMarkers: function(listData) {
  48. var market = [];
  49. // 待取货
  50. if(listData[0] && listData[0].length) {
  51. for (let item of listData[0]) {
  52. let marker1 = this.createMarker(item);
  53. market.push(marker1)
  54. }
  55. }
  56. // 配送中
  57. if(listData[1] && listData[1].length) {
  58. for (let item of listData[1]) {
  59. let marker1 = this.createMarker(item, 1);
  60. market.push(marker1)
  61. }
  62. }
  63. return market;
  64. },
  65. createMarker: function(point, type=0) {
  66. let latitude = point.shop_lat;
  67. let longitude = point.shop_lon;
  68. if(type==1){
  69. latitude = point.member_lat;
  70. longitude = point.member_lon;
  71. }
  72. let marker = {
  73. iconPath: type==0?"../images/location-red.png":"../images/location-green.png",
  74. id: point.order_id+'_'+type,
  75. title: type==0?'待取货':'配送中',
  76. latitude,
  77. longitude,
  78. label:{
  79. anchorX: -12,
  80. anchorY: 0,
  81. content: type==0?'商家':'客户'
  82. },
  83. width: 30,
  84. height: 30
  85. };
  86. return marker;
  87. },
  88. markertap: function(e){
  89. console.log(e.detail)
  90. },
  91. controltap: function(e) {
  92. this.moveToLocation()
  93. },
  94. moveToLocation: function () {
  95. this.mapCtx.moveToLocation()
  96. },
  97. regionchange: function(){
  98. },
  99. onShow: function () {
  100. this.getData();
  101. },
  102. getData: function () {
  103. let token = wx.getStorageSync('token');
  104. app.util.ProReq('localtown.get_orderdistribution_info', { token }).then(res => {
  105. let { orderdistribution_info, waite_get_count, sending_count, sended_count, waite_send_list, sending_send_list } = res.data;
  106. let markers = this.getMemberMarkers([waite_send_list, sending_send_list]);
  107. this.setData({
  108. orderdistribution_info, waite_get_count, sending_count, sended_count, waite_send_list, sending_send_list, markers
  109. })
  110. }).catch(err => {
  111. console.log(err)
  112. app.util.message(err.msg || '请求出错', 'switchTo:/lionfish_comshop/pages/user/me', 'error');
  113. })
  114. },
  115. goLink: function(event) {
  116. let link = event.currentTarget.dataset.link;
  117. var pages_all = getCurrentPages();
  118. if (pages_all.length > 3) {
  119. wx.redirectTo({
  120. url: link
  121. })
  122. } else {
  123. wx.navigateTo({
  124. url: link
  125. })
  126. }
  127. },
  128. // 接单状态切换
  129. switchState: function(e){
  130. console.log(e.detail.value)
  131. }
  132. })