quick.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view class="content">
  3. <view class="box padding-b-30">
  4. <view class="titlebox">
  5. <view class="titlename padding-l-30">
  6. 兑换文票
  7. </view>
  8. </view>
  9. <view class="row-box">
  10. <view class="title">兑入云票</view>
  11. <view class="row flex">
  12. <view class="flex name-box">
  13. <image class="nametip" src="../../static/icon/quick2.png" mode="scaleToFill"></image>
  14. <text class="padding-l-10 name">文票</text>
  15. </view>
  16. <input class="input margin-l-10" type="number" v-model="ticketnum"
  17. placeholder="请输入整数" placeholder-class="placeholder" />
  18. </view>
  19. </view>
  20. <view class="flex-center">
  21. <image class="tabquick" src="../../static/icon/quick0.png" mode="scaleToFill"></image>
  22. </view>
  23. <view class="row-box">
  24. <view class="title">兑出趣豆<text class="font-size-sm">(余额:{{userInfo.integral}})</text></view>
  25. <view class="row flex">
  26. <view class="flex name-box">
  27. <image class="nametip" src="../../static/icon/quick1.png" mode="scaleToFill"></image>
  28. <text class="padding-l-10 name">趣豆</text>
  29. </view>
  30. <view class="input margin-l-10" type="number" placeholder="0.00" placeholder-class="placeholder">
  31. {{ticketnum*ratio}}
  32. </view>
  33. </view>
  34. </view>
  35. <view class="row-box">
  36. <view class="title">输入账号</view>
  37. <view class="row flex">
  38. <view class="flex name-box">
  39. <image class="nametip" src="../../static/icon/quick3.png" mode="scaleToFill"></image>
  40. <text class="padding-l-10 name">文交所账号</text>
  41. </view>
  42. <input class="input margin-l-10" type="number" v-model="card" placeholder="请输入文交所账号"
  43. placeholder-class="placeholder" />
  44. </view>
  45. </view>
  46. <button class="add-btn up" :class="{ action: loding }" @click="!loding ? confirm() : ''">确认兑换</button>
  47. </view>
  48. <navigator url="./quickList">
  49. <view class="box margin-t-30">
  50. <view class="titlebox flex">
  51. <view class="flex-start">
  52. <image class="nametip" src="../../static/icon/quick4.png" mode="scaleToFill"></image>
  53. <text class="padding-l-10">兑换记录</text>
  54. </view>
  55. <image class="nextTip" src="../../static/img/back.png" mode="scaleToFill"></image>
  56. </view>
  57. </view>
  58. </navigator>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. getUserInfo,
  64. admintrade,
  65. trade
  66. } from '@/api/user.js';
  67. import {
  68. getTicket,
  69. getExchange
  70. } from '@/api/quick.js';
  71. import {
  72. mapMutations,
  73. mapState
  74. } from 'vuex';
  75. export default {
  76. data() {
  77. return {
  78. ticketnum: '', //兑换文票数
  79. integral: '', //兑换所需要的积分数
  80. card: '', //转账卡号
  81. ratio: 1, //兑换比例
  82. loding: false,
  83. type: '1'
  84. };
  85. },
  86. onLoad(options) {
  87. this.dataUp();
  88. // 加载文票比例
  89. this.getTicket();
  90. },
  91. computed: {
  92. ...mapState('user', ['userInfo'])
  93. },
  94. methods: {
  95. ...mapMutations('user', ['setUserInfo', 'login']),
  96. // 更新数据
  97. dataUp() {
  98. let obj = this;
  99. getUserInfo({})
  100. .then(e => {
  101. obj.login();
  102. // 保存返回用户数据
  103. obj.setUserInfo(e.data);
  104. })
  105. .catch(e => {
  106. console.log(e);
  107. });
  108. },
  109. getTicket() {
  110. getTicket().then(
  111. (res) => {
  112. console.log(res);
  113. if (res.data.v.CurPrice != 0 && res.data.integral_price != 0) {
  114. this.ratio = +(res.data.v.CurPrice / res.data.integral_price).toFixed(2);
  115. } else {
  116. this.loding = true;
  117. uni.showModal({
  118. title: '提示',
  119. content: '当前兑换暂未开放',
  120. showCancel: false,
  121. });
  122. }
  123. }
  124. ).catch(
  125. (res) => {
  126. console.log(res);
  127. }
  128. )
  129. },
  130. // 提交
  131. confirm() {
  132. let obj = this;
  133. obj.loding = true;
  134. if(!this.ticketnum){
  135. uni.showToast({
  136. title: '请输入兑换数量',
  137. icon:'error'
  138. });
  139. return
  140. }
  141. if(this.ticketnum.indexOf('.')>-1){
  142. uni.showToast({
  143. title: '请输入整数',
  144. icon:'error'
  145. });
  146. return
  147. }
  148. // if(this.ticketnum*this.ratio>this.userInfo.integral){
  149. // uni.showToast({
  150. // title: '趣豆不足无法兑换',
  151. // icon:'error'
  152. // });
  153. // return
  154. // }
  155. if(!this.card){
  156. uni.showToast({
  157. title: '请输入社交账号',
  158. icon:'error'
  159. });
  160. return
  161. }
  162. let data = {
  163. account: obj.card, //账号
  164. extract_ticket: obj.ticketnum, //数量
  165. };
  166. getExchange(data)
  167. .then(e => {
  168. // 允许按钮点击
  169. obj.loding = false;
  170. // 初始化提现金额
  171. obj.ticketnum = '';
  172. uni.showToast({
  173. title: e.msg,
  174. duration: 2000,
  175. position: 'top'
  176. });
  177. obj.dataUp();
  178. })
  179. .catch(e => {
  180. obj.$api.msg(e.msg);
  181. obj.loding = false;
  182. });
  183. }
  184. }
  185. };
  186. </script>
  187. <style lang="scss">
  188. page {
  189. height: 100%;
  190. }
  191. .content {
  192. padding-top: 30rpx;
  193. .box {
  194. background-color: #FFF;
  195. line-height: 1;
  196. .titlebox {
  197. padding: 30rpx;
  198. font-weight: bold;
  199. font-size: $font-lg;
  200. border-bottom: 1px solid $border-color-base;
  201. .titlename {
  202. border-left: 2px solid $color-red ;
  203. }
  204. .nextTip {
  205. width: 20rpx;
  206. height: 40rpx;
  207. }
  208. }
  209. .tabquick {
  210. width: 70rpx;
  211. height: 70rpx;
  212. }
  213. .nametip {
  214. width: 40rpx;
  215. height: 40rpx;
  216. }
  217. .row-box {
  218. padding: 30rpx;
  219. .title {
  220. font-size: $font-sm;
  221. color: $font-color-light;
  222. padding-bottom: 20rpx;
  223. }
  224. .row {
  225. position: relative;
  226. .name-box {
  227. font-weight: bold;
  228. font-size: $font-base;
  229. width: 220rpx;
  230. .name {
  231. flex-grow: 1;
  232. border-right: 2px solid $font-color-disabled;
  233. margin-right: 10rpx;
  234. }
  235. }
  236. .input {
  237. flex: 1;
  238. font-size: 30rpx;
  239. height: 60rpx;
  240. line-height: 60rpx;
  241. color: $font-color-dark;
  242. border-bottom: 1px solid $border-color-light;
  243. }
  244. }
  245. }
  246. }
  247. }
  248. .add-btn {
  249. height: 80rpx;
  250. border-radius: 10rpx;
  251. margin: 0 50rpx;
  252. margin-top: 30rpx;
  253. color: #FFF;
  254. background-color: $uni-color-error ;
  255. &.action{
  256. background-color: $border-color-light ;
  257. }
  258. }
  259. </style>