Browse Source

fix: 新增消耗金币分配问题,传adminId问题 汇率页面传adminId问题

lihui/feature-20250623144029-金币前端lihui
lihui 16 hours ago
parent
commit
a610f59f26
  1. 151
      src/views/consume/addCoinConsume.vue
  2. 10
      src/views/managerecharge/rate.vue

151
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,13 +92,46 @@ const getAdminData = async function () {
}
};
//
function validateInput() {
const sumGold = parseFloat(addConsume.value.sumGold);
trimJwCode();
if (user.value.jwcode == null) {
ElMessage.error("请先查询用户信息");
addConsume.value.sumGold = null;
return false;
}
//
if (user.value.jwcode && (isNaN(sumGold) || sumGold <= 0)) {
ElMessage.error("消费金币总数必须是大于0的数字");
// sumGoldnull
addConsume.value.sumGold = null;
return false;
}
//
const totalAvailableGold = (user.value.nowSumGold)
if (user.value.jwcode && sumGold > totalAvailableGold) {
ElMessage.error("消费金币总数超过可用金币总和");
// sumGoldnull
addConsume.value.sumGold = null;
return false;
}
return true;
}
//
function calculateCoins(sumGold) {
const {nowFreeGold, nowPermanentGold, nowTaskGold} = user.value;
if (user.value.jwcode) {
if (sumGold <= 0) return {free: 0, permanent: 0, task: 0};
console.log("消耗金币计算函数:计算金币", sumGold);
const parsedSumGold = parseFloat(sumGold);
if (isNaN(parsedSumGold) || parsedSumGold <= 0 || !user.value.jwcode) {
return {free: 0, permanent: 0, task: 0};
}
let remaining = sumGold;
const {nowFreeGold, nowPermanentGold, nowTaskGold} = user.value;
let remaining = parsedSumGold;
let freeUsed = 0, permanentUsed = 0, taskUsed = 0;
//
@ -122,46 +151,12 @@ function calculateCoins(sumGold) {
taskUsed = remaining;
}
return {free: freeUsed, permanent: permanentUsed, task: taskUsed};
}
//
return {free: 0, permanent: 0, task: 0};
}
//
addConsume.value.freeGold = freeUsed;
addConsume.value.permanentGold = permanentUsed;
addConsume.value.taskGold = taskUsed;
//
function validateInput() {
const sumGold = addConsume.value.sumGold;
trimJwCode();
trimJwCode();
if (user.value.jwcode == null) {
ElMessage.error("请先查询用户信息");
addConsume.value.sumGold = null;
}
//
if (user.value.jwcode && sumGold <= 0) {
ElMessage.error("消费金币总数必须大于0");
// sunGoldnull
addConsume.value.sumGold = null;
return false;
}
//
const totalAvailableGold = user.value.nowSumGold
console.log("可用金币总和", totalAvailableGold);
console.log("可用金币总和", sumGold);
if (user.value.jwcode && sumGold > totalAvailableGold) {
ElMessage.error("消费金币总数超过可用金币总和");
// sunGoldnull
addConsume.value.sumGold = null;
return false;
}
return true;
return {free: freeUsed, permanent: permanentUsed, task: taskUsed};
}
//
@ -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,11 +425,10 @@ 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">
@ -444,7 +437,7 @@ onMounted(async function () {
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'"> -->

10
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 () {
</p>
</el-form-item>
<el-form-item label="提交人:">
<el-input disabled :value="adminData.name" style="width: 240px"/>
<el-input disabled :value="adminData.adminName" style="width: 240px"/>
</el-form-item>
<el-form-item>
<div class="dialog-footer">

Loading…
Cancel
Save