338 lines
14 KiB
JavaScript
338 lines
14 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");
|
||
|
require("../../store/index.js");
|
||
|
const utils_commUtils = require("../../utils/commUtils.js");
|
||
|
const utils_http = require("../../utils/http.js");
|
||
|
const store_user = require("../../store/user.js");
|
||
|
if (!Array) {
|
||
|
const _easycom_wd_img2 = common_vendor.resolveComponent("wd-img");
|
||
|
const _easycom_wd_icon2 = common_vendor.resolveComponent("wd-icon");
|
||
|
const _easycom_wd_picker2 = common_vendor.resolveComponent("wd-picker");
|
||
|
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
|
||
|
(_easycom_wd_img2 + _easycom_wd_icon2 + _easycom_wd_picker2 + _component_layout_default_uni)();
|
||
|
}
|
||
|
const _easycom_wd_img = () => "../../node-modules/wot-design-uni/components/wd-img/wd-img.js";
|
||
|
const _easycom_wd_icon = () => "../../node-modules/wot-design-uni/components/wd-icon/wd-icon.js";
|
||
|
const _easycom_wd_picker = () => "../../node-modules/wot-design-uni/components/wd-picker/wd-picker.js";
|
||
|
if (!Math) {
|
||
|
(_easycom_wd_img + _easycom_wd_icon + _easycom_wd_picker)();
|
||
|
}
|
||
|
const _sfc_main = {
|
||
|
__name: "pet-add-page",
|
||
|
setup(__props) {
|
||
|
const petName = common_vendor.ref("");
|
||
|
const petBirthday = common_vendor.ref("");
|
||
|
const gender = common_vendor.ref("");
|
||
|
const petBreed = common_vendor.ref("");
|
||
|
const petColor = common_vendor.ref("");
|
||
|
const imageSrc = common_vendor.ref("https://via.placeholder.com/150");
|
||
|
const userId = common_vendor.ref("");
|
||
|
const petId = common_vendor.ref(null);
|
||
|
const imageLoadError = (errMsg) => {
|
||
|
console.log("图片加载失败");
|
||
|
imageSrc.value = "https://via.placeholder.com/150";
|
||
|
};
|
||
|
const userStore = store_user.useUserStore();
|
||
|
const breedOptions = common_vendor.ref([
|
||
|
{ value: "其他", label: "其他" },
|
||
|
{ value: "阿比西尼亚猫", label: "阿比西尼亚猫" },
|
||
|
{ value: "安哥拉猫", label: "安哥拉猫" },
|
||
|
{ value: "埃及猫", label: "埃及猫" },
|
||
|
{ value: "奥西猫", label: "奥西猫" },
|
||
|
{ value: "巴厘猫", label: "巴厘猫" },
|
||
|
{ value: "波米拉猫", label: "波米拉猫" },
|
||
|
{ value: "伯曼猫", label: "伯曼猫" },
|
||
|
{ value: "布偶猫", label: "布偶猫" },
|
||
|
{ value: "波斯猫", label: "波斯猫" }
|
||
|
]);
|
||
|
const colorOptions = common_vendor.ref([
|
||
|
{ value: "黑白色", label: "黑白色" },
|
||
|
{ value: "白色", label: "白色" },
|
||
|
{ value: "黑色", label: "黑色" },
|
||
|
{ value: "橘色", label: "橘色" },
|
||
|
{ value: "蓝色", label: "蓝色" },
|
||
|
{ value: "蓝白色", label: "蓝白色" },
|
||
|
{ value: "橘白色", label: "橘白色" },
|
||
|
{ value: "灰色", label: "灰色" },
|
||
|
{ value: "灰白色", label: "灰白色" },
|
||
|
{ value: "乳色", label: "乳色" },
|
||
|
{ value: "乳白色", label: "乳白色" },
|
||
|
{ value: "棕色", label: "棕色" },
|
||
|
{ value: "棕白色", label: "棕白色" },
|
||
|
{ value: "银色", label: "银色" },
|
||
|
{ value: "银白色", label: "银白色" },
|
||
|
{ value: "雪色", label: "雪色" },
|
||
|
{ value: "木炭色", label: "木炭色" },
|
||
|
{ value: "金渐层", label: "金渐层" },
|
||
|
{ value: "蓝金渐层", label: "蓝金渐层" },
|
||
|
{ value: "银渐层", label: "银渐层" },
|
||
|
{ value: "金点", label: "金点" },
|
||
|
{ value: "银点", label: "银点" },
|
||
|
{ value: "重点色", label: "重点色" },
|
||
|
{ value: "手套色", label: "手套色" },
|
||
|
{ value: "海豹色", label: "海豹色" },
|
||
|
{ value: "火焰色", label: "火焰色" },
|
||
|
{ value: "蓝双色", label: "蓝双色" },
|
||
|
{ value: "海豹双色", label: "海豹双色" },
|
||
|
{ value: "梵色", label: "梵色" },
|
||
|
{ value: "玳瑁色", label: "玳瑁色" },
|
||
|
{ value: "三花色", label: "三花色" },
|
||
|
{ value: "烟灰色", label: "烟灰色" },
|
||
|
{ value: "虎斑纹", label: "虎斑纹" },
|
||
|
{ value: "棕虎斑", label: "棕虎斑" },
|
||
|
{ value: "银虎斑", label: "银虎斑" },
|
||
|
{ value: "红虎斑", label: "红虎斑" },
|
||
|
{ value: "山猫纹", label: "山猫纹" },
|
||
|
{ value: "玫瑰纹", label: "玫瑰纹" },
|
||
|
{ value: "大理石纹", label: "大理石纹" },
|
||
|
{ value: "其他", label: "其他" },
|
||
|
{ value: "褐色", label: "褐色" },
|
||
|
{ value: "红色", label: "红色" },
|
||
|
{ value: "小鹿色", label: "小鹿色" },
|
||
|
{ value: "纯色", label: "纯色" },
|
||
|
{ value: "渐层色", label: "渐层色" },
|
||
|
{ value: "烟色", label: "烟色" },
|
||
|
{ value: "补丁", label: "补丁" },
|
||
|
{ value: "蓝虎斑", label: "蓝虎斑" },
|
||
|
{ value: "凯米尔虎斑", label: "凯米尔虎斑" },
|
||
|
{ value: "虎斑加白", label: "虎斑加白" },
|
||
|
{ value: "渐层加白", label: "渐层加白" },
|
||
|
{ value: "烟色加白", label: "烟色加白" },
|
||
|
{ value: "双色", label: "双色" },
|
||
|
{ value: "杂色", label: "杂色" },
|
||
|
{ value: "金吉拉银色", label: "金吉拉银色" },
|
||
|
{ value: "金吉拉金色", label: "金吉拉金色" },
|
||
|
{ value: "重点色加白", label: "重点色加白" },
|
||
|
{ value: "渐层重点色", label: "渐层重点色" },
|
||
|
{ value: "貂色", label: "貂色" },
|
||
|
{ value: "香槟色", label: "香槟色" },
|
||
|
{ value: "铂色", label: "铂色" },
|
||
|
{ value: "海豹山猫双色", label: "海豹山猫双色" },
|
||
|
{ value: "蓝山猫双色", label: "蓝山猫双色" },
|
||
|
{ value: "其他双色", label: "其他双色" },
|
||
|
{ value: "重点双色", label: "重点双色" },
|
||
|
{ value: "巧克力重点色", label: "巧克力重点色" },
|
||
|
{ value: "海豹重点色", label: "海豹重点色" },
|
||
|
{ value: "蓝重点色", label: "蓝重点色" },
|
||
|
{ value: "丁香重点色", label: "丁香重点色" },
|
||
|
{ value: "金色", label: "金色" },
|
||
|
{ value: "浅三花色", label: "浅三花色" },
|
||
|
{ value: "鱼骨纹色", label: "鱼骨纹色" },
|
||
|
{ value: "混合色", label: "混合色" },
|
||
|
{ value: "橙褐色", label: "橙褐色" },
|
||
|
{ value: "柏色", label: "柏色" },
|
||
|
{ value: "布伦海姆色", label: "布伦海姆色" },
|
||
|
{ value: "纯红色", label: "纯红色" },
|
||
|
{ value: "橙色", label: "橙色" },
|
||
|
{ value: "紫色", label: "紫色" },
|
||
|
{ value: "淡灰色", label: "淡灰色" },
|
||
|
{ value: "黄色", label: "黄色" },
|
||
|
{ value: "浅红色", label: "浅红色" },
|
||
|
{ value: "野猪色", label: "野猪色" },
|
||
|
{ value: "巧克力色", label: "巧克力色" },
|
||
|
{ value: "黑铁灰色", label: "黑铁灰色" },
|
||
|
{ value: "盐与胡椒色", label: "盐与胡椒色" },
|
||
|
{ value: "红褐色", label: "红褐色" },
|
||
|
{ value: "黑褐色", label: "黑褐色" },
|
||
|
{ value: "花斑色", label: "花斑色" },
|
||
|
{ value: "马斑色", label: "马斑色" },
|
||
|
{ value: "灰褐色", label: "灰褐色" },
|
||
|
{ value: "银灰色", label: "银灰色" },
|
||
|
{ value: "椒盐色", label: "椒盐色" },
|
||
|
{ value: "金黄色", label: "金黄色" },
|
||
|
{ value: "桃红色", label: "桃红色" },
|
||
|
{ value: "火烈鸟红色", label: "火烈鸟红色" },
|
||
|
{ value: "麦色", label: "麦色" },
|
||
|
{ value: "浅黄褐色", label: "浅黄褐色" },
|
||
|
{ value: "浅黄色", label: "浅黄色" },
|
||
|
{ value: "浅米色", label: "浅米色" },
|
||
|
{ value: "灰黄色", label: "灰黄色" },
|
||
|
{ value: "黄褐色", label: "黄褐色" },
|
||
|
{ value: "杏色", label: "杏色" },
|
||
|
{ value: "沙色", label: "沙色" },
|
||
|
{ value: "沙褐色", label: "沙褐色" },
|
||
|
{ value: "蓝灰色", label: "蓝灰色" },
|
||
|
{ value: "浅麦色", label: "浅麦色" },
|
||
|
{ value: "黑银色", label: "黑银色" },
|
||
|
{ value: "棕褐色", label: "棕褐色" },
|
||
|
{ value: "淡棕色", label: "淡棕色" },
|
||
|
{ value: "赤褐色", label: "赤褐色" },
|
||
|
{ value: "浅棕色", label: "浅棕色" },
|
||
|
{ value: "浅巧克力色", label: "浅巧克力色" },
|
||
|
{ value: "深棕色", label: "深棕色" },
|
||
|
{ value: "灰白色", label: "灰白色" },
|
||
|
{ value: "柠檬色", label: "柠檬色" },
|
||
|
{ value: "浅褐色", label: "浅褐色" },
|
||
|
{ value: "深红褐色", label: "深红褐色" },
|
||
|
{ value: "斑点色", label: "斑点色" },
|
||
|
{ value: "虎斑色", label: "虎斑色" },
|
||
|
{ value: "淡黄色", label: "淡黄色" },
|
||
|
{ value: "粉红色", label: "粉红色" },
|
||
|
{ value: "深灰色", label: "深灰色" },
|
||
|
{ value: "黑棕色", label: "黑棕色" },
|
||
|
{ value: "铁锈色", label: "铁锈色" },
|
||
|
{ value: "棕红色", label: "棕红色" },
|
||
|
{ value: "深红色", label: "深红色" },
|
||
|
{ value: "深褐色", label: "深褐色" },
|
||
|
{ value: "奶油色", label: "奶油色" },
|
||
|
{ value: "鹿皮色", label: "鹿皮色" },
|
||
|
{ value: "橙黄色", label: "橙黄色" }
|
||
|
]);
|
||
|
common_vendor.onLoad((options) => __async(this, null, function* () {
|
||
|
if (options && options.id) {
|
||
|
petId.value = options.id;
|
||
|
yield fetchPetData(petId.value);
|
||
|
}
|
||
|
}));
|
||
|
const fetchPetData = (id) => __async(this, null, function* () {
|
||
|
const response = yield utils_http.httpGet(`/petInfo/find_by_id/${id}`);
|
||
|
if (response.code === 200) {
|
||
|
const petData = response.data;
|
||
|
petName.value = petData.name || "";
|
||
|
petBirthday.value = petData.age || "";
|
||
|
gender.value = petData.sex === 1 ? "男孩" : "女孩";
|
||
|
petBreed.value = petData.breed || "";
|
||
|
petColor.value = petData.hairColor || "";
|
||
|
imageSrc.value = utils_commUtils.baseUrl + petData.profileUrl || "https://via.placeholder.com/150";
|
||
|
userId.value = petData.userId || "-1";
|
||
|
} else {
|
||
|
common_vendor.index.showToast({ title: "获取宠物信息失败", icon: "" });
|
||
|
}
|
||
|
});
|
||
|
const chooseImage = () => {
|
||
|
common_vendor.index.chooseImage({
|
||
|
count: 1,
|
||
|
success: (res) => {
|
||
|
imageSrc.value = res.tempFilePaths[0];
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
const onBirthdayChange = (e) => {
|
||
|
petBirthday.value = e.detail.value;
|
||
|
};
|
||
|
const createPetProfile = () => {
|
||
|
const formData = {
|
||
|
id: petId.value || void 0,
|
||
|
name: petName.value,
|
||
|
age: petBirthday.value + " 00:00:00",
|
||
|
sex: gender.value === "男孩" ? 1 : 0,
|
||
|
breed: petBreed.value,
|
||
|
hairColor: petColor.value
|
||
|
};
|
||
|
if (petId.value) {
|
||
|
formData.userId = userId.value;
|
||
|
}
|
||
|
const url = petId.value ? "/petInfo/update" : "/petInfo/addPet";
|
||
|
imageSrc.value.startsWith("http");
|
||
|
common_vendor.index.uploadFile({
|
||
|
url,
|
||
|
filePath: imageSrc.value,
|
||
|
name: "file",
|
||
|
formData,
|
||
|
header: {
|
||
|
satoken: `Bearer ${userStore.token}`
|
||
|
// 添加认证头部
|
||
|
},
|
||
|
success: (uploadRes) => {
|
||
|
const data = JSON.parse(uploadRes.data);
|
||
|
if (data.code === 200) {
|
||
|
common_vendor.index.showToast({ title: petId.value ? "更新成功" : "创建成功", icon: "success" });
|
||
|
resetForm();
|
||
|
common_vendor.index.navigateBack();
|
||
|
} else {
|
||
|
common_vendor.index.showToast({ title: data.message, icon: "none" });
|
||
|
}
|
||
|
},
|
||
|
fail: (e) => {
|
||
|
console.log(e);
|
||
|
common_vendor.index.showToast({ title: "上传失败", icon: "none" });
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
const deletePet = () => {
|
||
|
common_vendor.index.showModal({
|
||
|
title: "确认删除",
|
||
|
content: "你确定要删除这个宠物档案吗?",
|
||
|
success: (res) => {
|
||
|
if (res.confirm) {
|
||
|
utils_http.httpPost("/petInfo/delete", { id: petId.value }).then(() => {
|
||
|
common_vendor.index.showToast({ title: "删除成功", icon: "success" });
|
||
|
common_vendor.index.navigateBack();
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
};
|
||
|
const resetForm = () => {
|
||
|
petName.value = "";
|
||
|
petBirthday.value = "";
|
||
|
gender.value = "";
|
||
|
petBreed.value = "";
|
||
|
petColor.value = "";
|
||
|
imageSrc.value = "https://via.placeholder.com/150";
|
||
|
};
|
||
|
return (_ctx, _cache) => {
|
||
|
return common_vendor.e({
|
||
|
a: common_vendor.o(imageLoadError),
|
||
|
b: common_vendor.p({
|
||
|
round: true,
|
||
|
src: imageSrc.value,
|
||
|
mode: "aspectFill"
|
||
|
}),
|
||
|
c: common_vendor.o(chooseImage),
|
||
|
d: common_vendor.p({
|
||
|
name: "add",
|
||
|
color: "#ffc107"
|
||
|
}),
|
||
|
e: petName.value,
|
||
|
f: common_vendor.o(($event) => petName.value = $event.detail.value),
|
||
|
g: common_vendor.t(petBirthday.value || "请选择生日"),
|
||
|
h: petBirthday.value,
|
||
|
i: common_vendor.o(onBirthdayChange),
|
||
|
j: common_vendor.n(gender.value === "男孩" ? "bg-blue-500 text-white" : "bg-gray-200"),
|
||
|
k: common_vendor.o(($event) => gender.value = "男孩"),
|
||
|
l: common_vendor.n(gender.value === "女孩" ? "bg-pink-500 text-white" : "bg-gray-200"),
|
||
|
m: common_vendor.o(($event) => gender.value = "女孩"),
|
||
|
n: common_vendor.o(($event) => petBreed.value = $event),
|
||
|
o: common_vendor.p({
|
||
|
columns: breedOptions.value,
|
||
|
modelValue: petBreed.value
|
||
|
}),
|
||
|
p: common_vendor.o(($event) => petColor.value = $event),
|
||
|
q: common_vendor.p({
|
||
|
columns: colorOptions.value,
|
||
|
modelValue: petColor.value
|
||
|
}),
|
||
|
r: common_vendor.t(petId.value ? "更新电子身份证" : "创建电子身份证"),
|
||
|
s: common_vendor.o(createPetProfile),
|
||
|
t: petId.value
|
||
|
}, petId.value ? {
|
||
|
v: common_vendor.o(deletePet)
|
||
|
} : {});
|
||
|
};
|
||
|
}
|
||
|
};
|
||
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-f52f65e4"]]);
|
||
|
wx.createPage(MiniProgramPage);
|
||
|
//# sourceMappingURL=pet-add-page.js.map
|