174 lines
3.1 KiB
JavaScript
174 lines
3.1 KiB
JavaScript
import config from "./config.js";
|
|
import {
|
|
showModelMessage,
|
|
jkcBaseDecode
|
|
} from "./tools.js";
|
|
import {
|
|
callOrdereApi
|
|
} from "./api.js";
|
|
|
|
const imgPath = config.imgPath;
|
|
|
|
export const sdkKey = '22095eb86ca9e318c404f9f4a31b20d5';
|
|
|
|
export function getMap(mapid, instance) {
|
|
return uni.createMapContext(mapid, {
|
|
this: instance.proxy
|
|
});
|
|
}
|
|
|
|
//获取当前定位
|
|
export function getLoalcation(success, fail) {
|
|
uni.getLocation({
|
|
type: 'gcj02', // 返回可以用于 wx.openLocation 的经纬度
|
|
geocode: true,
|
|
success(res) {
|
|
const {
|
|
latitude,
|
|
longitude
|
|
} = res;
|
|
if (success) success({
|
|
latitude,
|
|
longitude
|
|
});
|
|
},
|
|
fail(res) {
|
|
if (fail) fail(res);
|
|
}
|
|
});
|
|
}
|
|
|
|
//逆解析地址
|
|
export function reverseGeocoder(mapsdk, longitude, latitude, success, fail) {
|
|
mapsdk.getRegeo({
|
|
location: `${longitude},${latitude}`,
|
|
success: function (res) {
|
|
const {
|
|
name,
|
|
regeocodeData
|
|
} = res[0];
|
|
const {
|
|
addressComponent: {
|
|
adcode,
|
|
province,
|
|
city,
|
|
district
|
|
},
|
|
formatted_address
|
|
} = regeocodeData
|
|
if (success) success({
|
|
name,
|
|
formatted_address,
|
|
adcode,
|
|
province,
|
|
city,
|
|
district
|
|
});
|
|
},
|
|
fail: function (info) {
|
|
if (fail) fail(res);
|
|
}
|
|
})
|
|
// qqmapsdk.reverseGeocoder({
|
|
// location: {
|
|
// latitude: latitude,
|
|
// longitude: longitude
|
|
// },
|
|
// success: (res) => {
|
|
// if (success) success(res.result);
|
|
// },
|
|
// fail: (res) => {
|
|
// if (fail) success(fail);
|
|
// }
|
|
// })
|
|
}
|
|
|
|
//添加点
|
|
export function addMarker(id, longitude, latitude, icon, joinCluster) {
|
|
return {
|
|
id: id,
|
|
latitude,
|
|
longitude,
|
|
width: 30,
|
|
height: 30,
|
|
zIndex: "100",
|
|
iconPath: imgPath + "static/userui/home/" + icon,
|
|
joinCluster: joinCluster ? true : false,
|
|
test: "1"
|
|
};
|
|
}
|
|
|
|
//添加线
|
|
export function addLine(scolor, arrPoints) {
|
|
return {
|
|
points: arrPoints,
|
|
color: scolor,
|
|
width: 3
|
|
}
|
|
}
|
|
|
|
//创建订单
|
|
export function addOrder(bikeCode, jumpFlag, callback) {
|
|
const oUser = JSON.parse(jkcBaseDecode(uni.getStorageSync("wechat_user")));
|
|
if (!oUser) {
|
|
uni.navigateTo({
|
|
url: "/pages/user/login/wx_login"
|
|
})
|
|
}
|
|
const {
|
|
userId
|
|
} = oUser;
|
|
const params = {
|
|
userId,
|
|
bikeCode
|
|
}
|
|
saveRide(params, 1, jumpFlag, callback)
|
|
}
|
|
|
|
function saveRide(params, icnt, jumpFlag, callback) {
|
|
if (icnt === 1) {
|
|
uni.showLoading({
|
|
title: '正在处理中...',
|
|
});
|
|
}
|
|
callOrdereApi("userOrders/saveRide", params, "post").then(res => {
|
|
const {
|
|
code,
|
|
message
|
|
} = res;
|
|
if (code != 200) {
|
|
if (icnt <= 3) {
|
|
saveRide(params, icnt + 1, callback);
|
|
return;
|
|
}
|
|
showModelMessage(message);
|
|
uni.hideLoading()
|
|
if (callback) callback(false);
|
|
return;
|
|
}
|
|
uni.hideLoading()
|
|
if (callback) callback(true);
|
|
if (jumpFlag) {
|
|
setTimeout(() => {
|
|
uni.navigateTo({
|
|
url: "/pages/user/home/home"
|
|
})
|
|
}, 1000)
|
|
}
|
|
}).catch(err => {
|
|
uni.hideLoading();
|
|
showModelMessage("服务异常,请稍后再试");
|
|
if (callback) callback(false);
|
|
});
|
|
}
|
|
|
|
//添加面
|
|
export function addPolygon(scolor, fcolor, arrPoints) {
|
|
return {
|
|
points: arrPoints,
|
|
fillColor: fcolor,
|
|
strokeWidth: 3,
|
|
strokeColor: scolor,
|
|
zIndex: 11
|
|
}
|
|
} |