金币系统前端
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.

571 lines
16 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
2 months ago
3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
2 months ago
3 months ago
  1. <script setup>
  2. import { onMounted, 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 '@/util/http'
  9. import moment from 'moment'
  10. // import _ from 'lodash'
  11. const addRe = ref({
  12. typeR: '0'
  13. })
  14. //这是获取用户信息的接口
  15. const adminData = ref({})
  16. const getAdminData = async function () {
  17. try {
  18. const result = await API({ url: '/admin/userinfo', data: {} })
  19. adminData.value = result
  20. addRefund.value.adminId = adminData.value.adminId
  21. console.log('请求成功', result)
  22. console.log('用户信息', user.value)
  23. } catch (error) {
  24. console.log('请求失败', error)
  25. }
  26. }
  27. // 精网号去空格
  28. const trimJwCode = () => {
  29. if (addRefund.value.jwcode) {
  30. addRefund.value.jwcode = addRefund.value.jwcode.replace(/\s/g, '');
  31. }
  32. }
  33. // 这是添加退款信息的表单
  34. const addRefund = ref({
  35. updateType: '3',
  36. allCoin: 0,
  37. orderCode: '',
  38. refundGoods: '',
  39. freeCoin: 0,
  40. rechargeCoin: 0,
  41. taskCoin: 0
  42. })
  43. // 取消按钮
  44. const cancel = function () {
  45. addRefund.value = {}
  46. addRefund.value.updateType = '3'
  47. addRefund.value.rechargeCoin = 0
  48. addRefund.value.freeCoin = 0
  49. addRefund.value.taskCoin = 0
  50. addRefund.value.allCoin = 0
  51. addRe.value.typeR = 0
  52. addRefund.value.adminId = adminData.value.adminId
  53. }
  54. // 这是添加退款信息的接口
  55. const add = async function () {
  56. try {
  57. // 发送POST请求
  58. const result = await API({ url: '/refund/add', data: addRefund.value })
  59. if (result.code === 0) {
  60. ElMessage.error(result.msg)
  61. return
  62. }
  63. console.log('请求成功', result)
  64. ElMessage.success('添加成功')
  65. // 重置表单
  66. addRefund.value = {}
  67. addRefund.value.adminId = adminData.value.adminId
  68. addRefund.value.updateType = '3'
  69. addRefund.value.allCoin = 0
  70. addRefund.value.orderCode = ''
  71. addRefund.value.refundGoods = ''
  72. addRefund.value.freeCoin = 0
  73. addRefund.value.rechargeCoin = 0
  74. addRefund.value.taskCoin = 0
  75. addRefund.value.typeR = 0
  76. user.value = {}
  77. } catch (error) {
  78. console.log('请求失败', error)
  79. // 在这里可以处理错误逻辑,比如显示错误提示等
  80. }
  81. }
  82. const addBefore = () => {
  83. Ref.value.validate(async (valid) => {
  84. if (valid) {
  85. ElMessageBox.confirm('确认添加?')
  86. .then(() => {
  87. add()
  88. console.log('添加成功')
  89. addRefund.value.allCoin = 0
  90. ;(addRefund.value.freeCoin = 0),
  91. (addRefund.value.rechargeCoin = 0),
  92. (addRefund.value.taskCoin = 0),
  93. (addRefund.value = {})
  94. })
  95. .catch(() => {
  96. console.log('取消添加')
  97. })
  98. } else {
  99. //提示
  100. ElMessage({
  101. type: 'error',
  102. message: '请检查输入内容'
  103. })
  104. }
  105. })
  106. }
  107. // 表单验证
  108. // 开始时间改变时,重新验证结束时间
  109. const Ref = ref(null)
  110. const startChange = (val) => {}
  111. const rules = reactive({
  112. jwcode: [{ required: true, message: '请输入精网号', trigger: 'blur' }],
  113. refundType: [{ required: true, message: '请选择退款类型', trigger: 'blur' }],
  114. orderCode: [{ required: true, message: '请选择退款商品', trigger: 'blur' }],
  115. taskCoin: [{ required: true, message: '请输入任务金币', trigger: 'blur' },
  116. {
  117. validator: (rule, value) => {
  118. if (value < 0) {
  119. return Promise.reject(new Error('任务金币至少为0'))
  120. }
  121. return Promise.resolve()
  122. },
  123. }
  124. ],
  125. freeCoin: [{ required: true, message: '请输入免费金币', trigger: 'blur' },
  126. {
  127. validator: (rule, value) => {
  128. if (value < 0) {
  129. return Promise.reject(new Error('免费金币至少为0'))
  130. }
  131. return Promise.resolve()
  132. },
  133. }
  134. ],
  135. rechargeCoin: [
  136. { required: true, message: '请输入永久金币', trigger: 'blur' },
  137. {
  138. validator: (rule, value) => {
  139. if (value < 0) {
  140. return Promise.reject(new Error('永久金币至少为0'))
  141. }
  142. return Promise.resolve()
  143. },
  144. }
  145. ],
  146. allCoin: [
  147. { required: true, message: '请选择付款方式', trigger: 'blur' },
  148. {
  149. validator: (rule, value) => {
  150. if (value === 0) {
  151. return Promise.reject(new Error('总金币不能为0'))
  152. }
  153. return Promise.resolve()
  154. },
  155. trigger: 'blur'
  156. }
  157. ]
  158. })
  159. // 查找客户信息的方法
  160. const user = ref({
  161. firstRechargeTime: ''
  162. })
  163. const getUser = async function (jwcode) {
  164. trimJwCode();
  165. try {
  166. // 发送POST请求
  167. const result = await API({
  168. url: '/recharge/user',
  169. data: {
  170. jwcode: addRefund.value.jwcode,
  171. area: adminData.value.area
  172. }
  173. })
  174. console.log('请求成功', result)
  175. //在此处错误逻辑的提示做了注释,在后续商品查询接口返回错误时,提示信息会显示在弹窗中
  176. if (result.code === 0) {
  177. //ElMessage.error(result.msg)
  178. } else {
  179. user.value = result.data
  180. user.value.A =
  181. Number(user.value.pendingRechargeTimes) +
  182. Number(user.value.pendingSpendTimes)
  183. console.log('用户信息', user.value)
  184. //ElMessage.success(result.msg)
  185. }
  186. } catch (error) {
  187. console.log('请求失败', error)
  188. ElMessage.error('查询失败,请检查精网号是否正确')
  189. // 在这里可以处理错误逻辑,比如显示错误提示等
  190. }
  191. }
  192. const calculatedAllGold = computed(() => {
  193. const sum =
  194. Number(addRefund.value.freeCoin) +
  195. Number(addRefund.value.rechargeCoin) +
  196. Number(addRefund.value.taskCoin)
  197. return !isNaN(sum) ? sum : 0
  198. })
  199. watch(calculatedAllGold, (newVal) => {
  200. addRefund.value.allCoin = newVal
  201. })
  202. const AAA = computed(() => {
  203. return addRefund.value.jwcode
  204. })
  205. watch(AAA, (newVal) => {})
  206. // 退款类型选项
  207. const refundType = [
  208. {
  209. value: '退款商品',
  210. label: '退款商品'
  211. }
  212. ]
  213. // 根据精网号查询商品
  214. // 查什么?????
  215. const goods = ref([])
  216. const getGoods = async function (jwcode) {
  217. trimJwCode();
  218. try {
  219. // 发送POST请求
  220. const result = await API({
  221. url: '/consume/getDeatil',
  222. data: {
  223. jwcode: addRefund.value.jwcode,
  224. area: adminData.value.area
  225. }
  226. })
  227. console.log('请求成功', result)
  228. if (result.code === 0) {
  229. ElMessage.error(result.msg)
  230. } else {
  231. // 存储表格数据
  232. goods.value = result.data
  233. console.log('用户信息', goods.value)
  234. ElMessage.success(result.msg)
  235. }
  236. } catch (error) {
  237. console.log('请求失败', error)
  238. ElMessage.error('查询失败,请检查精网号是否正确')
  239. // 在这里可以处理错误逻辑,比如显示错误提示等
  240. }
  241. }
  242. const calculatedRechargeGoods = computed(() => {
  243. return (
  244. +addRefund.value.freeCoin +
  245. +addRefund.value.rechargeCoin +
  246. +addRefund.value.taskCoin
  247. )
  248. })
  249. watch(calculatedRechargeGoods, (newVal) => {
  250. addRefund.value.allCoin = newVal
  251. })
  252. watch(calculatedRechargeGoods, (newVal) => {
  253. addRefund.value.allCoin = newVal
  254. console.log('计算的总金币', newVal)
  255. })
  256. // 绑定两个数据
  257. // 这是根据订单号查询消费信息的方法
  258. const getProductByOrderCode = async function (item) {
  259. try {
  260. // 发送POST请求
  261. const result = await API({
  262. url: '/refund/searchByOrderCode?orderCode=' + item,
  263. data: {}
  264. })
  265. addRefund.value.contactId = result.data.detailyId
  266. addRefund.value.refundGoods = result.data.productName
  267. addRefund.value.orderCode = result.data.orderCode
  268. addRefund.value.taskCoin = (result.data.taskCoin * -1) / 100
  269. addRefund.value.freeCoin = (result.data.freeCoin * -1) / 100
  270. addRefund.value.rechargeCoin = (result.data.rechargeCoin * -1) / 100
  271. addRefund.value.allCoin =
  272. (result.data.taskCoin * -1 +
  273. result.data.freeCoin * -1 +
  274. result.data.rechargeCoin * -1) /
  275. 100
  276. console.log('请求成功', addRefund.value)
  277. if (result.data.code === 0) {
  278. ElMessage.error(result.data.msg)
  279. } else {
  280. ElMessage.success('选择成功')
  281. }
  282. } catch (error) {
  283. console.log('请求失败', error)
  284. ElMessage.error('查询失败,请检查精网号是否正确')
  285. // 在这里可以处理错误逻辑,比如显示错误提示等
  286. }
  287. }
  288. const handleSelectionChange = (value) => {
  289. getProductByOrderCode(value)
  290. console.log('选择的订单号', value)
  291. const selectedItem = goods.value.find((item) => item.detailId === value)
  292. }
  293. // 挂载
  294. onMounted(async function () {
  295. await getAdminData()
  296. })
  297. </script>
  298. <template>
  299. <div style="font-weight: bold">新增退款</div>
  300. <el-form
  301. :model="addRefund"
  302. ref="Ref"
  303. :rules="rules"
  304. label-width="auto"
  305. style="max-width: 750px"
  306. class="form-style"
  307. >
  308. <el-form-item prop="jwcode" label="精网号">
  309. <el-input
  310. v-model="addRefund.jwcode"
  311. style="width: 220px"
  312. @change="getGoods(addRefund.jwcode)"
  313. />
  314. <el-button
  315. type="primary"
  316. @click="getUser(addRefund.jwcode)"
  317. style="margin-left: 20px"
  318. >查询</el-button
  319. >
  320. </el-form-item>
  321. <el-form-item prop="refundType" label="退款类型">
  322. <el-select
  323. v-model="addRefund.refundType"
  324. placeholder="请选择"
  325. style="width: 300px"
  326. >
  327. <el-option
  328. v-for="item in refundType"
  329. :key="item.value"
  330. :label="item.label"
  331. :value="item.value"
  332. />
  333. </el-select>
  334. </el-form-item>
  335. <el-form-item prop="orderCode" label="商品名">
  336. <el-select
  337. v-model="addRefund.orderCode"
  338. placeholder="请选择"
  339. style="width: 300px"
  340. @change="handleSelectionChange"
  341. >
  342. <el-option
  343. v-for="item in goods"
  344. :key="item.value"
  345. :label="item.productName + item.orderCode"
  346. :value="item.orderCode"
  347. />
  348. </el-select>
  349. </el-form-item>
  350. <el-form-item prop="typeR" label="退款方式:">
  351. <el-radio-group v-model="addRe.typeR">
  352. <el-radio value="0" @change="addRe.typeR = '0'">全部退款</el-radio>
  353. <el-radio value="1">部分退款</el-radio>
  354. </el-radio-group>
  355. </el-form-item>
  356. <div style="display: flex; align-items: center">
  357. <el-form-item prop="rechargeCoin" label="永久金币" style="float: left">
  358. <el-input
  359. v-model="addRefund.rechargeCoin"
  360. style="width: 100px"
  361. :disabled="addRe.typeR === '0' ? true : false"
  362. >
  363. </el-input>
  364. <p></p>
  365. </el-form-item>
  366. <el-form-item
  367. prop="freeCoin"
  368. label="免费金币"
  369. style="margin-left: -20px; float: left"
  370. >
  371. <el-input
  372. v-model="addRefund.freeCoin"
  373. style="float: left; width: 100px"
  374. :disabled="addRe.typeR === '0' ? true : false"
  375. />
  376. <p></p>
  377. </el-form-item>
  378. <el-form-item prop="taskCoin" label="任务金币" style="margin-left: -20px">
  379. <el-input
  380. v-model="addRefund.taskCoin"
  381. style="float: left; width: 100px"
  382. :disabled="addRe.typeR === '0' ? true : false"
  383. />
  384. <p></p>
  385. </el-form-item>
  386. </div>
  387. <el-form-item prop="allCoin" label="退款金币总数">
  388. <el-input disabled v-model="addRefund.allCoin" style="width: 100px">
  389. </el-input>
  390. </el-form-item>
  391. <el-form-item prop="remark" label="备注">
  392. <el-input
  393. v-model="addRefund.remark"
  394. style="width: 300px"
  395. :rows="2"
  396. maxlength="100"
  397. show-word-limit
  398. type="textarea"
  399. />
  400. </el-form-item>
  401. <el-form-item prop="commitName" label="提交人">
  402. <el-input
  403. style="width: 300px"
  404. :value="adminData.name"
  405. disabled
  406. placeholder="提交人姓名"
  407. />
  408. </el-form-item>
  409. <el-button type="success" @click="cancel()" style="margin-left: 280px">重置</el-button>
  410. <el-button type="primary" @click="addBefore"> 提交 </el-button>
  411. </el-form>
  412. <!-- 客户信息栏 -->
  413. <el-card style="width: 850px; float: right" class="customer-info">
  414. <el-form
  415. :model="user"
  416. label-width="auto"
  417. style="max-width: 1000px"
  418. label-position="left"
  419. >
  420. <el-text size="large" style="margin-left: 20px">客户信息</el-text>
  421. <el-row style="margin-top: 20px">
  422. <el-col :span="10">
  423. <el-form-item label="姓名:">
  424. <p>{{ user.name }}</p>
  425. </el-form-item>
  426. </el-col>
  427. <el-col :span="14">
  428. <el-form-item label="历史金币总数">
  429. <!-- 检查 user.totalRechargeGold 是否为有效的数字 -->
  430. <p v-if="!isNaN(Number(user.totalRechargeGold))">
  431. {{ Number(user.totalRechargeGold / 100) }}
  432. </p>
  433. <!-- 如果不是有效的数字显示默认值 -->
  434. <p v-else></p>
  435. </el-form-item>
  436. </el-col>
  437. <el-col :span="10">
  438. <el-form-item label="精网号">
  439. <p>{{ user.jwcode }}</p>
  440. </el-form-item>
  441. </el-col>
  442. <el-col :span="14">
  443. <el-form-item label="当前金币总数" style="width: 500px">
  444. <span
  445. style="color: #2fa1ff; margin-right: 5px"
  446. v-if="user.buyJb !== undefined"
  447. >{{
  448. (user.buyJb + user.free6 + user.free12 + user.coreJb) / 100
  449. }}</span
  450. >
  451. <span
  452. style="display: inline; white-space: nowrap; color: #b1b1b1"
  453. v-if="user.buyJb !== undefined"
  454. >(永久金币:{{ user.buyJb / 100 }};免费金币:{{
  455. (user.free6 + user.free12) / 100
  456. }};任务金币:{{ user.coreJb / 100 }})</span
  457. >
  458. </el-form-item>
  459. </el-col>
  460. <el-col :span="10">
  461. <el-form-item label="首次充值日期">
  462. <p v-if="user.firstRechargeDate">
  463. {{ moment(user.firstRechargeDate).format('YYYY-MM-DD HH:mm:ss') }}
  464. </p>
  465. </el-form-item>
  466. </el-col>
  467. <el-col :span="14">
  468. <el-form-item label="充值次数">
  469. <p style="color: #2fa1ff">{{ user.rechargeTimes }}</p>
  470. </el-form-item>
  471. </el-col>
  472. <!-- <el-col :span="10">
  473. <el-form-item label="负责客服">
  474. <p>{{ adminData.name }}</p>
  475. </el-form-item>
  476. </el-col> -->
  477. <el-col :span="10">
  478. <el-form-item label="消费次数">
  479. <p style="color: #2fa1ff">{{ user.spendTimes }}</p>
  480. </el-form-item>
  481. </el-col>
  482. <el-col :span="10">
  483. <el-form-item label="所属门店">
  484. <p>{{ adminData.area }}</p>
  485. </el-form-item>
  486. </el-col>
  487. <el-col :span="14">
  488. <!-- <el-form-item label="待审核">
  489. <p style="color: #2fa1ff">
  490. {{ user.A }}
  491. </p>
  492. </el-form-item> -->
  493. </el-col>
  494. </el-row>
  495. </el-form>
  496. </el-card>
  497. </template>
  498. <style scoped>
  499. p {
  500. margin: 0px;
  501. }
  502. .el-form-item {
  503. margin-left: 50px;
  504. }
  505. /* 上传图片的格式 */
  506. .avatar-uploader .avatar {
  507. width: 50px;
  508. height: 50px;
  509. display: block;
  510. }
  511. </style>
  512. <style>
  513. .avatar-uploader .el-upload {
  514. border: 1px dashed var(--el-border-color);
  515. border-radius: 6px;
  516. cursor: pointer;
  517. position: relative;
  518. overflow: hidden;
  519. transition: var(--el-transition-duration-fast);
  520. }
  521. .avatar-uploader .el-upload:hover {
  522. border-color: var(--el-color-primary);
  523. }
  524. .el-icon.avatar-uploader-icon {
  525. font-size: 28px;
  526. color: #8c939d;
  527. width: 50px;
  528. height: 50px;
  529. text-align: center;
  530. }
  531. .form-style {
  532. margin-top: 50px;
  533. max-width: 50%;
  534. float: left;
  535. }
  536. .form-style2 {
  537. max-width: 60%;
  538. }
  539. p {
  540. font-size: 13px;
  541. transform: scale(1);
  542. }
  543. </style>