model.ts 1.6 KB

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