myWallet.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <route lang="json5" type="page">
  2. {
  3. layout: 'default',
  4. needLogin: true,
  5. style: {
  6. navigationBarTitleText: '%wallet.myWallet.title%',
  7. navigationBarBackgroundColor: '#fff',
  8. },
  9. }
  10. </route>
  11. <script lang="ts" setup>
  12. // eslint-disable-next-line unused-imports/no-unused-imports
  13. import { onPageScroll, onReachBottom } from '@dcloudio/uni-app' // 必须导入需要用到的页面生命周期(即使在当前页面上没有直接使用到)
  14. import useZPaging from 'z-paging/components/z-paging/js/hooks/useZPaging.js'
  15. import { getEnum as _getEnum } from '@/api/common'
  16. import { getWalletAccountInfo, unpaidOrder, walletFlowList } from '@/api/wallet'
  17. import DialogBox from '@/components/DialogBox/DialogBox.vue'
  18. import { DialogUtils } from '@/components/DialogBox/utils'
  19. import { t } from '@/locale'
  20. import { formatNumber } from '@/utils'
  21. import { toPage } from '@/utils/page'
  22. // z-paging
  23. const paging = ref(null)
  24. // 类似mixins,如果是页面滚动务必要写这一行,并传入当前ref绑定的paging,注意此处是paging,而非paging.value
  25. useZPaging(paging)
  26. // DialogBox 函数式调用配置
  27. const dialogConfig = ref<any>({})
  28. const dayType = ref(1)
  29. const walletInfo = ref<any>({})
  30. async function getWalletInfo() {
  31. // 获取钱包信息-查询余额
  32. const res = await getWalletAccountInfo()
  33. console.log(res)
  34. walletInfo.value = res?.data
  35. }
  36. const dataList = ref<any[]>([])
  37. async function getWalletFlowList(pageNo: number, pageSize: number) {
  38. const data = {
  39. page: pageNo,
  40. size: pageSize,
  41. type: dayType.value,
  42. }
  43. try {
  44. const res = await walletFlowList(data)
  45. console.log(res)
  46. paging.value.complete(res.data.list)
  47. }
  48. catch (error) {
  49. paging.value.complete(false)
  50. }
  51. }
  52. // 显示取消订单确认对话框
  53. function showUnpaidOrderDialog() {
  54. Object.assign(dialogConfig.value, DialogUtils.info(
  55. t('wallet.unpaidOrderDialog.title'),
  56. {
  57. showCancel: true,
  58. confirmText: t('wallet.unpaidOrderDialog.confirm'),
  59. cancelText: t('wallet.unpaidOrderDialog.cancel'),
  60. },
  61. ))
  62. }
  63. // 处理对话框关闭事件
  64. function handleDialogClose() {
  65. dialogConfig.value.show = false
  66. }
  67. // 处理对话框确认事件
  68. function handleDialogConfirm() {
  69. // 继续充值
  70. handleDialogClose()
  71. toPage({ url: '/pages/wallet/rechargeRecord' })
  72. // 关闭对话框
  73. }
  74. function handleDialogCancel() {
  75. // 新充值
  76. handleDialogClose()
  77. toPage({ url: '/pages/wallet/recharge' })
  78. }
  79. // 查询未完成的充值订单
  80. async function getUnpaidOrder() {
  81. try {
  82. const res = await unpaidOrder()
  83. console.log(res)
  84. if (res.code === '200' && res.data) {
  85. showUnpaidOrderDialog()
  86. }
  87. }
  88. catch (error) {
  89. console.log(error)
  90. }
  91. }
  92. const typeEnum = ref<any[]>([])
  93. async function getEnum() {
  94. const res = await _getEnum({ id: 1 })
  95. typeEnum.value = res.data
  96. }
  97. onShow(() => {
  98. getEnum()
  99. getWalletInfo()
  100. getUnpaidOrder()
  101. })
  102. </script>
  103. <template>
  104. <z-paging ref="paging" v-model="dataList" use-page-scroll @on-refresh="getWalletInfo" @query="getWalletFlowList">
  105. <view class="px-24rpx pt-20rpx">
  106. <view
  107. class="mb-20rpx flex items-center justify-around rounded-12rpx bg-[rgba(var(--wot-color-theme-rgb),0.1)] px-16rpx py-22rpx"
  108. >
  109. <view class="text-center">
  110. <view class="text-22rpx text-#595959">
  111. {{ $t('wallet.balance') }}
  112. </view>
  113. <view class="mb-22rpx text-44rpx text-[var(--wot-color-theme)] font-bold">
  114. {{ formatNumber(walletInfo.balance) }}
  115. </view>
  116. <view class="flex items-center text-22rpx text-#595959">
  117. <text class="mr-1px">
  118. {{ $t('wallet.frozenBalance') }}
  119. </text>
  120. <wd-icon name="help-circle" size="20rpx" />
  121. </view>
  122. <view class="text-26rpx font-bold">
  123. {{ formatNumber(walletInfo.freezeAmount) }}
  124. </view>
  125. </view>
  126. <view class="flex flex-col items-end">
  127. <wd-button size="small" @click="toPage({ url: '/pages/wallet/recharge' })">
  128. {{ $t('wallet.recharge') }}
  129. </wd-button>
  130. </view>
  131. </view>
  132. <view class="mb-20rpx flex justify-center">
  133. <view class="flex items-center justify-center" @click="toPage({ url: '/pages/wallet/withdraw', params: { balance: walletInfo.balance, type: 1 } })">
  134. <text class="mr-8rpx">
  135. {{ $t('wallet.withdrawNow') }}
  136. </text>
  137. <wd-icon name="arrow-right" size="28rpx" />
  138. </view>
  139. </view>
  140. <view>
  141. <view class="mb-20rpx text-32rpx">
  142. {{ $t('wallet.record') }}
  143. </view>
  144. <view class="mb-20rpx">
  145. <wd-radio-group v-model="dayType" shape="button" @change="() => getWalletFlowList(1, 20)">
  146. <wd-radio :value="1">
  147. {{ $t('wallet.record.type.DT') }}
  148. </wd-radio>
  149. <wd-radio :value="2">
  150. {{ $t('wallet.record.type.YT') }}
  151. </wd-radio>
  152. <wd-radio :value="3">
  153. {{ $t('wallet.record.type.L7D') }}
  154. </wd-radio>
  155. <wd-radio :value="4">
  156. {{ $t('wallet.record.type.MTD') }}
  157. </wd-radio>
  158. <wd-radio :value="5">
  159. {{ $t('wallet.record.type.YTD') }}
  160. </wd-radio>
  161. </wd-radio-group>
  162. </view>
  163. <view class="rounded-16rpx bg-white px-20rpx">
  164. <view
  165. v-for="(item, index) in dataList" :key="item.id" class="py-20rpx"
  166. :class="{ 'border-b-1 border-b-solid border-b-#e8e8e8': index !== dataList.length - 1 }"
  167. >
  168. <view class="mb-8rpx flex items-center justify-between text-24rpx">
  169. <text class="truncate">
  170. Order ID:{{ item.bizNo }}
  171. </text>
  172. <text class="flex-shrink-0 pl-16rpx">
  173. {{ item.type === 1 ? '-' : '+' }}৳{{ formatNumber(item.amount) }}
  174. </text>
  175. </view>
  176. <view class="flex items-center justify-between text-22rpx">
  177. <text class="text-#5B5B5B">
  178. {{ item.createTime }}
  179. </text>
  180. <wd-text :type="item.bizType === 8001 || item.bizType === 9001 ? 'primary' : 'success'" :text="item.bizType === 8001 || item.bizType === 9001 ? typeEnum.find(i => i.code === item.bizType)?.name : 'Completed'" />
  181. </view>
  182. </view>
  183. </view>
  184. </view>
  185. <DialogBox
  186. v-bind="dialogConfig"
  187. @confirm="handleDialogConfirm"
  188. @cancel="handleDialogCancel"
  189. @close="handleDialogClose"
  190. />
  191. </view>
  192. </z-paging>
  193. </template>
  194. <style lang="scss" scoped>
  195. :deep(.wd-radio-group) {
  196. background: transparent;
  197. .wd-radio.is-button.is-checked {
  198. .wd-radio__label {
  199. background: #ff334a !important;
  200. border-color: #ff334a !important;
  201. color: #fff !important;
  202. }
  203. }
  204. .wd-radio__label {
  205. width: 100rpx !important;
  206. min-width: 100rpx !important;
  207. max-width: 100rpx !important;
  208. height: 36rpx !important;
  209. line-height: 36rpx !important;
  210. padding: 0 !important;
  211. font-size: 22rpx !important;
  212. background: rgba(255, 255, 255, 0.2) !important;
  213. border-color: rgba(151, 151, 151, 0.2) !important;
  214. }
  215. }
  216. </style>