recharge.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <view class="layout-page bg-panel-1" :style="themeStyle">
  3. <v-header>
  4. <template #title>
  5. <span class="color-theme-1 m-r-xs">{{coin}}</span>
  6. {{$t('assets.e5')}}
  7. </template>
  8. </v-header>
  9. <view class="layout-main p-x-lg">
  10. <!-- <van-tabs :ellipsis="false" :border="false" :active="tab" @change="changeTab">
  11. <van-tab class="height-max" :title="$t('assets.g1')"></van-tab>
  12. <van-tab class="height-max" :title="$t('assets.g3')"></van-tab>
  13. <van-tab class="height-max" :title="$t('assets.g2')"></van-tab>
  14. </van-tabs> -->
  15. <block v-if="tab==0">
  16. <view class="coin p-md d-flex justify-between bg-panel-3 m-y-md rounded-md box-shadow"
  17. >
  18. <view class="fn-lg color-light">{{coin}}</view>
  19. <view>
  20. <!-- <van-icon name="arrow" /> -->
  21. </view>
  22. </view>
  23. <view class="m-y-md rounded-md overflow-hidden">
  24. <view class="bg-panel-3 rounded-md box-shadow">
  25. <view class="d-flex justify-center align-center border-b p-x-md p-y-xs color-light"
  26. v-if="coin=='USDT'">
  27. <view class="group d-flex fn-12 color-light">
  28. <!-- <view class="rounded-md color-plain p-x-sm p-y-xs m-r-sm" size="mini"
  29. @click="changeRechargeType(2)"
  30. :class="rechargeType==2?'bg-gradient-green':'bg-gray-7'">
  31. ERC20</view>
  32. <view class="rounded-md color-plain p-x-sm p-y-xs m-r-sm"
  33. :class="rechargeType==1?'bg-gradient-green':'bg-gray-7'" size="mini"
  34. @click="changeRechargeType(1)">OMNI</view> -->
  35. <view class="rounded-md color-plain p-x-sm p-y-xs m-r-sm" size="mini"
  36. @click="changeRechargeType(3)"
  37. :class="rechargeType==3?'bg-gradient-green':'bg-gray-7'">
  38. TRC20</view>
  39. </view>
  40. </view>
  41. <view class="p-t-md p-b-md ">
  42. <view class="fn-center">
  43. <v-qr v-if="form.address" class="qr-box" :text="form.address||' '"></v-qr>
  44. </view>
  45. <view class="tips fn-center color-light m-y-xs">{{$t('assets.e6')}}</view>
  46. </view>
  47. </view>
  48. <view class="info m-t-md p-xs bg-panel-3 rounded-md box-shadow">
  49. <view class="address">
  50. <view class="d-flex align-center justify-between">
  51. <view class="border-r address-txt flex-fill color-light fn-12 fn-center">
  52. {{form.address}}
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. <view class="m-b-lg m-t-lg">
  58. <v-button type="yellow" @click="$copy(form.address,$t('common.a1'))" block
  59. class="w-max rounded-md" key="loginbtn">
  60. <text class="color-light" style="color:#2c2c2c">{{$t('assets.g4')}}</text>
  61. <i class="iconfont" style="color:#2c2c2c;font-size: 34rpx;">&#xe706;</i>
  62. </v-button>
  63. </view>
  64. <view class="m-y-md bg-panel-3 rounded-md box-shadow">
  65. <ul class=" p-xs fn-sm rounded-md m-y-xs">
  66. <li>·{{$t('assets.f0')}}{{$t('assets.f1',{num:10,name: coin })}}</li>
  67. <li>·{{$t('assets.f3',{name:coin})}}</li>
  68. </ul>
  69. </view>
  70. </view>
  71. <view class=" m-b-lg" v-if="list.length">
  72. <view class="title d-flex justify-between p-y-xs align-center color-light">
  73. <span class="fn-lg">{{$t('assets.f4')}}</span>
  74. </view>
  75. <view class="">
  76. <table class="w-max">
  77. <thead class="p-x-md">
  78. <tr class="fn-sm p-x-md ">
  79. <th class=" p-b-md fn-left p-l-md">{{$t('assets.c9')}}</th>
  80. <th class=" p-b-md fn-left">{{$t('assets.d0')}}</th>
  81. <th class=" p-b-md fn-right p-r-md">{{$t('assets.c0')}}</th>
  82. </tr>
  83. </thead>
  84. <tbody>
  85. <tr class="color-light trChange p-x-md" v-for="(item) in list" :key="item.id">
  86. <td class="p-y-xs p-l-md rounded-tl-sm rounded-bl-sm" v-if="item.created_at">{{$date(item.created_at)}}
  87. </td>
  88. <td>
  89. <view v-if="item.status==0">{{$t('assets.d1')}}</view>
  90. <view v-if="item.status==1" class="color-buy">{{$t('assets.d2')}}</view>
  91. <view v-if="item.status==2" class="color-sell">{{$t('assets.d3')}}</view>
  92. </td>
  93. <td class="fn-right p-r-md rounded-tr-sm rounded-br-sm">
  94. {{item.amount}}
  95. <span class="color-default">({{item.coin_name}})</span>
  96. </td>
  97. </tr>
  98. <tr v-if="loadMore">
  99. <td colspan="3" class="fn-center p-xs link-active" @click="more">{{$t('assets.d4')}}
  100. </td>
  101. </tr>
  102. </tbody>
  103. </table>
  104. </view>
  105. </view>
  106. </block>
  107. <block v-if="tab==1">
  108. <view class="coin p-md d-flex justify-between bg-panel-3 m-y-md rounded-md box-shadow"
  109. @click="fiatListShow=true">
  110. <view class="fn-lg color-light">{{fiat}}</view>
  111. <view>
  112. <van-icon name="arrow" />
  113. </view>
  114. </view>
  115. <view>
  116. <view class="uni-padding-wrap">
  117. <view class="uni-title">{{$t('add.a1')}}</view>
  118. <radio-group class="p-t-md" @change="radioChange">
  119. <label class="radio m-r-lg">
  120. <radio :checked="type==1" value="1" color="#f7427b" style="transform: scale(.7);"/>Credit card-A
  121. </label>
  122. <label class="radio">
  123. <radio :checked="type==2" value="2" color="#f7427b" style="transform: scale(.7);"/>Credit card-B
  124. </label>
  125. </radio-group>
  126. </view>
  127. </view>
  128. <view class="form bg-panel-3 rounded-md p-x-md m-y-md box-shadow">
  129. <view class="d-flex align-end p-y-xs justify-between">
  130. <v-input type="number" v-model="form.amount" class="w-8/12 color-light"
  131. :placeholder="$t('assets.c2')"></v-input>
  132. <view class="d-flex align-end">
  133. <span class="unit flex-shrink">{{ fiat }}</span>
  134. </view>
  135. </view>
  136. <block v-if="type==2">
  137. <view class="d-flex align-end p-y-xs justify-center">
  138. <view class="d-flex align-end">
  139. <span class="unit flex-shrink">{{$t('reg.a2')}}:</span>
  140. </view>
  141. <v-input type="text" v-model="form.cellphone" class="w-8/12 flex-fill color-light"
  142. :placeholder="$t('assets.h1')">
  143. <template v-slot:left>+</template>
  144. </v-input>
  145. </view>
  146. <view class="d-flex align-end p-y-xs justify-center">
  147. <view class="d-flex align-end">
  148. <span class="unit flex-shrink">{{$t('reg.a4')}}:</span>
  149. </view>
  150. <v-input type="text" v-model="form.email" class="w-8/12 flex-fill color-light"
  151. :placeholder="$t('reg.a5')"></v-input>
  152. </view>
  153. </block>
  154. </view>
  155. <view style="margin-top:120rpx;">
  156. <v-button class="w-max rounded-md" block type="green" @click="toRecharge" ref="btn">
  157. {{$t('assets.e5')}}
  158. </v-button>
  159. </view>
  160. </block>
  161. </view>
  162. <coin-list ref="coinList" v-model="coin" @close="coinListShow=false" v-show="coinListShow" />
  163. <fiat-list ref="fiatList" v-model="fiat" @close="fiatListShow=false" v-show="fiatListShow" />
  164. <van-toast id="van-toast" />
  165. <van-dialog id="van-dialog" />
  166. </view>
  167. </template>
  168. <script>
  169. import coinList from "./coin-list";
  170. import fiatList from "./fiat-list";
  171. import Wallet from "@/api/wallet";
  172. import formData from "@/utils/class/date";
  173. import {
  174. mapGetters
  175. } from 'vuex'
  176. export default {
  177. components: {
  178. coinList,
  179. fiatList
  180. },
  181. data() {
  182. return {
  183. qbList: {},
  184. tab: 0,
  185. coinListShow: false,
  186. fiatListShow: false,
  187. fiat: "",
  188. coin: "",
  189. rechargeType: 3,
  190. address: "",
  191. form: {
  192. coin_id: "",
  193. amount: "",
  194. address: "",
  195. cellphone:'',
  196. email:''
  197. },
  198. list: [],
  199. page: 1,
  200. loadMore: true,
  201. type:1
  202. };
  203. },
  204. computed: {
  205. activeCoin() {
  206. if (!this.coin) return {};
  207. return this.$refs.coinList.coinList.find(
  208. (item) => item.coin_name == this.coin
  209. );
  210. },
  211. activeFiat() {
  212. if (!this.coin) return {};
  213. return this.$refs.fiatList.fiatList.find(
  214. (item) => item.fiat == this.fiat
  215. );
  216. },
  217. ...mapGetters(['themeStyle'])
  218. },
  219. filters: {
  220. parseTime(val) {
  221. return formData.parseTime(val);
  222. },
  223. },
  224. watch: {
  225. coin(n) {
  226. if (n) {
  227. this.form.address = "";
  228. if (this.coin != "USDT") {
  229. this.rechargeType = 1;
  230. }
  231. // this.getQb()
  232. this.walletImage();
  233. }
  234. },
  235. rechargeType() {
  236. // 优先清空地址 避免用户充错地址
  237. },
  238. },
  239. methods: {
  240. getQb() {
  241. Wallet.getQb().then(res => {
  242. console.log(res)
  243. this.qbList = res.data
  244. if(this.coin) {
  245. this.form.address = this.qbList[this.coin]
  246. }
  247. })
  248. },
  249. radioChange(e){
  250. this.type = e.detail.value
  251. },
  252. changeTab(e) {
  253. if (e.detail.index == 0) {
  254. this.tab = e.detail.index
  255. } else if (e.detail.index == 1) {
  256. this.tab = e.detail.index
  257. } else if (e.detail.index == 2) {
  258. uni.navigateTo({
  259. url: './web-view'
  260. })
  261. }
  262. },
  263. changeRechargeType(idx) {
  264. this.rechargeType = idx;
  265. this.form.address = "";
  266. this.walletImage();
  267. },
  268. // 获取充币地址
  269. walletImage() {
  270. if(!this.activeCoin.coin_id)return
  271. let data = {
  272. coin_id: this.activeCoin.coin_id,
  273. address_type: this.rechargeType,
  274. };
  275. uni.showLoading({
  276. title: ''
  277. })
  278. Wallet.walletImage(data).then((res) => {
  279. if (res.message == 'FAILED') {
  280. this.$dialog
  281. .confirm({
  282. title: this.$t("common.error"),
  283. message: this.$t("common.error1"),
  284. cancelButtonText: this.$t('common.cancelButtonText'),
  285. confirmButtonText: this.$t('common.confirmButtonText'),
  286. })
  287. .then(() => {
  288. });
  289. } else {
  290. this.form.address = res.data.address;
  291. }
  292. uni.hideLoading()
  293. }).catch(() => {
  294. uni.hideLoading()
  295. });
  296. },
  297. // 充值
  298. recharge() {
  299. this.form.coin_id = this.activeCoin.coin_id;
  300. Wallet.recharge(this.form, {
  301. btn: this.$refs.btn
  302. })
  303. .then(() => {
  304. this.$back();
  305. this.$toast.success(this.$t('assets.d5') + "!");
  306. this.reset();
  307. })
  308. .catch(() => {});
  309. },
  310. // 信用卡充值
  311. toRecharge() {
  312. // return this.$toast(this.$t('base.h1'))
  313. uni.showLoading({
  314. title: ''
  315. })
  316. let cellphone = this.form.cellphone
  317. if(!this.form.amount){
  318. return this.$toast(this.$t('assets.c2'))
  319. }
  320. if(this.type==2){
  321. if(!cellphone){
  322. return this.$toast(this.$t('assets.h1'))
  323. }
  324. if(!this.form.email){
  325. return this.$toast(this.$t('reg.a5'))
  326. }
  327. }
  328. Wallet.xinRecharge({
  329. amount: this.form.amount,
  330. fait: this.activeFiat.id,
  331. type:this.type,
  332. cellphone:cellphone||'',
  333. email:this.form.email||''
  334. }).then((res) => {
  335. let payUrl = res.data.payUrl
  336. location.href = payUrl
  337. // console.log(res)
  338. // this.$back();
  339. // uni.hideLoading()
  340. // this.$toast.success(this.$t('assets.d5') + "!");
  341. })
  342. .catch((err) => {
  343. console.log(err)
  344. uni.hideLoading()
  345. });
  346. },
  347. reset() {
  348. this.loadMore = true;
  349. this.page = 1;
  350. this.depositHistory();
  351. },
  352. more() {
  353. this.page++;
  354. this.depositHistory();
  355. },
  356. // 获取充值记录
  357. depositHistory() {
  358. let data = {
  359. page: this.page,
  360. };
  361. Wallet.depositHistory(data).then((res) => {
  362. if (res.data.current_page == 1) this.list = [];
  363. this.list = [...this.list, ...res.data.data];
  364. if (res.data.data.length < res.data.per_page) this.loadMore = false;
  365. });
  366. },
  367. },
  368. created() {
  369. this.depositHistory();
  370. this.walletImage()
  371. // this.getQb()
  372. },
  373. };
  374. </script>
  375. <style lang="scss" scoped>
  376. .address {
  377. .label {
  378. white-space: nowrap;
  379. }
  380. .address-txt {
  381. // word-break: break-all;
  382. // overflow: hidden;
  383. // text-overflow: ellipsis;
  384. // white-space: nowrap;
  385. display: -webkit-box;
  386. word-break: break-all;
  387. text-overflow: ellipsis;
  388. overflow: hidden;
  389. -webkit-box-orient: vertical;
  390. -webkit-line-clamp: 2;
  391. }
  392. }
  393. .qr-box {
  394. height: 150px;
  395. width: 150px;
  396. margin: 0 auto;
  397. border: 4px solid $white;
  398. }
  399. .trChange:nth-child(2n-1) {
  400. box-shadow: $shadow;
  401. border-radius: $border-radius-xs;
  402. td {
  403. background: $panel-3;
  404. padding-top: $padding-sm;
  405. padding-bottom: $padding-sm;
  406. }
  407. }
  408. </style>