index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <Field v-bind="$attrs" :placeholder="t('common.choice')" arrow-direction="down" is-link readonly @click="showSheet = true">
  3. <template #input v-if="currencyItem">
  4. <app-image-icon :url="getCurrencyIconUrl(currencyItem.enumitemvalue)" size="small" />
  5. <span>{{ currencyItem.label }}</span>
  6. </template>
  7. </Field>
  8. <ActionSheet v-model:show="showSheet" :title="t('common.choice')" teleport="body">
  9. <CellGroup style="min-height: 200px;">
  10. <RadioGroup v-model="currencyId" v-if="currencyList.length">
  11. <template v-for="(item, index) in currencyList" :key="index">
  12. <Cell size="large" :title="item.label" :border="false" clickable center
  13. @click="onRadioClick(item.value)">
  14. <template #icon>
  15. <app-image-icon :url="getCurrencyIconUrl(item.enumitemvalue)" size="small"
  16. style="margin-right: 8px;" />
  17. </template>
  18. <template #right-icon>
  19. <Radio :name="item.value" />
  20. </template>
  21. </Cell>
  22. </template>
  23. </RadioGroup>
  24. <Empty :description="t('common.nodatas')" v-else />
  25. </CellGroup>
  26. </ActionSheet>
  27. </template>
  28. <script lang="ts" setup>
  29. import { shallowRef, computed, onMounted, nextTick } from 'vue'
  30. import { Field, ActionSheet, CellGroup, RadioGroup, Cell, Radio, Empty } from 'vant'
  31. import { getCurrencyIconUrl } from '@/filters'
  32. import { getDigitalCurrencyList } from '@/constants/order'
  33. import { useSpotAccountStore } from '../../views/wallet/components/spot/composables'
  34. import AppImageIcon from '@mobile/components/base/image-icon/index.vue'
  35. import { i18n } from '@/stores'
  36. const props = defineProps({
  37. modelValue: {
  38. type: Number
  39. }
  40. })
  41. const emit = defineEmits(['update:modelValue', 'change'])
  42. const { global: { t } } = i18n
  43. const showSheet = shallowRef(false)
  44. const spotAccountStore = useSpotAccountStore()
  45. const digitalCurrencyList = getDigitalCurrencyList()
  46. // 过滤未激活账户
  47. const currencyList = computed(() => {
  48. const ids = new Set()
  49. for (const item of spotAccountStore.dataList) {
  50. if (item.digitalaccountid) {
  51. ids.add(item.currencyid)
  52. }
  53. }
  54. return digitalCurrencyList.filter((e) => ids.has(e.enumitemname))
  55. })
  56. const currencyItem = computed(() => currencyList.value.find((e) => e.enumitemname === currencyId.value))
  57. const currencyId = computed({
  58. get: () => props.modelValue,
  59. set: (val) => emit('update:modelValue', val)
  60. })
  61. const onChange = () => {
  62. emit('change', currencyItem.value)
  63. }
  64. const onRadioClick = (value: number) => {
  65. currencyId.value = value
  66. showSheet.value = false
  67. nextTick(() => onChange())
  68. }
  69. onMounted(() => {
  70. onChange()
  71. })
  72. </script>