Wallet.vue 20 KB

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