recharge.vue 7.2 KB

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