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

267 lines
9.9 KiB
JavaScript

"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());
});
};
const common_vendor = require("../../common/vendor.js");
const utils_http = require("../../utils/http.js");
const utils_commUtils = require("../../utils/commUtils.js");
const logic_pay = require("../../logic/pay.js");
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");
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
(_easycom_wd_icon2 + _component_w_avatar + _easycom_wd_input_number2 + _component_layout_default_uni)();
}
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";
if (!Math) {
(TopBar + _easycom_wd_icon + Map + _easycom_wd_input_number + LoadingAnimation)();
}
const TopBar = () => "../../components/TopBar.js";
const Map = () => "../../components/Map.js";
const LoadingAnimation = () => "../../components/LoadingAnimation.js";
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({});
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* () {
const order = {
reservationTime: `${reservationDate.value} 00:00:00`,
personalServiceId: personalServiceId.value,
personalServiceUserId: serviceData.value.serviceUserId,
price: serviceData.value.price * hours.value,
paymentMethod: "wxpay",
address: selectedAddress.value.id,
pet: selectedPetId.value,
serviceHours: hours.value
};
yield logic_pay.pay(order);
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;
};
const closeReservationModal = () => {
showReservationModal.value = false;
};
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;
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;
}));
return (_ctx, _cache) => {
return common_vendor.e({
a: common_vendor.unref(utils_commUtils.baseUrl) + serviceData.value.bgUrl,
b: common_vendor.unref(utils_commUtils.baseUrl) + serviceData.value.userAvatar,
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 {
a: "dbbf9860-8-" + i0 + ",dbbf9860-0"
};
}),
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)
} : {}, {
w: common_vendor.p({
locationName: "服务位置",
initialLatitude: serviceData.value.latitude,
initialLongitude: serviceData.value.longitude
}),
x: common_vendor.t(serviceData.value.price),
y: common_vendor.o(message),
z: common_vendor.o(openReservationModal),
A: showReservationModal.value
}, showReservationModal.value ? common_vendor.e({
B: pets.value.length > 0
}, pets.value.length > 0 ? {
C: common_vendor.f(pets.value, (pet, k0, i0) => {
return {
a: common_vendor.unref(utils_commUtils.baseUrl) + pet.profileUrl,
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
}),
E: common_vendor.o(($event) => common_vendor.unref(utils_commUtils.toPath)("/pages/pet/pet-add-page"))
}, {
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
}),
R: common_vendor.o(($event) => common_vendor.unref(utils_commUtils.toPath)("/pages/address/index"))
}, {
S: common_vendor.o(closeReservationModal),
T: common_vendor.o(confirmReservation)
}) : {}, {
U: common_vendor.o(($event) => loading.value = $event),
V: common_vendor.p({
modelValue: loading.value
})
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-dbbf9860"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=detail.js.map