acdr-ui/dist/dev/mp-weixin/pages/push/door.js

224 lines
8.6 KiB
JavaScript
Raw Normal View History

2024-09-19 07:20:14 +08:00
"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("../../utils/map-utils.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 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: "/pages/permission/bind-phone" });
return;
}
} catch (e) {
console.log("手机号发送验证信息失败:", e);
}
utils_commUtils.toast("请先实名认证!");
common_vendor.index.navigateTo({ url: "/pages/permission/real-name-auth" });
return;
}
});
const doneFun = (mapDetail2) => {
loadmap.value = false;
mapDetail2.value = mapDetail2;
serviceLocation.value = mapDetail2.formatted_address;
};
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 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: location.value.address,
latitude: `${location.value.latitude}`,
longitude: `${location.value.longitude}`,
country: mapDetail.value.country,
province: mapDetail.value.province,
city: mapDetail.value.city,
district: mapDetail.value.district,
township: mapDetail.value.township,
streetNumber: mapDetail.value.streetNumber.street + mapDetail.value.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" });
} else {
common_vendor.index.showToast({ title: isEditMode.value ? "更新失败" : "发布失败", 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: serviceDescription.value,
f: common_vendor.o(($event) => serviceDescription.value = $event.detail.value),
g: common_vendor.o(($event) => startIncrement(false)),
h: common_vendor.o(stopIncrement),
i: common_vendor.o(($event) => incrementPrice(1)),
j: servicePrice.value,
k: common_vendor.o(($event) => servicePrice.value = $event.detail.value),
l: common_vendor.o(($event) => startIncrement(true)),
m: common_vendor.o(stopIncrement),
n: common_vendor.o(($event) => incrementPrice(1)),
o: common_vendor.t(serviceLocation.value),
p: loadmap.value,
q: common_vendor.o(doneFun),
r: serviceState.value,
s: common_vendor.o(switchChange),
t: common_vendor.o(chooseImage),
v: uploadedImages.value.length > 0
}, uploadedImages.value.length > 0 ? {
w: common_vendor.f(uploadedImages.value, (image, index, i0) => {
return {
a: index,
b: "url(" + common_vendor.unref(utils_commUtils.baseUrl) + image + ")"
};
})
} : {}, {
x: common_vendor.t(isEditMode.value ? "更新服务" : "发布上门服务"),
y: common_vendor.o(submitService)
});
};
}
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-74338421"]]);
wx.createPage(MiniProgramPage);
//# sourceMappingURL=door.js.map