280 lines
8.6 KiB
JavaScript
280 lines
8.6 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const API_api = require("../../API/api.js");
|
||
if (!Array) {
|
||
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
||
_easycom_uni_icons2();
|
||
}
|
||
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
|
||
if (!Math) {
|
||
_easycom_uni_icons();
|
||
}
|
||
const _sfc_main = {
|
||
__name: "deliveryDetail",
|
||
setup(__props) {
|
||
const orderDetail = common_vendor.ref(common_vendor.index.getStorageSync("orderDetail"));
|
||
const apartmentLocations = {
|
||
"1公寓": {
|
||
latitude: 45.878148,
|
||
longitude: 126.542369
|
||
},
|
||
"2公寓": {
|
||
latitude: 45.878016,
|
||
longitude: 126.542924
|
||
},
|
||
"3公寓": {
|
||
latitude: 45.878117,
|
||
longitude: 126.543476
|
||
},
|
||
"4公寓": {
|
||
latitude: 45.878118,
|
||
longitude: 126.54415
|
||
},
|
||
"5公寓": {
|
||
latitude: 45.878978,
|
||
longitude: 126.54127
|
||
},
|
||
"6公寓": {
|
||
latitude: 45.878982,
|
||
longitude: 126.541879
|
||
},
|
||
"9公寓": {
|
||
latitude: 45.878435,
|
||
longitude: 126.544863
|
||
},
|
||
"10公寓": {
|
||
latitude: 45.879196,
|
||
longitude: 126.543891
|
||
},
|
||
"11公寓": {
|
||
latitude: 45.879157,
|
||
longitude: 126.542722
|
||
},
|
||
"12公寓": {
|
||
latitude: 45.875638,
|
||
longitude: 126.540502
|
||
},
|
||
"育才大厦": {
|
||
latitude: 45.875638,
|
||
longitude: 126.540502
|
||
}
|
||
};
|
||
const formatDate = (dateString) => {
|
||
const date = new Date(dateString);
|
||
const year = date.getFullYear();
|
||
const month = String(date.getMonth() + 1).padStart(2, "0");
|
||
const day = String(date.getDate()).padStart(2, "0");
|
||
const hours = String(date.getHours()).padStart(2, "0");
|
||
const minutes = String(date.getMinutes()).padStart(2, "0");
|
||
const seconds = String(date.getSeconds()).padStart(2, "0");
|
||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||
};
|
||
const handlePickup = (id, imageUrl) => {
|
||
common_vendor.index.showLoading({
|
||
title: "提交中...",
|
||
mask: true
|
||
});
|
||
common_vendor.index.request({
|
||
url: API_api.apiImageUrl + "/api/errand/update/state",
|
||
method: "POST",
|
||
data: {
|
||
errandsState: 4,
|
||
orderId: id,
|
||
imageAddress: imageUrl
|
||
},
|
||
header: {
|
||
"Content-Type": "application/json",
|
||
// 确保设置正确的 Content-Type
|
||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||
},
|
||
success(res) {
|
||
console.log(res);
|
||
common_vendor.index.hideLoading();
|
||
if (res.data.code === 0) {
|
||
common_vendor.index.showToast({
|
||
title: "成功送达",
|
||
icon: "none",
|
||
duration: 2e3,
|
||
success: () => {
|
||
const pages = getCurrentPages();
|
||
const prevPage = pages[pages.length - 3];
|
||
if (prevPage && prevPage.robOrder) {
|
||
prevPage.robOrder(3);
|
||
}
|
||
common_vendor.index.navigateBack({
|
||
delta: 2,
|
||
success: () => {
|
||
common_vendor.index.$emit("refresh-delivery-list");
|
||
}
|
||
});
|
||
}
|
||
});
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: res.data.message || "送达失败",
|
||
icon: "none"
|
||
});
|
||
}
|
||
},
|
||
fail(err) {
|
||
console.log(err);
|
||
common_vendor.index.showToast({
|
||
title: "网络异常,请检查连接",
|
||
icon: "none"
|
||
});
|
||
}
|
||
});
|
||
};
|
||
const handleContact = (item) => {
|
||
common_vendor.index.makePhoneCall({
|
||
phoneNumber: item
|
||
});
|
||
};
|
||
const handleCall = (item) => {
|
||
console.log(item);
|
||
common_vendor.index.makePhoneCall({
|
||
phoneNumber: item
|
||
});
|
||
};
|
||
const latitude = common_vendor.ref("");
|
||
const longitude = common_vendor.ref("");
|
||
const includePoints = common_vendor.ref([]);
|
||
const covers = common_vendor.ref([]);
|
||
common_vendor.onMounted(() => {
|
||
getLocation();
|
||
});
|
||
function getLocation() {
|
||
common_vendor.index.getLocation({
|
||
type: "gcj02",
|
||
// 返回可以用于uni.openLocation的坐标
|
||
success(res) {
|
||
console.log("当前位置的经度:" + res.longitude);
|
||
console.log("当前位置的纬度:" + res.latitude);
|
||
latitude.value = res.latitude;
|
||
longitude.value = res.longitude;
|
||
updateCover(res.latitude, res.longitude, 2, "我的位置", "/static/logo.png");
|
||
if (orderDetail.value.location in apartmentLocations) {
|
||
const targetApartment = apartmentLocations[orderDetail.value.location];
|
||
updateCover(
|
||
targetApartment.latitude,
|
||
targetApartment.longitude,
|
||
1,
|
||
orderDetail.value.location,
|
||
"/static/errand.jpg"
|
||
);
|
||
includePoints.value = [
|
||
{
|
||
latitude: targetApartment.latitude,
|
||
longitude: targetApartment.longitude
|
||
},
|
||
// 目标公寓的位置
|
||
{
|
||
latitude: res.latitude,
|
||
longitude: res.longitude
|
||
}
|
||
// 用户的位置
|
||
];
|
||
} else {
|
||
console.warn(`未找到名为"${orderDetail.value.location}"的公寓位置`);
|
||
}
|
||
},
|
||
fail(err) {
|
||
console.error("获取位置失败", err);
|
||
}
|
||
});
|
||
}
|
||
function updateCover(lat, lng, id, title, iconPath) {
|
||
const position = {
|
||
id,
|
||
latitude: lat,
|
||
longitude: lng,
|
||
iconPath,
|
||
// 标记图标路径,现在通过参数传递
|
||
width: 30,
|
||
height: 30,
|
||
title
|
||
// 可选:标记点标题
|
||
};
|
||
const existingIndex = covers.value.findIndex((item) => item.id === position.id);
|
||
if (existingIndex !== -1) {
|
||
covers.value[existingIndex] = position;
|
||
} else {
|
||
covers.value.push(position);
|
||
}
|
||
}
|
||
const takephoto = () => {
|
||
common_vendor.index.chooseImage({
|
||
count: 1,
|
||
// 默认9,这里设置为1因为只需要一张照片
|
||
sizeType: ["compressed"],
|
||
// 可以指定是原图还是压缩图,默认二者都有
|
||
sourceType: ["camera"],
|
||
// 从相机选择
|
||
success: function(res) {
|
||
const tempFilePaths = res.tempFilePaths;
|
||
uploadPhoto(tempFilePaths[0]);
|
||
}
|
||
});
|
||
};
|
||
const uploadPhoto = (filePath) => {
|
||
common_vendor.index.uploadFile({
|
||
url: `${API_api.apiImageUrl}/api/file/upload/server`,
|
||
// 接口地址
|
||
filePath,
|
||
name: "file",
|
||
formData: {
|
||
biz: "takeout"
|
||
// 根据要求填写的biz参数
|
||
},
|
||
header: {
|
||
"Content-Type": "application/json",
|
||
// 确保设置正确的 Content-Type
|
||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||
},
|
||
success(res) {
|
||
console.log("上传成功", res);
|
||
const imageUrl = JSON.parse(res.data).data;
|
||
handlePickup(orderDetail.value.id, imageUrl);
|
||
},
|
||
fail(err) {
|
||
console.error("上传失败", err);
|
||
}
|
||
});
|
||
};
|
||
return (_ctx, _cache) => {
|
||
return {
|
||
a: latitude.value,
|
||
b: longitude.value,
|
||
c: covers.value,
|
||
d: includePoints.value,
|
||
e: common_vendor.t(orderDetail.value.address),
|
||
f: common_vendor.t(orderDetail.value.location),
|
||
g: common_vendor.p({
|
||
type: "phone",
|
||
size: "30"
|
||
}),
|
||
h: common_vendor.o(($event) => {
|
||
var _a;
|
||
return handleCall((_a = orderDetail.value.businessVO) == null ? void 0 : _a.businessPhone);
|
||
}),
|
||
i: common_vendor.p({
|
||
type: "phone-filled",
|
||
size: "30"
|
||
}),
|
||
j: common_vendor.o(($event) => handleContact(orderDetail.value.phone)),
|
||
k: common_vendor.o(($event) => takephoto(orderDetail.value.id)),
|
||
l: common_vendor.p({
|
||
type: "camera",
|
||
size: "30"
|
||
}),
|
||
m: common_vendor.t(orderDetail.value.address),
|
||
n: common_vendor.t(formatDate(orderDetail.value.createTime)),
|
||
o: common_vendor.t(formatDate(orderDetail.value.pickupEndTime)),
|
||
p: common_vendor.t(orderDetail.value.location)
|
||
};
|
||
};
|
||
}
|
||
};
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-3d78755a"]]);
|
||
my.createPage(MiniProgramPage);
|