48 lines
870 B
JavaScript
48 lines
870 B
JavaScript
import request from "@/utils/request"
|
||
Page({
|
||
data: {
|
||
detail: {
|
||
overview: {},
|
||
tasks: [{}, {}, {}],
|
||
},
|
||
loading: true,
|
||
},
|
||
|
||
onLoad() {
|
||
this.init()
|
||
},
|
||
|
||
onShow() {
|
||
this.getTabBar((tabBar) => {
|
||
tabBar.setData({
|
||
selected: '首页',
|
||
})
|
||
})
|
||
},
|
||
|
||
async init() {
|
||
let res = await request.get("/home")
|
||
this.setData({
|
||
detail: res,
|
||
loading: false,
|
||
})
|
||
},
|
||
//手动标记是否完成
|
||
handDone(e) {
|
||
const { data } = e.currentTarget.dataset;
|
||
const newTasks = this.data.detail.tasks.map(v => {
|
||
if (v.task_id == data.task_id) {
|
||
// 如果当前是 1 则变为 0,如果是 0 则变为 1
|
||
return { ...v, is_completed: v.is_completed == 1 ? 0 : 1 };
|
||
}
|
||
return v;
|
||
});
|
||
request.post("/home/task-record", {
|
||
...data,
|
||
is_completed: data.is_completed == 1 ? 0 : 1
|
||
})
|
||
this.setData({
|
||
'detail.tasks': newTasks
|
||
});
|
||
}
|
||
}) |