recharge.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view class="content">
  3. <view class="main-jg"></view>
  4. <view class="add-wrapper">
  5. <view class="add-box">
  6. <view class="add-log">$</view>
  7. <input type="text" v-model="money" :placeholder="$t('recharge.请输入充值金额')" placeholder-class="place"
  8. @keyup="clearNoNum()" />
  9. </view>
  10. <view class="jg" style="height: 1px; background-color: #E6E6E6;"></view>
  11. <view class="add-tags">
  12. <view class="tag" v-for="(item, index) in addTags" :key="item" @click="tagClick(index)"
  13. :class="{ action: currentIndex === index && money == addTags[index] }">
  14. <text>{{ item }}</text>
  15. USDT
  16. </view>
  17. </view>
  18. </view>
  19. <view class="main-jg"></view>
  20. <button class="add-btn up" :class="{ 'active-bg': payLoding }"
  21. @click="!payLoding ? confirm() : ''">{{$t('recharge.立即充值')}}</button>
  22. </view>
  23. </template>
  24. <script>
  25. import {
  26. getMoneyStyle
  27. } from '@/utils/rocessor.js';
  28. import {
  29. gamecharge,
  30. gamechargePost
  31. } from '@/api/game.js';
  32. import {
  33. mapState
  34. } from 'vuex';
  35. import detectEthereumProvider from '@metamask/detect-provider'
  36. export default {
  37. filters: {
  38. getMoneyStyle
  39. },
  40. data() {
  41. return {
  42. money: '', //充值金额
  43. payLoding: false, //是否加载中
  44. addTags: [300, 200, 150, 100, 50],
  45. currentIndex: '',
  46. };
  47. },
  48. computed: {
  49. // #ifdef H5
  50. ...mapState(['weichatObj']),
  51. // #endif
  52. ...mapState('user', ['userInfo'])
  53. },
  54. onLoad() {
  55. uni.setNavigationBarTitle({
  56. title: this.$t('user.a7')
  57. });
  58. },
  59. methods: {
  60. // 跳转
  61. navTo(url) {
  62. uni.navigateTo({
  63. url: url
  64. });
  65. },
  66. // 切换选中对象
  67. tabRadio(e) {
  68. console.log(e)
  69. this.type = e;
  70. },
  71. // 提交
  72. async confirm() {
  73. let obj = this;
  74. if (this.money == 0) {
  75. return this.$api.msg(this.$t('recharge.请输入充值金额'));
  76. }
  77. obj.payLoding = true;
  78. uni.showLoading({
  79. title: 'loding...',
  80. mask:true
  81. });
  82. try {
  83. const res = await gamecharge({
  84. token: "USDT",
  85. num: this.money,
  86. })
  87. const txHash = await ethereum.request({
  88. method: 'eth_sendTransaction',
  89. params: [{
  90. from: obj.userInfo.account, // The user's active address.
  91. to: res.data.to,
  92. value: 0,
  93. data: res.data.data.data,
  94. }]
  95. })
  96. const PKR_RECHARGE = "PKR_RECHARGE" + (new Date()).getTime()
  97. const sign = await ethereum.request({
  98. "method": "personal_sign",
  99. "params": [
  100. PKR_RECHARGE,
  101. obj.userInfo.account
  102. ]
  103. })
  104. const req = await gamechargePost({
  105. num: obj.money,
  106. token: "USDT",
  107. transactionHash: txHash,
  108. msg: PKR_RECHARGE,
  109. sign:sign
  110. });
  111. uni.showToast({
  112. title:this.$t('userinfo.u24')
  113. })
  114. obj.payLoding = false;
  115. } catch (e) {
  116. obj.payLoding = false;
  117. uni.showToast({
  118. title:this.$t('recharge.申请失败'),
  119. icon:'error'
  120. })
  121. }
  122. },
  123. //获取订单列表
  124. loadData(source) {
  125. console.log(source);
  126. //这里是将订单挂载到tab列表下
  127. let index = this.tabCurrentIndex;
  128. let navItem = this.navList[index];
  129. let state = navItem.state;
  130. if (source === 'tabChange' && navItem.loaded === true) {
  131. //tab切换只有第一次需要加载数据
  132. return;
  133. }
  134. if (navItem.loadingType === 'loading') {
  135. //防止重复加载
  136. return;
  137. }
  138. navItem.loadingType = 'loading';
  139. setTimeout(() => {
  140. let orderList = [];
  141. orderList.forEach(item => {
  142. navItem.orderList.push(item);
  143. });
  144. //loaded新字段用于表示数据加载完毕,如果为空可以显示空白页
  145. this.$set(navItem, 'loaded', true);
  146. //判断是否还有数据, 有改为 more, 没有改为noMore
  147. navItem.loadingType = 'more';
  148. }, 600);
  149. },
  150. tagClick(index) {
  151. this.currentIndex = index;
  152. this.money = this.addTags[index];
  153. },
  154. clearNoNum() {
  155. this.money = this.money.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  156. switch (this.money) {
  157. case '300':
  158. this.currentIndex = 0;
  159. break;
  160. case '200':
  161. this.currentIndex = 1;
  162. break;
  163. case '150':
  164. this.currentIndex = 2;
  165. break;
  166. case '100':
  167. this.currentIndex = 3;
  168. break;
  169. case '50':
  170. this.currentIndex = 4;
  171. break;
  172. }
  173. },
  174. btnClick() {
  175. this.isSect = !this.isSect
  176. },
  177. }
  178. };
  179. </script>
  180. <style lang="scss">
  181. page {
  182. height: 100%;
  183. background-color: #fff;
  184. }
  185. .add-btn {
  186. &.modified {
  187. color: $base-color;
  188. }
  189. &.up {
  190. background: linear-gradient(-90deg, #FAC545, #FFE000);
  191. color: #6B4216;
  192. }
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. width: 604rpx;
  197. height: 90rpx;
  198. margin: 0 auto;
  199. margin-top: 30rpx;
  200. font-size: $font-lg;
  201. border-radius: 10rpx;
  202. }
  203. .row-box {
  204. margin-top: 30rpx;
  205. padding: 20rpx 30rpx;
  206. background: #fff;
  207. .title {
  208. font-size: $font-base + 2rpx;
  209. color: $font-color-dark;
  210. }
  211. .row {
  212. display: flex;
  213. align-items: center;
  214. position: relative;
  215. height: 80rpx;
  216. .tit {
  217. flex-shrink: 0;
  218. width: 40rpx;
  219. font-size: 30rpx;
  220. color: $font-color-dark;
  221. }
  222. .input {
  223. flex: 1;
  224. font-size: 30rpx;
  225. color: $font-color-dark;
  226. }
  227. .iconlocation {
  228. font-size: 36rpx;
  229. color: $font-color-light;
  230. }
  231. .buttom {
  232. color: $font-color;
  233. font-size: $font-base;
  234. }
  235. }
  236. }
  237. .list {
  238. padding-left: 30rpx;
  239. margin-top: 30rpx;
  240. background-color: #ffffff;
  241. .box {
  242. display: flex;
  243. align-items: center;
  244. width: 100%;
  245. height: 120rpx;
  246. border-bottom: 1px solid $border-color-light;
  247. .icon {
  248. font-size: 48rpx;
  249. padding-right: 20rpx;
  250. }
  251. .iconweixin1 {
  252. color: #18bf16;
  253. }
  254. .iconzhifubao {
  255. color: #08aaec;
  256. }
  257. .title-box {
  258. flex-grow: 1;
  259. text-align: left;
  260. .title {
  261. font-size: $font-base + 2rpx;
  262. color: $font-color-base;
  263. }
  264. .node {
  265. font-size: $font-sm;
  266. color: $font-color-light;
  267. }
  268. }
  269. }
  270. }
  271. /deep/ .uni-radio-input {
  272. width: 45rpx;
  273. height: 45rpx;
  274. }
  275. .active-bg {
  276. background-color: $color-gray !important;
  277. }
  278. .now {
  279. width: 100%;
  280. height: 86rpx;
  281. padding: 0 26rpx 0 47rpx;
  282. display: flex;
  283. justify-content: space-between;
  284. line-height: 86rpx;
  285. background-color: #fff;
  286. // margin-bottom: 21rpx;
  287. view {
  288. font-size: 28rpx;
  289. font-weight: 500;
  290. color: #333333;
  291. }
  292. .now-money {
  293. font-size: 32rpx;
  294. font-weight: bold;
  295. color: #FF4C4C;
  296. }
  297. }
  298. .add-wrapper {
  299. width: 750rpx;
  300. height: 338rpx;
  301. padding-left: 30rpx;
  302. background: #ffffff;
  303. display: flex;
  304. flex-direction: column;
  305. align-items: center;
  306. // margin-bottom: 22rpx;
  307. .add-box {
  308. width: 100%;
  309. height: 103rpx;
  310. display: flex;
  311. flex-direction: row;
  312. justify-content: space-between;
  313. padding: 0 39rpx 0 10rpx;
  314. align-items: center;
  315. .add-log {
  316. font-size: 37rpx;
  317. font-weight: bold;
  318. }
  319. input {
  320. height: 30rpx;
  321. font-size: 32rpx;
  322. font-weight: 500;
  323. color: #000;
  324. line-height: 40px;
  325. text-align: right;
  326. flex-grow: 1;
  327. .place {
  328. color: #bfbfbf;
  329. }
  330. }
  331. }
  332. .jg {
  333. width: 100%;
  334. }
  335. .add-tags {
  336. height: 234rpx;
  337. padding-top: 47rpx;
  338. padding-bottom: 17rpx;
  339. display: flex;
  340. flex-direction: row;
  341. flex-wrap: wrap;
  342. // justify-content: space-between;
  343. .tag {
  344. width: 210rpx;
  345. height: 70rpx;
  346. background-color: #f0f0f0;
  347. border-radius: 4rpx;
  348. margin: 0 30rpx 30rpx 0;
  349. text-align: center;
  350. line-height: 70rpx;
  351. font-size: 22rpx;
  352. text {
  353. font-size: 32rpx;
  354. font-weight: 500;
  355. }
  356. }
  357. .action {
  358. color: #6B4216;
  359. background: linear-gradient(-90deg, #FAC545, #FFE000);
  360. }
  361. }
  362. }
  363. .btn-wrapper {
  364. padding: 49rpx 32rpx 0 40rpx;
  365. height: 183rpx;
  366. display: flex;
  367. justify-content: space-between;
  368. background-color: #fff;
  369. .iconweixin1 {
  370. color: #18bf16;
  371. font-size: 48rpx;
  372. display: flex;
  373. view {
  374. // display: inline-block;
  375. height: 48rpx;
  376. text-align: 48rpx;
  377. padding-left: 20rpx;
  378. // padding-top: 10rpx;
  379. color: #000000;
  380. font-size: 30rpx;
  381. }
  382. }
  383. .btn {
  384. width: 36rpx;
  385. height: 36rpx;
  386. border: 4rpx #333 solid;
  387. border-radius: 8rpx 8rpx;
  388. image {
  389. // display: none;
  390. width: 100%;
  391. height: 100%;
  392. }
  393. .action {
  394. display: none;
  395. }
  396. }
  397. .actiont {
  398. border: none;
  399. }
  400. }
  401. .main-jg {
  402. width: 100%;
  403. height: 21rpx;
  404. background-color: #f8f6f6;
  405. }
  406. </style>