金币系统前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

484 lines
14 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <script setup>
  2. import { reactive } from "vue";
  3. import { ref, computed, watch } from "vue";
  4. import { ElMessage } from "element-plus";
  5. import { Plus } from "@element-plus/icons-vue";
  6. import axios from "axios";
  7. import { ElMessageBox } from "element-plus";
  8. import API from "../../api/index.js";
  9. import moment from "moment";
  10. import _ from 'lodash';
  11. //这是获取用户信息的接口
  12. const adminData = ref({});
  13. const getAdminData = async function () {
  14. try {
  15. const result = await API.post(
  16. "/hwjb/admin/userinfo",
  17. {}
  18. );
  19. adminData.value = result;
  20. addConsume.value.adminId = adminData.value.adminId;
  21. addConsume.value.name = adminData.value.name;
  22. console.log("请求成功", result);
  23. console.log("用户信息", adminData.value);
  24. } catch (error) {
  25. console.log("请求失败", error);
  26. }
  27. };
  28. getAdminData();
  29. // 这是添加消费信息的表单
  30. const addConsume = ref({
  31. freeCoin: 0,
  32. rechargeCoin: 0,
  33. taskCoin: 0,
  34. updateType: "1",
  35. });
  36. // 这是添加消费信息的接口
  37. const add = async function () {
  38. try {
  39. // 发送POST请求
  40. const result = await API.post(
  41. "/hwjb/consume/add",
  42. addConsume.value
  43. );
  44. if (result.code === 0) {
  45. ElMessage.error(result.msg);
  46. return;
  47. } else {
  48. ElMessage.success("添加成功");
  49. }
  50. //重置表单
  51. addConsume.value = {};
  52. addConsume.value.adminId = adminData.value.adminId;
  53. addConsume.value.adminName = adminData.value.adminName;
  54. addConsume.value.updateType = "1";
  55. addConsume.value.freeCoin = 0;
  56. addConsume.value.rechargeCoin = 0;
  57. addConsume.value.taskCoin = 0;
  58. console.log("请求成功", result);
  59. user.value = {};
  60. } catch (error) {
  61. console.log("请求失败", error);
  62. ElMessage.error("添加失败,请检查输入内容是否正确");
  63. // 在这里可以处理错误逻辑,比如显示错误提示等
  64. }
  65. };
  66. const addBefore = () => {
  67. Ref.value.validate(async (valid) => {
  68. if (valid) {
  69. ElMessageBox.confirm("确认添加?")
  70. .then(() => {
  71. addConsume.value.freeCoin = Number(-addConsume.value.freeCoin);
  72. addConsume.value.rechargeCoin = Number(
  73. -addConsume.value.rechargeCoin
  74. );
  75. addConsume.value.taskCoin = Number(-addConsume.value.taskCoin);
  76. add();
  77. console.log("添加成功");
  78. imageUrl.value = "";
  79. addConsume.value = {};
  80. })
  81. .catch(() => {
  82. console.log("取消添加");
  83. });
  84. } else {
  85. //提示
  86. ElMessage({
  87. type: "error",
  88. message: "请检查输入内容",
  89. });
  90. }
  91. });
  92. };
  93. // 表单验证
  94. // 开始时间改变时,重新验证结束时间
  95. const Ref = ref(null);
  96. const checkEndTime = function (rule, value, callback) {
  97. if (value <= new Date()) {
  98. callback(new Error("付款时间不能小于当前时间"));
  99. }
  100. };
  101. const checkFreeGoldRadio = function (rule, value, callback) {
  102. if (value == "0" || value == null || value == "") {
  103. callback(new Error("请输入消费金币总数"));
  104. } else if (value < 0 || isNaN(value)) {
  105. callback(new Error("请输入正确的格式"));
  106. } else {
  107. callback();
  108. }
  109. };
  110. const rules = reactive({
  111. jwcode: [{ required: true, message: "请输入精网号", trigger: "blur" }],
  112. productId: [{ required: true, message: "请选择消费商品", trigger: "blur" }],
  113. taskCoin: [{ required: true, message: "请输入任务金币", trigger: "blur" }],
  114. freeCoin: [{ required: true, message: "请输入免费金币", trigger: "blur" }],
  115. rechargeCoin: [
  116. { required: true, message: "请输入免费金币", trigger: "blur" },
  117. ],
  118. allGold: [{ validator: checkFreeGoldRadio, trigger: "blur" }],
  119. });
  120. //这是重置方法
  121. const delteConsume = function () {
  122. addConsume.value = {};
  123. addConsume.value.adminId = adminData.value.adminId;
  124. addConsume.value.adminName = adminData.value.adminName;
  125. addConsume.value.updateType = "1";
  126. addConsume.value.freeCoin = 0;
  127. addConsume.value.rechargeCoin = 0;
  128. addConsume.value.taskCoin = 0;
  129. };
  130. // 查找客户信息的方法
  131. const user = ref({
  132. firstRechargeTime: "",
  133. });
  134. const getUser = async function (jwcode) {
  135. try {
  136. // 发送POST请求
  137. const result = await API.post("/hwjb/recharge/user", {
  138. jwcode: jwcode,
  139. });
  140. console.log("请求成功", result);
  141. user.value = result.data;
  142. console.log("用户a信息aaaaaaaaaaa", user.value);
  143. user.value.A =
  144. Number(user.value.pendingRechargeTimes) +
  145. Number(user.value.pendingSpendTimes);
  146. console.log("用户信息", user.value);
  147. console.log("用户信息", user.value.firstRechargeDate);
  148. if (result.data.code === 0) {
  149. ElMessage.error(result.msg);
  150. } else {
  151. ElMessage.success(result.msg);
  152. }
  153. } catch (error) {
  154. console.log("请求失败", error);
  155. ElMessage.error("查询失败,请检查精网号是否正确");
  156. // 在这里可以处理错误逻辑,比如显示错误提示等
  157. }
  158. };
  159. // 查询商品的接口
  160. const goods = ref([]);
  161. const getGoods = async function () {
  162. try {
  163. // 发送POST请求
  164. const result = await API.post("/hwjb/product", {});
  165. // 将响应结果存储到响应式数据中
  166. console.log("请求成功", result);
  167. // 存储全部数据
  168. goods.value = result.data;
  169. console.log("allData", allData.value);
  170. console.log("地区", area.value);
  171. } catch (error) {
  172. console.log("请求失败", error);
  173. // 在这里可以处理错误逻辑,比如显示错误提示等
  174. }
  175. };
  176. getGoods();
  177. //这是查询用户金币信息的接口
  178. const userGold = ref({});
  179. const getUserGold = async function (jwcode) {
  180. try {
  181. // 发送POST请求
  182. const result = await API.post("/hwjb/recharge/user", {
  183. jwcode: jwcode,
  184. });
  185. // 将响应结果存储到响应式数据中
  186. console.log("请求成功", result);
  187. // 存储表格数据
  188. userGold.value = result.data;
  189. addConsume.value.username = result.data.name;
  190. addConsume.value.area = result.data.area;
  191. if (result.data.code === 0) {
  192. ElMessage.error("查询失败,请检查精网号是否正确");
  193. }
  194. } catch (error) {
  195. console.log("请求失败", error);
  196. ElMessage.error("无此精网号");
  197. addConsume.value.jwcode = "";
  198. // 在这里可以处理错误逻辑,比如显示错误提示等
  199. }
  200. };
  201. function calculateCoins() {
  202. if (
  203. userGold.value.coreJb +
  204. userGold.value.free6 +
  205. userGold.value.free12 +
  206. userGold.value.buyJb <
  207. addConsume.value.allGold
  208. ) {
  209. addConsume.value.allGold = 0;
  210. addConsume.value.taskCoin = 0;
  211. addConsume.value.freeCoin = 0;
  212. addConsume.value.rechargeCoin = 0;
  213. ElMessage.error("金币不足,请充值");
  214. return;
  215. } else {
  216. // 保存原始的allGold值
  217. const originalAllGold = addConsume.value.allGold;
  218. // 确保todayTask和todayFree是有效的数字
  219. const todayTask =
  220. typeof userGold.value.coreJb === "number" ? userGold.value.coreJb : 0;
  221. const todayFree =
  222. typeof (userGold.value.free6 + userGold.value.free12) === "number"
  223. ? userGold.value.free6 + userGold.value.free12
  224. : 0;
  225. // 根据用户输入的消费金币总数和已有的金币数量进行计算
  226. addConsume.value.taskCoin = Math.min(originalAllGold, todayTask);
  227. let remainingGold = originalAllGold - addConsume.value.taskCoin;
  228. addConsume.value.freeCoin = Math.min(remainingGold, todayFree);
  229. remainingGold -= addConsume.value.freeCoin;
  230. addConsume.value.rechargeCoin = remainingGold; // 剩余的都算作永久金币
  231. // 恢复allGold的原始值
  232. addConsume.value.allGold = originalAllGold;
  233. // 确保taskCoin, freeCoin, rechargeCoin不是NaN,如果是,则设置为0
  234. if (isNaN(addConsume.value.taskCoin)) addConsume.value.taskCoin = 0;
  235. if (isNaN(addConsume.value.freeCoin)) addConsume.value.freeCoin = 0;
  236. if (isNaN(addConsume.value.rechargeCoin)) addConsume.value.rechargeCoin = 0;
  237. console.log("计算结果", addConsume.value);
  238. }
  239. }
  240. </script>
  241. <template>
  242. <div style="margin-bottom: 20px; font-weight: bolder">新增消费</div>
  243. <el-form
  244. :model="addConsume"
  245. ref="Ref"
  246. :rules="rules"
  247. label-width="auto"
  248. style="max-width: 750px"
  249. class="form-style"
  250. >
  251. <el-form-item prop="jwcode" label="精网号">
  252. <el-input
  253. v-model="addConsume.jwcode"
  254. style="width: 220px"
  255. @change="getUserGold(addConsume.jwcode)"
  256. />
  257. <el-button
  258. type="primary"
  259. @click="getUser(addConsume.jwcode)"
  260. style="margin-left: 20px"
  261. >查询</el-button
  262. >
  263. </el-form-item>
  264. <el-form-item prop="productId" label="商品名称">
  265. <el-select
  266. v-model="addConsume.productId"
  267. placeholder="请选择"
  268. style="width: 300px"
  269. >
  270. <el-option
  271. v-for="item in goods"
  272. :key="item.value"
  273. :label="item.name"
  274. :value="item.productId"
  275. />
  276. </el-select>
  277. </el-form-item>
  278. <el-form-item prop="allGold" label="消费金币总数">
  279. <el-input
  280. v-model="addConsume.allGold"
  281. style="width: 100px"
  282. @change="calculateCoins()"
  283. />
  284. </el-form-item>
  285. <div style="display: flex; align-items: center">
  286. <el-form-item prop="rechargeCoin" label="永久金币" style="float: left">
  287. <el-input
  288. disabled
  289. v-model="addConsume.rechargeCoin"
  290. style="width: 100px; margin-left: -5px"
  291. />
  292. <p style="margin-right: 0px"></p>
  293. </el-form-item>
  294. <el-form-item
  295. prop="freeCoin"
  296. label="免费金币"
  297. style="float: left; margin-left: -20px"
  298. >
  299. <el-input
  300. disabled
  301. v-model="addConsume.freeCoin"
  302. style="width: 100px; margin-left: -5px"
  303. />
  304. <p style="margin-right: 0px"></p>
  305. </el-form-item>
  306. <el-form-item prop="taskCoin" label="任务金币" style="margin-left: -20px">
  307. <el-input
  308. disabled
  309. v-model="addConsume.taskCoin"
  310. style="width: 100px; margin-left: -5px"
  311. />
  312. <p style="margin-right: 20px"></p>
  313. </el-form-item>
  314. </div>
  315. <el-form-item prop="remark" label="备注">
  316. <el-input
  317. v-model="addConsume.remark"
  318. style="width: 300px"
  319. :rows="2"
  320. maxlength="100"
  321. show-word-limit
  322. type="textarea"
  323. />
  324. </el-form-item>
  325. <el-form-item prop="commitName" label="提交人">
  326. <el-input
  327. style="width: 300px"
  328. :value="adminData.name"
  329. disabled
  330. placeholder="提交人姓名"
  331. />
  332. </el-form-item>
  333. <el-button @click="delteConsume" style="margin-left: 280px">重置</el-button>
  334. <el-button type="primary" @click="addBefore"> 提交 </el-button>
  335. </el-form>
  336. <!-- 客户信息栏 -->
  337. <el-card style="width: 850px; float: right" class="customer-info">
  338. <el-form
  339. :model="user"
  340. label-width="auto"
  341. style="max-width: 1200px"
  342. label-position="left"
  343. >
  344. <el-text size="large" style="margin-left: 20px">客户信息</el-text>
  345. <el-row style="margin-top: 20px">
  346. <el-col :span="10">
  347. <el-form-item label="姓名:">
  348. <p>{{ user.name }}</p>
  349. </el-form-item>
  350. </el-col>
  351. <el-col :span="14">
  352. <el-form-item label="历史金币总数">
  353. <p>{{ user.totalRechargeGold }}</p>
  354. </el-form-item>
  355. </el-col>
  356. <el-col :span="10">
  357. <el-form-item label="精网号">
  358. <p>{{ user.jwcode }}</p>
  359. </el-form-item>
  360. </el-col>
  361. <el-col :span="14">
  362. <el-form-item label="当前金币总数" style="width: 500px">
  363. <span style="color: #2fa1ff; margin-right: 5px" v-if="user.buyJb">{{
  364. user.buyJb + user.free6 + user.free12 + user.coreJb
  365. }}</span>
  366. <span
  367. style="display: inline; white-space: nowrap; color: #b1b1b1"
  368. v-if="user.buyJb"
  369. >(永久金币:{{ user.buyJb }};免费金币:{{
  370. user.free6 + user.free12
  371. }};任务金币:{{ user.coreJb }})</span
  372. >
  373. </el-form-item>
  374. </el-col>
  375. <el-col :span="10">
  376. <el-form-item label="首次充值日期">
  377. <p v-if="user.firstRechargeDate">
  378. {{ moment(user.firstRechargeDate).format("YYYY-MM-DD HH:mm:ss") }}
  379. </p>
  380. </el-form-item>
  381. </el-col>
  382. <el-col :span="14">
  383. <el-form-item label="充值次数">
  384. <p style="color: #2fa1ff">{{ user.rechargeTimes }}</p>
  385. </el-form-item>
  386. </el-col>
  387. <el-col :span="10">
  388. <el-form-item label="负责客服">
  389. <p>{{ adminData.name }}</p>
  390. </el-form-item>
  391. </el-col>
  392. <el-col :span="14">
  393. <el-form-item label="消费次数">
  394. <p style="color: #2fa1ff">{{ user.spendTimes }}</p>
  395. </el-form-item>
  396. </el-col>
  397. <el-col :span="10">
  398. <el-form-item label="所属门店">
  399. <p>{{ adminData.area }}</p>
  400. </el-form-item>
  401. </el-col>
  402. <el-col :span="14">
  403. <el-form-item label="待审核">
  404. <p style="color: #2fa1ff">
  405. {{ user.A }}
  406. </p>
  407. </el-form-item>
  408. </el-col>
  409. </el-row>
  410. </el-form>
  411. </el-card>
  412. </template>
  413. <style scoped>
  414. p {
  415. margin: 0px;
  416. }
  417. .el-form-item {
  418. margin-left: 50px;
  419. }
  420. /* 上传图片的格式 */
  421. .avatar-uploader .avatar {
  422. width: 50px;
  423. height: 50px;
  424. display: block;
  425. }
  426. </style>
  427. <style>
  428. .avatar-uploader .el-upload {
  429. border: 1px dashed var(--el-border-color);
  430. border-radius: 6px;
  431. cursor: pointer;
  432. position: relative;
  433. overflow: hidden;
  434. transition: var(--el-transition-duration-fast);
  435. }
  436. .avatar-uploader .el-upload:hover {
  437. border-color: var(--el-color-primary);
  438. }
  439. .el-icon.avatar-uploader-icon {
  440. font-size: 28px;
  441. color: #8c939d;
  442. width: 50px;
  443. height: 50px;
  444. text-align: center;
  445. }
  446. .form-style {
  447. margin-top: 50px;
  448. max-width: 50%;
  449. float: left;
  450. }
  451. .form-style2 {
  452. max-width: 60%;
  453. }
  454. p {
  455. font-size: 13px;
  456. transform: scale(1);
  457. }
  458. </style>