Wallet.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <template>
  2. <div class="wallet-page">
  3. <ul class="wallet-list flex-between">
  4. <li class="gradient flex-center-between" 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 ? userInfo.pointsBalance || 0 || 0 : userInfo.baoMiBalance || 0 }}</div>
  8. </div>
  9. <div class="wallet-list-li-right flex-align-center">
  10. <div class="flex-align-center btn" v-if="index == 1">
  11. <img src="/src/assets/imgs/my/tixian@2x.png" alt="">
  12. <div class="">{{ $t('personalCenter.shenqingtixian') }}</div>
  13. </div>
  14. <div @click="changeTransformation(index)" class="flex-align-center btn">
  15. <img src="/src/assets/imgs/my/zhuanhuan@2x.png" alt="">
  16. <div class="">{{ index == 0 ? $t('personalCenter.zhuanhuanbaomibi') : $t('personalCenter.zhuanghuanmibi') }}
  17. </div>
  18. </div>
  19. </div>
  20. </li>
  21. </ul>
  22. <el-tabs v-model="form.activeName" class="demo-tabs" @tab-click="handleClick">
  23. <el-tab-pane :label="$t(tab.label)" v-for="tab in tabs" :key="tab.name" :name="tab.name">
  24. <div class="tabs flex-align-center">
  25. <div :class="{ active: index == 0 }" class="tab" v-for="(item, index) in 2">{{ index == 0 ? '米币' : '暴米币' }}明细
  26. </div>
  27. </div>
  28. <ul class="wallet-page-list">
  29. <li v-for="(item, index) in list" :key="index">
  30. <div class="title">
  31. <div class="">订单米币</div>
  32. <div class="">2024-08-24 14:11:11</div>
  33. </div>
  34. <div class="price">+1000</div>
  35. </li>
  36. </ul>
  37. </el-tab-pane>
  38. </el-tabs>
  39. <template v-if="list.length">
  40. <Pagination :total="form.total" :page-size="form.pageSize" :current-page="form.pageNum"
  41. @page-change="handlePageChange" />
  42. </template>
  43. <el-empty v-else :description="$t('common.empty')" />
  44. <el-dialog v-model="dialogVisible"
  45. :title="`${transformationIndex == 0 ? $t('personalCenter.zhuanhuanbaomibi') : $t('personalCenter.zhuanghuanmibi')}`"
  46. width="523" :before-close="handleClose">
  47. <el-form :model="walletForm" label-width="auto" label-position="top">
  48. <el-row :gutter="16" v-if="transformationIndex">
  49. <el-col :span="24">
  50. <el-form-item :label="$t('common.baomibi')">
  51. <el-input-number v-model="walletForm.orderAmt" :min="1" controls-position="right" size="large"
  52. @change="handleChange" style="width: 100%;" />
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="24">
  56. <el-form-item :label="$t('common.mibi')">
  57. <el-input v-model="walletForm.targetAmount" placeholder="请输入" readonly disabled />
  58. </el-form-item>
  59. </el-col>
  60. <el-col :span="24">
  61. <el-form-item label="手续费率">
  62. <el-input v-model="walletForm.feeRate" placeholder="请输入" readonly disabled />
  63. </el-form-item>
  64. </el-col>
  65. </el-row>
  66. <el-row :gutter="16" v-else>
  67. <el-col :span="12">
  68. <el-form-item :label="$t('common.mibi')">
  69. <el-input-number v-model="walletForm.orderAmt" :min="configTxt.configValue" :step="configTxt.configValue" controls-position="right" size="large"
  70. @change="handleChange" style="width: 100%;" />
  71. </el-form-item>
  72. </el-col>
  73. <el-col :span="12">
  74. <el-form-item :label="$t('common.baomibi')">
  75. <el-input v-model="walletForm.targetAmount" placeholder="请输入" readonly disabled />
  76. </el-form-item>
  77. </el-col>
  78. </el-row>
  79. <div class="">{{ configTxt.configName }}{{ configTxt.configValue }}</div>
  80. </el-form>
  81. <template #footer>
  82. <div class="dialog-footer flex-center">
  83. <el-button @click="dialogVisible = false">{{ $t('common.cancel') }}</el-button>
  84. <el-button class="gradient" type="primary" @click="confirmTransformation">
  85. {{ $t('common.confirm') }}
  86. </el-button>
  87. </div>
  88. </template>
  89. </el-dialog>
  90. </div>
  91. </template>
  92. <script lang="ts" setup>
  93. import { ref, onMounted } from 'vue'
  94. import type { TabsPaneContext } from 'element-plus'
  95. import Pagination from '@/components/Pagination.vue'
  96. import { getUserInfo } from '@/api/auth'
  97. import { payConfigDearch, calRate } from '@/api/order'
  98. import { createOrder } from '@/api/order.js'
  99. import { useAppStore } from '@/pinia/appStore'
  100. import DGTMessage from '@/utils/message'
  101. import { useI18n } from 'vue-i18n'
  102. const { t } = useI18n()
  103. const appStore = useAppStore();
  104. const tabs = ref([
  105. { label: 'personalCenter.incomeDetails', name: 0 },
  106. { label: 'personalCenter.usageRecord', name: 1 }
  107. ])
  108. const list = ref([])
  109. const form = ref({
  110. activeName: 0,
  111. pageNum: 1,
  112. pageSize: 10,
  113. total: 0,
  114. })
  115. const walletForm = ref({
  116. payMethod: '',
  117. orderType: '',
  118. productId: '',
  119. orderNum: null,
  120. orderAmt: 1,
  121. feeRate: 0,
  122. targetAmount:0
  123. })
  124. const configTxt = ref({})
  125. const userInfo = ref({})//用户信息
  126. const dialogVisible = ref(false);
  127. const transformationIndex = ref(0)
  128. // 确认转换
  129. const confirmTransformation = async () =>{
  130. let res = await createOrder({
  131. payMethod: walletForm.value.payMethod,
  132. orderType: walletForm.value.orderType,
  133. productId: '',
  134. orderNum: walletForm.value.targetAmount,
  135. orderAmt: walletForm.value.orderAmt
  136. })
  137. console.log(res);
  138. if (res.code === 200) {
  139. if (res.data.paySuccess) {
  140. dialogVisible.value = false;
  141. appStore.USERINFO();
  142. DGTMessage.success(` ${ transformationIndex.value ? t('common.zhuanhuanbaomibi') : t('common.zhuanghuanmibi')}${t('common.success')}`)
  143. }
  144. }
  145. }
  146. // 米币暴米币转换
  147. const changeTransformation = async (index:any) => {
  148. transformationIndex.value = index;
  149. walletForm.value.payMethod = index ? 'BMI' : 'MI';
  150. walletForm.value.orderType = index ? 'exchange_mi' : 'exchange_bmi';
  151. let { data } = await payConfigDearch({ id: '03' });
  152. let result = data.filter((item:any) => item.configCode == 'bmb_to_mb_rate')
  153. if (result.length) {
  154. configTxt.value = result[0]
  155. }
  156. walletForm.value.orderAmt = index == 0 ? configTxt.value.configValue : 1
  157. handleChange()
  158. dialogVisible.value = true;
  159. }
  160. const handleChange = async () => {
  161. let res = await calRate({
  162. orderType:walletForm.value.orderType,
  163. orderNum:walletForm.value.orderAmt
  164. });
  165. walletForm.value.feeRate = res.data.feeRate
  166. walletForm.value.targetAmount = res.data.targetAmount
  167. console.log(res);
  168. }
  169. const handleClick = (tab: TabsPaneContext) => {
  170. list.value = []
  171. form.value.pageNum = 1;
  172. form.value.activeName = tab.props.name;
  173. getList()
  174. }
  175. const getList = async () => {
  176. }
  177. const handlePageChange = (newPage: number) => {
  178. list.value = []
  179. form.value.pageNum = page;
  180. getList()
  181. }
  182. // 获取用户信息
  183. const getInfo = async () => {
  184. let res = await getUserInfo();
  185. userInfo.value = res.user;
  186. }
  187. onMounted(() => {
  188. getInfo()
  189. getList()
  190. })
  191. </script>
  192. <style scoped lang="scss">
  193. .wallet-page {
  194. padding-bottom: 16px;
  195. .tabs {
  196. .tab {
  197. cursor: pointer;
  198. color: #2D71FF;
  199. padding: 0 12px;
  200. line-height: 30px;
  201. font-size: 14px;
  202. background: #EAF0FF;
  203. border-radius: 4px;
  204. margin-right: 16px;
  205. }
  206. .active {
  207. color: #FFFFFF;
  208. background: linear-gradient(90deg, #0055FE 0%, #C832FA 100%);
  209. }
  210. }
  211. .wallet-list {
  212. gap: 16px;
  213. padding: 16px;
  214. li {
  215. flex: 1;
  216. padding: 16px;
  217. border-radius: 16px;
  218. .wallet-list-li-left {
  219. div {
  220. color: #FFFFFF;
  221. font-size: 14px;
  222. line-height: 1;
  223. &:last-child {
  224. margin-top: 8px;
  225. font-size: 32px;
  226. font-weight: bold;
  227. }
  228. }
  229. }
  230. .wallet-list-li-right {
  231. .btn {
  232. cursor: pointer;
  233. margin-left: 8px;
  234. color: #2D71FF;
  235. font-size: 14px;
  236. padding: 0 20px;
  237. height: 40px;
  238. background: #FFFFFF;
  239. border-radius: 10px;
  240. img {
  241. width: 16px;
  242. height: 16px;
  243. margin-right: 4px;
  244. }
  245. &:hover {
  246. opacity: 0.7;
  247. }
  248. }
  249. }
  250. }
  251. }
  252. }
  253. .wallet-page-list {
  254. li {
  255. display: flex;
  256. align-items: center;
  257. justify-content: space-between;
  258. padding: 16px;
  259. border-radius: 16px;
  260. background: #F5F7FA;
  261. margin-bottom: 16px;
  262. &:last-child {
  263. margin-bottom: 0;
  264. }
  265. .title {
  266. div {
  267. font-size: 16px;
  268. line-height: 1;
  269. &:last-child {
  270. margin-top: 8px;
  271. color: #666666;
  272. font-size: 14px;
  273. }
  274. }
  275. }
  276. .price {
  277. font-size: 16px;
  278. font-weight: bold;
  279. color: #F52929;
  280. }
  281. }
  282. }
  283. </style>