recharge.vue 7.9 KB

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