import request from '../../Utils/RequestUtils'; import Toast from '../../flooks/Toast'; import { getLocation, getSearch } from '../../Utils/MapUtils'; const MapModel = (now) => ({ locationInfo: {}, // 当前定位信息 chooseInfo: null, // 当前选点信息, city: '南京', // 选择城市 personImg: 'https%3a%2f%2fidingdong.oss-cn-hangzhou.aliyuncs.com%2fimage%2f2020-07-03-16-19-50ghUJhqpC.png', merchatImg: 'https%3a%2f%2fidingdong.oss-cn-hangzhou.aliyuncs.com%2fimage%2f2020-07-03-16-18-00PhLyNwTp.png', riderImg: 'https%3a%2f%2fidingdong.oss-cn-hangzhou.aliyuncs.com%2fimage%2f2020-07-03-16-50-16UqCgAfFD.png', // 获取当前定位 getNowLocation() { return getLocation().then((res) => { now({ locationInfo: res }); return Promise.resolve(res); }); }, searchInfo(searchKey, type, callBack) { const { city, chooseInfo, getChooseInfo, searchInfo } = now(); let boundary = ''; if (type === 'city') { boundary = `region(${city}, 0)`; } else if (!chooseInfo) { getChooseInfo().then(() => { searchInfo(searchKey, type, callBack); }); return; } else { boundary = `nearby(31.983908,118.730357,100000)`; } getSearch(searchKey, boundary).then(({ pois }) => callBack(pois)); }, getChooseInfo() { const { getNowLocation } = now(); return getNowLocation().then((res) => { now({ chooseInfo: res }); }); }, changeChooseInfo(info) { now({ chooseInfo: info, }); }, }); export default MapModel;