currency-list.vue 14 KB

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