currency-list.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. <!-- 货币列表 -->
  2. <template>
  3. <div class="currency-list-wrapper">
  4. <div class="search-input-wrapper">
  5. <input class="input" v-model="keywords" @input="onInput" placeholder="Search name" />
  6. <img :src="require('../../assets/svg/icon-form-refresh.svg')"
  7. class="icon"
  8. :class="{ 'icon-refresh-rotate': refreshRotate }"
  9. @click="refresh">
  10. <img :src="require('../../assets/svg/icon-clear-search.svg')" class="icon-clear"
  11. v-if="keywords"
  12. @click="clearIpt" >
  13. </div>
  14. <div class="list-wrapper" ref="listWrapperDom" @scroll="listScroll">
  15. <div class="page-list" ref="listContentDom" v-if="!showSearch">
  16. <div class="list-item" v-for="(item, index) in currencyInfoList" :key="index">
  17. <template v-if="props.page != 'top-up' || item.type != 1">
  18. <div class="item-title" v-if="item.data.length">
  19. <img class="icon"
  20. :src="item.type == 1 ? require('../../assets/svg/icon-currency-category-01.svg') : require('../../assets/svg/icon-currency-category-02.svg')" />
  21. {{ item.type == 1 ? 'Cash' : 'Crypto' }}
  22. </div>
  23. <div class="item-detail" v-for="(data, idx) in item.data" :key="idx"
  24. @click="selectCurrency(data.currencies)">
  25. <div class="left">
  26. <img class="icon-currency" :src="data.currencies[0].iconPath" />
  27. <div class="currency-info">
  28. <div class="name">{{ data.currencies[0].currencyCode == 'USD' ? 'USD' : data.currencies[0].tokenSymbol }}</div>
  29. <div class="desc">{{ data.currencies[0].currencyCode == 'USD' ? 'Paypal' : data.currencies[0].currencyName }}
  30. </div>
  31. </div>
  32. </div>
  33. <div class="right">
  34. <div class="num">
  35. <a-tooltip :title="data.totalBalance">
  36. {{ getBit(data.totalBalance) }}
  37. </a-tooltip>
  38. </div>
  39. <div class="amount" v-if="data.currencies[0].currencyType == 2">
  40. <a-tooltip :title="'$'+data.totalUsdEstimateBalance">
  41. ${{ getBit(data.totalUsdEstimateBalance) }}
  42. </a-tooltip>
  43. </div>
  44. </div>
  45. </div>
  46. </template>
  47. </div>
  48. <div class="no-data" v-if="show_empty">
  49. {{page != 'top-up' ? 'Not found' : 'No balance'}}
  50. </div>
  51. </div>
  52. <!-- 显示搜索结果列表 -->
  53. <div class="search-list" v-else>
  54. <div class="item-detail" v-for="(data, idx) in searchList" :key="idx" @click="selectCurrency(data.currencies)">
  55. <div class="left">
  56. <img class="icon-currency" :src="data.currencies[0].iconPath" />
  57. <div class="currency-info">
  58. <div class="name">{{ data.currencies[0].currencyCode == 'USD' ? 'USD' : data.currencies[0].tokenSymbol }}</div>
  59. <div class="desc">{{ data.currencies[0].currencyName }}</div>
  60. </div>
  61. </div>
  62. <div class="right">
  63. <div class="num">
  64. <a-tooltip :title="data.currencies[0].balance">
  65. {{ getBit(data.currencies[0].balance) }}
  66. </a-tooltip>
  67. </div>
  68. <div class="amount" v-if="data.currencies[0].currencyType == 2">
  69. <a-tooltip :title="'$'+data.currencies[0].usdEstimateBalance">
  70. ${{ getBit(data.currencies[0].usdEstimateBalance) }}
  71. </a-tooltip>
  72. </div>
  73. </div>
  74. </div>
  75. <div class="no-data" v-if="!searchList.length">
  76. {{page != 'top-up' ? 'Not found' : 'No balance'}}
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. </template>
  82. <script setup>
  83. /* eslint-disable */
  84. import { defineEmits, ref, onMounted, defineProps, defineExpose } from "vue";
  85. import { getCurrencyInfo, searchCurrencyInfo, syncChainTokenRechargeRecord } from "@/http/publishApi";
  86. import { debounce, getBit } from "@/uilts/help";
  87. const props = defineProps({
  88. page: {
  89. type: String,
  90. default: '',
  91. },
  92. filterEmptyBalance: {
  93. type: Boolean,
  94. default: false
  95. }
  96. })
  97. let keywords = ref('');
  98. let showSearch = ref(false);
  99. let currencyInfoList = ref([]);
  100. let searchList = ref([]);
  101. let refreshRotate = ref(false);
  102. let listWrapperDom = ref(null);
  103. let listContentDom = ref(null);
  104. let listReqParams = {
  105. params: {
  106. pageNum: 1,
  107. pageSize: 100,
  108. },
  109. loadMore: false,
  110. };
  111. let show_empty = ref(false)
  112. const emits = defineEmits(["selectCurrency", "setCurrencyList"]);
  113. const selectCurrency = (params) => {
  114. emits("selectCurrency", params);
  115. };
  116. const onInput = (val) => {
  117. console.log(keywords.value);
  118. if (keywords.value) {
  119. showSearch.value = true;
  120. searchCurrency(keywords.value);
  121. } else {
  122. showSearch.value = false;
  123. searchList.value = [];
  124. }
  125. }
  126. const clearIpt = () => {
  127. keywords.value = '';
  128. showSearch.value = false;
  129. searchList.value = [];
  130. }
  131. const refresh = () => {
  132. if (!refreshRotate.value) {
  133. refreshRotate.value = true;
  134. setTimeout(() => {
  135. refreshRotate.value = false;
  136. }, 1000)
  137. asyncTokenRechRecord(() => {
  138. getCurrencyInfoList();
  139. })
  140. }
  141. }
  142. /**
  143. * 搜索结果列表
  144. */
  145. const searchCurrency = debounce(function (searchWords) {
  146. searchCurrencyInfo({
  147. params: {
  148. pageNum: 1,
  149. pageSize: 100,
  150. searchWords,
  151. filterFiatCurrency: props.page == 'top-up'
  152. }
  153. }).then(res => {
  154. if (res.code == 0) {
  155. if (res.data.currencyCategories && res.data.currencyCategories.length) {
  156. let list = res.data.currencyCategories[0];
  157. if (list && list.data && list.data.length) {
  158. searchList.value = list.data;
  159. } else {
  160. searchList.value = [];
  161. }
  162. } else {
  163. searchList.value = [];
  164. }
  165. }
  166. })
  167. }, 500)
  168. /**
  169. * 获取货币列表
  170. */
  171. const getCurrencyInfoList = () => {
  172. let params = {
  173. params: {
  174. pageNum: listReqParams.params.pageNum,
  175. pageSize: listReqParams.params.pageSize,
  176. filterFiatCurrency: props.page == 'top-up',
  177. filterEmptyBalance: props.filterEmptyBalance
  178. }
  179. };
  180. getCurrencyInfo(params).then(res => {
  181. if (res.code == 0) {
  182. let resData = res.data;
  183. if (resData && resData.currencyCategories.length) {
  184. if (listReqParams.params.pageNum < 2) {
  185. currencyInfoList.value = res.data.currencyCategories;
  186. emits('setCurrencyList', { list: currencyInfoList.value })
  187. if(resData.currencyCategories.length == 1 && (!resData.currencyCategories[0]['data'] || !resData.currencyCategories[0]['data'].length)) {
  188. show_empty.value = true
  189. }
  190. } else {
  191. let data = currencyInfoList.value;
  192. let currencyCategories = resData.currencyCategories;
  193. data = data.concat(currencyCategories);
  194. currencyInfoList.value = data;
  195. }
  196. listReqParams.loadMore = false;
  197. }else{
  198. show_empty.value = true
  199. }
  200. }
  201. })
  202. }
  203. /**
  204. * 同步链上交易
  205. */
  206. const asyncTokenRechRecord = (cb) => {
  207. syncChainTokenRechargeRecord({
  208. params: {
  209. currencyCode: ''
  210. }
  211. }).then(res => {
  212. if (res.code == 0) {
  213. cb && cb(res.data)
  214. }
  215. })
  216. }
  217. const listScroll = (e) => {
  218. let wrapperHeight = listWrapperDom.value.offsetHeight;
  219. let listContentHeight = listContentDom.value.offsetHeight;
  220. let scrollTop = e.target.scrollTop || 0;
  221. if (
  222. listReqParams.loadMore === false &&
  223. wrapperHeight + scrollTop >= listContentHeight
  224. ) {
  225. listReqParams.loadMore = true;
  226. listReqParams.params.pageNum++;
  227. getCurrencyInfoList();
  228. }
  229. }
  230. onMounted(() => {
  231. getCurrencyInfoList();
  232. })
  233. defineExpose({
  234. getCurrencyInfoList
  235. })
  236. </script>
  237. <style scoped lang="scss">
  238. .currency-list-wrapper {
  239. width: 100%;
  240. height: 100%;
  241. background-color: #fff;
  242. box-sizing: border-box;
  243. .search-input-wrapper {
  244. padding: 10px;
  245. box-sizing: border-box;
  246. background: #f7f7f7;
  247. display: flex;
  248. align-items: center;
  249. justify-content: space-between;
  250. position: relative;
  251. .input {
  252. background: #f1f1f1;
  253. border-radius: 110px;
  254. width: 88%;
  255. height: 40px;
  256. box-sizing: border-box;
  257. border: none;
  258. outline: none;
  259. padding: 10px 80px 10px 22px;
  260. }
  261. .icon {
  262. width: 32px;
  263. cursor: pointer;
  264. }
  265. .icon-refresh-rotate {
  266. transform: rotate(360deg);
  267. transition-duration: 1s;
  268. }
  269. .icon-clear {
  270. position: absolute;
  271. right: 16%;
  272. cursor: pointer;
  273. }
  274. }
  275. .list-wrapper {
  276. height: calc(100% - 60px);
  277. overflow-y: auto;
  278. .list-item {
  279. .item-title {
  280. display: flex;
  281. align-items: center;
  282. height: 42px;
  283. padding: 0 10px;
  284. box-sizing: border-box;
  285. background: #f7f7f7;
  286. font-weight: 500;
  287. font-size: 14px;
  288. color: #a2a2a2;
  289. .icon {
  290. width: 24px;
  291. height: 24px;
  292. margin-right: 6px;
  293. }
  294. }
  295. }
  296. .item-detail {
  297. display: flex;
  298. justify-content: space-between;
  299. align-items: center;
  300. padding: 12px 20px;
  301. box-sizing: border-box;
  302. cursor: pointer;
  303. .left {
  304. display: flex;
  305. .icon-currency {
  306. width: 24px;
  307. height: 24px;
  308. margin-right: 12px;
  309. }
  310. .currency-info {
  311. .name {
  312. font-weight: 500;
  313. font-size: 15px;
  314. margin-bottom: 5px;
  315. }
  316. .desc {
  317. font-weight: 400;
  318. font-size: 12px;
  319. color: #a2a2a2;
  320. }
  321. }
  322. }
  323. .right {
  324. text-align: right;
  325. max-width: calc(100% - 150px);
  326. .num, .amount {
  327. word-break: break-all;
  328. }
  329. .num {
  330. font-weight: 500;
  331. font-size: 15px;
  332. margin-bottom: 5px;
  333. }
  334. .amount {
  335. font-weight: 400;
  336. font-size: 12px;
  337. color: #a2a2a2;
  338. }
  339. }
  340. }
  341. .no-data {
  342. font-weight: 500;
  343. font-size: 22px;
  344. color: #BBBBBB;
  345. position: absolute;
  346. top: 50%;
  347. left: 50%;
  348. transform: translate(-50%, -50%);
  349. }
  350. }
  351. }
  352. </style>