422 lines
14 KiB
JavaScript
422 lines
14 KiB
JavaScript
"use strict";
|
||
const common_vendor = require("../../common/vendor.js");
|
||
const API_api = require("../../API/api.js");
|
||
if (!Array) {
|
||
const _easycom_uni_notice_bar2 = common_vendor.resolveComponent("uni-notice-bar");
|
||
const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
|
||
const _easycom_uni_popup2 = common_vendor.resolveComponent("uni-popup");
|
||
(_easycom_uni_notice_bar2 + _easycom_uni_icons2 + _easycom_uni_popup2)();
|
||
}
|
||
const _easycom_uni_notice_bar = () => "../../uni_modules/uni-notice-bar/components/uni-notice-bar/uni-notice-bar.js";
|
||
const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
|
||
const _easycom_uni_popup = () => "../../uni_modules/uni-popup/components/uni-popup/uni-popup.js";
|
||
if (!Math) {
|
||
(_easycom_uni_notice_bar + _easycom_uni_icons + _easycom_uni_popup)();
|
||
}
|
||
const _sfc_main = {
|
||
__name: "index",
|
||
setup(__props) {
|
||
const radius = common_vendor.ref(common_vendor.index.getStorageSync("currentUser.distributionScope"));
|
||
const currentIndex = common_vendor.ref(0);
|
||
const tabs = [
|
||
{
|
||
name: "待抢单"
|
||
},
|
||
{
|
||
name: "待取货"
|
||
},
|
||
{
|
||
name: "待送达"
|
||
}
|
||
];
|
||
const switchTab = (index) => {
|
||
currentIndex.value = index;
|
||
const stateMap = [1, 2, 3];
|
||
if (index >= 0 && index < stateMap.length) {
|
||
robOrder(stateMap[index]);
|
||
}
|
||
};
|
||
const switchTabs = (index) => {
|
||
activeTab.value = index;
|
||
};
|
||
const type = common_vendor.ref("center");
|
||
const activeTab = common_vendor.ref(0);
|
||
const selectedItem = common_vendor.ref(null);
|
||
const popupRef = common_vendor.ref(null);
|
||
const array = common_vendor.ref(["1公寓", "2公寓", "3公寓", "4公寓", "5公寓", "6公寓", "7公寓", "8公寓", "9公寓", "10公寓", "11公寓", "12公寓", "育才大厦"]);
|
||
common_vendor.ref(0);
|
||
const items = common_vendor.ref([
|
||
"考核时间从多到少",
|
||
"运单金额从高到低",
|
||
"配送距离从近到远",
|
||
"取货距离从近到远",
|
||
"推荐排序"
|
||
]);
|
||
const tipsItems = common_vendor.ref([
|
||
"新单置顶",
|
||
"已抢商户置顶"
|
||
]);
|
||
const change = (e) => {
|
||
console.log("当前模式:" + e.type + ",状态:" + e.show);
|
||
};
|
||
const toggle = (typeValue) => {
|
||
type.value = typeValue;
|
||
popupRef.value.open(typeValue);
|
||
};
|
||
const map = () => {
|
||
common_vendor.index.navigateTo({
|
||
url: "/pages/map/map"
|
||
});
|
||
};
|
||
const bindPickerChange = (e) => {
|
||
console.log("picker发送选择改变,携带值为", e.detail.value);
|
||
const newValue = array.value[e.detail.value];
|
||
radius.value = newValue;
|
||
const requestData = {
|
||
distributionScope: newValue,
|
||
errandName: currentUser.value.errandName,
|
||
// 动态获取
|
||
errandPhone: currentUser.value.errandPhone,
|
||
// 动态获取
|
||
gender: currentUser.value.gender,
|
||
// 动态获取
|
||
id: currentUser.value.id,
|
||
// 动态获取
|
||
state: currentUser.value.state
|
||
// 动态获取
|
||
};
|
||
common_vendor.index.request({
|
||
url: API_api.apiImageUrl + "/api/errand/update/my",
|
||
method: "POST",
|
||
data: requestData,
|
||
header: {
|
||
"Content-Type": "application/json",
|
||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||
},
|
||
success(res) {
|
||
console.log("配送范围更新成功:", res);
|
||
console.log(res.data.code);
|
||
if (res.data.code === 50001) {
|
||
common_vendor.index.showToast({
|
||
title: "还有未送达订单",
|
||
icon: "fail"
|
||
});
|
||
} else if (res.data.code === 0) {
|
||
common_vendor.index.showToast({
|
||
title: "配送范围已更新",
|
||
icon: "success"
|
||
});
|
||
refreshOrders();
|
||
}
|
||
},
|
||
fail(err) {
|
||
console.error("配送范围更新失败:", err);
|
||
common_vendor.index.showToast({
|
||
title: "更新失败,请重试",
|
||
icon: "none"
|
||
});
|
||
}
|
||
});
|
||
};
|
||
const handleClick = (item) => {
|
||
selectedItem.value = item;
|
||
};
|
||
const refreshOrders = () => {
|
||
const stateMap = [1, 2, 3];
|
||
const currentState = stateMap[currentIndex.value] || 1;
|
||
robOrder(currentState);
|
||
};
|
||
common_vendor.onMounted(() => {
|
||
robOrder(1);
|
||
});
|
||
let errandOrder = common_vendor.ref([]);
|
||
const robOrder = (errandStateValue) => {
|
||
if (typeof errandStateValue !== "number" || isNaN(errandStateValue)) {
|
||
console.error("Invalid errandState value:", errandStateValue);
|
||
return;
|
||
}
|
||
const params = `errandState=${encodeURIComponent(errandStateValue.toString())}`;
|
||
common_vendor.index.request({
|
||
url: API_api.apiImageUrl + "/api/errand/list/order",
|
||
method: "POST",
|
||
header: {
|
||
"Content-Type": "application/x-www-form-urlencoded",
|
||
// 设置正确的内容类型
|
||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||
},
|
||
data: params,
|
||
// 直接使用构建好的查询字符串
|
||
success(res) {
|
||
console.log("请求成功:", res);
|
||
if (res.data.code !== 0) {
|
||
common_vendor.index.showToast({
|
||
title: `请求失败:${res.data.message}`,
|
||
icon: "none"
|
||
});
|
||
} else {
|
||
console.log(res.data.data);
|
||
errandOrder.value = res.data.data;
|
||
console.log("Updated errandOrder:", errandOrder.value);
|
||
}
|
||
},
|
||
fail(err) {
|
||
console.log("请求失败:", err);
|
||
}
|
||
});
|
||
};
|
||
const plunder = (id) => {
|
||
console.log(id);
|
||
common_vendor.index.request({
|
||
url: API_api.apiImageUrl + "/api/errand/get/order",
|
||
method: "POST",
|
||
data: {
|
||
id
|
||
},
|
||
header: {
|
||
"Content-Type": "application/json",
|
||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||
},
|
||
success: (res) => {
|
||
console.log(res);
|
||
if (res.data.code === 0) {
|
||
common_vendor.index.showToast({
|
||
title: "抢单成功",
|
||
icon: "success",
|
||
success: () => {
|
||
const stateMap = [1, 2, 3];
|
||
const currentState = stateMap[currentIndex.value];
|
||
robOrder(currentState);
|
||
if (currentIndex.value === 0) {
|
||
robOrder(2);
|
||
}
|
||
}
|
||
});
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: res.data.message || "抢单失败",
|
||
icon: "none"
|
||
});
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
console.log(err);
|
||
common_vendor.index.showToast({
|
||
title: "网络错误,请重试",
|
||
icon: "none"
|
||
});
|
||
}
|
||
});
|
||
};
|
||
const obtain = (id) => {
|
||
common_vendor.index.request({
|
||
url: API_api.apiImageUrl + "/api/errand/update/state",
|
||
method: "POST",
|
||
data: {
|
||
errandsState: 3,
|
||
orderId: id
|
||
},
|
||
header: {
|
||
"Content-Type": "application/json",
|
||
"cookie": common_vendor.index.getStorageSync("cookie") || ""
|
||
},
|
||
success: (res) => {
|
||
console.log(res);
|
||
if (res.data.code === 0) {
|
||
common_vendor.index.showToast({
|
||
title: "取货成功",
|
||
icon: "success",
|
||
success: () => {
|
||
robOrder(2);
|
||
robOrder(3);
|
||
}
|
||
});
|
||
} else {
|
||
common_vendor.index.showToast({
|
||
title: res.data.description || "取货失败",
|
||
icon: "none"
|
||
});
|
||
}
|
||
},
|
||
fail: (err) => {
|
||
console.log(err);
|
||
common_vendor.index.showToast({
|
||
title: "网络异常,请检查连接",
|
||
icon: "none"
|
||
});
|
||
}
|
||
});
|
||
};
|
||
let currentUser = common_vendor.ref({});
|
||
const getCurrentUser = () => {
|
||
common_vendor.index.request({
|
||
url: API_api.apiImageUrl + "/api/errand/get/current",
|
||
method: "POST",
|
||
header: {
|
||
"Content-Type": "application/json",
|
||
"cookie": common_vendor.index.getStorageSync("cookie")
|
||
},
|
||
success(res) {
|
||
console.log(res);
|
||
if (res.data.code === 0) {
|
||
const userData = res.data.data;
|
||
currentUser.value = userData;
|
||
if (array.value.includes(userData.distributionScope)) {
|
||
radius.value = userData.distributionScope;
|
||
} else {
|
||
console.warn("用户的配送范围不在预设的选项中");
|
||
}
|
||
}
|
||
},
|
||
fail(err) {
|
||
console.error("请求失败:", err);
|
||
}
|
||
});
|
||
};
|
||
common_vendor.onMounted(() => {
|
||
robOrder(1);
|
||
getCurrentUser();
|
||
});
|
||
common_vendor.onShow(() => {
|
||
getCurrentUser();
|
||
robOrder(1);
|
||
});
|
||
const orderDetail = (item) => {
|
||
common_vendor.index.setStorageSync("orderDetail", item);
|
||
common_vendor.index.navigateTo({
|
||
url: "/pages/orderDetail/orderDetail"
|
||
});
|
||
};
|
||
const deliveryDetail = (item) => {
|
||
console.log("4567845678945678900");
|
||
console.log(item);
|
||
common_vendor.index.setStorageSync("orderDetail", item);
|
||
common_vendor.index.navigateTo({
|
||
url: "/pages/deliveryDetail/deliveryDetail"
|
||
});
|
||
};
|
||
const formatDate = (isoString) => {
|
||
if (!isoString)
|
||
return "";
|
||
return isoString.slice(5, 10) + " " + isoString.slice(11, 19);
|
||
};
|
||
common_vendor.index.$on("refresh-delivery-list", () => {
|
||
this.robOrder(3);
|
||
});
|
||
return (_ctx, _cache) => {
|
||
return common_vendor.e({
|
||
a: common_vendor.f(tabs, (tab, index, i0) => {
|
||
return {
|
||
a: common_vendor.t(tab.name),
|
||
b: tab.name,
|
||
c: currentIndex.value === index ? 1 : "",
|
||
d: common_vendor.o(($event) => switchTab(index))
|
||
};
|
||
}),
|
||
b: common_vendor.p({
|
||
["show-icon"]: true,
|
||
scrollable: true,
|
||
text: "今日放假"
|
||
}),
|
||
c: currentIndex.value === 0
|
||
}, currentIndex.value === 0 ? {
|
||
d: common_vendor.f(common_vendor.unref(errandOrder), (item, index, i0) => {
|
||
var _a;
|
||
return {
|
||
a: common_vendor.t(item.id),
|
||
b: common_vendor.t(formatDate(item.pickupEndTime)),
|
||
c: common_vendor.t(item.address),
|
||
d: common_vendor.t((_a = item.businessVO) == null ? void 0 : _a.businessName),
|
||
e: common_vendor.t(item.location),
|
||
f: common_vendor.o(($event) => plunder(item.id)),
|
||
g: index
|
||
};
|
||
})
|
||
} : {}, {
|
||
e: currentIndex.value === 1
|
||
}, currentIndex.value === 1 ? {
|
||
f: common_vendor.f(common_vendor.unref(errandOrder), (item, index, i0) => {
|
||
var _a;
|
||
return {
|
||
a: common_vendor.t(item.id),
|
||
b: common_vendor.t(formatDate(item.pickupEndTime)),
|
||
c: common_vendor.t(item.address),
|
||
d: common_vendor.t((_a = item.businessVO) == null ? void 0 : _a.businessName),
|
||
e: common_vendor.t(item.location),
|
||
f: common_vendor.o(($event) => obtain(item.id)),
|
||
g: index,
|
||
h: common_vendor.o(($event) => orderDetail(item))
|
||
};
|
||
})
|
||
} : {}, {
|
||
g: currentIndex.value === 2
|
||
}, currentIndex.value === 2 ? {
|
||
h: common_vendor.f(common_vendor.unref(errandOrder), (item, index, i0) => {
|
||
var _a;
|
||
return {
|
||
a: common_vendor.t(item.id),
|
||
b: common_vendor.t(formatDate(item.pickupEndTime)),
|
||
c: common_vendor.t(item.address),
|
||
d: common_vendor.t((_a = item.businessVO) == null ? void 0 : _a.businessName),
|
||
e: common_vendor.t(item.location),
|
||
f: index,
|
||
g: common_vendor.o(($event) => deliveryDetail(item))
|
||
};
|
||
})
|
||
} : {}, {
|
||
i: common_vendor.p({
|
||
type: "gear-filled",
|
||
size: "24"
|
||
}),
|
||
j: common_vendor.o(($event) => toggle("bottom")),
|
||
k: common_vendor.p({
|
||
type: "location-filled",
|
||
size: "24"
|
||
}),
|
||
l: common_vendor.o(map),
|
||
m: common_vendor.o(refreshOrders),
|
||
n: activeTab.value === 0 ? 1 : "",
|
||
o: common_vendor.o(($event) => switchTabs(0)),
|
||
p: activeTab.value === 1 ? 1 : "",
|
||
q: common_vendor.o(($event) => switchTabs(1)),
|
||
r: activeTab.value === 0
|
||
}, activeTab.value === 0 ? {
|
||
s: common_vendor.t(radius.value.value || "修改配送区域"),
|
||
t: array.value.indexOf(radius.value.value),
|
||
v: array.value,
|
||
w: common_vendor.o(bindPickerChange)
|
||
} : {}, {
|
||
x: activeTab.value === 1
|
||
}, activeTab.value === 1 ? {
|
||
y: common_vendor.f(items.value, (item, index, i0) => {
|
||
return {
|
||
a: common_vendor.t(item),
|
||
b: common_vendor.o(($event) => handleClick(item)),
|
||
c: index,
|
||
d: selectedItem.value === item ? 1 : ""
|
||
};
|
||
}),
|
||
z: common_vendor.f(tipsItems.value, (item, index, i0) => {
|
||
return {
|
||
a: common_vendor.t(item),
|
||
b: common_vendor.o(($event) => handleClick(item)),
|
||
c: index,
|
||
d: selectedItem.value === item ? 1 : ""
|
||
};
|
||
})
|
||
} : {}, {
|
||
A: type.value === "left" || type.value === "right" ? 1 : "",
|
||
B: () => ({
|
||
r: popupRef,
|
||
k: "popupRef"
|
||
}),
|
||
C: common_vendor.o(change),
|
||
D: common_vendor.p({
|
||
["background-color"]: "#fff"
|
||
})
|
||
});
|
||
};
|
||
}
|
||
};
|
||
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-1cf27b2a"]]);
|
||
my.createPage(MiniProgramPage);
|