diff --git a/vue/gold-system/src/views/consume/addConsume.vue b/vue/gold-system/src/views/consume/addConsume.vue index 5b1119c..637222b 100644 --- a/vue/gold-system/src/views/consume/addConsume.vue +++ b/vue/gold-system/src/views/consume/addConsume.vue @@ -6,14 +6,19 @@ import { Plus } from "@element-plus/icons-vue"; import axios from "axios"; import { ElMessageBox } from "element-plus"; -// 这是添加充值信息的表单 -const addConsume = ref({}); -// 这是添加充值信息的接口 +// 这是添加消费信息的表单 +const addConsume = ref({ + freeCoin: 0, + rechargeCoin: 0, + taskCoin: 0, + updateType: "消费", +}); +// 这是添加消费信息的接口 const add = async function () { try { // 发送POST请求 const result = await axios.post( - "http://192.168.8.93:10010/recharge/recharge/add", + "http://192.168.8.147:10030/consume/add", addConsume.value ); @@ -59,7 +64,7 @@ const checkEndTime = function (rule, value, callback) { }; const rules = reactive({ jwcode: [{ required: true, message: "请输入精网号", trigger: "blur" }], - refundGoods: [{ required: true, message: "请选择退款商品", trigger: "blur" }], + goods: [{ required: true, message: "请选择消费商品", trigger: "blur" }], taskCoin: [{ required: true, message: "请输入任务金币", trigger: "blur" }], freeCoin: [{ required: true, message: "请输入免费金币", trigger: "blur" }], rechargeCoin: [ @@ -94,97 +99,70 @@ const getUser = async function (jwcode) { } }; -// 这是查询活动的接口 -const activity = ref([]); -const getActivity = async function () { +// 查询商品的接口 +const goods = ref([]); +const getGoods = async function () { try { // 发送POST请求 - const result = await axios.post( - "http://192.168.8.93:10010/recharge/activity/select", - {} - ); - + const result = await axios.post("http://192.168.8.93:10020/product", {}); // 将响应结果存储到响应式数据中 console.log("请求成功", result); - // 存储表格数据 - activity.value = result.data.data; - console.log("活动信息", activity.value); + // 存储全部数据 + goods.value = result.data.data; + console.log("allData", allData.value); + console.log("地区", area.value); } catch (error) { console.log("请求失败", error); // 在这里可以处理错误逻辑,比如显示错误提示等 } }; -getActivity(); +getGoods(); -// 这是查询货币的接口 -const currency = ref([]); -const getCurrency = async function () { +//这是查询用户金币信息的接口 +const userGold = ref({}); +const getUserGold = async function (jwcode) { try { - // 发送POST请求 const result = await axios.post( - "http://192.168.8.174:10010/rates/search", - {} + "http://192.168.8.147:10070/statistics/getMess/" + jwcode ); - - // 将响应结果存储到响应式数据中 - console.log("货币请求成功", result); - // 存储表格数据 - currency.value = result.data.data; - console.log("tableData", currency.value); - // 在这里可以根据需求进一步处理成功后的逻辑,比如更新UI显示成功消息等 + console.log("请求成功", result); + // 存储全部数据 + userGold.value = result.data.data; + console.log("userGold", userGold.value); } catch (error) { console.log("请求失败", error); - // 在这里可以处理错误逻辑,比如显示错误提示等 } }; -getCurrency(); -// 这是添加上传图片的接口 -const imageUrl = ref(""); +function calculateCoins() { + // 保存原始的allGold值 + const originalAllGold = addConsume.value.allGold; -// 上传图片成功的回调函数 -const handleAvatarSuccess = (response, uploadFile) => { - imageUrl.value = URL.createObjectURL(uploadFile.raw); - console.log("图片上传成功", response, uploadFile); - addConsume.value.rechargeVoucher = - "http://192.168.8.93:10010/upload/" + response.data; - console.log("图片名称", addConsume.value.rechargeVoucher); -}; -// 上传图片之前的校验函数 -const beforeAvatarUpload = (rawFile) => { - if (rawFile.type !== "image/jpeg") { - ElMessage.error("Avatar picture must be JPG format!"); - return false; - } else if (rawFile.size / 1024 / 1024 > 2) { - ElMessage.error("Avatar picture size can not exceed 2MB!"); - return false; - } - return true; -}; + // 确保todayTask和todayFree是有效的数字 + const todayTask = + typeof userGold.value.todayTask === "number" ? userGold.value.todayTask : 0; + const todayFree = + typeof userGold.value.todayFree === "number" ? userGold.value.todayFree : 0; -//充值方式条目 -const options = [ - { - value: "现金充值", - label: "现金充值", - }, - { - value: "龙鳞卡", - label: "龙鳞卡", - }, - { - value: "弘粉卡", - label: "弘粉卡", - }, -]; + // 根据用户输入的消费金币总数和已有的金币数量进行计算 + addConsume.value.taskCoin = Math.min(originalAllGold, todayTask); + let remainingGold = originalAllGold - addConsume.value.taskCoin; -const calculatedFreeGold = computed(() => { - return addConsume.value.paidGold * addConsume.value.activityId; -}); + addConsume.value.freeCoin = Math.min(remainingGold, todayFree); + remainingGold -= addConsume.value.freeCoin; -watch(calculatedFreeGold, (newVal) => { - addConsume.value.freeGold = newVal; -}); + addConsume.value.rechargeCoin = remainingGold; // 剩余的都算作充值金币 + + // 恢复allGold的原始值 + addConsume.value.allGold = originalAllGold; + + // 确保taskCoin, freeCoin, rechargeCoin不是NaN,如果是,则设置为0 + if (isNaN(addConsume.value.taskCoin)) addConsume.value.taskCoin = 0; + if (isNaN(addConsume.value.freeCoin)) addConsume.value.freeCoin = 0; + if (isNaN(addConsume.value.rechargeCoin)) addConsume.value.rechargeCoin = 0; + + console.log("计算结果", addConsume.value); +}