86 lines
1.7 KiB
TypeScript
86 lines
1.7 KiB
TypeScript
// pages/main/travel/luggage/index.ts
|
|
|
|
import { LuggageItem } from "..";
|
|
import config from "../../../../config/index"
|
|
|
|
interface ILuggageData {
|
|
name: string;
|
|
value: LuggageItem[];
|
|
keyboardHeight: number;
|
|
addValue: string;
|
|
}
|
|
|
|
Page({
|
|
data: <ILuggageData>{
|
|
name: "",
|
|
value: [],
|
|
keyboardHeight: 0,
|
|
addValue: ""
|
|
},
|
|
onLoad() {
|
|
wx.onKeyboardHeightChange(res => {
|
|
this.setData({
|
|
keyboardHeight: res.height
|
|
})
|
|
})
|
|
},
|
|
onShow() {
|
|
const store = wx.getStorageSync("luggage");
|
|
const value = store.luggage[store.name];
|
|
this.setData({
|
|
value,
|
|
name: store.name === "gao" ? "小糕" : "夜雨"
|
|
});
|
|
},
|
|
doBack() {
|
|
const store = wx.getStorageSync("luggage");
|
|
store.luggage[store.name] = this.data.value;
|
|
wx.request({
|
|
url: `${config.url}/journal/travel/luggage/update`,
|
|
method: "POST",
|
|
header: {
|
|
Key: wx.getStorageSync("key")
|
|
},
|
|
data: store.luggage,
|
|
success: () => {
|
|
wx.navigateBack();
|
|
}
|
|
});
|
|
},
|
|
onTapItem(e: WechatMiniprogram.BaseEvent) {
|
|
const index = e.currentTarget.dataset.index;
|
|
this.data.value[index].isTaken = !this.data.value[index].isTaken;
|
|
this.setData({ value: this.data.value });
|
|
},
|
|
showMenu(e: WechatMiniprogram.BaseEvent) {
|
|
const index = e.currentTarget.dataset.index;
|
|
wx.showActionSheet({
|
|
itemList: ["删除"],
|
|
itemColor: "red",
|
|
success: () => {
|
|
this.data.value.splice(index, 1);
|
|
this.setData({ value: this.data.value })
|
|
}
|
|
});
|
|
},
|
|
onInputFocus() {
|
|
this.setData({
|
|
keyboardHeight: this.data.keyboardHeight
|
|
})
|
|
},
|
|
onInputBlur() {
|
|
this.setData({
|
|
keyboardHeight: 0
|
|
})
|
|
},
|
|
add() {
|
|
this.data.value.push({
|
|
name: this.data.addValue,
|
|
isTaken: false
|
|
})
|
|
this.setData({
|
|
value: this.data.value,
|
|
addValue: ""
|
|
})
|
|
}
|
|
}) |