120 lines
4.2 KiB
JavaScript
120 lines
4.2 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const modules_api_AppServer = require("../../modules/api/AppServer.js");
|
|
const modules_Config = require("../../modules/Config.js");
|
|
const _sfc_main = {
|
|
data() {
|
|
return {
|
|
serviceKey: "",
|
|
service: null,
|
|
loading: false,
|
|
currentLanguage: "zh"
|
|
};
|
|
},
|
|
onLoad(options) {
|
|
if (options.key) {
|
|
this.serviceKey = options.key;
|
|
this.currentLanguage = common_vendor.index.getStorageSync("language") || "zh";
|
|
this.loadServiceDetail();
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: "服务Key缺失",
|
|
icon: "none"
|
|
});
|
|
setTimeout(() => {
|
|
common_vendor.index.navigateBack();
|
|
}, 1500);
|
|
}
|
|
},
|
|
methods: {
|
|
// 加载服务详情
|
|
async loadServiceDetail() {
|
|
this.loading = true;
|
|
try {
|
|
const appserver = new modules_api_AppServer.AppServer();
|
|
const response = await appserver.GetServiceByKey(this.serviceKey, this.currentLanguage);
|
|
common_vendor.index.__f__("log", "at pages/service-detail/service-detail.vue:83", "服务详情响应:", response);
|
|
if (response.code === 0 && response.data) {
|
|
this.service = response.data;
|
|
} else {
|
|
common_vendor.index.__f__("error", "at pages/service-detail/service-detail.vue:88", "获取服务详情失败:", response.message);
|
|
common_vendor.index.showToast({
|
|
title: response.message || "获取服务详情失败",
|
|
icon: "none"
|
|
});
|
|
this.service = null;
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.__f__("error", "at pages/service-detail/service-detail.vue:96", "加载服务详情异常:", error);
|
|
common_vendor.index.showToast({
|
|
title: "加载失败",
|
|
icon: "none"
|
|
});
|
|
this.service = null;
|
|
} finally {
|
|
this.loading = false;
|
|
}
|
|
},
|
|
// 获取服务名称
|
|
getServiceName(service) {
|
|
if (!service)
|
|
return "";
|
|
return service.title || "";
|
|
},
|
|
// 获取服务描述
|
|
getServiceDescription(service) {
|
|
if (!service)
|
|
return "";
|
|
return service.description || "";
|
|
},
|
|
// 获取完整的图片 URL
|
|
getImageUrl(imagePath) {
|
|
if (!imagePath)
|
|
return "";
|
|
if (imagePath.startsWith("http"))
|
|
return imagePath;
|
|
const baseUrl = modules_Config.Config.API_BASE_URL || "http://localhost:3000";
|
|
return `${baseUrl}${imagePath}`;
|
|
},
|
|
// 处理预约
|
|
handleBook() {
|
|
if (!this.service)
|
|
return;
|
|
common_vendor.index.navigateTo({
|
|
url: `/pages/booking-form/booking-form?serviceId=${this.serviceId}`
|
|
});
|
|
},
|
|
// 处理图片加载错误
|
|
handleImageError() {
|
|
common_vendor.index.__f__("error", "at pages/service-detail/service-detail.vue:142", "图片加载失败:", this.service.image);
|
|
this.service.image = null;
|
|
}
|
|
}
|
|
};
|
|
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
return common_vendor.e({
|
|
a: $data.loading
|
|
}, $data.loading ? {
|
|
b: common_vendor.t(_ctx.$t("common.loading") || "加载中...")
|
|
} : $data.service ? common_vendor.e({
|
|
d: $data.service.image
|
|
}, $data.service.image ? {
|
|
e: $options.getImageUrl($data.service.image),
|
|
f: common_vendor.o((...args) => $options.handleImageError && $options.handleImageError(...args))
|
|
} : {}, {
|
|
g: common_vendor.t($options.getServiceName($data.service)),
|
|
h: common_vendor.t($options.getServiceDescription($data.service)),
|
|
i: common_vendor.t(_ctx.$t("appointment.bookNow") || "立即预约"),
|
|
j: common_vendor.o((...args) => $options.handleBook && $options.handleBook(...args))
|
|
}) : {
|
|
k: common_vendor.t(_ctx.$t("common.loadFailed") || "加载失败"),
|
|
l: common_vendor.t(_ctx.$t("common.retry") || "重试"),
|
|
m: common_vendor.o((...args) => $options.loadServiceDetail && $options.loadServiceDetail(...args))
|
|
}, {
|
|
c: $data.service
|
|
});
|
|
}
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-ee5c4025"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/service-detail/service-detail.js.map
|