From bae599c1e28ad39094798898c235624d6f4dfbdf Mon Sep 17 00:00:00 2001 From: lihui Date: Sat, 28 Jun 2025 16:39:41 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=B6=88=E8=80=97?= =?UTF-8?q?=EF=BC=88=E5=AE=8C=E6=88=90=EF=BC=89=20=E6=B6=88=E8=80=97?= =?UTF-8?q?=E6=98=8E=E7=BB=86=EF=BC=88=E6=80=BB=E8=AE=A1=E9=87=91=E5=B8=81?= =?UTF-8?q?=E6=95=B0[=E5=90=8E=E7=AB=AF=E4=B8=8D=E8=83=BD=E7=AD=9B?= =?UTF-8?q?=E9=80=89]=EF=BC=89=20=E6=B1=87=E7=8E=87=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=EF=BC=88=E5=AE=8C=E6=88=90=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/consume/addCoinConsume.vue | 143 +++++++++++++++----------------- src/views/consume/coinConsumeDetail.vue | 90 ++++++++++++-------- 2 files changed, 121 insertions(+), 112 deletions(-) diff --git a/src/views/consume/addCoinConsume.vue b/src/views/consume/addCoinConsume.vue index 063615e..da0679c 100644 --- a/src/views/consume/addCoinConsume.vue +++ b/src/views/consume/addCoinConsume.vue @@ -5,8 +5,9 @@ import moment from "moment"; import request from "@/util/http"; - -/*====================工具方法==============================*/ +/* +====================工具方法============================== +*/ // 精网号去空格 const trimJwCode = () => { if (addConsume.value.jwcode) { @@ -23,35 +24,11 @@ const trimJwCode = () => { } } -// ====================数据================================= - -/*====================方法=================================*/ - -/*====================监听=================================*/ - -/*====================挂载=================================*/ - - - -//这是获取当前登录的用户信息的接口 +/* +====================数据================================= +*/ +//这是获取当前登录的用户信息 const adminData = ref({}); - -const getAdminData = async function () { - try {//await 暂停函数执行,直到请求完成 - const result = await request({ - url: "/admin/userinfo", - data: {}, - }); - adminData.value = result; - addConsume.value.adminId = adminData.value.adminId; - addConsume.value.name = adminData.value.name; - console.log("请求成功", result); - console.log("用户信息", adminData.value); - } catch (error) { - console.log("请求失败", error); - } -}; - // 通过精网号查询用户(客户)信息 表单 const user = ref({ jwcode: null, @@ -71,12 +48,11 @@ const user = ref({ nowFreeGold: null, nowSumGold: null }) - // 这是添加消费信息的表单(金币) const addConsume = ref({ // jwcode 是数字 jwcode: null, //精网号 - goodsName: "",// 商品名称 // todo 之后会用3楼的接口 已改用 + goodsName: "",// 商品名称 sumGold: null, // 消费金币总数 freeGold: null, // 免费金币 permanentGold: null, // 永久金币 @@ -85,6 +61,40 @@ const addConsume = ref({ adminId: null,// 当前管理员id }); +// 表单验证 +const Ref = ref(null); +// 表单验证规则 +const rules = reactive({ + jwcode: [{required: true, message: "请输入精网号", trigger: "blur"}], + goodsName: [{required: true, message: "请选择消费商品", trigger: "change"}], // 修改为 change + sumGold: [ + {required: true, message: "消费金币总数不能为空", trigger: "blur"}, + + ], + +}); +// 查询商品的表单 +const goods = ref([]); + + +/* +====================方法================================= +*/ +const getAdminData = async function () { + try {//await 暂停函数执行,直到请求完成 + const result = await request({ + url: "/admin/userinfo", + data: {}, + }); + adminData.value = result; + addConsume.value.adminId = adminData.value.adminId; + addConsume.value.name = adminData.value.name; + console.log("请求成功", result); + console.log("用户信息", adminData.value); + } catch (error) { + console.log("请求失败", error); + } +}; // 消耗金币计算函数 function calculateCoins(sumGold) { @@ -119,24 +129,6 @@ function calculateCoins(sumGold) { return {free: 0, permanent: 0, task: 0}; } - -// 监听消费总金额变化,自动计算三类金币 -watch( - () => addConsume.value.sumGold, - (newValue) => { - if (newValue > 0) { - const {free, permanent, task} = calculateCoins(newValue); - addConsume.value.freeGold = free; - addConsume.value.permanentGold = permanent; - addConsume.value.taskGold = task; - } else { - addConsume.value.freeGold = null; - addConsume.value.permanentGold = null; - addConsume.value.taskGold = null; - } - } -); - // 输入验证函数 function validateInput() { const sumGold = addConsume.value.sumGold; @@ -170,8 +162,6 @@ function validateInput() { return true; } - - // 这是添加消费信息的接口 const add = async function () { try { @@ -201,7 +191,6 @@ const add = async function () { ElMessage.error("添加失败,请检查网络连接或联系管理员"); } }; - // 响应处理函数 function handleResponse(result) { console.log("响应结果", result) @@ -212,7 +201,6 @@ function handleResponse(result) { ElMessage.error(result.msg || "添加失败,未知错误"); } } - // 重置表单函数 function resetForm() { // 清空表单数据 @@ -251,7 +239,7 @@ function resetForm() { // user.value.jwcode = null; // user.value = null; } - +// 添加前验证 const addBefore = () => { Ref.value.validate(async (valid) => { if (valid) { @@ -274,22 +262,6 @@ const addBefore = () => { } }); }; - -// 表单验证 -// 开始时间改变时,重新验证结束时间 -const Ref = ref(null); - -const rules = reactive({ - jwcode: [{required: true, message: "请输入精网号", trigger: "blur"}], - goodsName: [{required: true, message: "请选择消费商品", trigger: "change"}], // 修改为 change - sumGold: [ - {required: true, message: "消费金币总数不能为空", trigger: "blur"}, - - ], - - -}); - // 查询客户信息(通过精网号) const getUser = async function (jwcode) { trimJwCode(); @@ -320,10 +292,7 @@ const getUser = async function (jwcode) { // 在这里可以处理错误逻辑,比如显示错误提示等 } }; - -// 查询商品的接口 -const goods = ref([]); - +// 获取商品信息(三楼接口) const getGoods = async function () { try { // 发送POST请求 @@ -348,7 +317,30 @@ const getGoods = async function () { } }; +/* +====================监听================================= +*/ + +// 监听消费总金额变化,自动计算三类金币 +watch( + () => addConsume.value.sumGold, + (newValue) => { + if (newValue > 0) { + const {free, permanent, task} = calculateCoins(newValue); + addConsume.value.freeGold = free; + addConsume.value.permanentGold = permanent; + addConsume.value.taskGold = task; + } else { + addConsume.value.freeGold = null; + addConsume.value.permanentGold = null; + addConsume.value.taskGold = null; + } + } +); +/* +====================挂载================================= +*/ // 挂载 onMounted(async function () { await getAdminData(); @@ -356,7 +348,6 @@ onMounted(async function () { }); -