index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view class="container">
  3. <view class="con">
  4. <view class="list flex_r flex_ac" v-if="type == 'local'">
  5. <view class="list_name">当前余额:</view>
  6. <span>{{localInfo.property}}</span>
  7. </view>
  8. <view class="list flex_r flex_ac" v-else>
  9. <view class="list_name">当前云宝:</view>
  10. <span>{{userinfo.user_money}}</span>
  11. </view>
  12. <view class="list flex_r flex_ac">
  13. <view class="list_name">充值金额:</view>
  14. <input class="list_input flex_grow" type="text" v-model="price" placeholder="请输入充值金额" />
  15. </view>
  16. <view class="list flex_r flex_ac">
  17. <view class="list_name">支付方式:</view>
  18. <view class="flex_r flex_ac">
  19. <view class="way_con flex_r flex_ac">
  20. <span class="iconfont icow">&#xe650;</span>
  21. <view class="way_text">微信支付</view>
  22. </view>
  23. </view>
  24. </view>
  25. <div class="checkbox-box flex_r flex_ac">
  26. <checkbox-group @change="checkboxChange" class="flex_r flex_ac">
  27. <label class="checkbox flex_r flex_ac">
  28. <checkbox class="checkboxCom" value="agree" />
  29. <view>我同意</view>
  30. </label>
  31. <span @click="goto('/pages/agreement/index',{tit:'充值协议',type:28})" class="hover_a">《充值协议》</span>
  32. </checkbox-group>
  33. </div>
  34. <view class="btn flex_r flex_ac flex_jc" @tap="confimTopUp">立即充值</view>
  35. <view>
  36. <image class="adv_img" :src="advertisingImg"></image>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { ToPayOpre } from "@/utils/reqTools.js";
  43. var toPayOpre = new ToPayOpre();
  44. import { post } from "@/request/api.js";
  45. export default {
  46. data() {
  47. return {
  48. price: "",
  49. isSelect: 1,
  50. detail: {},
  51. array: ["云宝充值"],
  52. index: 0,
  53. userinfo: uni.getStorageSync("userinfo"), // 获取用户信息
  54. localInfo: uni.getStorageSync("localInfo"), // 获取数智生活用户信息
  55. isDisabled: false, //是否选中协议
  56. advertisingImg: "", //广告图片
  57. type: undefined
  58. };
  59. },
  60. onLoad(e) {
  61. this.type = e.type
  62. this.getAdvImg();
  63. },
  64. methods: {
  65. confimTopUp() {
  66. let that = this
  67. if (!this.price) {
  68. this.$toast("充值不能为0");
  69. return;
  70. } else if (!this.isDisabled) {
  71. this.$toast("请阅读并同意相关协议");
  72. return;
  73. } else {
  74. let trade_type = "";
  75. // #ifdef H5
  76. trade_type = "H5";
  77. // #endif
  78. // #ifdef APP
  79. trade_type = "app";
  80. // #endif
  81. // #ifdef MP-WEIXIN
  82. trade_type = "jsapi";
  83. // #endif
  84. let data = {
  85. type: this.type == "local" ? 2 : 1,
  86. trade_type: trade_type,
  87. amount: this.price,
  88. };
  89. post("v1/user/recharge", data).then((res) => {
  90. toPayOpre.toPay(res.data.data, (rea) => {
  91. if (!rea) {
  92. // 支付成功
  93. this.$toast("支付成功");
  94. that.$set(that,"price","");
  95. if(that.type == "local") that.getLU();
  96. else that.getuserInfo();
  97. } else {
  98. // 支付失败
  99. this.$toast("支付已取消");
  100. }
  101. });
  102. });
  103. }
  104. },
  105. getAdvImg() {
  106. post("v1/adImgages").then((res) => {
  107. if (res.code === 0) {
  108. this.advertisingImg = res.data.data;
  109. }
  110. });
  111. },
  112. async getuserInfo() {
  113. this.userinfo = await uni.userfun();
  114. },
  115. async getLU() {
  116. this.localInfo = await uni.Luserfun()
  117. },
  118. checkboxChange(e) {
  119. var value = e.detail.value;
  120. if (value.length == 0) {
  121. this.isDisabled = false
  122. } else {
  123. this.isDisabled = true
  124. }
  125. },
  126. },
  127. };
  128. </script>
  129. <style lang="scss" scoped>
  130. // 页面配置
  131. page {
  132. background: #f4f4f4;
  133. }
  134. // 页面配置-end
  135. // 页面内容
  136. .con {
  137. width: 1005;
  138. overflow: hidden;
  139. padding: 30rpx;
  140. box-sizing: border-box;
  141. }
  142. .adv_img {
  143. margin-top: 20px;
  144. width: 690rpx;
  145. // height: 100%;
  146. height: 345rpx;
  147. }
  148. .list {
  149. width: 100%;
  150. height: 100rpx;
  151. border-bottom: 3rpx solid rgba(0, 0, 0, 0.12);
  152. }
  153. .list_name {
  154. font-size: 28rpx;
  155. color: #333;
  156. font-weight: "SourceHanSansCN-Medium";
  157. width: 150rpx;
  158. }
  159. .list_input {
  160. width: calc(100% - 140rpx);
  161. margin-left: 10rpx;
  162. height: 100%;
  163. font-size: 28rpx;
  164. color: #333;
  165. }
  166. .btn {
  167. width: 395rpx;
  168. height: 95rpx;
  169. border-radius: 10rpx;
  170. background: #17bb87;
  171. color: #fff;
  172. font-size: 34rpx;
  173. font-family: "SourceHanSansCN-Medium";
  174. margin: 100rpx auto 0;
  175. }
  176. // 提交内容-end
  177. .checkbox-box {
  178. margin-top: 60rpx;
  179. margin-bottom: -20px;
  180. font-size: 28rpx;
  181. }
  182. .checkbox-box text {
  183. /* color: #07d; */
  184. /* color: #44A92F; */
  185. color: #44a92f;
  186. }
  187. .checkbox-box .checkbox .checkboxCom {
  188. transform: scale(0.84);
  189. -webkit-transform: scale(0.84);
  190. }
  191. .way_radio {
  192. width: 39rpx;
  193. height: 35rpx;
  194. background: url("~@/static/sgin/weixuanzhong_icon.png");
  195. background-repeat: no-repeat;
  196. background-size: 35rpx 35rpx;
  197. background-position: center center;
  198. }
  199. .select_way {
  200. background: url("~@/static/sgin/xuanzhong_icon.png");
  201. background-repeat: no-repeat;
  202. background-size: 39rpx 35rpx;
  203. background-position: center center;
  204. }
  205. .way_text {
  206. font-size: 22rpx;
  207. color: #333333;
  208. font-family: "SourceHanSansCN-Medium";
  209. }
  210. .icow{
  211. color: #00C800;
  212. margin-right: 6rpx;
  213. }
  214. .way_text,.icow{
  215. vertical-align: middle;
  216. }
  217. // 页面内容-end
  218. </style>