237 lines
9.1 KiB
JavaScript
237 lines
9.1 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");
|
|
require("../../../store/index.js");
|
|
const service_auth = require("../../../service/auth.js");
|
|
const store_user = require("../../../store/user.js");
|
|
if (!Array) {
|
|
const _component_layout_default_uni = common_vendor.resolveComponent("layout-default-uni");
|
|
_component_layout_default_uni();
|
|
}
|
|
if (!Math) {
|
|
Map();
|
|
}
|
|
const Map = () => "../../../components/Map.js";
|
|
const _sfc_main = {
|
|
__name: "door",
|
|
setup(__props) {
|
|
let incrementInterval = null;
|
|
const serviceId = common_vendor.ref(null);
|
|
const isEditMode = common_vendor.ref(!!serviceId.value);
|
|
const serviceName = common_vendor.ref("");
|
|
const serviceTypes = common_vendor.ref(["宠物看护", "宠物洗澡", "宠物训练", "宠物寄养"]);
|
|
const selectedServiceType = common_vendor.ref(0);
|
|
const serviceDescription = common_vendor.ref("");
|
|
const servicePrice = common_vendor.ref(0);
|
|
const serviceLocation = common_vendor.ref("");
|
|
const serviceState = common_vendor.ref(true);
|
|
const uploadedImages = common_vendor.ref([]);
|
|
const loadmap = common_vendor.ref(true);
|
|
const location = common_vendor.ref({});
|
|
const mapDetail = common_vendor.ref({});
|
|
const userStore = store_user.useUserStore();
|
|
common_vendor.onLoad((options) => __async(this, null, function* () {
|
|
if (options.id) {
|
|
serviceId.value = options.id;
|
|
yield fetchServiceData();
|
|
}
|
|
}));
|
|
common_vendor.onShow(() => __async(this, null, function* () {
|
|
yield auth();
|
|
}));
|
|
const serviceTypesChange = (value) => {
|
|
const index = value.detail.value;
|
|
selectedServiceType.value = index;
|
|
};
|
|
const auth = () => __async(this, null, function* () {
|
|
if (!userStore.userInfo.isRealName) {
|
|
utils_commUtils.toast("您还未实名认证,请先实名认证!");
|
|
try {
|
|
const res = yield service_auth.isBindPhone();
|
|
if (res.code != 200 || !res.data) {
|
|
utils_commUtils.toast("您手机号还未绑定!");
|
|
common_vendor.index.navigateTo({ url: "/modules/pet/permission/bind-phone" });
|
|
return;
|
|
}
|
|
} catch (e) {
|
|
console.log("手机号发送验证信息失败:", e);
|
|
}
|
|
utils_commUtils.toast("请先实名认证!");
|
|
common_vendor.index.navigateTo({ url: "/modules/pet/permission/real-name-auth" });
|
|
return;
|
|
}
|
|
if (!userStore.userInfo.isPetNursery) {
|
|
utils_commUtils.toPath("/modules/pet/certification/index");
|
|
return;
|
|
}
|
|
});
|
|
const doneFun = (md) => {
|
|
loadmap.value = false;
|
|
mapDetail.value = md;
|
|
serviceLocation.value = mapDetail.value.formatted_address;
|
|
location.value = mapDetail.value.location;
|
|
};
|
|
const fetchServiceData = () => __async(this, null, function* () {
|
|
try {
|
|
const response = yield utils_http.httpPost("/personal-service/get", { id: serviceId.value });
|
|
if (response.code == 200) {
|
|
const service = response.data;
|
|
serviceName.value = service.serviceName;
|
|
selectedServiceType.value = serviceTypes.value.indexOf(service.type);
|
|
serviceDescription.value = service.description;
|
|
servicePrice.value = service.price;
|
|
serviceLocation.value = service.serviceHost;
|
|
serviceState.value = service.state === 1;
|
|
uploadedImages.value = [service.url];
|
|
location.value = {
|
|
latitude: service.latitude,
|
|
longitude: service.longitude,
|
|
address: service.address
|
|
};
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.showToast({ title: "获取服务数据失败", icon: "none" });
|
|
console.error("Error fetching service data:", error);
|
|
}
|
|
});
|
|
const incrementPrice = (increment) => {
|
|
servicePrice.value = Math.max(servicePrice.value + increment, 0);
|
|
};
|
|
const startIncrement = (isIncrement) => {
|
|
incrementInterval = setInterval(() => {
|
|
incrementPrice(isIncrement ? 10 : -10);
|
|
}, 200);
|
|
};
|
|
const stopIncrement = () => {
|
|
clearInterval(incrementInterval);
|
|
};
|
|
const switchChange = (e) => {
|
|
serviceState.value = e.value;
|
|
};
|
|
const chooseImage = () => {
|
|
common_vendor.index.chooseImage({
|
|
count: 1,
|
|
success: (res) => __async(this, null, function* () {
|
|
for (const filePath of res.tempFilePaths) {
|
|
const uploadedUrl = yield uploadImage(filePath);
|
|
if (uploadedUrl) {
|
|
uploadedImages.value.pop();
|
|
uploadedImages.value.push(uploadedUrl);
|
|
}
|
|
}
|
|
}),
|
|
fail: () => {
|
|
common_vendor.index.showToast({ title: "图片选择失败", icon: "none" });
|
|
}
|
|
});
|
|
};
|
|
const uploadImage = (filePath) => __async(this, null, function* () {
|
|
try {
|
|
const uploadResult = yield utils_http.httpUploadFile("/file/upload", filePath);
|
|
if (uploadResult && uploadResult.data && uploadResult.data.url) {
|
|
return uploadResult.data.url;
|
|
} else {
|
|
common_vendor.index.showToast({ title: "图片上传失败", icon: "none" });
|
|
return "";
|
|
}
|
|
} catch (error) {
|
|
common_vendor.index.showToast({ title: "图片上传失败", icon: "none" });
|
|
return "";
|
|
}
|
|
});
|
|
const submitService = () => {
|
|
const district = mapDetail.value.addressComponent.district;
|
|
const serviceData = {
|
|
id: serviceId.value,
|
|
serviceName: serviceName.value,
|
|
type: serviceTypes.value[selectedServiceType.value],
|
|
description: serviceDescription.value,
|
|
price: servicePrice.value,
|
|
serviceHost: serviceLocation.value,
|
|
state: serviceState.value ? 1 : 0,
|
|
url: uploadedImages.value[0],
|
|
address: serviceLocation.value,
|
|
latitude: `${location.value.latitude}`,
|
|
longitude: `${location.value.longitude}`,
|
|
country: mapDetail.value.addressComponent.country,
|
|
province: mapDetail.value.addressComponent.province,
|
|
city: mapDetail.value.addressComponent.city,
|
|
district: district.length > 0 ? district : "市直辖",
|
|
township: mapDetail.value.addressComponent.township,
|
|
streetNumber: mapDetail.value.addressComponent.streetNumber.street + mapDetail.value.addressComponent.streetNumber.number
|
|
};
|
|
const endpoint = isEditMode.value ? "/personal-service/update" : "/personal-service/push";
|
|
utils_http.httpPost(endpoint, serviceData).then((response) => {
|
|
if (response.code === 200) {
|
|
common_vendor.index.showToast({ title: isEditMode.value ? "更新成功" : "发布成功", icon: "success" });
|
|
utils_commUtils.toPath(-1);
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: isEditMode.value ? "更新失败" : "发布失败:" + response.msg,
|
|
icon: "none"
|
|
});
|
|
}
|
|
});
|
|
};
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: serviceName.value,
|
|
b: common_vendor.o(($event) => serviceName.value = $event.detail.value),
|
|
c: common_vendor.t(serviceTypes.value[selectedServiceType.value]),
|
|
d: serviceTypes.value,
|
|
e: common_vendor.o(serviceTypesChange),
|
|
f: serviceDescription.value,
|
|
g: common_vendor.o(($event) => serviceDescription.value = $event.detail.value),
|
|
h: common_vendor.o(($event) => startIncrement(false)),
|
|
i: common_vendor.o(stopIncrement),
|
|
j: common_vendor.o(($event) => incrementPrice(1)),
|
|
k: servicePrice.value,
|
|
l: common_vendor.o(($event) => servicePrice.value = $event.detail.value),
|
|
m: common_vendor.o(($event) => startIncrement(true)),
|
|
n: common_vendor.o(stopIncrement),
|
|
o: common_vendor.o(($event) => incrementPrice(1)),
|
|
p: common_vendor.t(serviceLocation.value),
|
|
q: loadmap.value,
|
|
r: common_vendor.o(doneFun),
|
|
s: serviceState.value,
|
|
t: common_vendor.o(switchChange),
|
|
v: common_vendor.o(chooseImage),
|
|
w: uploadedImages.value.length > 0
|
|
}, uploadedImages.value.length > 0 ? {
|
|
x: common_vendor.f(uploadedImages.value, (image, index, i0) => {
|
|
return {
|
|
a: index,
|
|
b: image
|
|
};
|
|
})
|
|
} : {}, {
|
|
y: common_vendor.t(isEditMode.value ? "更新服务" : "发布上门服务"),
|
|
z: common_vendor.o(submitService)
|
|
});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-07d2e2d0"]]);
|
|
wx.createPage(MiniProgramPage);
|