feat: rebuild pet app and backend around core care flows
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
const { secure, toast } = require("../../utils/api");
|
||||
Page({
|
||||
data: {
|
||||
pets: [],
|
||||
selected: [],
|
||||
title: "",
|
||||
description: "",
|
||||
place_name: "",
|
||||
latitude: 0,
|
||||
longitude: 0,
|
||||
date: "",
|
||||
time: "",
|
||||
max_people: 8,
|
||||
},
|
||||
onLoad() {
|
||||
this.load();
|
||||
},
|
||||
async load() {
|
||||
try {
|
||||
this.setData({ pets: await secure("/pets") });
|
||||
} catch (e) {
|
||||
toast(e);
|
||||
}
|
||||
},
|
||||
field(e) {
|
||||
this.setData({ [e.currentTarget.dataset.key]: e.detail.value });
|
||||
},
|
||||
pick(e) {
|
||||
this.setData({ selected: e.detail.selected });
|
||||
},
|
||||
date(e) {
|
||||
this.setData({ date: e.detail.value });
|
||||
},
|
||||
time(e) {
|
||||
this.setData({ time: e.detail.value });
|
||||
},
|
||||
async location() {
|
||||
try {
|
||||
const r = await wx.chooseLocation();
|
||||
this.setData({
|
||||
place_name: r.name || r.address,
|
||||
latitude: r.latitude,
|
||||
longitude: r.longitude,
|
||||
});
|
||||
} catch (e) {
|
||||
toast(e);
|
||||
}
|
||||
},
|
||||
async save() {
|
||||
const d = this.data;
|
||||
if (
|
||||
!d.title.trim() ||
|
||||
!d.place_name ||
|
||||
!d.date ||
|
||||
!d.time ||
|
||||
!d.selected.length
|
||||
) {
|
||||
wx.showToast({ title: "请填完时间地点并选择狗狗", icon: "none" });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await secure("/meetups", "POST", {
|
||||
title: d.title,
|
||||
description: d.description,
|
||||
place_name: d.place_name,
|
||||
latitude: d.latitude,
|
||||
longitude: d.longitude,
|
||||
starts_at: new Date(d.date + "T" + d.time + ":00+08:00").toISOString(),
|
||||
max_people: Number(d.max_people),
|
||||
pet_ids: d.selected,
|
||||
});
|
||||
wx.navigateBack();
|
||||
} catch (e) {
|
||||
toast(e);
|
||||
}
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user