From a610f59f2689293dc403dd1d9c66676b349eaf1b Mon Sep 17 00:00:00 2001 From: lihui Date: Fri, 4 Jul 2025 13:54:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=B0=E5=A2=9E=E6=B6=88=E8=80=97?= =?UTF-8?q?=E9=87=91=E5=B8=81=E5=88=86=E9=85=8D=E9=97=AE=E9=A2=98=EF=BC=8C?= =?UTF-8?q?=E4=BC=A0adminId=E9=97=AE=E9=A2=98=20=E6=B1=87=E7=8E=87?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=A0adminId=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/consume/addCoinConsume.vue | 159 +++++++++++++++++------------------ src/views/managerecharge/rate.vue | 10 +-- 2 files changed, 80 insertions(+), 89 deletions(-) diff --git a/src/views/consume/addCoinConsume.vue b/src/views/consume/addCoinConsume.vue index 3b4a05f..5a4cf90 100644 --- a/src/views/consume/addCoinConsume.vue +++ b/src/views/consume/addCoinConsume.vue @@ -4,7 +4,6 @@ import {ElMessage, ElMessageBox} from "element-plus"; import moment from "moment"; import request from "@/util/http"; - /* ====================工具方法============================== */ @@ -48,6 +47,7 @@ const user = ref({ nowFreeGold: null, nowSumGold: null }) + // 这是添加消费信息的表单(金币) const addConsume = ref({ // jwcode 是数字 @@ -59,7 +59,6 @@ const addConsume = ref({ taskGold: null, // 任务金币 remark: "",//备注 adminId: null,// 当前管理员id - }); // 表单验证 const Ref = ref(null); @@ -69,14 +68,11 @@ const rules = reactive({ goodsName: [{required: true, message: "请选择消费商品", trigger: "change"}], // 修改为 change sumGold: [ {required: true, message: "消费金币总数不能为空", trigger: "blur"}, - ], - }); // 查询商品的表单 const goods = ref([]); - /* ====================方法================================= */ @@ -87,8 +83,8 @@ const getAdminData = async function () { data: {}, }); adminData.value = result; - addConsume.value.adminId = adminData.value.adminId; - addConsume.value.name = adminData.value.name; + addConsume.value.adminId = adminData.value.id; + addConsume.value.name = adminData.value.adminName; console.log("请求成功", result); console.log("用户信息", adminData.value); } catch (error) { @@ -96,67 +92,29 @@ const getAdminData = async function () { } }; -// 消耗金币计算函数 -function calculateCoins(sumGold) { - const {nowFreeGold, nowPermanentGold, nowTaskGold} = user.value; - if (user.value.jwcode) { - if (sumGold <= 0) return {free: 0, permanent: 0, task: 0}; - - let remaining = sumGold; - let freeUsed = 0, permanentUsed = 0, taskUsed = 0; - - // 优先消耗免费金币 - if (nowFreeGold > 0) { - freeUsed = Math.min(nowFreeGold, remaining); - remaining -= freeUsed; - } - - // 其次消耗永久金币 - if (remaining > 0 && nowPermanentGold > 0) { - permanentUsed = Math.min(nowPermanentGold, remaining); - remaining -= permanentUsed; - } - - // 最后消耗任务金币 - if (remaining > 0 && nowTaskGold > 0) { - taskUsed = remaining; - } - - return {free: freeUsed, permanent: permanentUsed, task: taskUsed}; - - } - // 提示 - return {free: 0, permanent: 0, task: 0}; - -} - // 输入验证函数 function validateInput() { - const sumGold = addConsume.value.sumGold; - trimJwCode(); + const sumGold = parseFloat(addConsume.value.sumGold); trimJwCode(); if (user.value.jwcode == null) { ElMessage.error("请先查询用户信息"); addConsume.value.sumGold = null; + return false; } // 验证金币数值 - if (user.value.jwcode && sumGold <= 0) { - ElMessage.error("消费金币总数必须大于0"); - // 将sunGold设置为null + if (user.value.jwcode && (isNaN(sumGold) || sumGold <= 0)) { + ElMessage.error("消费金币总数必须是大于0的数字"); + // 将sumGold设置为null addConsume.value.sumGold = null; return false; } // 验证金币总和 - const totalAvailableGold = user.value.nowSumGold - - console.log("可用金币总和", totalAvailableGold); - console.log("可用金币总和", sumGold); - + const totalAvailableGold = (user.value.nowSumGold) if (user.value.jwcode && sumGold > totalAvailableGold) { ElMessage.error("消费金币总数超过可用金币总和"); - // 将sunGold设置为null + // 将sumGold设置为null addConsume.value.sumGold = null; return false; } @@ -164,6 +122,43 @@ function validateInput() { return true; } +// 消耗金币计算函数 +function calculateCoins(sumGold) { + console.log("消耗金币计算函数:计算金币", sumGold); + const parsedSumGold = parseFloat(sumGold); + if (isNaN(parsedSumGold) || parsedSumGold <= 0 || !user.value.jwcode) { + return {free: 0, permanent: 0, task: 0}; + } + + const {nowFreeGold, nowPermanentGold, nowTaskGold} = user.value; + let remaining = parsedSumGold; + let freeUsed = 0, permanentUsed = 0, taskUsed = 0; + + // 优先消耗免费金币 + if (nowFreeGold > 0) { + freeUsed = Math.min(nowFreeGold, remaining); + remaining -= freeUsed; + } + + // 其次消耗永久金币 + if (remaining > 0 && nowPermanentGold > 0) { + permanentUsed = Math.min(nowPermanentGold, remaining); + remaining -= permanentUsed; + } + + // 最后消耗任务金币 + if (remaining > 0 && nowTaskGold > 0) { + taskUsed = remaining; + } + + // 更新金币值 + addConsume.value.freeGold = freeUsed; + addConsume.value.permanentGold = permanentUsed; + addConsume.value.taskGold = taskUsed; + + return {free: freeUsed, permanent: permanentUsed, task: taskUsed}; +} + // 这是添加消费信息的接口 const add = async function () { try { @@ -182,11 +177,7 @@ const add = async function () { data: { ...addConsume.value, jwcode: addConsume.value.jwcode, - // adminId: addConsume.value.adminId, - // todo 一定要删除 换成上面的 - adminId: 1, - - + adminId: addConsume.value.adminId, sumGold: addConsume.value.sumGold * 100, freeGold: addConsume.value.freeGold * 100, taskGold: addConsume.value.taskGold * 100, @@ -194,7 +185,6 @@ const add = async function () { goodsName: addConsume.value.goodsName, remark: addConsume.value.remark } - }); console.log("add请求", result); @@ -255,8 +245,6 @@ function resetForm() { nowFreeGold: null, nowSumGold: null } - // user.value.jwcode = null; - // user.value = null; } // 添加前验证 @@ -297,12 +285,25 @@ const getUser = async function (jwcode) { }); console.log("请求成功", result); + if (result.code === 200) { + user.value = result.data; + user.value.nowPermanentGold = result.data.nowPermanentGold / 100; + user.value.nowFreeGold = result.data.nowFreeGold / 100; + user.value.nowSumGold = result.data.nowSumGold / 100; + user.value.nowTaskGold = result.data.nowTaskGold / 100; + user.value.nowFreeJune = (result.data.nowFreeJune) / 100; + user.value.nowFreeDecember = (result.data.nowFreeDecember) / 100; + + user.value.historySumGold = (result.data.historySumGold) / 100; + user.value.historyPermanentGold = (result.data.historyPermanentGold) / 100; + user.value.historyFreeGold = (result.data.historyFreeGold) / 100; + user.value.historyTaskGold = (result.data.historyTaskGold) / 100; + } if (result.code === 0) { ElMessage.error(result.msg); } else if (result.data === null) { ElMessage.error("用户不存在"); } else { - user.value = result.data; console.log("用户信息", user.value); ElMessage.success(result.msg); } @@ -327,10 +328,6 @@ const getGoods = async function () { label: item.name, value: item.name })); - - - // // 存储全部数据 - // goods.value = result.data; } catch (error) { console.log("请求失败", error); // 在这里可以处理错误逻辑,比如显示错误提示等 @@ -345,8 +342,9 @@ const getGoods = async function () { watch( () => addConsume.value.sumGold, (newValue) => { - if (newValue > 0) { - const {free, permanent, task} = calculateCoins(newValue); + const parsedNewValue = parseFloat(newValue); + if (!isNaN(parsedNewValue) && parsedNewValue > 0) { + const {free, permanent, task} = calculateCoins(parsedNewValue); addConsume.value.freeGold = free; addConsume.value.permanentGold = permanent; addConsume.value.taskGold = task; @@ -365,7 +363,6 @@ watch( onMounted(async function () { await getAdminData(); await getGoods(); - }); @@ -374,7 +371,6 @@ onMounted(async function () {
- @@ -388,8 +384,6 @@ onMounted(async function () { style="max-width: 750px;" class="form-style" > - - -
- +

@@ -484,7 +477,7 @@ onMounted(async function () { @@ -495,7 +488,6 @@ onMounted(async function () { 提交 - -

{{ user.historySumGold / 100 }}

+

{{ user.historySumGold }}

@@ -528,14 +520,14 @@ onMounted(async function () { style="color: #2fa1ff; margin-right: 5px" v-if="user.nowSumGold !== undefined" > - {{ user.nowSumGold / 100 }} (永久金币:{{ user.nowPermanentGold / 100 }};免费金币:{{ - (user.nowFreeGold) / 100 - }};任务金币:{{ user.nowTaskGold / 100 }}) + >(永久金币:{{ user.nowPermanentGold }};免费金币:{{ + (user.nowFreeGold) + }};任务金币:{{ user.nowTaskGold }})
@@ -569,7 +561,6 @@ onMounted(async function () {
- @@ -632,4 +623,4 @@ p { font-size: 13px; transform: scale(1); } - + \ No newline at end of file diff --git a/src/views/managerecharge/rate.vue b/src/views/managerecharge/rate.vue index a0c464d..2dcd191 100644 --- a/src/views/managerecharge/rate.vue +++ b/src/views/managerecharge/rate.vue @@ -13,8 +13,8 @@ import request from '@/util/http' // 查询当前登录的信息 const adminData = ref({ - adminId: '', - name: '' + id: '', + adminName: '' }) // 默认 编辑板块是关的 @@ -113,7 +113,7 @@ const getAdminData = async function () { data: {} }) adminData.value = result - rateEdit.value.adminId = adminData.value.adminId + rateEdit.value.adminId = adminData.value.id console.log('请求成功', result) } catch (error) { console.log('请求失败', error) @@ -183,7 +183,7 @@ const getEditData = async function (row) { rateEdit.value.rateName = row.rateName rateEdit.value.num = row.num console.log('根据id获取的数据', rateEdit.value) - rateEdit.value.adminId = adminData.value.adminId + rateEdit.value.adminId = adminData.value.id } catch (error) { console.log('请求失败', error) @@ -416,7 +416,7 @@ onMounted(async function () {

- +