transfer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <view class="main">
  3. <view class="collection">
  4. <view class="head">
  5. <view class="title">{{lang.link_name}}</view>
  6. <view class="links">
  7. <text :class="'btn trc' + (formData.contact_type==1? ' active' :'')"
  8. @click="(formData.contact_type=1) && (formData.to_address='')">TRC20</text>
  9. <text :class="'btn erc' + (formData.contact_type==2? ' active' :'')"
  10. @click="(formData.contact_type=2) && (formData.to_address='')">ERC20</text>
  11. </view>
  12. <text class="btn-link" @click="gotoPage('/pages/account/transfer')">{{lang.detailed}}</text>
  13. </view>
  14. <view class="form" v-if="formData.contact_type==1">
  15. <view class="form-item">
  16. <view class="title">{{lang.collection_address}}</view>
  17. <view class="input-item">
  18. <image class="icon plane" src="/static/icons/transfer_icon.png" mode=""></image>
  19. <input class="input" v-model="formData.to_address" type="text" :placeholder="lang.input_address"
  20. @input="inputAddress">
  21. <image class="icon address" src="/static/icons/address_light.png" mode=""
  22. @click="gotoPage('/pages/center/address?ct=1&type=2')"></image>
  23. <image class="icon scan" src="/static/icons/scan_light.png" mode=""></image>
  24. </view>
  25. </view>
  26. <view class="form-item">
  27. <view class="title">{{lang.transfer_num}}</view>
  28. <view class="input-item">
  29. <image class="icon usdt" src="/static/icons/usdt_icon.png" mode=""></image>
  30. <input class="input" v-model="formData.num" type="text"
  31. :placeholder="lang.limit+' '+config.trc_out_limit+'~'+config.trc_out_max"
  32. @input="countTotal" :max="config.trc_out_max" maxlength="6" :min="config.trc_out_limit">
  33. <text class="text all">{{lang.all}}</text>
  34. </view>
  35. <view class="tips">
  36. <text class="text">{{lang.transfer_balance}}: {{userInfo.usdt_num}} USDT</text>
  37. </view>
  38. </view>
  39. <view class="form-item">
  40. <view class="title">{{lang.transfer_fee}}</view>
  41. <view class="input-item">
  42. <input class="input" v-model="formData.fee" type="text" placeholder="-" :disabled="true">
  43. <text class="text unit">USDT</text>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="form" v-else-if="formData.contact_type==2">
  48. <view class="form-item">
  49. <view class="title">{{lang.collection_address}}</view>
  50. <view class="input-item">
  51. <image class="icon plane" src="/static/icons/transfer_icon.png" mode=""></image>
  52. <input class="input" v-model="formData.to_address" type="text"
  53. :placeholder="lang.input_address">
  54. <image class="icon address" src="/static/icons/address_light.png" mode=""
  55. @click="gotoPage('/pages/center/address?ct=2&type=2')"></image>
  56. <image class="icon scan" src="/static/icons/scan_light.png" mode=""></image>
  57. </view>
  58. </view>
  59. <view class="form-item">
  60. <view class="title">{{lang.transfer_num}}</view>
  61. <view class="input-item">
  62. <image class="icon usdt" src="/static/icons/usdt_icon.png" mode=""></image>
  63. <input class="input" v-model="formData.num" type="text"
  64. :placeholder="lang.limit+' '+config.erc_out_limit+'~'+config.erc_out_max"
  65. @input="countTotal" :max="config.erc_out_max" maxlength="6" :min="config.erc_out_limit">
  66. <text class="text all">{{lang.all}}</text>
  67. </view>
  68. <view class="tips">
  69. <text class="text">{{lang.transfer_balance}}: {{userInfo.usdt_num}} USDT</text>
  70. </view>
  71. </view>
  72. <view class="form-item">
  73. <view class="title">{{lang.transfer_fee}}</view>
  74. <view class="input-item">
  75. <input class="input" v-model="formData.fee" type="text" placeholder="-" :disabled="true">
  76. <text class="text unit">USDT</text>
  77. </view>
  78. </view>
  79. </view>
  80. <view class="action submit">
  81. <view class="total-box">
  82. <text class="text name">{{lang.transfer_total}}</text>
  83. <text class="text total">{{formData.total? formData.total+' USDT': '-'}}</text>
  84. </view>
  85. <button class="btn" @click="showPopupModal">{{lang.transfer}}</button>
  86. </view>
  87. </view>
  88. <u-modal :title="lang.op_tips" v-model="showPopup" @confirm="transfer" ref="uModal" :async-close="true"
  89. :mask-close-able="true" width="90%" :zIndex="996" :show-title="true" :show-cancel-button="true"
  90. :confirm-text="lang.confirm" confirm-color="#bb955e">
  91. <view v-slot class="u-modal-content">
  92. <u-form labelPosition="left" :model="formData" :rules="rules" ref="form" :labelWidth="'178rpx'">
  93. <u-form-item :label="lang.trade_password" prop="formData.trade_password">
  94. <u-input type="password" v-model="formData.trade_password"
  95. :placeholder="lang.input_trade_password" clearable>
  96. </u-input>
  97. </u-form-item>
  98. </u-form>
  99. </view>
  100. </u-modal>
  101. </view>
  102. </template>
  103. <script>
  104. export default {
  105. data() {
  106. return {
  107. showPopup: false,
  108. config: {
  109. trc_out_limit: '0.00',
  110. trc_out_max: '1000.00',
  111. erc_out_limit: '0.00',
  112. erc_out_max: '1000.00',
  113. },
  114. formData: {
  115. to_address: '',
  116. num: '',
  117. fee: '',
  118. total: '',
  119. contact_type: 1,
  120. coin_type: 1
  121. },
  122. userInfo: {
  123. usdt_num: '0.00'
  124. },
  125. }
  126. },
  127. onLoad(options) {
  128. let addressData = uni.getStorageSync('otc.select_address');
  129. addressData = typeof(addressData) != 'undefined' ? addressData : {};
  130. let address = typeof(addressData.address) != 'undefined' ? addressData.address : '';
  131. let coin_type = typeof(addressData.ct) != 'undefined' ? addressData.ct : 0;
  132. this.formData.coin_type = coin_type > 0 ? coin_type : 1;
  133. if (address && !this.checkAddress(address)) {
  134. this.$u.toast(this.lang.incorret_address);
  135. } else {
  136. this.formData.to_address = address ? address : '';
  137. }
  138. this.getConfig();
  139. this.getUserInfo()
  140. },
  141. methods: {
  142. // 验证地址格式
  143. checkAddress(addess) {
  144. if (this.formData.coin_type == 1) {
  145. let patt = /^T[a-zA-Z0-9]{20,50}/;
  146. return patt.test(addess);
  147. } else {
  148. let patt = /^0x[a-zA-Z0-9]{20,50}/;
  149. return patt.test(addess);
  150. }
  151. },
  152. inputAddress() {
  153. uni.clearStorageSync('otc.select_address');
  154. },
  155. countTotal() {
  156. let num = this.formData.num > 0 ? parseFloat(this.formData.num) : 0;
  157. this.formData.fee = parseFloat(num * this.config.coin_out_free / 100).toFixed(2)
  158. this.formData.total = parseFloat(parseFloat(num) + parseFloat(this.formData.fee)).toFixed(2)
  159. },
  160. // 扫码
  161. scan() {
  162. let _this = this;
  163. uni.scanCode({
  164. success: function(res) {
  165. if (_this.checkAddress(res.result)) {
  166. _this.formData.to_address = res.result;
  167. return false;
  168. }
  169. _this.$u.toast(_this.lang.incorret_address);
  170. }
  171. });
  172. },
  173. // 获取配置
  174. getConfig() {
  175. this.$request.sendToken('/api/config', {
  176. type: 2
  177. }, 'POST').then(res => {
  178. // 打印调用成功回调
  179. this.config = res.data.trade;
  180. })
  181. },
  182. //获取用户数据
  183. getUserInfo() {
  184. this.$request.sendToken('/api/user/info', {}, 'POST').then(res => {
  185. if (res.success == true) {
  186. this.userInfo = res.data;
  187. } else {
  188. this.$u.toast(res.msg);
  189. setTimeout(function() {
  190. uni.navigateTo({
  191. url: '/pages/login/login',
  192. });
  193. }, 2000)
  194. }
  195. })
  196. },
  197. showPopupModal() {
  198. let _this = this
  199. if (this.formData.address == '') {
  200. _this.$u.toast(_this.lang.input_address);
  201. return false;
  202. }
  203. if (this.formData.num <= 0) {
  204. _this.$u.toast(_this.lang.input_num);
  205. return false;
  206. }
  207. if (this.formData.num <= 0) {
  208. _this.$u.toast(_this.lang.input_num);
  209. return false;
  210. }
  211. if (this.formData.trade_password == '') {
  212. _this.$u.toast(_this.lang.input_trade_password);
  213. return false;
  214. }
  215. _this.showPopup = true;
  216. },
  217. // 转账提现
  218. transfer() {
  219. let _this = this
  220. if (this.formData.address == '') {
  221. _this.$u.toast(_this.lang.input_address);
  222. return false;
  223. }
  224. if (this.formData.num <= 0) {
  225. _this.$u.toast(_this.lang.input_num);
  226. return false;
  227. }
  228. if (this.formData.num <= 0) {
  229. _this.$u.toast(_this.lang.input_num);
  230. return false;
  231. }
  232. if (this.formData.trade_password == '') {
  233. _this.$u.toast(_this.lang.input_trade_password);
  234. return false;
  235. }
  236. uni.showLoading({
  237. title: _this.catch
  238. })
  239. _this.$request.sendToken('/api/coin/withdraw', _this.formData, 'POST').then(res => {
  240. uni.hideLoading();
  241. if (res.success == true) {
  242. _this.$u.toast(res.msg);
  243. setTimeout(function() {
  244. _this.showPopup = false
  245. _this.formData.trade_password = ''
  246. _this.getUserInfo()
  247. }, 800)
  248. } else {
  249. _this.$refs.uModal.clearLoading();
  250. _this.$u.toast(res.msg);
  251. }
  252. });
  253. }
  254. },
  255. }
  256. </script>
  257. <style lang="scss" scoped>
  258. .collection {
  259. margin: 19rpx 38rpx 38rpx;
  260. color: #6e6c6b;
  261. .head {
  262. .title {
  263. // font-size: 30rpx;
  264. margin: 28rpx 0;
  265. }
  266. .links {
  267. margin: 28rpx 0;
  268. .btn {
  269. padding: 6rpx 16rpx;
  270. border: 2rpx solid #bb955e;
  271. border-radius: 14rpx;
  272. margin-right: 28rpx;
  273. color: #bb955e;
  274. font-weight: bold;
  275. }
  276. .btn.active {
  277. color: #333;
  278. background-color: #bb955e;
  279. }
  280. }
  281. .btn-link {
  282. float: right;
  283. color: #bb955e;
  284. padding: 8rpx 10rpx;
  285. position: fixed;
  286. top: 26rpx;
  287. right: 28rpx;
  288. z-index: 998;
  289. }
  290. }
  291. .form {
  292. margin-top: 56rpx;
  293. .form-item {
  294. padding-bottom: 38rpx;
  295. font-size: 26rpx;
  296. .icon {
  297. width: 34rpx;
  298. height: 34rpx;
  299. vertical-align: middle;
  300. }
  301. .icon.address {
  302. margin-right: 28rpx;
  303. }
  304. .input-item {
  305. display: flex;
  306. padding: 19rpx 0;
  307. border-bottom: 2rpx solid #6e6c6b;
  308. .input {
  309. width: calc(100% - 100rpx);
  310. margin: 0 10rpx;
  311. font-size: 26rpx;
  312. vertical-align: middle;
  313. color: #6e6c6b;
  314. }
  315. .text {
  316. font-size: 26rpx;
  317. width: 80rpx;
  318. }
  319. .text.all {
  320. color: #bb955e;
  321. }
  322. }
  323. .tips {
  324. .text {
  325. margin: 16rpx 0;
  326. font-size: 24rpx;
  327. color: #6e6c6b;
  328. display: inline-block;
  329. }
  330. }
  331. }
  332. }
  333. .action {
  334. width: 100%;
  335. position: fixed;
  336. bottom: 0;
  337. left: 0;
  338. padding: 19rpx 0;
  339. border-radius: 10rpx;
  340. background-color: #2c2b2b;
  341. .total-box {
  342. width: 90%;
  343. margin: 0 auto;
  344. padding: 19rpx 0;
  345. display: flex;
  346. .text.name {
  347. width: calc(100% - 130rpx);
  348. }
  349. .text.total {
  350. min-width: 120rpx;
  351. text-align: right;
  352. color: #bb955e;
  353. float: right;
  354. }
  355. }
  356. .btn {
  357. width: 90%;
  358. text-align: center;
  359. font-size: 36rpx;
  360. // font-weight: bold;
  361. background-color: #bb955e;
  362. color: 2c2b2b;
  363. padding: 12rpx 8rpx;
  364. margin: 19rpx auto;
  365. }
  366. }
  367. }
  368. .u-modal-content {
  369. padding: 19rpx;
  370. .u-form-item {
  371. .icon {
  372. width: 36rpx;
  373. height: 36rpx;
  374. padding: 8rpx;
  375. margin-left: 4rpx;
  376. }
  377. }
  378. }
  379. </style>