recharge.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <view class="recharge">
  3. <view class="recharge_head">
  4. <view class="czbj">
  5. <view class="czbj-img"><image src="https://www.chaomangdao.com/image/me/czbj.jpg"></image></view>
  6. <view class="czbj-text">
  7. <text>当前金币</text>
  8. <span>{{ capital.coin }}</span>
  9. </view>
  10. <!-- #ifndef MP -->
  11. <a href="https://www.chaomangdao.com/image/me/czsp.mp4">
  12. <view class="czbj-czjc">
  13. <text>充值教程</text>
  14. <span></span>
  15. </view>
  16. </a>
  17. <!-- #endif -->
  18. </view>
  19. <view class="recharge_head_txt flex">
  20. <text>选择充值金额</text>
  21. <text>
  22. 实际到账金币:
  23. <text class="real-coin">{{ realCoin }}</text>
  24. </text>
  25. </view>
  26. <view class="recharge_head_ul flexs">
  27. <view class="recharge_head_li center" :class="{ active: index == i }" @click="changeI(index)" v-for="(item, index) in rechargeList" :key="index">
  28. <text>¥</text>
  29. <text>{{ item.coin }}</text>
  30. </view>
  31. </view>
  32. </view>
  33. <view class="deposit_main">
  34. <view class="deposit_main_name">选择支付方式</view>
  35. <view class="deposit_main_ul">
  36. <view class="deposit_main_li flex" v-for="(item, index) in payList" :key="index" @click="changePay(item.type)">
  37. <view class="deposit_main_img flexs">
  38. <image :src="item.image" mode=""></image>
  39. <text>{{ item.name }}</text>
  40. </view>
  41. <view class="deposit_main_li_select">
  42. <image :src="item.type == payIndex ? '/static/image/publice/xuanzhong1@2x.png' : '/static/image/publice/weixuanzhong@2x.png'" mode=""></image>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="deposit_main_txt"><u-parse :content="message"></u-parse></view>
  47. </view>
  48. <button class="recharge_btn" hover-class="hover-view" @click="submitPay">支付</button>
  49. </view>
  50. </template>
  51. <script>
  52. export default {
  53. data() {
  54. return {
  55. capital: {
  56. box: 0,
  57. coin: 0
  58. },
  59. i: 0, //选择金额
  60. message: '',
  61. tips: '',
  62. payIndex: 1, //支付方式
  63. rechargeList: [], //
  64. bili: 0, //充值比例
  65. payList: [
  66. {
  67. name: '微信支付',
  68. type: '0',
  69. image: '/static/image/me/weixin@2x.png'
  70. }
  71. // {
  72. // name:'支付宝支付',
  73. // type:'1',
  74. // image:'/static/image/me/zhifubao@2x.png'
  75. // },
  76. /* {
  77. name:'普通支付',
  78. type:'2',
  79. image:'/static/image/me/zhifubao@2x_no.png'
  80. },
  81. */
  82. // {
  83. // name:'卡密充值',
  84. // type:'3',
  85. // image:'/static/image/me/kmcz.png'
  86. // },
  87. // {
  88. // name:'人工充值',
  89. // type:'4',
  90. // image:'/static/image/me/rgcz.png'
  91. // },
  92. ] //支付列表
  93. };
  94. },
  95. computed: {
  96. realCoin() {
  97. if (!this.rechargeList || this.rechargeList.length < 1) {
  98. return 0;
  99. }
  100. let recharge = this.rechargeList[this.i];
  101. console.log(recharge.rmb * this.bili * 1, '123456');
  102. return recharge.rmb * (this.bili * 1);
  103. }
  104. },
  105. created() {
  106. this.$api.getUserCapital().then(({ code, data }) => {
  107. if (code == 1) {
  108. this.capital = data;
  109. }
  110. });
  111. //渲染分类列表
  112. // this.getCategoryList();
  113. },
  114. methods: {
  115. //提交支付
  116. submitPay() {
  117. if (this.payIndex == 3) {
  118. //充值卡密
  119. this.rechargePassword();
  120. return;
  121. }
  122. if (this.payIndex == 4) {
  123. //人工充值
  124. this.rengong();
  125. return;
  126. }
  127. this.$api.createRechargeOrder({ amount: this.rechargeList[this.i].coin }).then(res => {
  128. if (res.code === 1) {
  129. console.log(this.payIndex, '1111');
  130. if (this.payIndex == 0) {
  131. // #ifdef MP
  132. this.$http.post(res.data.wechat).then(res => {
  133. let da = res.jsConfig;
  134. let data = {
  135. // #ifdef MP
  136. timeStamp: da.timeStamp,
  137. // #endif
  138. nonceStr: da.nonceStr,
  139. package: da.package,
  140. signType: da.signType,
  141. paySign: da.paySign,
  142. success: function(res) {
  143. uni.showToast({ title: '支付成功' });
  144. setTimeout(() => {
  145. uni.redirectTo({ url: '/pages/me/wallet' });
  146. }, 800);
  147. },
  148. fail: () => {
  149. uni.showToast({ title: '支付失败' });
  150. }
  151. };
  152. console.log(data);
  153. wx.requestPayment(data);
  154. });
  155. // #endif
  156. }
  157. }
  158. });
  159. },
  160. //选择金额
  161. changeI(index) {
  162. this.i = index;
  163. },
  164. //切换支付方式
  165. changePay(index) {
  166. this.payIndex = index;
  167. },
  168. //获取充值列表
  169. getRechargeList() {
  170. this.$api.rechargeList().then(res => {
  171. if (res.code === 1) {
  172. this.tips = res.data.tips;
  173. this.message = res.data.notice;
  174. this.rechargeList = res.data.list;
  175. this.bili = res.data.bili;
  176. }
  177. });
  178. },
  179. //卡密充值跳转
  180. rechargePassword() {
  181. uni.navigateTo({
  182. url: '/pages/me/passwordRecharge/passwordRecharge'
  183. });
  184. },
  185. //人工充值跳转
  186. rengong() {
  187. uni.navigateTo({
  188. url: '/pagesB/pages/server'
  189. });
  190. }
  191. },
  192. onLoad() {
  193. this.getRechargeList();
  194. }
  195. };
  196. </script>
  197. <style lang="scss">
  198. .czbj {
  199. margin-top: 1%;
  200. overflow: hidden;
  201. width: 100%;
  202. background: rgb(255, 255, 255);
  203. box-shadow: rgba(0, 0, 0, 0.04) 0px 4px 20px 0px;
  204. border-radius: 32rpx;
  205. }
  206. .czbj .czbj-img {
  207. height: 175rpx;
  208. width: 100%;
  209. position: relative;
  210. uin-image {
  211. width: 100%;
  212. height: 100%;
  213. }
  214. }
  215. .czbj .czbj-text {
  216. position: absolute;
  217. width: 100%;
  218. height: 175rpx;
  219. left: 0;
  220. top: 0;
  221. padding: 30rpx 65rpx;
  222. uni-text {
  223. font-size: 32rpx;
  224. color: #fff;
  225. display: block;
  226. }
  227. span {
  228. font-size: 46rpx;
  229. font-weight: bold;
  230. color: #fff;
  231. display: block;
  232. margin-top: 20rpx;
  233. }
  234. }
  235. .czbj .czbj-czjc {
  236. padding: 11px 15px;
  237. span {
  238. width: 29px;
  239. height: 29px;
  240. float: right;
  241. background: url(../../static/image/me/czjc.png);
  242. display: block;
  243. background-size: 100% 100%;
  244. }
  245. uni-text {
  246. font-weight: 600;
  247. line-height: 48rpx;
  248. }
  249. }
  250. .recharge {
  251. min-height: calc(100vh - 44px);
  252. position: relative;
  253. padding: 0 30rpx;
  254. .recharge_head {
  255. .recharge_head_txt {
  256. padding: 20rpx 0 20rpx 0;
  257. text {
  258. &:first-child {
  259. font-size: 32rpx;
  260. font-weight: bold;
  261. }
  262. &:last-child {
  263. color: #999999;
  264. }
  265. .real-coin {
  266. color: #ff0000;
  267. font-size: 32rpx;
  268. font-weight: bold;
  269. }
  270. }
  271. }
  272. }
  273. .recharge_head_ul {
  274. flex-wrap: wrap;
  275. .recharge_head_li {
  276. margin: 0 24rpx 20rpx 0;
  277. width: 214rpx;
  278. height: 160rpx;
  279. background: #ffffff;
  280. border: 2rpx solid #ebebeb;
  281. border-radius: 10rpx;
  282. &:nth-child(3n) {
  283. margin-right: 0;
  284. }
  285. text {
  286. color: #66a6ff;
  287. font-size: 30rpx;
  288. &:last-child {
  289. font-size: 44rpx;
  290. }
  291. }
  292. }
  293. .active {
  294. border: 2rpx solid #66a6ff;
  295. }
  296. }
  297. }
  298. .deposit_main {
  299. padding-bottom: 30rpx;
  300. .deposit_main_name {
  301. font-size: 32rpx;
  302. font-weight: bold;
  303. padding: 10rpx 0 30rpx 10rpx;
  304. }
  305. .deposit_main_ul {
  306. background: #ffffff;
  307. .deposit_main_li {
  308. padding: 30rpx 20rpx;
  309. border: 1px solid #66a6ff;
  310. border-radius: 60rpx;
  311. .deposit_main_img {
  312. image {
  313. width: 50rpx;
  314. height: 50rpx;
  315. margin-right: 20rpx;
  316. }
  317. text {
  318. font-size: 28rpx;
  319. }
  320. }
  321. .deposit_main_li_select {
  322. width: 32rpx;
  323. height: 32rpx;
  324. }
  325. }
  326. }
  327. .deposit_main_txt {
  328. padding: 30rpx 0;
  329. }
  330. }
  331. .recharge_btn {
  332. /*position: absolute;
  333. left: 50%;
  334. transform: translateX(-50%);
  335. */
  336. width: 690rpx;
  337. bottom: 34rpx;
  338. color: #fff;
  339. height: 88rpx;
  340. background: -webkit-linear-gradient(0deg, #89f7fe 0%, #66a6ff 100%);
  341. box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(220, 220, 220, 0.2);
  342. border-radius: 8rpx;
  343. }
  344. .password_btn {
  345. height: 44px;
  346. }
  347. </style>