currency-list.vue 11 KB

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