currency-list.vue 12 KB

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