appointment_system/unpackage/dist/dev/mp-weixin/pages/appointment/appointment-page.js
2025-12-15 23:42:31 +08:00

155 lines
5.6 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const utils_tabbarI18n = require("../../utils/tabbar-i18n.js");
const modules_api_AppServer = require("../../modules/api/AppServer.js");
const modules_Config = require("../../modules/Config.js");
const _sfc_main = {
data() {
return {
currentIndex: 0,
currentCategoryId: null,
categories: [],
services: [],
loading: false,
currentLanguage: "zh"
};
},
onLoad() {
this.currentLanguage = common_vendor.index.getStorageSync("language") || "zh";
this.loadCategories();
},
onShow() {
utils_tabbarI18n.updateTabBarI18n(this);
},
methods: {
// 加载分类列表
async loadCategories() {
try {
const appserver = new modules_api_AppServer.AppServer();
const response = await appserver.GetCategories({ language: this.currentLanguage });
common_vendor.index.__f__("log", "at pages/appointment/appointment-page.vue:100", "分类列表响应:", response);
if (response.code === 0 && response.data) {
this.categories = response.data.categories || response.data || [];
if (this.categories.length > 0) {
this.currentIndex = 0;
this.currentCategoryId = this.categories[0].id;
this.loadServices(this.currentCategoryId);
}
} else {
common_vendor.index.__f__("error", "at pages/appointment/appointment-page.vue:112", "获取分类失败:", response.message);
common_vendor.index.showToast({
title: response.message || "获取分类失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/appointment/appointment-page.vue:119", "加载分类异常:", error);
common_vendor.index.showToast({
title: "加载分类失败",
icon: "none"
});
}
},
// 加载服务列表
async loadServices(categoryId) {
this.loading = true;
try {
const appserver = new modules_api_AppServer.AppServer();
const params = {
categoryId,
language: this.currentLanguage
};
const response = await appserver.GetServices(params);
common_vendor.index.__f__("log", "at pages/appointment/appointment-page.vue:138", "服务列表响应:", response);
if (response.code === 0 && response.data) {
this.services = response.data.services || response.data || [];
} else {
common_vendor.index.__f__("error", "at pages/appointment/appointment-page.vue:143", "获取服务失败:", response.message);
this.services = [];
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/appointment/appointment-page.vue:147", "加载服务异常:", error);
this.services = [];
} finally {
this.loading = false;
}
},
// 点击分类
clickType(index, categoryId) {
this.currentIndex = index;
this.currentCategoryId = categoryId;
this.loadServices(categoryId);
},
// 获取分类名称(根据当前语言)
getCategoryName(category) {
if (!category)
return "";
return category.name || "";
},
// 获取服务名称(根据当前语言)
getServiceName(service) {
if (!service)
return "";
return service.title || "";
},
// 获取完整的图片 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}`;
},
// 跳转到服务详情页
goToServiceDetail(serviceId) {
common_vendor.index.navigateTo({
url: `/pages/service-detail/service-detail?id=${serviceId}`
});
},
// 处理图片加载错误
handleImageError(service) {
common_vendor.index.__f__("error", "at pages/appointment/appointment-page.vue:193", "图片加载失败:", service.image);
service.image = null;
}
}
};
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.t(_ctx.$t("appointment.allServices")),
b: common_vendor.f($data.categories, (category, index, i0) => {
return common_vendor.e({
a: $data.currentIndex === index
}, $data.currentIndex === index ? {} : {}, {
b: common_vendor.t($options.getCategoryName(category)),
c: category.id,
d: common_vendor.o(($event) => $options.clickType(index, category.id), category.id),
e: $data.currentIndex === index ? 1 : ""
});
}),
c: $data.loading
}, $data.loading ? {
d: common_vendor.t(_ctx.$t("common.loading") || "加载中...")
} : $data.services.length > 0 ? {
f: common_vendor.f($data.services, (service, k0, i0) => {
return common_vendor.e({
a: service.image
}, service.image ? {
b: $options.getImageUrl(service.image),
c: common_vendor.o(($event) => $options.handleImageError(service), service.id)
} : {}, {
d: common_vendor.t($options.getServiceName(service)),
e: service.id,
f: common_vendor.o(($event) => $options.goToServiceDetail(service.id), service.id)
});
})
} : {
g: common_vendor.t(_ctx.$t("common.noData") || "暂无服务")
}, {
e: $data.services.length > 0
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/appointment/appointment-page.js.map