Files
ShaFaFanXin/前端/unpackage/dist/dev/mp-weixin/pages/cases/detail.js

211 lines
7.7 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_index = require("../../api/index.js");
const utils_config = require("../../utils/config.js");
if (!Array) {
const _easycom_before_after_1 = common_vendor.resolveComponent("before-after");
_easycom_before_after_1();
}
const _easycom_before_after = () => "../../components/before-after/before-after.js";
if (!Math) {
_easycom_before_after();
}
class CaseDetail extends UTS.UTSType {
static get$UTSMetadata$() {
return {
kind: 2,
get fields() {
return {
id: { type: String, optional: false },
title: { type: String, optional: false },
category: { type: String, optional: false },
categoryName: { type: String, optional: false },
beforeImages: { type: UTS.UTSType.withGenerics(Array, [String]), optional: false },
afterImages: { type: UTS.UTSType.withGenerics(Array, [String]), optional: false },
compareAfterImages: { type: UTS.UTSType.withGenerics(Array, [String]), optional: false },
description: { type: String, optional: false },
material: { type: String, optional: false },
duration: { type: String, optional: false },
price: { type: String, optional: false },
views: { type: Number, optional: false },
likes: { type: Number, optional: false },
createTime: { type: String, optional: false }
};
},
name: "CaseDetail"
};
}
constructor(options, metadata = CaseDetail.get$UTSMetadata$(), isJSONParse = false) {
super();
this.__props__ = UTS.UTSType.initProps(options, metadata, isJSONParse);
this.id = this.__props__.id;
this.title = this.__props__.title;
this.category = this.__props__.category;
this.categoryName = this.__props__.categoryName;
this.beforeImages = this.__props__.beforeImages;
this.afterImages = this.__props__.afterImages;
this.compareAfterImages = this.__props__.compareAfterImages;
this.description = this.__props__.description;
this.material = this.__props__.material;
this.duration = this.__props__.duration;
this.price = this.__props__.price;
this.views = this.__props__.views;
this.likes = this.__props__.likes;
this.createTime = this.__props__.createTime;
delete this.__props__;
}
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
__name: "detail",
setup(__props) {
const caseId = common_vendor.ref("");
const caseDetail = common_vendor.ref(new CaseDetail({
id: "",
title: "",
category: "",
categoryName: "",
beforeImages: [],
afterImages: [],
compareAfterImages: [],
description: "",
material: "",
duration: "",
price: "",
views: 0,
likes: 0,
createTime: ""
}));
const isFavorite = common_vendor.ref(false);
const fetchCaseDetail = () => {
return common_vendor.__awaiter(this, void 0, void 0, function* () {
try {
const res = yield api_index.getCaseDetail(caseId.value);
if (res.code === 0 && res.data != null) {
const data = res.data;
const images = data["images"] || [];
const beforeImages = data["beforeImages"] || [];
const afterImages = data["afterImages"] || [];
const createdAt = data["createdAt"] || "";
const displayAfterImages = afterImages.length > 0 ? afterImages : images;
const compareAfterImages = afterImages.length > 0 ? afterImages : [];
caseDetail.value = new CaseDetail(
{
id: String(data["id"]),
title: data["title"],
category: data["serviceType"] || "",
categoryName: utils_config.getServiceTypeName(data["serviceType"]),
beforeImages,
afterImages: displayAfterImages,
compareAfterImages,
description: data["description"],
material: data["materials"] || "优质材料",
duration: (data["duration"] || 0) + "天",
price: data["price"] != null ? "¥" + data["price"] : "面议",
views: data["views"] || 0,
likes: data["likes"] || 0,
createTime: createdAt.split("T")[0] || ""
}
// 更新标题
);
common_vendor.index.setNavigationBarTitle({
title: caseDetail.value.title
});
} else {
common_vendor.index.showToast({
title: res.message || "加载失败",
icon: "none"
});
}
} catch (error) {
common_vendor.index.__f__("error", "at pages/cases/detail.uvue:197", "获取案例详情失败:", error);
common_vendor.index.showToast({
title: "加载失败",
icon: "none"
});
}
});
};
const previewImages = (index) => {
const urls = caseDetail.value.afterImages || [];
const current = urls[index] || urls[0] || "";
common_vendor.index.previewImage({
current,
urls
});
};
const handleFavorite = () => {
isFavorite.value = !isFavorite.value;
common_vendor.index.showToast({
title: isFavorite.value ? "已收藏" : "已取消收藏",
icon: "none"
});
};
const handleShare = () => {
common_vendor.index.showToast({
title: "分享功能开发中",
icon: "none"
});
};
const handleContact = () => {
common_vendor.index.makePhoneCall({
phoneNumber: "400-888-8888",
fail: () => {
common_vendor.index.showToast({
title: "拨打电话失败",
icon: "none"
});
}
});
};
const goToBooking = () => {
common_vendor.index.navigateTo({
url: "/pages/booking/index"
});
};
common_vendor.onLoad((options) => {
var _a;
caseId.value = (_a = options["id"]) !== null && _a !== void 0 ? _a : "";
if (caseId.value != "") {
fetchCaseDetail();
}
});
return (_ctx, _cache) => {
"raw js";
const __returned__ = {
a: common_vendor.f(common_vendor.unref(caseDetail).afterImages, (item, index, i0) => {
return {
a: item,
b: common_vendor.o(($event) => {
return previewImages(index);
}, index),
c: index
};
}),
b: common_vendor.t(common_vendor.unref(caseDetail).categoryName),
c: common_vendor.t(common_vendor.unref(caseDetail).title),
d: common_vendor.t(common_vendor.unref(caseDetail).price),
e: common_vendor.t(common_vendor.unref(caseDetail).views),
f: common_vendor.t(common_vendor.unref(caseDetail).likes),
g: common_vendor.p({
beforeImage: common_vendor.unref(caseDetail).beforeImages[0] || "",
afterImage: common_vendor.unref(caseDetail).compareAfterImages[0] || "",
showTitle: true
}),
h: common_vendor.t(common_vendor.unref(caseDetail).material),
i: common_vendor.t(common_vendor.unref(caseDetail).duration),
j: common_vendor.t(common_vendor.unref(caseDetail).createTime),
k: common_vendor.t(common_vendor.unref(caseDetail).description),
l: common_vendor.t(common_vendor.unref(isFavorite) ? "❤️" : "🤍"),
m: common_vendor.o(handleFavorite),
n: common_vendor.o(handleShare),
o: common_vendor.o(handleContact),
p: common_vendor.o(goToBooking),
q: common_vendor.sei(common_vendor.gei(_ctx, ""), "view")
};
return __returned__;
};
}
});
wx.createPage(_sfc_main);
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/cases/detail.js.map