currency-list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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" :style="{'paddingBottom': showGeneralLottery ? '50px' : '0'}" 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].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. <!-- 添加通用奖品 -->
  87. <div class="add-general-lottery" v-if="showGeneralLottery" @click="addGeneralLottery">
  88. <img class="add-general-lottery-icon" :src="require('@/assets/svg/icon-add-white.svg')" />
  89. <span class="add-general-lottery-text">Customize</span>
  90. </div>
  91. </div>
  92. </div>
  93. </template>
  94. <script setup>
  95. /* eslint-disable */
  96. import { defineEmits, ref, onMounted, defineProps, defineExpose } from "vue";
  97. import { getCurrencyInfo, searchCurrencyInfo, syncChainTokenRechargeRecord } from "@/http/publishApi";
  98. import { debounce, getBit } from "@/uilts/help";
  99. const props = defineProps({
  100. page: {
  101. type: String,
  102. default: '',
  103. },
  104. filterEmptyBalance: {
  105. type: Boolean,
  106. default: false
  107. },
  108. showRefresh: {
  109. type: Boolean,
  110. default: true
  111. },
  112. // 是否显示 通用奖品选项
  113. showGeneralLottery: {
  114. type: Boolean,
  115. default: false
  116. }
  117. })
  118. let keywords = ref('');
  119. let showSearch = ref(false);
  120. let currencyInfoList = ref([]);
  121. let searchList = ref([]);
  122. let refreshRotate = ref(false);
  123. let listWrapperDom = ref(null);
  124. let listContentDom = ref(null);
  125. let listReqParams = {
  126. params: {
  127. pageNum: 1,
  128. pageSize: 100,
  129. },
  130. loadMore: false,
  131. requestIng: false
  132. };
  133. let show_empty = ref(false);
  134. const emits = defineEmits(["selectCurrency", "setCurrencyList", "addGeneralLottery"]);
  135. const selectCurrency = (params) => {
  136. emits("selectCurrency", params);
  137. };
  138. const onInput = (val) => {
  139. console.log(keywords.value);
  140. if (keywords.value) {
  141. showSearch.value = true;
  142. searchCurrency(keywords.value);
  143. } else {
  144. showSearch.value = false;
  145. searchList.value = [];
  146. }
  147. }
  148. const clearIpt = () => {
  149. keywords.value = '';
  150. showSearch.value = false;
  151. searchList.value = [];
  152. }
  153. const refresh = () => {
  154. if (!refreshRotate.value) {
  155. refreshRotate.value = true;
  156. setTimeout(() => {
  157. refreshRotate.value = false;
  158. }, 1000)
  159. asyncTokenRechRecord(() => {
  160. listReqParams.params.pageNum = 1;
  161. getCurrencyInfoList();
  162. })
  163. }
  164. }
  165. /**
  166. * 搜索结果列表
  167. */
  168. const searchCurrency = debounce(function (searchWords) {
  169. searchCurrencyInfo({
  170. params: {
  171. pageNum: 1,
  172. pageSize: 100,
  173. searchWords,
  174. filterFiatCurrency: props.page == 'top-up'
  175. }
  176. }).then(res => {
  177. if (res.code == 0) {
  178. if (res.data.currencyCategories && res.data.currencyCategories.length) {
  179. let list = res.data.currencyCategories[0];
  180. if (list && list.data && list.data.length) {
  181. searchList.value = list.data;
  182. } else {
  183. searchList.value = [];
  184. }
  185. } else {
  186. searchList.value = [];
  187. }
  188. }
  189. })
  190. }, 500)
  191. /**
  192. * 获取货币列表
  193. */
  194. const getCurrencyInfoList = (_params = {}) => {
  195. if(listReqParams.requestIng) {
  196. return;
  197. }
  198. listReqParams.requestIng = true;
  199. if(_params.pageNum) {
  200. listReqParams.params.pageNum = _params.pageNum;
  201. }
  202. let params = {
  203. params: {
  204. pageNum: listReqParams.params.pageNum,
  205. pageSize: listReqParams.params.pageSize,
  206. filterFiatCurrency: props.page == 'top-up',
  207. filterEmptyBalance: props.filterEmptyBalance
  208. }
  209. };
  210. getCurrencyInfo(params).then(res => {
  211. listReqParams.requestIng = false;
  212. if (res.code == 0) {
  213. let resData = res.data;
  214. if (resData && resData.currencyCategories.length) {
  215. if (listReqParams.params.pageNum < 2) {
  216. currencyInfoList.value = res.data.currencyCategories;
  217. emits('setCurrencyList', { list: currencyInfoList.value })
  218. if(resData.currencyCategories.length == 1 && (!resData.currencyCategories[0]['data'] || !resData.currencyCategories[0]['data'].length)) {
  219. show_empty.value = true
  220. }
  221. } else {
  222. let data = currencyInfoList.value;
  223. let currencyCategories = resData.currencyCategories;
  224. if(currencyCategories.length) {
  225. let tokenData = currencyCategories.find(item => item.type == 2);
  226. if(tokenData && tokenData.data && tokenData.data.length) {
  227. let index = data.findIndex(item => item.type == 2);
  228. let tokenList = data[index]['data'];
  229. data[index]['data'] = tokenList.concat(tokenData.data);
  230. currencyInfoList.value = data;
  231. }
  232. }
  233. }
  234. listReqParams.loadMore = false;
  235. }else{
  236. show_empty.value = true
  237. }
  238. }
  239. }).catch(err => {
  240. listReqParams.requestIng = false;
  241. })
  242. }
  243. /**
  244. * 同步链上交易
  245. */
  246. const asyncTokenRechRecord = (cb) => {
  247. syncChainTokenRechargeRecord({
  248. params: {
  249. currencyCode: ''
  250. }
  251. }).then(res => {
  252. if (res.code == 0) {
  253. cb && cb(res.data)
  254. }
  255. })
  256. }
  257. const listScroll = (e) => {
  258. let wrapperHeight = listWrapperDom.value.offsetHeight;
  259. let listContentHeight = listContentDom.value.offsetHeight;
  260. let scrollTop = e.target.scrollTop || 0;
  261. if (
  262. listReqParams.loadMore === false &&
  263. wrapperHeight + scrollTop >= (listContentHeight - 50)
  264. ) {
  265. listReqParams.loadMore = true;
  266. listReqParams.params.pageNum++;
  267. getCurrencyInfoList();
  268. }
  269. }
  270. /**
  271. * 添加通用奖品 按钮点击
  272. */
  273. const addGeneralLottery = () => {
  274. emits('addGeneralLottery');
  275. }
  276. onMounted(() => {
  277. getCurrencyInfoList();
  278. })
  279. defineExpose({
  280. getCurrencyInfoList,
  281. refresh
  282. })
  283. </script>
  284. <style scoped lang="scss">
  285. .currency-list-wrapper {
  286. width: 100%;
  287. height: 100%;
  288. background-color: #fff;
  289. box-sizing: border-box;
  290. .search-input-wrapper {
  291. padding: 10px;
  292. box-sizing: border-box;
  293. background: #f7f7f7;
  294. display: flex;
  295. align-items: center;
  296. justify-content: space-between;
  297. position: relative;
  298. .input {
  299. background: #f1f1f1;
  300. border-radius: 110px;
  301. width: 88%;
  302. height: 40px;
  303. box-sizing: border-box;
  304. border: none;
  305. outline: none;
  306. padding: 10px 80px 10px 22px;
  307. color: #adadad;
  308. }
  309. input::placeholder {
  310. color: #adadad;
  311. }
  312. .icon {
  313. width: 32px;
  314. cursor: pointer;
  315. }
  316. .icon-refresh-rotate {
  317. transform: rotate(360deg);
  318. transition-duration: 1s;
  319. }
  320. .icon-clear {
  321. position: absolute;
  322. right: 16%;
  323. cursor: pointer;
  324. }
  325. }
  326. .list-wrapper {
  327. height: calc(100% - 60px);
  328. overflow-y: auto;
  329. padding-bottom: 50px;
  330. .list-item {
  331. .item-title {
  332. display: flex;
  333. align-items: center;
  334. height: 42px;
  335. padding: 0 10px;
  336. box-sizing: border-box;
  337. background: #f7f7f7;
  338. font-size: 14px;
  339. color: #a2a2a2;
  340. .icon {
  341. width: 24px;
  342. height: 24px;
  343. margin-right: 6px;
  344. }
  345. }
  346. }
  347. .item-detail {
  348. display: flex;
  349. justify-content: space-between;
  350. align-items: center;
  351. padding: 12px 20px;
  352. box-sizing: border-box;
  353. cursor: pointer;
  354. .left {
  355. display: flex;
  356. .icon-currency {
  357. width: 24px;
  358. height: 24px;
  359. margin-right: 12px;
  360. margin-top: 4px;
  361. }
  362. .currency-info {
  363. .name {
  364. font-weight: 500;
  365. font-size: 15px;
  366. margin-bottom: 5px;
  367. word-break: break-all;
  368. }
  369. .desc {
  370. font-weight: 400;
  371. font-size: 12px;
  372. color: #a2a2a2;
  373. }
  374. }
  375. }
  376. .right {
  377. text-align: right;
  378. max-width: calc(100% - 150px);
  379. .num, .amount {
  380. word-break: break-all;
  381. }
  382. .num {
  383. font-weight: 500;
  384. font-size: 15px;
  385. margin-bottom: 5px;
  386. }
  387. .amount {
  388. font-weight: 400;
  389. font-size: 12px;
  390. color: #a2a2a2;
  391. }
  392. }
  393. }
  394. .no-data {
  395. font-weight: 500;
  396. font-size: 22px;
  397. color: #BBBBBB;
  398. position: absolute;
  399. top: 50%;
  400. left: 50%;
  401. transform: translate(-50%, -50%);
  402. }
  403. .add-general-lottery {
  404. position: absolute;
  405. bottom: 0;
  406. left: 0;
  407. display: flex;
  408. width: 100%;
  409. height: 50px;
  410. align-items: center;
  411. justify-content: center;
  412. background-color: #1D9BF0;
  413. color: #fff;
  414. cursor: pointer;
  415. &-icon {
  416. margin-right: 8px;
  417. }
  418. &-text {
  419. font-size: 16px;
  420. }
  421. }
  422. }
  423. }
  424. </style>