123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <template>
- <template v-if="!isSelect">
- <div class="header">
- <input
- class="input"
- @input="onInput"
- v-model="keywords"
- placeholder="Search name" />
- <img
- class="icon-clear"
- src="../static/img/icon-clear-search.svg"
- v-if="keywords"
- @click="clearIpt" >
- </div>
- <div class="list-wrapper" :class="{min: showSearch}">
- <template v-if="!showSearch">
- <div
- class="list-item"
- :key="index"
- v-for="(item, index) in currencyInfoList">
- <div
- class="item-title"
- v-if="item.data.length">
- <template v-if="item.type == 1">
- <img class="icon" src="../static/img/icon-currency-category-01.svg" />
- <span>Cash</span>
- </template>
- <template v-else>
- <img class="icon" src="../static/img/icon-currency-category-02.svg" />
- <span>Crypto</span>
- </template>
- </div>
- <div
- class="item-detail"
- v-for="(data, idx) in item.data"
- :key="idx"
- @click="selectCurrency(data)">
- <div class="left">
- <img class="icon-currency" :src="data.currencies[0].iconPath" />
- <div class="currency-info">
- <div class="name">{{ data.currencies[0].currencyCode == 'USD' ? 'USD' : data.currencies[0].tokenSymbol }}</div>
- <div class="desc">{{ data.currencies[0].currencyCode == 'USD' ? 'Paypal' : data.currencies[0].currencyName }}
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="no-data" v-if="show_empty">
- Not found
- </div>
- </template>
- <template v-else>
- <div
- class="item-detail"
- :key="idx"
- v-for="(data, idx) in searchList"
- @click="selectCurrency(data)">
- <div class="left">
- <img class="icon-currency" :src="data.currencies[0].iconPath" />
- <div class="currency-info">
- <div class="name">{{ data.currencies[0].currencyCode == 'USD' ? 'USD' : data.currencies[0].tokenSymbol }}</div>
- <div class="desc">{{ data.currencies[0].currencyName }}</div>
- </div>
- </div>
- </div>
- <div class="no-data" v-if="!searchList.length">
- Not found
- </div>
- </template>
- </div>
- </template>
- <template v-else>
- <div class="list-wrapper">
- <div class="list-item">
- <div
- :key="idx"
- v-for="(data, idx) in isSelectData"
- @click="selectItem(data)">
- <div class="item-title">
- <img class="icon" :src="data.chainInfo.iconPath" />
- {{data.chainInfo.chainName}}
- </div>
- <div class="item-detail">
- <div class="left">
- <img class="icon-currency" :src="data?.iconPath" />
- <div class="currency-info">
- <div class="name">{{ data.currencyCode == 'USD' ? 'USD' : data.tokenSymbol }}</div>
- <div class="desc">{{ data.currencyCode == 'USD' ? 'Paypal' : data.currencyName }}</div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- </template>
- <script lang="ts" setup>
- import { ref, onBeforeMount, defineEmits } from 'vue';
- import Api from '../static/http/api';
- import { postRequest } from '../static/http';
- import { debounce } from '../static/utils';
- const keywords = ref('');
- const showSearch = ref(false);
- const currencyInfoList = ref([]);
- const searchList = ref([]);
- const show_empty = ref(false);
- const isSelect = ref(false);
- const isSelectData = ref(null);
- const listReqParams = {
- params: {
- pageNum: 1,
- pageSize: 100,
- },
- loadMore: false,
- };
- const emits = defineEmits(['selectCurrencyItem'])
- const clearIpt = () => {
- keywords.value = '';
- showSearch.value = false;
- searchList.value = [];
- }
- const onInput = (val: any) => {
- console.log(keywords.value);
- if (keywords.value) {
- showSearch.value = true;
- searchCurrency(keywords.value);
- } else {
- showSearch.value = false;
- searchList.value = [];
- }
- }
- const searchCurrency = debounce(function (searchWords: any) {
- postRequest(Api.searchCurrencyInfo, {
- params: {
- pageNum: 1,
- pageSize: 100,
- searchWords,
- filterFiatCurrency: false
- }
- }).then(res => {
- if (res.code == 0) {
- if (res.data.currencyCategories && res.data.currencyCategories.length) {
- let list = res.data.currencyCategories[0];
- if (list && list.data && list.data.length) {
- searchList.value = list.data;
- } else {
- searchList.value = [];
- }
- } else {
- searchList.value = [];
- }
- }
- })
- }, 500)
- const getCurrencyInfoList = () => {
- postRequest(Api.getCurrencyInfo, {
- params: {
- pageNum: listReqParams.params.pageNum,
- pageSize: listReqParams.params.pageSize,
- filterFiatCurrency: true,
- filterEmptyBalance: false
- }
- }).then(res => {
- if (res.code == 0) {
- let resData = res.data;
- if (resData && resData.currencyCategories.length) {
- if (listReqParams.params.pageNum < 2) {
- currencyInfoList.value = res.data.currencyCategories;
- if(resData.currencyCategories.length == 1 && (!resData.currencyCategories[0]['data'] || !resData.currencyCategories[0]['data'].length)) {
- show_empty.value = true
- }
- } else {
- let data = currencyInfoList.value;
- let currencyCategories = resData.currencyCategories;
- data = data.concat(currencyCategories);
- currencyInfoList.value = data;
- }
- listReqParams.loadMore = false;
- } else {
- show_empty.value = true
- }
- }
- })
- }
- const selectItem = (data: any) => {
- emits('selectCurrencyItem', data);
- }
- const selectCurrency = (data: any) => {
- if (data.currencies.length > 1) {
- isSelect.value = true;
- isSelectData.value = data.currencies;
- } else {
- emits('selectCurrencyItem', data.currencies[0]);
- }
- }
- onBeforeMount(() => {
- getCurrencyInfoList()
- })
- </script>
- <style lang="less" scoped>
- .header {
- display: flex;
- align-items: center;
- justify-content: center;
- height: 60px;
- background: #F7F7F7;
- .input {
- width: calc(100% - 20px);
- height: calc(100% - 20px);
- background: #f1f1f1;
- border-radius: 110px;
- box-sizing: border-box;
- border: none;
- outline: none;
- padding: 10px 80px 10px 22px;
- color: #adadad;
- }
- input::placeholder {
- color: #adadad;
- }
- .icon-clear {
- position: absolute;
- right: 6%;
- cursor: pointer;
- }
- }
- .list-wrapper {
- overflow-y: auto;
- max-height: calc(420px - 60px);
- &.min {
- min-height: 200px;
- }
- .list-item {
- .item-title {
- display: flex;
- align-items: center;
- height: 42px;
- padding: 0 10px;
- box-sizing: border-box;
- background: #fafafa;
- font-size: 14px;
- color: #a2a2a2;
- .icon {
- width: 24px;
- height: 24px;
- margin-right: 6px;
- }
- }
- }
- .item-detail {
- display: flex;
- justify-content: space-between;
- align-items: center;
- padding: 12px 20px;
- box-sizing: border-box;
- cursor: pointer;
- .left {
- display: flex;
- .icon-currency {
- width: 24px;
- height: 24px;
- margin-right: 12px;
- margin-top: 4px;
- }
- .currency-info {
- .name {
- font-weight: 500;
- font-size: 15px;
- margin-bottom: 5px;
- word-break: break-all;
- }
- .desc {
- font-weight: 400;
- font-size: 12px;
- color: #a2a2a2;
- }
- }
- }
- }
- .no-data {
- font-weight: 500;
- font-size: 22px;
- color: #BBBBBB;
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- }
- }
- </style>
|