conversion.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div class="conversion">
  3. <view class="list flex_r flex_ac flex_jb mar_t16">
  4. <view class="list_name">可转化云宝:</view>
  5. <view class="list_text">{{ userinfo.user_money }}</view>
  6. </view>
  7. <view class="list flex_r flex_ac flex_jb mar_t16">
  8. <view class="list_name">需要转化的云宝:</view>
  9. <view class="list_text">
  10. <input
  11. type="number"
  12. v-model="give_num"
  13. placeholder="请输入需要转化的云宝"
  14. placeholder-style="color:#ddd;"
  15. />
  16. </view>
  17. </view>
  18. <view class="list flex_r flex_ac flex_jb mar_t16">
  19. <view class="list_name">你将得到的茶宝:</view>
  20. <view class="list_text">{{ give_num * (1 - fee) || 0 }}</view>
  21. </view>
  22. <view class="tips">{{ tips }}</view>
  23. <view class="btn flex_r flex_ac flex_jc" @tap="exchange">立即转化</view>
  24. </div>
  25. </template>
  26. <script>
  27. import { post } from "@/request/api.js";
  28. let app = getApp();
  29. var appEv = app.$vm.$options;
  30. export default {
  31. name: "conversion",
  32. data() {
  33. return {
  34. give_num: undefined,
  35. userinfo: undefined, // 获取用户信息
  36. fee: undefined,
  37. tips: undefined,
  38. };
  39. },
  40. onLoad(option) {
  41. this.userinfo = uni.getStorageSync("userinfo");
  42. this.getMoneyChabao();
  43. },
  44. onLaunch() {},
  45. onShow() {},
  46. onHide() {},
  47. methods: {
  48. getMoneyChabao() {
  49. post("v1/moneyChabao").then((res) => {
  50. this.fee = res.data.data.fee;
  51. this.tips = res.data.data.tips;
  52. });
  53. },
  54. exchange() {
  55. if (this.give_num == 0) {
  56. appEv.errTips("赠送数量不得为0");
  57. return;
  58. } else if (this.give_num > Number(this.userinfo.user_money)) {
  59. appEv.errTips("转化数量不得超过云宝");
  60. return;
  61. } else {
  62. let content = `您将转化${this.give_num}云宝为${
  63. this.give_num * (1 - this.fee)
  64. }茶宝`;
  65. let that = this;
  66. uni.showModal({
  67. title: "提示",
  68. content: content,
  69. showCancel: true,
  70. success: function (res) {
  71. if (res.confirm) {
  72. that.turn();
  73. } else {
  74. }
  75. },
  76. });
  77. }
  78. },
  79. turn() {
  80. let data = {
  81. number: this.give_num,
  82. };
  83. post("v1/my/moneyTurn", data).then( async (res) => {
  84. if (res.code === 0) {
  85. this.give_num = undefined;
  86. this.userinfo = await uni.userfun();
  87. appEv.errTips(res.msg);
  88. } else {
  89. appEv.errTips(res.msg);
  90. }
  91. });
  92. },
  93. },
  94. computed: {},
  95. watch: {},
  96. };
  97. </script>
  98. <style scoped lang='scss'>
  99. // 页面配置
  100. page {
  101. background: #f4f4f4;
  102. }
  103. // 页面配置-end
  104. .list {
  105. width: 100%;
  106. height: 86rpx;
  107. padding: 0 30rpx;
  108. box-sizing: border-box;
  109. background: #fff;
  110. }
  111. .list_text {
  112. flex: 1;
  113. font-family: "SourceHanSansCN-Bold";
  114. text-align: right;
  115. }
  116. .list_name {
  117. flex: 1;
  118. color: #333333;
  119. font-size: 28rpx;
  120. font-family: "SourceHanSansCN-Medium";
  121. font-weight: 500;
  122. }
  123. .list_text input {
  124. font-size: 30rpx;
  125. color: #333;
  126. text-align: right;
  127. font-weight: bold;
  128. // margin-left: 20rpx;
  129. }
  130. .list_text text {
  131. font-family: "SourceHanSansCN-Medium";
  132. font-size: 36rpx;
  133. font-weight: bold;
  134. color: #17bb87;
  135. }
  136. .tips {
  137. margin-top: 100rpx;
  138. text-align: center;
  139. color: #999;
  140. font-size: 30rpx;
  141. }
  142. .btn {
  143. width: 689rpx;
  144. height: 92rpx;
  145. background: #17bb87;
  146. color: #fff;
  147. font-size: 42rpx;
  148. font-family: "SourceHanSansCN-Medium";
  149. font-weight: 500;
  150. margin: 20rpx auto 0;
  151. border-radius: 10rpx;
  152. }
  153. </style>