|
|
@ -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(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
</script> |
|
|
@ -374,7 +371,6 @@ onMounted(async function () { |
|
|
|
|
|
|
|
<div> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 根据activeTab切换显示内容 --> |
|
|
|
<!-- 新增消耗的布局---------------------------------------------------------- --> |
|
|
|
<!-- <div v-if="activeTab === 'addConsume'"> --> |
|
|
@ -388,8 +384,6 @@ onMounted(async function () { |
|
|
|
style="max-width: 750px;" |
|
|
|
class="form-style" |
|
|
|
> |
|
|
|
<!-- todo 添加错误提示--> |
|
|
|
|
|
|
|
<el-form-item prop="jwcode" label="精网号"> |
|
|
|
|
|
|
|
<el-input |
|
|
@ -431,20 +425,19 @@ onMounted(async function () { |
|
|
|
v-model="addConsume.sumGold" |
|
|
|
style="width: 100px" |
|
|
|
@input="validateInput()" |
|
|
|
@change="calculateCoins()" |
|
|
|
@change="calculateCoins(addConsume.sumGold)" |
|
|
|
/> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 三类金币自动计算(禁用状态,不可编辑) --> |
|
|
|
<div style="display: flex; align-items: center"> |
|
|
|
<el-form-item prop="permanentGold" label="永久金币" style="float: left"> |
|
|
|
<el-input |
|
|
|
v-model="addConsume.permanentGold" |
|
|
|
v-model="addConsume.permanentGold" |
|
|
|
disabled |
|
|
|
style="width: 100px; margin-left: -5px" |
|
|
|
> |
|
|
|
<template #default="scope">{{ scope.row.permanentGold / 100 }}</template> |
|
|
|
<template #default="scope">{{ scope.row.permanentGold }}</template> |
|
|
|
</el-input> |
|
|
|
<p style="margin-right: 0px">个</p> |
|
|
|
</el-form-item> |
|
|
@ -484,7 +477,7 @@ onMounted(async function () { |
|
|
|
<el-form-item prop="commitName" label="提交人"> |
|
|
|
<el-input |
|
|
|
style="width: 300px" |
|
|
|
:value="adminData.name" |
|
|
|
:value="adminData.adminName" |
|
|
|
disabled |
|
|
|
placeholder="提交人姓名" |
|
|
|
/> |
|
|
@ -495,7 +488,6 @@ onMounted(async function () { |
|
|
|
<el-button type="primary" @click="addBefore"> 提交</el-button> |
|
|
|
</el-form> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 客户信息栏 --> |
|
|
|
<el-card v-if="user.jwcode" style="width: 850px; float: right" class="customer-info"> |
|
|
|
<el-form |
|
|
@ -513,7 +505,7 @@ onMounted(async function () { |
|
|
|
</el-col> |
|
|
|
<el-col :span="14"> |
|
|
|
<el-form-item label="历史金币总数"> |
|
|
|
<p>{{ user.historySumGold / 100 }}</p> |
|
|
|
<p>{{ user.historySumGold }}</p> |
|
|
|
|
|
|
|
</el-form-item> |
|
|
|
</el-col> |
|
|
@ -528,14 +520,14 @@ onMounted(async function () { |
|
|
|
style="color: #2fa1ff; margin-right: 5px" |
|
|
|
v-if="user.nowSumGold !== undefined" |
|
|
|
> |
|
|
|
{{ user.nowSumGold / 100 }}</span |
|
|
|
{{ user.nowSumGold }}</span |
|
|
|
> |
|
|
|
<span |
|
|
|
style="display: inline; white-space: nowrap; color: #b1b1b1" |
|
|
|
v-if="user.nowSumGold !== null " |
|
|
|
>(永久金币:{{ user.nowPermanentGold / 100 }};免费金币:{{ |
|
|
|
(user.nowFreeGold) / 100 |
|
|
|
}};任务金币:{{ user.nowTaskGold / 100 }})</span> |
|
|
|
>(永久金币:{{ user.nowPermanentGold }};免费金币:{{ |
|
|
|
(user.nowFreeGold) |
|
|
|
}};任务金币:{{ user.nowTaskGold }})</span> |
|
|
|
|
|
|
|
</el-form-item> |
|
|
|
</el-col> |
|
|
@ -569,7 +561,6 @@ onMounted(async function () { |
|
|
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<!-- 金币消耗明细的布局------------------------------------------------------- --> |
|
|
|
<!-- <div v-else-if="activeTab === 'detail'"> --> |
|
|
|
|
|
|
|