From 245d11576adfe9431cb6e9853d0bbd155370fdb7 Mon Sep 17 00:00:00 2001
From: hongxilin <17663930442@163.com>
Date: Fri, 3 Jan 2025 18:37:55 +0800
Subject: [PATCH 1/3] =?UTF-8?q?1.3=E6=97=A5=E4=BF=AE=E6=94=B9=E8=A7=81?=
=?UTF-8?q?=E6=97=A5=E6=8A=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
vue/gold-system/src/views/recharge/addRecharge.vue | 313 +++++++++++----------
vue/gold-system/src/views/usergold/index.vue | 7 +
2 files changed, 177 insertions(+), 143 deletions(-)
diff --git a/vue/gold-system/src/views/recharge/addRecharge.vue b/vue/gold-system/src/views/recharge/addRecharge.vue
index c827f00..eefe256 100644
--- a/vue/gold-system/src/views/recharge/addRecharge.vue
+++ b/vue/gold-system/src/views/recharge/addRecharge.vue
@@ -8,7 +8,8 @@ import API from "../../api/index.js";
import moment from "moment";
import { range, re } from "mathjs";
import * as xlsx from 'xlsx';
-import _ from 'lodash';
+import _, { before } from 'lodash';
+import { th } from "element-plus/es/locales.mjs";
// 这是添加上传图片的接口
const imageUrl = ref("");
@@ -281,6 +282,7 @@ const deleteRecharge = function () {
// 批量充值
// jwcode列表
const jwcodeList = ref([]);
+let jwcodeSet;
// 获取jwcode列表
const getJwcodeList = async function () {
try {
@@ -294,16 +296,34 @@ const getJwcodeList = async function () {
console.log("请求成功", result);
// 存储表格数据
jwcodeList.value = result.data;
- jwcodeList.value = jwcodeList.value.map((item) => ({
- value: item,
- label: item,
- }));
console.log("精网号", jwcodeList.value);
+ // 将数组转换为set
+ jwcodeSet = new Set(jwcodeList.value);
+ console.log("精网号set", jwcodeSet);
} catch (error) {
console.log("请求失败", error);
// 在这里可以处理错误逻辑,比如显示错误提示等
}
};
+
+// 校验精网号
+// 精网号错误对象
+const errorCount = ref(0);
+// 校验规则
+const validateInput = function (row, index) {
+ console.log(jwcodeSet.has(row.jwcode), "has");
+ if (!jwcodeSet.has(row.jwcode) && row.jwcode != '' && row.jwcode != null) {
+ row.isInputInvalid = true;
+ row.inputErrorMessage = '精网号不存在';
+ errorCount.value++;
+ return;
+ } else {
+ row.isInputInvalid = false;
+ row.inputErrorMessage = '';
+ errorCount.value--;
+ }
+}
+
// 批量充值弹窗
const batchRechargeVisible = ref(false);
const jwcodeSelectRef = ref(null);
@@ -316,6 +336,11 @@ const batchData = ref([
{
line: 1,
showInput: true,
+ isInputInvalid: false,
+ inputErrorMessage: '',
+ freeGold: "0",
+ rechargeGold: "0",
+ paidGold: "0",
},
]);
@@ -332,52 +357,6 @@ const batchInit = function () {
openBatchRechargeVisible();
};
-// 提取添加滚动监听的逻辑到单独函数
-const addScrollListener = () => {
- const SELECTWRAP_DOM = document.querySelector(
- ".el-select-dropdown .el-select-dropdown__wrap"
- );
- if (SELECTWRAP_DOM) {
- SELECTWRAP_DOM.addEventListener("scroll", function () {
- const condition = this.scrollHeight - this.scrollTop <= this.clientHeight;
- if (condition) binding.value();
- });
- }
-};
-// 局部注册指令
-const vJwcodeLoadmore = {
- mounted(el, binding) {
- nextTick(() => {
- console.log("el===", el, "binding===", binding);
- const SELECTWRAP_DOM = el.querySelector(
- ".el-select-dropdown .el-select-dropdown__wrap"
- );
- console.log("SELECTWRAP_DOM===", SELECTWRAP_DOM);
- if (SELECTWRAP_DOM) {
- SELECTWRAP_DOM.addEventListener("scroll", function () {
- /**
- * scrollHeight 获取元素内容高度(只读)
- * scrollTop 获取或者设置元素的偏移值,
- * 常用于:计算滚动条的位置, 当一个元素的容器没有产生垂直方向的滚动条, 那它的scrollTop的值默认为0.
- * clientHeight 读取元素的可见高度(只读)
- * 如果元素滚动到底, 下面等式返回true, 没有则返回false:
- * ele.scrollHeight - ele.scrollTop === ele.clientHeight;
- */
- const condition =
- this.scrollHeight - this.scrollTop <= this.clientHeight;
- if (condition) binding.value();
- });
- }
- });
- },
-};
-// 下拉框打开时调用添加滚动监听函数
-// const jwcodeSelectScrollerListener = () => {
-// console.log(jwcodeSelectRef.value, 'jwcodeSelectRef.value')
-// if (jwcodeSelectRef.value) {
-// directives.loadmore(jwcodeSelectRef.value, loadMore(rangeNumber.value));
-// }
-// };
// 添加行数对象
const addLineObj = ref(0);
//添加一行
@@ -385,6 +364,11 @@ const addLine = function () {
batchData.value.unshift({
line: ++i.value,
showInput: true,
+ isInputInvalid: false,
+ inputErrorMessage: '',
+ freeGold: "0",
+ rechargeGold: "0",
+ paidGold: "0",
});
};
const loading = ref(false);
@@ -403,36 +387,34 @@ const loading = ref(false);
// ElMessage.error("添加失败");
// }
// }
+
+// 添加多行点击按钮
const addLines = async function () {
try {
- loading.value = true; // 操作开始前,将loading设为true,显示加载动画
- await nextTick(); // 等待视图更新,确保加载动画能及时显示出来
+ // loading.value = true; // 操作开始前,将loading设为true,显示加载动画
+ // console.log(loading.value, "loading.value");
- const addLinesPromises = [];
- for (let j = 0; j < addLineObj.value; j++) {
- addLinesPromises.push(
- new Promise((resolve) => {
- batchData.value.unshift({
- line: ++i.value,
- showInput: true,
- });
- resolve();
- })
- );
- }
- await Promise.all(addLinesPromises);
+ const newItems = Array.from({ length: addLineObj.value }, (_, index) => reactive({
+ line: ++i.value,
+ showInput: true,
+ isInputInvalid: false,
+ inputErrorMessage: '',
+ freeGold: "0",
+ rechargeGold: "0",
+ paidGold: "0",
+ }));
+ batchData.value = [...newItems, ...batchData.value];
- // 所有数据添加操作完成后,准备关闭加载动画
- await nextTick(); // 再次等待视图更新,确保数据添加操作引起的视图变化已完成
- loading.value = false; // 将loading设为false,关闭加载动画
ElMessage.success("添加成功");
+ // loading.value = false; // 将loading设为false,关闭加载动画
} catch (error) {
console.log("添加失败", error);
ElMessage.error("添加失败");
// 如果出现异常,也要确保关闭加载动画
- loading.value = false;
+ // loading.value = false;
}
};
+
// 导入excel按钮的ref
const uploadRefMap = ref({});
// 获取excel数据
@@ -634,79 +616,105 @@ const handleBatchAvatarSuccess = (response, uploadFile) => {
};
//批量充值确认按钮
const batchAdd = async function () {
- console.log("batchData===", batchData.value);
- let msg = '';
- if (batchData.value.length == 0) {
- ElMessage({
- type: "error",
- message: "至少需要输入一条数据!",
- });
- return;
- }
- for (let i = 0; i < batchData.value.length; i++) {
- batchData.value[i].adminId = adminData.value.adminId;
- batchData.value[i].area = adminData.value.area;
- batchData.value[i].rechargeWay = "客服充值";
- if (
- batchData.value[i].jwcode == "" ||
- batchData.value[i].jwcode == null) {
- msg += `精网号不能为空!
`;
- }
- if (
- batchData.value[i].activityId == "" ||
- batchData.value[i].activityId == null) {
- msg += `活动不能为空!
`;
- }
- if (
- batchData.value[i].paidGold == "" ||
- batchData.value[i].paidGold == null) {
- msg += `充值金币不能为空!
`;
+ try {
+ console.log("batchData===", batchData.value);
+ let msg = '';
+ if (batchData.value.length == 0) {
+ ElMessage({
+ type: "error",
+ message: "至少需要输入一条数据!",
+ });
+ return;
}
- if (
- batchData.value[i].rechargeGold == "" ||
- batchData.value[i].rechargeGold == null) {
- msg += `充值金额不能为空!
`;
+ if (errorCount.value > 0) {
+ console.log("errorCount.value", errorCount.value);
+ ElMessage({
+ type: "error",
+ message: "请检查输入的精网号是否正确!",
+ });
+ return;
}
- if (
- batchData.value[i].payWay == "" ||
- batchData.value[i].payWay == null) {
- msg += `收款方式不能为空!
`;
+ for (let i = 0; i < batchData.value.length; i++) {
+ batchData.value[i].adminId = adminData.value.adminId;
+ batchData.value[i].area = adminData.value.area;
+ batchData.value[i].rechargeWay = "客服充值";
+ if (
+ batchData.value[i].jwcode == "" ||
+ batchData.value[i].jwcode == null) {
+ msg += `精网号不能为空!
`;
+ }
+ if (
+ batchData.value[i].activityId == "" ||
+ batchData.value[i].activityId == null) {
+ msg += `活动不能为空!
`;
+ }
+ if (
+ batchData.value[i].paidGold == "" ||
+ batchData.value[i].paidGold == null) {
+ msg += `充值金币不能为空!
`;
+ }
+ if (
+ batchData.value[i].freeGold == "" ||
+ batchData.value[i].freeGold == null) {
+ msg += `免费金币不能为空!
`;
+ }
+ if (
+ batchData.value[i].rechargeGold == "" ||
+ batchData.value[i].rechargeGold == null) {
+ msg += `充值金额不能为空!
`;
+ }
+ if (
+ batchData.value[i].payWay == "" ||
+ batchData.value[i].payWay == null) {
+ msg += `收款方式不能为空!
`;
+ }
+ if (
+ batchData.value[i].rechargeTime == "" ||
+ batchData.value[i].rechargeTime == null) {
+ msg += `交款时间不能为空!
`;
+ }
+ if (msg != '' && msg != null) {
+ console.log(batchData.value[i]);
+ ElMessage({
+ dangerouslyUseHTMLString: true,
+ type: "error",
+ message: msg,
+ });
+ return;
+ }
}
- if (
- batchData.value[i].rechargeTime == "" ||
- batchData.value[i].rechargeTime == null) {
- msg += `交款时间不能为空!
`;
+ console.log("batchData::", batchData.value);
+
+ const result = await API.post(
+ "http://192.168.8.93:10010/recharge/recharge/addmore",
+ { ...batchData.value }
+ );
+
+ if (result.code === 0) {
+ ElMessage.error("添加失败");
+ return;
}
+
ElMessage({
- dangerouslyUseHTMLString: true,
- type: "error",
- message: msg,
+ type: "success",
+ message: "添加成功!",
});
- return;
- }
- console.log("batchData===", batchData.value);
- const result = await API.post(
- "http://192.168.8.93:10010/recharge/recharge/addmore",
- { ...batchData.value }
- );
-
- if (result.code === 0) {
+ closeBatchRechargeVisible();
+ } catch (error) {
+ console.log("error===", error);
ElMessage.error("添加失败");
return;
- }
-
- ElMessage({
- type: "success",
- message: "添加成功!",
- });
-
- closeBatchRechargeVisible();
-};
+ };
+}
// 使用 _.throttle 并设置 trailing 为 false 实现严格节流,只执行一次
-const throttledBatchAdd = _.throttle(batchAdd, 5000, { trailing: false });
+const throttledBatchAdd = _.throttle(batchAdd, 2000, { trailing: false });
// 批量设置的对象
-const batchSettingObj = ref({});
+const batchSettingObj = ref({
+ rechargeGold: "0",
+ paidGold: "0",
+ freeGold: "0",
+});
// 批量充值弹窗
const batchSettingVisible = ref(false);
// 打开批量充值弹窗
@@ -730,7 +738,11 @@ const batchSettingHandleAvatarSuccess = (response, uploadFile) => {
};
// 批量设置取消按钮
const cancelBatchSetting = function () {
- batchSettingObj.value = {};
+ batchSettingObj.value = {
+ rechargeGold: "0",
+ paidGold: "0",
+ freeGold: "0",
+ };
closeBatchSettingVisible();
};
// 批量设置确认按钮
@@ -804,7 +816,11 @@ const batchSettingConfirm = function () {
batchData.value[i].remark = batchSettingObj.value.remark;
}
}
- batchSettingObj.value = {};
+ batchSettingObj.value = {
+ rechargeGold: "0",
+ paidGold: "0",
+ freeGold: "0",
+ };
closeBatchSettingVisible();
};
@@ -949,9 +965,9 @@ onMounted(async function () {
个
免费金币
@@ -946,7 +946,7 @@ onMounted(async function () { {{ user.buyJb + user.free6 + user.free12 + user.coreJb }} - (充值金币:{{ user.buyJb + (永久金币:{{ user.buyJb }};免费金币:{{ user.free6 + user.free12 }};任务金币:{{ user.coreJb }}) @@ -1041,7 +1041,7 @@ onMounted(async function () { {{ scope.row.activityName }} -