energy.vue 7.7 KB

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