energy.vue 11 KB

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