recharge.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <view>
  3. <u-navbar title="充值">
  4. </u-navbar>
  5. <view class="recharge">
  6. <view class="recharge-text">
  7. <p>账户余额(元)</p>
  8. <h1>{{detail.balance}}</h1>
  9. </view>
  10. <view
  11. @click="gotoUrl('pages/user/rechargeList')"
  12. class="recharge-btn">
  13. 账单
  14. </view>
  15. </view>
  16. <view class="charge">
  17. <view class="chargeTit">
  18. 选择充值金额
  19. </view>
  20. <view class="chargeMain">
  21. <template v-for="(item,i) in list">
  22. <view :key="i" :class="{
  23. 'active':chargingMarketingId==item.id
  24. }" @click="chargingMarketingId=item.id,selectItem=item"
  25. class="chargeMain-item "><p>{{item.rechargeAmount}}元</p> <span v-if="item.giftAmount">赠{{item.giftAmount}}元</span></view>
  26. </template>
  27. </view>
  28. </view>
  29. <view style=" padding-bottom: 120px; ">
  30. <view class="charge">
  31. <view class="chargeRadio">
  32. <view class="u-flex">
  33. <u-icon name="weixinzhifu" custom-prefix="custom-icon" color="#22ac38" size="80"></u-icon>
  34. <view class="chargeRadio-text">
  35. <h4>微信支付</h4>
  36. <p>推荐微信支付</p>
  37. </view>
  38. </view>
  39. <u-radio-group>
  40. <u-radio></u-radio>
  41. </u-radio-group>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="foot-btn">
  46. <view class="foot-pirce">
  47. <u-icon name="tikuan" custom-prefix="custom-icon" color="#FF9502" size="48"></u-icon>
  48. <span>支付 ¥{{selectItem.rechargeAmount}}</span>
  49. </view>
  50. <u-button type="primary" @click="submit" :custom-style="customStyle" shape="square">确定充值</u-button>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. import * as Pay from '@/apis/weixin.js'
  56. import {
  57. wxPayJs
  58. } from '@/utils/wxpay'
  59. import * as API from '@/apis/index.js'
  60. export default {
  61. data() {
  62. return {
  63. isReady:false,
  64. customStyle: {
  65. background: '#1677ff'
  66. },
  67. detail:{},
  68. chargingMarketingId:'',
  69. selectItem:{},
  70. list:[],
  71. }
  72. },
  73. onReady() {
  74. this.init();
  75. },
  76. methods: {
  77. submit(){
  78. uni.showLoading({
  79. title: "加载中",
  80. mask: true,
  81. })
  82. Pay.wxpay(this.chargingMarketingId).then((response) => {
  83. if(!response.result){
  84. uni.showToast({
  85. title: response.message
  86. })
  87. return
  88. }
  89. var data = response.data
  90. uni.hideLoading()
  91. console.log("Pay+"+new Date().getTime())
  92. wxPayJs(data);
  93. }).catch(error => {
  94. this.$refs.common.showLoading(false, error);
  95. })
  96. },
  97. init1(){
  98. uni.showLoading({
  99. title: "加载中",
  100. mask: true,
  101. })
  102. API.personalCenter().then((res) => {
  103. this.detail = res.data
  104. this.isReady=true;
  105. uni.hideLoading()
  106. }).catch(error => {
  107. uni.showToast({
  108. title: error
  109. })
  110. })
  111. },
  112. init(){
  113. uni.showLoading({
  114. title: "加载中",
  115. mask: true,
  116. })
  117. var data = {
  118. };
  119. API.marketingData(data).then((res) => {
  120. this.list = res.data.chargingMarketingList
  121. if(this.list.length>0){
  122. this.selectItem=this.list[0];
  123. this.chargingMarketingId=this.list[0].id
  124. }
  125. uni.hideLoading()
  126. this.init1()
  127. }).catch(error => {
  128. uni.showToast({
  129. title: error
  130. })
  131. })
  132. }
  133. },onShow(){
  134. if(this.isReady){
  135. this.init1()
  136. }
  137. }
  138. }
  139. </script>
  140. <style>
  141. page{
  142. background-color: #f7f7f7;
  143. }
  144. </style>
  145. <style lang="scss" scoped>
  146. .recharge{
  147. padding: 15px;
  148. background-color: #1677FF;
  149. margin-bottom: 10px;
  150. display: flex;
  151. justify-content: space-between;
  152. align-items: center;
  153. .recharge-text{
  154. color:#fff;
  155. }
  156. .recharge-btn{
  157. width: 60px;
  158. height: 30px;
  159. text-align: center;
  160. line-height: 30px;
  161. background-color: #589EFF;
  162. color:#fff;
  163. border-radius: 15px;
  164. }
  165. }
  166. .charge{
  167. padding: 15px;
  168. background-color: #fff;
  169. margin-bottom: 10px;
  170. }
  171. .chargeRadio{
  172. display: flex;
  173. justify-content: space-between;
  174. align-items: center;
  175. width: 100%;
  176. .chargeRadio-text{
  177. margin-left: 5px;
  178. h4{
  179. font-weight: normal;
  180. font-size: 15px;
  181. }
  182. p{
  183. font-size: 12px;
  184. color:#999;
  185. margin-top: 5px;
  186. }
  187. }
  188. }
  189. .chargeTit{
  190. border-bottom: 1px solid #f7f7f7;
  191. padding-bottom: 10px;
  192. font-size: 15px;
  193. }
  194. .chargeMain{
  195. display: flex;
  196. flex-wrap: wrap;
  197. justify-content: space-between;
  198. margin-top: 20px;
  199. .chargeMain-item{
  200. width: 48%;
  201. text-align: center;
  202. padding: 25px 10px;
  203. border: 2px solid #cacaca;
  204. margin-bottom: 10px;
  205. border-radius: 10px;
  206. color:#333;
  207. position: relative;
  208. p{
  209. font-size: 20px;
  210. }
  211. span{
  212. background-color: #ff8d00;
  213. color:#fff;
  214. padding: 2px 10px;
  215. border-radius:0 10px 0 10px;
  216. position: absolute;
  217. font-size: 12px;
  218. right: -2px;
  219. top: -2px;
  220. }
  221. }
  222. .active{
  223. border-color:#ff8d00;
  224. color:#ff8d00;
  225. }
  226. .fault{
  227. background-color:#e1e1e1;
  228. color:#666;
  229. border: 1px solid #ccc;
  230. }
  231. .occupy{
  232. color:#FF4F3F;
  233. border: 1px solid #FF4F3F;
  234. }
  235. }
  236. .foot-btn{
  237. padding: 10px;
  238. position: fixed;
  239. left: 0;
  240. right: 0;
  241. bottom: 0;
  242. background-color: #fff;
  243. .foot-pirce{
  244. display: flex;
  245. align-items: center;
  246. span{
  247. margin-left: 5px;
  248. font-size: 16px;
  249. }
  250. padding-bottom: 10px;
  251. border-bottom: 1px solid #f7f7f7;
  252. margin-bottom: 10px;
  253. }
  254. }
  255. </style>