model.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import request from '../../Utils/RequestUtils';
  2. import Toast from '../../flooks/Toast';
  3. import { getLocation, getSearch } from '../../Utils/MapUtils';
  4. const MapModel = (now) => ({
  5. locationInfo: {}, // 当前定位信息
  6. chooseInfo: null, // 当前选点信息,
  7. city: '南京', // 选择城市
  8. personImg:
  9. 'https%3a%2f%2fidingdong.oss-cn-hangzhou.aliyuncs.com%2fimage%2f2020-07-03-16-19-50ghUJhqpC.png',
  10. merchatImg:
  11. 'https%3a%2f%2fidingdong.oss-cn-hangzhou.aliyuncs.com%2fimage%2f2020-07-03-16-18-00PhLyNwTp.png',
  12. riderImg:
  13. 'https%3a%2f%2fidingdong.oss-cn-hangzhou.aliyuncs.com%2fimage%2f2020-07-03-16-50-16UqCgAfFD.png',
  14. // 获取当前定位
  15. getNowLocation() {
  16. return getLocation().then((res) => {
  17. now({ locationInfo: res });
  18. return Promise.reslove(res);
  19. });
  20. },
  21. searchInfo(searchKey, type, callBack) {
  22. const { city, chooseInfo, getChooseInfo, searchInfo } = now();
  23. let boundary = '';
  24. if (type === 'city') {
  25. boundary = `region(${city}, 0)`;
  26. } else if (!chooseInfo) {
  27. getChooseInfo().then(() => {
  28. searchInfo(searchKey, type, callBack);
  29. });
  30. return;
  31. } else {
  32. boundary = `nearby(31.983908,118.730357,100000)`;
  33. }
  34. getSearch(searchKey, boundary).then(({ pois }) => callBack(pois));
  35. },
  36. getChooseInfo() {
  37. const { getNowLocation } = now();
  38. return getNowLocation().then((res) => {
  39. now({ chooseInfo: res });
  40. });
  41. },
  42. });
  43. export default MapModel;