Wallet.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <div class="wallet-page">
  3. <div class="wallet-list flex-between">
  4. <div class="gradient flex-center-between li" v-for="(item, index) in 2" :key="index">
  5. <div class="wallet-list-li-left">
  6. <div class="">{{ index == 0 ? $t('common.mibi') : $t('common.baomibi') }} {{ $t('personalCenter.yue') }}</div>
  7. <div class="">{{ index == 0 ? appStore?.userInfo?.pointsBalance || 0 || 0 : appStore?.userInfo?.baoMiBalance
  8. || 0 }}</div>
  9. </div>
  10. <div class="wallet-list-li-right flex-align-center">
  11. <div @click="show = true" class="flex-align-center btn" v-if="index == 1">
  12. <img src="/src/assets/imgs/my/tixian@2x.png" alt="">
  13. <div class="">{{ $t('personalCenter.shenqingtixian') }}</div>
  14. </div>
  15. <div @click="changeTransformation(index)" class="flex-align-center btn">
  16. <img src="/src/assets/imgs/my/zhuanhuan@2x.png" alt="">
  17. <div class="">{{ index == 0 ? $t('personalCenter.zhuanhuanbaomibi') : $t('personalCenter.zhuanghuanmibi') }}
  18. </div>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. <el-tabs v-model="form.changeType" class="demo-tabs" @tab-click="handleClick">
  24. <el-tab-pane :label="$t(tab.label)" v-for="tab in tabs" :key="tab.name" :name="tab.name">
  25. <div class="tabs flex-align-center" v-if="form.changeType != 3">
  26. <div @click="changeType(index)" :class="{ active: index + 1 == form.balanceType }" class="tab"
  27. v-for="(item, index) in 2">{{
  28. index == 0 ? $t('common.mibi') : $t('common.baomibi') }}{{ $t('personalCenter.details') }}
  29. </div>
  30. </div>
  31. <template v-if="form.changeType == 3">
  32. <div class="wallet-page-list">
  33. <div class="lis" v-for="(item, index) in list" :key="index">
  34. <div class="flex-center-between">
  35. <div class="">{{ item.applyStatus == 0 ? '待审核' : item.applyStatus == 1 ? '已通过' : '未通过' }}</div>
  36. <div class="price">¥{{ item.applyAmount }}</div>
  37. </div>
  38. <div class="flex-center-between">
  39. <div class="">订单号:{{ item.applyNo }}</div>
  40. <div class="">手续费:{{ item.feeAmount }}</div>
  41. </div>
  42. <div class="flex-center-between">
  43. <div class="">提现方式:{{ item.settleType == 'alipay' ? '支付宝' : item.settleType == 'wechat' ? '微信' : '银行卡'
  44. }}</div>
  45. <div class="">提现账号:{{ item.receiveAccount }}</div>
  46. </div>
  47. <div class="">申请时间:{{ item.createTime }}</div>
  48. </div>
  49. </div>
  50. </template>
  51. <template v-else>
  52. <div class="wallet-page-list" v-if="list?.length">
  53. <div v-for="(item, index) in list" :key="index" class="li">
  54. <div class="title">
  55. <div class="">{{ item.bizTypeName }}</div>
  56. <div class="">{{ item.createTime }}</div>
  57. </div>
  58. <div class="price" :class="{ green: form.changeType == 1 }">{{ form.changeType == 1 ? '+' : '' }}{{
  59. item.balanceChange }}</div>
  60. </div>
  61. </div>
  62. </template>
  63. </el-tab-pane>
  64. </el-tabs>
  65. <template v-if="list?.length">
  66. <Pagination :total="form.total" :page-size="form.pageSize" :current-page="form.pageNum"
  67. @page-change="handlePageChange" />
  68. </template>
  69. <el-empty v-else :description="$t('common.empty')" />
  70. <el-dialog v-model="dialogVisible"
  71. :title="`${transformationIndex == 0 ? $t('personalCenter.zhuanhuanbaomibi') : $t('personalCenter.zhuanghuanmibi')}`"
  72. width="523">
  73. <el-form :model="walletForm" label-width="auto" label-position="top" :rules="rules" ref="ruleFormRefs">
  74. <el-row>
  75. <el-col :span="24">
  76. <div class="input">
  77. <el-form-item :label="$t('common.use') + $t('common.baomibi')" v-if="transformationIndex" prop="orderAmt">
  78. <el-input-number v-model="walletForm.orderAmt" :min="1" :max="appStore?.userInfo?.baoMiBalance"
  79. controls-position="right" size="large" @change="handleChange" style="width: 100%;"
  80. :placeholder="$t('common.placeholderInput')" align="left" :input-style="{ fontSize: '28px' }"
  81. class="inputStyle" />
  82. </el-form-item>
  83. <el-form-item :label="$t('common.use') + $t('common.mibi')" v-else prop="orderAmt">
  84. <el-input-number v-model="walletForm.orderAmt" :min="Number(configTxt.configValue)"
  85. :max="appStore?.userInfo?.pointsBalance" :step="Number(configTxt.configValue)"
  86. controls-position="right" size="large" @change="handleChange" style="width: 100%;"
  87. :placeholder="$t('common.placeholderInput')" align="left" :input-style="{ fontSize: '28px' }"
  88. class="inputStyle" />
  89. </el-form-item>
  90. </div>
  91. </el-col>
  92. </el-row>
  93. <div class="line">
  94. <img src="/src/assets/imgs/my/arrow-left-right-fill@2x.png" alt="">
  95. </div>
  96. <el-row>
  97. <el-col :span="24">
  98. <div class="input">
  99. <el-form-item v-if="transformationIndex"
  100. :label="$t('common.available') + $t('common.mibi') + `(手续费率:${walletForm.feeRate})`">
  101. <el-input v-model="walletForm.targetAmount" :placeholder="$t('common.placeholderInput')" readonly
  102. disabled :input-style="{ fontSize: '28px' }" class="inputStyle" />
  103. </el-form-item>
  104. <el-form-item v-else :label="$t('common.available') + $t('common.baomibi')">
  105. <el-input v-model="walletForm.targetAmount" :placeholder="$t('common.placeholderInput')" readonly
  106. disabled :input-style="{ fontSize: '28px' }" class="inputStyle" />
  107. </el-form-item>
  108. </div>
  109. </el-col>
  110. </el-row>
  111. <div class="" style="font-size: 14px;margin-top: 16px;"> <text style="color: #E43434;">*</text> {{
  112. configTxt.configName }}{{ configTxt.configValue }}</div>
  113. </el-form>
  114. <template #footer>
  115. <div class="dialog-footer flex-center">
  116. <el-button @click="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
  117. <el-button class="gradient" type="primary" @click="confirmTransformation(ruleFormRefs)">
  118. {{ $t('common.confirm') }}
  119. </el-button>
  120. </div>
  121. </template>
  122. </el-dialog>
  123. <el-dialog v-model="show" :title="$t('personalCenter.shenqingtixian')" width="500">
  124. <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="auto">
  125. <el-row>
  126. <el-col :span="24">
  127. <el-form-item label="提现金额" prop="applyAmount">
  128. <el-input type="number" :min="1" :max="appStore?.userInfo?.baoMiBalance" v-model="ruleForm.applyAmount"
  129. :placeholder="$t('common.placeholderInput')" />
  130. </el-form-item>
  131. </el-col>
  132. </el-row>
  133. <el-row>
  134. <el-col :span="24">
  135. <el-form-item label="提现方式" prop="settleType">
  136. <el-select v-model="ruleForm.settleType" placeholder="Select" style="width: 100%">
  137. <el-option label="支付宝" value="alipay" />
  138. <el-option label="银行卡" value="bank_card" />
  139. </el-select>
  140. </el-form-item>
  141. </el-col>
  142. </el-row>
  143. <el-row>
  144. <el-col :span="24">
  145. <el-form-item label="姓名" prop="withdrawPerson">
  146. <el-input v-model="ruleForm.withdrawPerson" :placeholder="$t('common.placeholderInput')" />
  147. </el-form-item>
  148. </el-col>
  149. </el-row>
  150. <el-row>
  151. <el-col :span="24">
  152. <el-form-item label="账号" prop="receiveAccount">
  153. <el-input v-model="ruleForm.receiveAccount" :placeholder="$t('common.placeholderInput')" />
  154. </el-form-item>
  155. </el-col>
  156. </el-row>
  157. </el-form>
  158. <template #footer>
  159. <div class="dialog-footer flex-center">
  160. <el-button @click="show = false">{{ $t('common.cancel') }}</el-button>
  161. <el-button class="gradient" type="primary" @click="submitForm(ruleFormRef)">{{
  162. $t('common.confirm') }}</el-button>
  163. </div>
  164. </template>
  165. </el-dialog>
  166. </div>
  167. </template>
  168. <script lang="ts" setup>
  169. import { ref, onMounted } from 'vue'
  170. import type { TabsPaneContext } from 'element-plus'
  171. import Pagination from '@/components/Pagination.vue'
  172. import { getUserInfo } from '@/api/auth'
  173. import { payConfigDearch, calRate } from '@/api/order'
  174. import { recordList, applyWithdraw, withdrawList } from '@/api/my'
  175. import { createOrder } from '@/api/order.js'
  176. import { useAppStore } from '@/pinia/appStore'
  177. import DGTMessage from '@/utils/message'
  178. import { useI18n } from 'vue-i18n'
  179. const { t } = useI18n()
  180. const appStore = useAppStore();
  181. const tabs = ref([
  182. { label: 'personalCenter.incomeDetails', name: 1 },
  183. { label: 'personalCenter.usageRecord', name: 2 },
  184. { label: 'personalCenter.withdrawHistory', name: 3 },
  185. ])
  186. const list = ref([])
  187. const form = ref({
  188. pageNum: 1,
  189. pageSize: 10,
  190. total: 0,
  191. balanceType: 1,//1-米币 2-暴米币
  192. changeType: 1,//1-增加 2-减少
  193. orderByColumn: 'create_time',
  194. isAsc: 'desc'
  195. })
  196. const walletForm = ref({
  197. payMethod: '',
  198. orderType: '',
  199. productId: '',
  200. orderNum: null,
  201. orderAmt: 1,
  202. feeRate: 0,
  203. targetAmount: 0
  204. })
  205. const ruleFormRef = ref()
  206. const configTxt = ref({})
  207. const userInfo = ref({})//用户信息
  208. const dialogVisible = ref(false);
  209. const transformationIndex = ref(0);
  210. const show = ref(false);
  211. const ruleForm = ref({
  212. applyAmount: null,
  213. settleType: "alipay",
  214. withdrawPerson: "",
  215. receiveAccount: ""
  216. })
  217. const ruleFormRefs = ref()
  218. const validatePass = (rule: any, value: any, callback: any) => {
  219. if (!value) {
  220. callback(new Error(t('common.placeholderInput')))
  221. } else if (Number(value) % Number(configTxt.value.configValue) !== 0 && transformationIndex.value == 0) {
  222. callback(new Error(`米币数量必须为${configTxt.value.configValue}的整倍数`))
  223. } else {
  224. callback()
  225. }
  226. }
  227. const validatePass1 = (rule: any, value: any, callback: any) => {
  228. if (!value) {
  229. callback(new Error(t('common.placeholderInput')))
  230. return
  231. } else if (Number(value) > appStore.userInfo.baoMiBalance) {
  232. callback(new Error(`余额不足`))
  233. } else {
  234. callback()
  235. }
  236. }
  237. const rules = ref({
  238. applyAmount: [
  239. { required: true, validator: validatePass1, trigger: 'blur' }
  240. ],
  241. settleType: [
  242. { required: true, message: t('common.qingxuanze'), trigger: 'blur' }
  243. ],
  244. withdrawPerson: [
  245. { required: true, message: t('common.placeholderInput'), trigger: 'blur' }
  246. ],
  247. receiveAccount: [
  248. { required: true, message: t('common.placeholderInput'), trigger: 'blur' }
  249. ],
  250. orderAmt: [
  251. { required: true, trigger: 'blur', validator: validatePass },
  252. ],
  253. })
  254. const submitForm = async (formEl) => {
  255. console.log(formEl)
  256. if (!formEl) return
  257. await formEl.validate(async (valid, fields) => {
  258. if (valid) {
  259. let res = await applyWithdraw(ruleForm.value);
  260. if (res.code === 200) {
  261. show.value = false;
  262. appStore.USERINFO();
  263. getList()
  264. DGTMessage.success(t('common.success'));
  265. }
  266. }
  267. })
  268. }
  269. // 确认转换
  270. const confirmTransformation = async (formEl) => {
  271. if (!formEl) return
  272. await formEl.validate(async (valid, fields) => {
  273. if (valid) {
  274. let res = await createOrder({
  275. payMethod: walletForm.value.payMethod,
  276. orderType: walletForm.value.orderType,
  277. productId: '',
  278. orderNum: walletForm.value.targetAmount,
  279. orderAmt: walletForm.value.orderAmt
  280. })
  281. if (res.code === 200) {
  282. if (res.data.paySuccess) {
  283. dialogVisible.value = false;
  284. appStore.USERINFO();
  285. DGTMessage.success(`${transformationIndex.value ? t('personalCenter.zhuanhuanbaomibi') : t('personalCenter.zhuanghuanmibi')}${t('common.success')}`)
  286. }
  287. }
  288. }
  289. })
  290. }
  291. // 米币暴米币转换
  292. const changeTransformation = async (index: any) => {
  293. transformationIndex.value = index;
  294. walletForm.value.payMethod = index ? 'BMI' : 'MI';
  295. walletForm.value.orderType = index ? 'exchange_mi' : 'exchange_bmi';
  296. let { data } = await payConfigDearch({ id: '03' });
  297. let result = data.filter((item: any) => item.configCode == 'bmb_to_mb_rate')
  298. if (result.length) {
  299. configTxt.value = result[0]
  300. }
  301. walletForm.value.orderAmt = index == 0 ? Number(configTxt.value.configValue) : 1
  302. handleChange()
  303. dialogVisible.value = true;
  304. }
  305. const handleChange = async () => {
  306. if (walletForm.value.orderAmt) {
  307. if (transformationIndex.value == 0 && Number(walletForm.value.orderAmt) % Number(configTxt.value.configValue) !== 0) return
  308. let res = await calRate({
  309. orderType: walletForm.value.orderType,
  310. orderNum: walletForm.value.orderAmt
  311. });
  312. if (res.code === 200) {
  313. walletForm.value.feeRate = res.data.feeRate
  314. walletForm.value.targetAmount = res.data.targetAmount
  315. }
  316. }
  317. }
  318. // 米币暴米币切换
  319. const changeType = (index) => {
  320. form.value.pageNum = 1;
  321. form.value.balanceType = index + 1;
  322. getList()
  323. }
  324. const handleClick = (tab: TabsPaneContext) => {
  325. form.value.pageNum = 1;
  326. form.value.changeType = tab.props.name;
  327. getList()
  328. }
  329. const getList = async () => {
  330. let api = form.value.changeType == 3 ? withdrawList(form.value) : recordList(form.value)
  331. let res = await api;
  332. list.value = res.rows;
  333. form.value.total = res.total;
  334. }
  335. const handlePageChange = (newPage: number) => {
  336. // list.value = []
  337. form.value.pageNum = page;
  338. getList()
  339. }
  340. // 获取用户信息
  341. const getInfo = async () => {
  342. let res = await getUserInfo();
  343. userInfo.value = res.user;
  344. }
  345. onMounted(() => {
  346. getInfo()
  347. getList()
  348. })
  349. </script>
  350. <style scoped lang="scss">
  351. .wallet-page {
  352. padding-bottom: 16px;
  353. .tabs {
  354. margin-bottom: 16px;
  355. .tab {
  356. cursor: pointer;
  357. color: #2D71FF;
  358. padding: 0 12px;
  359. line-height: 30px;
  360. font-size: 14px;
  361. background: #EAF0FF;
  362. border-radius: 4px;
  363. margin-right: 16px;
  364. }
  365. .active {
  366. color: #FFFFFF;
  367. background: linear-gradient(90deg, #0055FE 0%, #C832FA 100%);
  368. }
  369. }
  370. .wallet-list {
  371. gap: 16px;
  372. padding: 16px;
  373. .li {
  374. flex: 1;
  375. padding: 16px;
  376. border-radius: 16px;
  377. .wallet-list-li-left {
  378. div {
  379. color: #FFFFFF;
  380. font-size: 14px;
  381. line-height: 1;
  382. &:last-child {
  383. margin-top: 8px;
  384. font-size: 32px;
  385. font-weight: bold;
  386. }
  387. }
  388. }
  389. .wallet-list-li-right {
  390. .btn {
  391. cursor: pointer;
  392. margin-left: 8px;
  393. color: #2D71FF;
  394. font-size: 14px;
  395. padding: 0 20px;
  396. height: 40px;
  397. background: #FFFFFF;
  398. border-radius: 10px;
  399. img {
  400. width: 16px;
  401. height: 16px;
  402. margin-right: 4px;
  403. }
  404. &:hover {
  405. opacity: 0.7;
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. .wallet-page-list {
  413. .li {
  414. display: flex;
  415. align-items: center;
  416. justify-content: space-between;
  417. padding: 16px;
  418. border-radius: 16px;
  419. background: #F5F7FA;
  420. margin-bottom: 16px;
  421. &:last-child {
  422. margin-bottom: 0;
  423. }
  424. .title {
  425. div {
  426. font-size: 16px;
  427. line-height: 1;
  428. &:last-child {
  429. margin-top: 8px;
  430. color: #666666;
  431. font-size: 14px;
  432. }
  433. }
  434. }
  435. }
  436. .price {
  437. font-size: 16px;
  438. font-weight: bold;
  439. color: #F52929;
  440. }
  441. .green {
  442. color: #1FB362;
  443. }
  444. .lis {
  445. padding: 16px;
  446. border-radius: 16px;
  447. background: #F5F7FA;
  448. margin-bottom: 16px;
  449. &:last-child {
  450. margin-bottom: 0;
  451. }
  452. }
  453. }
  454. .input {
  455. padding: 16px;
  456. background: #F5F7FA;
  457. border-radius: 16px;
  458. }
  459. .line {
  460. height: 16px;
  461. position: relative;
  462. img {
  463. top: 50%;
  464. width: 40px;
  465. height: 40px;
  466. left: 50%;
  467. z-index: 9;
  468. transform: translate(-50%, -50%);
  469. position: absolute;
  470. }
  471. }
  472. .inputStyle {
  473. :deep(.el-input__wrapper) {
  474. background-color: transparent;
  475. box-shadow: none !important;
  476. padding: 0;
  477. }
  478. :deep(.el-input__inner) {
  479. font-size: 28px;
  480. }
  481. :deep(.el-input-number__increase),
  482. :deep(.el-input-number__decrease) {
  483. display: none;
  484. }
  485. }
  486. </style>