diff --git a/src/api/gift.js b/src/api/gift.js index e17e8e9..e18f469 100644 --- a/src/api/gift.js +++ b/src/api/gift.js @@ -57,6 +57,14 @@ export function updateGiftList(data) { }) } +export function resetGiftList(data) { + return request({ + url: '/games/gift/list', + method: 'patch', + data, + }) +} + export function delGiftList(data) { return request({ url: '/games/gift/list', diff --git a/src/views/games/details/gift.vue b/src/views/games/details/gift.vue index fab86e9..2e9fe90 100644 --- a/src/views/games/details/gift.vue +++ b/src/views/games/details/gift.vue @@ -133,6 +133,17 @@ > 格式:物品id-数量, 使用回车分隔 + + + 删除 + + 还原 + @@ -243,6 +262,7 @@ import { getGiftList, addGiftList, updateGiftList, + resetGiftList, delGiftList, getGifts, } from '@/api/gift' @@ -429,8 +449,6 @@ export default { giftList.numList[arr[0]] = arr[1] }) - console.log(giftList) - if (giftList._id) { // 更新 const self = this @@ -444,13 +462,14 @@ export default { condition: giftList.condition, list: giftList.itemsId, numList: giftList.numList, + usedList: giftList.usedList, }) .then(res => { const data = res.data if (data.errcode === 0) { this.$message.success('物品兑换列表修改成功!') this.$refs[`giftList${index}`][0].clearValidate() - // this.getGiftList() + this.getGiftList() } }) .catch(err => { @@ -469,13 +488,14 @@ export default { condition: giftList.condition, list: giftList.itemsId, numList: giftList.numList, + usedList: giftList.usedList, }) .then(res => { const data = res.data if (data.errcode === 0) { this.$message.success('兑换物品列表新增成功!') this.$refs[`giftList${index}`][0].clearValidate() - // this.getGiftList() + this.getGiftList() } }) .catch(err => { @@ -486,6 +506,35 @@ export default { this.$message.error('请按要求填写表单!') } }, + async resetGiftList(index) { + this.$confirm('是否要还原兑换物品的使用量?', '提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning', + }) + .then(() => { + const giftList = JSON.parse(JSON.stringify(this.allGiftList[index])) + resetGiftList({ + uid: this.uid, + _id: giftList._id, + usedList: {}, + }) + .then(res => { + const data = res.data + if (data.errcode === 0) { + this.$message.success('物品使用数量已还原!') + this.getGiftList() + } + }) + .catch(err => { + console.log(err) + }) + }) + .catch(() => { + this.$message.info('已取消还原!') + }) + }, + validForm(formName) { return new Promise((resolve, reject) => { this.$refs[formName][0].validate(valid => {