Skip to content

Commit

Permalink
-2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
QlQlqiqi committed Oct 9, 2021
1 parent a0204df commit c643691
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
65 changes: 51 additions & 14 deletions src/pages/add-self-list/add-self-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,31 @@ Component({
});
this.handleBack();
},
// 询问是否删除
handleShowDialog(e) {
if(!this.data.readyTitle) {
this.handleBack();
return;
}
this.setData({
Dialogshow: true,
});
},
// dialog buttons
async handleDeleteButtons(e) {
let index = e.detail.index;
if(index === 1) {
this.setData({
Dialogshow: false,
});
await this.handleDelete();
}
else {
this.setData({
Dialogshow: false,
});
}
},
// 删除清单
handleDelete: async function () {
// 如果是新建清单,直接返回上一个页面
Expand All @@ -109,22 +134,34 @@ Component({
title: "正在保存数据...",
mask: true,
});
let { owner, token } = await util.getTokenAndOwner(app.globalData.url + "login/login/");
let urlSql, res = [];
for(let list of lists) {
if(list.title === this.data.readyTitle) {
urlSql = list.urlSql;
continue;
let readyTitle = this.data.readyTitle;
let tasks = [],
listsRemain = [],
tasksSave = [],
listDelete = null;
for (let list of lists)
list.title === readyTitle
? (listDelete = list)
: listsRemain.push(list);
for (let task of JSON.parse(wx.getStorageSync('tasks'))) {
if (task.list.title === readyTitle) {
task.list = {
icon: "/src/image/menu-self-list0.svg",
title: "个人清单",
};
tasksSave.push(task);
}
res.push(list);
tasks.push(task);
}
let { owner, token } = await util.getTokenAndOwner(app.globalData.url + "login/login/");
await store.saveTasksToSql(tasksSave, listsRemain, { owner, token });
await util.myRequest({
url: urlSql,
header: {Authorization: 'Token ' + token},
method: 'DELETE'
})
.then(res => console.log(res));
wx.setStorageSync('lists', JSON.stringify(res));
url: listDelete.urlSql,
header: { Authorization: "Token " + token },
method: "DELETE",
});
wx.setStorageSync("tasks", JSON.stringify(tasks));
wx.setStorageSync("lists", JSON.stringify(listsRemain));
wx.hideLoading({
success: () => {
wx.showToast({
Expand All @@ -136,7 +173,7 @@ Component({
this.handleBack();

},
dialogClose: function () {
handleDialogClose: function () {
this.setData({
show: false,
});
Expand Down
9 changes: 7 additions & 2 deletions src/pages/add-self-list/add-self-list.wxml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@
></input>
<view class="cancel" bind:tap="handleBack">取消</view>
<view class="ensure" bind:tap="handleEnsure">确定</view>
<view class="delete" bind:tap="handleDelete">删除</view>
<view class="delete" bind:tap="handleShowDialog">删除</view>
<mp-dialog mask="{{ true }}" mask-closable="{{ false }}" show="{{ show }}" title="提示"
buttons="{{ [{text: '确定'}] }}" bind:buttontap="dialogClose"
buttons="{{ [{text: '确定'}] }}" bind:buttontap="handleDialogClose"
>
输入不得为空
</mp-dialog>
<mp-dialog mask="{{ true }}" mask-closable="{{ false }}" show="{{ Dialogshow }}" title="提示"
buttons="{{ [{text: '取消'}, {text: '确定'}] }}" bind:buttontap="handleDeleteButtons"
>
是否删除清单「{{ readyTitle }}」?(清单内任务自动进入「个人清单」内)
</mp-dialog>

0 comments on commit c643691

Please sign in to comment.