energy.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='cash-withdrawal'>
  4. <view class='wrapper'>
  5. <view class='list'>
  6. <form @submit="subCash">
  7. <view class='item acea-row row-between-wrapper'>
  8. <view class='name'>持卡人</view>
  9. <view class='input'><input placeholder='请输入持卡人姓名' placeholder-class='placeholder'
  10. name="name"
  11. onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;"></input>
  12. </view>
  13. </view>
  14. <view class='item acea-row row-between-wrapper'>
  15. <view class='name'>卡号</view>
  16. <view class='input'><input type='number' placeholder='请填写卡号' placeholder-class='placeholder'
  17. name="cardnum"></input></view>
  18. </view>
  19. <view class='item acea-row row-between-wrapper'>
  20. <view class='name'>开户行</view>
  21. <view class='input'><input placeholder='请输入开户行名称' placeholder-class='placeholder'
  22. name="bankname"
  23. onKeypress="javascript:if(event.keyCode == 32)event.returnValue = false;"></input>
  24. </view>
  25. </view>
  26. <view class='item acea-row row-between-wrapper'>
  27. <view class='name'>交易账号</view>
  28. <view class='input'><input placeholder='请输入交易账号' placeholder-class='placeholder'
  29. name="account"></input>
  30. </view>
  31. </view>
  32. <view class='item acea-row row-between-wrapper'>
  33. <view class='name'>转换能量</view>
  34. <view class='input'><input v-model="allMoney" @input='inputNum' :maxlength="moneyMaxLeng"
  35. :placeholder='"最低转换能量值:"+minPrice' placeholder-class='placeholder' name="energy"
  36. type='digit'></input></view>
  37. </view>
  38. <view class='tip'>
  39. 当前可转能量值:<text class="price">{{userInfo.energy}}</text>
  40. 时价:<text class="price">{{stock_price}}</text>
  41. </view>
  42. <view class='tip'>
  43. 手续费:<text class="price">{{withdraw_fee}}%</text>实际到账:<text
  44. class="price">{{true_money}}</text>
  45. </view>
  46. <button formType="submit" class='bnt bg-color'>立即转换</button>
  47. </form>
  48. </view>
  49. </view>
  50. </view>
  51. <home v-if="navigation"></home>
  52. </view>
  53. </template>
  54. <script>
  55. import {
  56. energyExchange,
  57. energyBank,
  58. getUserInfo
  59. } from '@/api/user.js';
  60. import {
  61. toLogin
  62. } from '@/libs/login.js';
  63. import {
  64. calculator,
  65. } from '@/api/new.js';
  66. import {
  67. mapGetters
  68. } from "vuex";
  69. import colors from '@/mixins/color.js';
  70. import home from '@/components/home';
  71. export default {
  72. components: {
  73. home
  74. },
  75. mixins: [colors],
  76. data() {
  77. return {
  78. minPrice: 0.00, //最低提现金额
  79. userInfo: [],
  80. prevent: true, //避免重复提交成功多次
  81. moneyMaxLeng: 8,
  82. withdraw_fee: '0',
  83. true_money: 0,
  84. allMoney: '', //保存当前提现金额
  85. };
  86. },
  87. computed: mapGetters(['isLogin']),
  88. watch: {
  89. isLogin: {
  90. handler: function(newV, oldV) {
  91. if (newV) {
  92. this.getUserInfo();
  93. this.getUserExtractBank();
  94. }
  95. },
  96. deep: true
  97. }
  98. },
  99. onLoad() {
  100. if (this.isLogin) {
  101. this.getUserInfo();
  102. this.getUserExtractBank();
  103. } else {
  104. toLogin()
  105. }
  106. },
  107. methods: {
  108. inputNum: async function(e) {
  109. let val = e.detail.value;
  110. let dot = val.indexOf('.');
  111. if (dot > -1) {
  112. this.moneyMaxLeng = dot + 3;
  113. } else {
  114. this.moneyMaxLeng = 8
  115. }
  116. try {
  117. this.true_money = +((val - val * this.withdraw_fee / 100) / this.stock_price).toFixed(2);
  118. console.log(this.true_money, 'this.true_money');
  119. } catch (e) {
  120. uni.showToast({
  121. title: e,
  122. icon: "error"
  123. });
  124. //TODO handle the exception
  125. }
  126. },
  127. getUserExtractBank: function() {
  128. let that = this;
  129. energyBank().then(res => {
  130. that.minPrice = res.data.minEnergy;
  131. that.stock_price = res.data.stock_price;
  132. that.withdraw_fee = res.data.exchange_fee;
  133. });
  134. },
  135. /**
  136. * 获取个人用户信息
  137. */
  138. getUserInfo: function() {
  139. let that = this;
  140. getUserInfo().then(res => {
  141. that.userInfo = res.data;
  142. })
  143. },
  144. subCash: function(e) {
  145. let that = this,
  146. value = e.detail.value;
  147. console.log(value,'value')
  148. if (value.account.length == 0) return that.$util.Tips({
  149. title: '请填写交易账户'
  150. });
  151. if (value.name.length == 0) return that.$util.Tips({
  152. title: '请填写持卡人姓名'
  153. });
  154. if (value.cardnum.length == 0) return that.$util.Tips({
  155. title: '请填写卡号'
  156. });
  157. if (value.energy.length == 0) return that.$util.Tips({
  158. title: '请填写转换能量'
  159. });
  160. if (value.bankname.length == 0) return that.$util.Tips({
  161. title: '请填写开户行名称'
  162. });
  163. if (Number(value.energy) < Number(that.minPrice)) return that.$util.Tips({
  164. title: '转换能量不能低于:' + that.minPrice
  165. });
  166. if (that.prevent) {
  167. that.prevent = false
  168. } else {
  169. return
  170. }
  171. energyExchange({
  172. ...value,
  173. }).then(res => {
  174. return this.$util.Tips({
  175. title: res.msg,
  176. icon: 'success'
  177. }, {
  178. url: '/pages/users/user_spread_user/index',
  179. tab: 2
  180. });
  181. }).catch(err => {
  182. setTimeout(e => {
  183. this.prevent = true
  184. }, 1500)
  185. return this.$util.Tips({
  186. title: err
  187. });
  188. });
  189. }
  190. }
  191. }
  192. </script>
  193. <style lang="scss">
  194. page {
  195. background-color: #fff !important;
  196. }
  197. .fontcolor {
  198. color: var(--view-theme) !important;
  199. }
  200. .cash-withdrawal .nav {
  201. height: 130rpx;
  202. box-shadow: 0 10rpx 10rpx #f8f8f8;
  203. }
  204. .cash-withdrawal .nav .item {
  205. font-size: 26rpx;
  206. flex: 1;
  207. text-align: center;
  208. }
  209. .cash-withdrawal .nav .item~.item {
  210. border-left: 1px solid #f0f0f0;
  211. }
  212. .cash-withdrawal .nav .item .iconfont {
  213. width: 40rpx;
  214. height: 40rpx;
  215. border-radius: 50%;
  216. border: 2rpx solid var(--view-theme);
  217. text-align: center;
  218. line-height: 37rpx;
  219. margin: 0 auto 6rpx auto;
  220. font-size: 22rpx;
  221. box-sizing: border-box;
  222. }
  223. .cash-withdrawal .nav .item .iconfont.on {
  224. background-color: var(--view-theme);
  225. color: #fff;
  226. border-color: var(--view-theme);
  227. }
  228. .cash-withdrawal .nav .item .line {
  229. width: 2rpx;
  230. height: 20rpx;
  231. margin: 0 auto;
  232. transition: height 0.3s;
  233. }
  234. .cash-withdrawal .nav .item .line.on {
  235. height: 39rpx;
  236. }
  237. .cash-withdrawal .wrapper .list {
  238. padding: 0 30rpx;
  239. }
  240. .cash-withdrawal .wrapper .list .item {
  241. border-bottom: 1rpx solid #eee;
  242. min-height: 28rpx;
  243. font-size: 30rpx;
  244. color: #333;
  245. padding: 39rpx 0;
  246. }
  247. .cash-withdrawal .wrapper .list .item .name {
  248. width: 130rpx;
  249. }
  250. .cash-withdrawal .wrapper .list .item .input {
  251. width: 505rpx;
  252. }
  253. .cash-withdrawal .wrapper .list .item .input .placeholder {
  254. color: #bbb;
  255. }
  256. .cash-withdrawal .wrapper .list .item .picEwm,
  257. .cash-withdrawal .wrapper .list .item .pictrue {
  258. width: 140rpx;
  259. height: 140rpx;
  260. border-radius: 3rpx;
  261. position: relative;
  262. margin-right: 23rpx;
  263. }
  264. .cash-withdrawal .wrapper .list .item .picEwm image {
  265. width: 100%;
  266. height: 100%;
  267. border-radius: 3rpx;
  268. }
  269. .cash-withdrawal .wrapper .list .item .picEwm .icon-guanbi1 {
  270. position: absolute;
  271. right: -14rpx;
  272. top: -16rpx;
  273. font-size: 40rpx;
  274. }
  275. .cash-withdrawal .wrapper .list .item .pictrue {
  276. border: 1px solid rgba(221, 221, 221, 1);
  277. font-size: 22rpx;
  278. color: #BBBBBB;
  279. }
  280. .cash-withdrawal .wrapper .list .item .pictrue .icon-icon25201 {
  281. font-size: 47rpx;
  282. color: #DDDDDD;
  283. margin-bottom: 3px;
  284. }
  285. .cash-withdrawal .wrapper .list .tip {
  286. font-size: 26rpx;
  287. color: #999;
  288. margin-top: 25rpx;
  289. }
  290. .cash-withdrawal .wrapper .list .bnt {
  291. font-size: 32rpx;
  292. color: #fff;
  293. width: 690rpx;
  294. height: 90rpx;
  295. text-align: center;
  296. border-radius: 50rpx;
  297. line-height: 90rpx;
  298. margin: 64rpx auto;
  299. }
  300. .cash-withdrawal .wrapper .list .tip2 {
  301. font-size: 26rpx;
  302. color: #999;
  303. text-align: center;
  304. margin: 44rpx 0 20rpx 0;
  305. }
  306. .cash-withdrawal .wrapper .list .value {
  307. height: 135rpx;
  308. line-height: 135rpx;
  309. border-bottom: 1rpx solid #eee;
  310. width: 690rpx;
  311. margin: 0 auto;
  312. }
  313. .cash-withdrawal .wrapper .list .value input {
  314. font-size: 80rpx;
  315. color: #282828;
  316. height: 135rpx;
  317. text-align: center;
  318. }
  319. .cash-withdrawal .wrapper .list .value .placeholder2 {
  320. color: #bbb;
  321. }
  322. .price {
  323. color: var(--view-priceColor);
  324. margin-right: 20rpx;
  325. }
  326. </style>