acdr-ui/dist/dev/mp-weixin/modules/pet/service/detail.js

282 lines
10 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"use strict";
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
2024-10-01 09:15:35 +08:00
const common_vendor = require("../../../common/vendor.js");
const utils_http = require("../../../utils/http.js");
const utils_commUtils = require("../../../utils/commUtils.js");
2024-09-19 07:20:14 +08:00
if (!Array) {
const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon");
const _component_w_avatar = common_vendor.resolveComponent("w-avatar");
const _easycom_wd_input_number2 = common_vendor.resolveComponent("wd-input-number");
2024-10-01 09:15:35 +08:00
const _easycom_wd_overlay2 = common_vendor.resolveComponent("wd-overlay");
2024-09-19 07:20:14 +08:00
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
2024-10-01 09:15:35 +08:00
(_easycom_wd_icon2 + _component_w_avatar + _easycom_wd_input_number2 + _easycom_wd_overlay2 + _component_layout_default_uni)();
2024-09-19 07:20:14 +08:00
}
2024-10-01 09:15:35 +08:00
const _easycom_wd_icon = () => "../../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js";
const _easycom_wd_input_number = () => "../../../node-modules/wot-design-uni/components/wd-input-number/wd-input-number.js";
const _easycom_wd_overlay = () => "../../../node-modules/wot-design-uni/components/wd-overlay/wd-overlay.js";
2024-09-19 07:20:14 +08:00
if (!Math) {
2024-10-01 09:15:35 +08:00
(TopBar + _easycom_wd_icon + Map + _easycom_wd_input_number + _easycom_wd_overlay + LoadingAnimation)();
2024-09-19 07:20:14 +08:00
}
2024-10-01 09:15:35 +08:00
const TopBar = () => "../../../components/TopBar.js";
const Map = () => "../../../components/Map.js";
const LoadingAnimation = () => "../../../components/LoadingAnimation.js";
2024-09-19 07:20:14 +08:00
const _sfc_main = {
__name: "detail",
setup(__props) {
const nowday = /* @__PURE__ */ new Date();
const year = nowday.getFullYear();
const month = (nowday.getMonth() + 1).toString().padStart(2, "0");
const day = nowday.getDate().toString().padStart(2, "0");
const reservationDate = common_vendor.ref(`${year}-${month}-${day}`);
const loading = common_vendor.ref(false);
const serviceData = common_vendor.ref({});
const pets = common_vendor.ref([]);
const addressList = common_vendor.ref([]);
const showReservationModal = common_vendor.ref(false);
const selectedPetId = common_vendor.ref("");
const today = common_vendor.ref("");
const weekFromToday = common_vendor.ref("");
const personalServiceId = common_vendor.ref("");
const hours = common_vendor.ref(1);
const selectedAddress = common_vendor.ref({});
2024-10-01 09:15:35 +08:00
const mapShow = common_vendor.ref(true);
2024-09-19 07:20:14 +08:00
const hoursHandleChange = ({ value }) => {
if (value >= 1 && value <= 12) {
hours.value = value;
} else {
utils_commUtils.toast("选择的服务时长在1-12小时");
}
};
const message = () => {
};
const detailPay = () => __async(this, null, function* () {
2024-10-01 09:15:35 +08:00
console.log(reservationDate.value);
2024-09-19 07:20:14 +08:00
const order = {
2024-10-01 09:15:35 +08:00
reservationTime: (/* @__PURE__ */ new Date(`${reservationDate.value} 00:00:00`)).getTime(),
2024-09-19 07:20:14 +08:00
personalServiceId: personalServiceId.value,
personalServiceUserId: serviceData.value.serviceUserId,
price: serviceData.value.price * hours.value,
2024-10-01 09:15:35 +08:00
paymentMethod: "alipay",
2024-09-19 07:20:14 +08:00
address: selectedAddress.value.id,
pet: selectedPetId.value,
serviceHours: hours.value
};
2024-10-01 09:15:35 +08:00
const createOrder = yield utils_http.httpPost("/order/create", order);
if (createOrder.code === 200)
;
2024-09-19 07:20:14 +08:00
closeReservationModal();
});
const setDateRange = () => {
const now = /* @__PURE__ */ new Date();
today.value = now.toISOString().split("T")[0];
const weekLater = new Date(now);
weekLater.setDate(now.getDate() + 7);
weekFromToday.value = weekLater.toISOString().split("T")[0];
};
const handleDateChange = (e) => {
reservationDate.value = e.detail.value;
};
const handleAddressChange = (e) => {
selectedAddress.value = addressList.value[e.detail.value];
};
const openReservationModal = () => {
showReservationModal.value = true;
2024-10-01 09:15:35 +08:00
mapShow.value = false;
2024-09-19 07:20:14 +08:00
};
const closeReservationModal = () => {
showReservationModal.value = false;
2024-10-01 09:15:35 +08:00
mapShow.value = true;
2024-09-19 07:20:14 +08:00
};
const selectPet = (id) => {
selectedPetId.value = id;
};
const confirmReservation = () => __async(this, null, function* () {
if (!selectedPetId.value || !reservationDate.value || !selectedAddress.value.display) {
utils_commUtils.toast("请选择宠物、日期和地址");
return;
}
yield detailPay();
closeReservationModal();
});
common_vendor.onLoad((options) => __async(this, null, function* () {
loading.value = true;
2024-10-01 09:15:35 +08:00
mapShow.value = false;
setTimeout(() => {
if (!loading.value && mapShow.value) {
loading.value = false;
mapShow.value = true;
}
}, 5e3);
2024-09-19 07:20:14 +08:00
try {
if (!options.id) {
utils_commUtils.toast("该服务不存在!");
common_vendor.index.navigateBack();
return;
}
const id = options.id;
personalServiceId.value = options.id;
setDateRange();
const serviceResponse = yield utils_http.httpGet(`/personal-service/service/${id}`);
if (serviceResponse.code === 200) {
serviceData.value = serviceResponse.data;
} else {
utils_commUtils.toast(serviceResponse.message);
}
const petsResponse = yield utils_http.httpGet("/petInfo/my");
if (petsResponse.code === 200) {
pets.value = petsResponse.data;
if (pets.value.length !== 0)
selectedPetId.value = pets.value[0].id;
} else {
utils_commUtils.toast(petsResponse.message);
}
const addressResponse = yield utils_http.httpGet("/china-address/my");
if (addressResponse.code === 200) {
addressList.value = addressResponse.data;
addressList.value.forEach((item) => {
item.display = `${item.province} ${item.city} ${item.district} ${item.detailAddress}`;
});
selectedAddress.value = addressList.value[0];
} else {
utils_commUtils.toast(addressResponse.message);
}
} catch (e) {
console.log(e);
utils_commUtils.toast("获取服务详情失败!");
}
loading.value = false;
2024-10-01 09:15:35 +08:00
mapShow.value = true;
2024-09-19 07:20:14 +08:00
}));
return (_ctx, _cache) => {
return common_vendor.e({
2024-10-01 09:15:35 +08:00
a: serviceData.value.bgUrl,
b: serviceData.value.userAvatar,
2024-09-19 07:20:14 +08:00
c: common_vendor.t(serviceData.value.userName),
d: common_vendor.t(serviceData.value.certificationTime),
e: common_vendor.t(serviceData.value.serviceNumber),
f: common_vendor.p({
name: "location",
size: "20"
}),
g: common_vendor.t(serviceData.value.address),
h: common_vendor.t(serviceData.value.description),
i: common_vendor.t(serviceData.value.serviceName),
j: common_vendor.p({
name: "bowl",
size: "24"
}),
k: common_vendor.p({
name: "water",
size: "24"
}),
l: common_vendor.p({
name: "litter",
size: "24"
}),
m: common_vendor.t(serviceData.value.price),
n: common_vendor.p({
name: "home",
size: "24"
}),
o: common_vendor.p({
name: "scooter",
size: "24"
}),
p: serviceData.value.comment
}, serviceData.value.comment ? {
q: common_vendor.t(serviceData.value.comment.star),
r: common_vendor.f(serviceData.value.comment.star, (num, k0, i0) => {
return {
2024-10-01 09:15:35 +08:00
a: "46bbd0c2-8-" + i0 + ",46bbd0c2-0"
2024-09-19 07:20:14 +08:00
};
}),
s: common_vendor.p({
name: "star-on",
size: "20"
}),
t: common_vendor.t(serviceData.value.comment.commentNum),
v: common_vendor.t(serviceData.value.comment.comment)
} : {}, {
2024-10-01 09:15:35 +08:00
w: mapShow.value,
x: common_vendor.p({
2024-09-19 07:20:14 +08:00
locationName: "服务位置",
initialLatitude: serviceData.value.latitude,
initialLongitude: serviceData.value.longitude
}),
2024-10-01 09:15:35 +08:00
y: common_vendor.t(serviceData.value.price),
z: common_vendor.o(message),
A: common_vendor.o(openReservationModal),
2024-09-19 07:20:14 +08:00
B: pets.value.length > 0
}, pets.value.length > 0 ? {
C: common_vendor.f(pets.value, (pet, k0, i0) => {
return {
2024-10-01 09:15:35 +08:00
a: common_vendor.unref(utils_commUtils.imgUrl)(pet.profileUrl),
2024-09-19 07:20:14 +08:00
b: common_vendor.t(pet.name),
c: pet.id,
d: common_vendor.o(($event) => selectPet(pet.id), pet.id),
e: common_vendor.n(selectedPetId.value == pet.id ? "border-4 border-_a__a_ffc107_a_ color-_a__a_ffc107_a_" : "")
};
})
} : {
D: common_vendor.p({
size: 80
}),
2024-10-01 09:15:35 +08:00
E: common_vendor.o(($event) => common_vendor.unref(utils_commUtils.toPath)("/modules/pet/pet/pet-add-page"))
2024-09-19 07:20:14 +08:00
}, {
F: common_vendor.t(reservationDate.value || "选择日期"),
G: today.value,
H: weekFromToday.value,
I: common_vendor.o(handleDateChange),
J: common_vendor.o(hoursHandleChange),
K: common_vendor.o(($event) => hours.value = $event),
L: common_vendor.p({
min: 1,
max: 12,
modelValue: hours.value
}),
M: addressList.value.length > 0
}, addressList.value.length > 0 ? {
N: common_vendor.t(selectedAddress.value.display || "请选择地址"),
O: addressList.value,
P: common_vendor.o(handleAddressChange)
} : {
Q: common_vendor.p({
size: 80
}),
2024-10-01 09:15:35 +08:00
R: common_vendor.o(($event) => common_vendor.unref(utils_commUtils.toPath)("/modules/pet/address/index"))
2024-09-19 07:20:14 +08:00
}, {
S: common_vendor.o(closeReservationModal),
2024-10-01 09:15:35 +08:00
T: common_vendor.o(confirmReservation),
U: common_vendor.p({
show: showReservationModal.value
}),
V: common_vendor.o(($event) => loading.value = $event),
W: common_vendor.p({
2024-09-19 07:20:14 +08:00
modelValue: loading.value
})
});
};
}
};
2024-10-01 09:15:35 +08:00
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-46bbd0c2"]]);
2024-09-19 07:20:14 +08:00
wx.createPage(MiniProgramPage);