charge.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="page">
  3. <view class="content">
  4. <view class="charge-head">
  5. <view class="charge-msg">
  6. <text>充值金额</text>
  7. </view>
  8. <view class="charge-show">
  9. <text>¥</text>
  10. </view>
  11. <view class="charge">
  12. <input class="uni-input" type="number" placeholder-class="placeholder" :value="amount" focus placeholder="请输入充值金额" @input="doAmount"/>
  13. </view>
  14. <view class="charge-cell-list">
  15. <view class="charge-item">
  16. <view><text data-index="0" :class="setIndex == 0 ? 'active' : ''" @tap="selectTab">{{amount_arr[0]}}</text></view>
  17. <view><text data-index="1" :class="setIndex == 1 ? 'active' : ''" @tap="selectTab">{{amount_arr[1]}}</text></view>
  18. <view><text data-index="2" :class="setIndex == 2 ? 'active' : ''" @tap="selectTab">{{amount_arr[2]}}</text></view>
  19. </view>
  20. <view class="charge-item">
  21. <view><text data-index="3" :class="setIndex == 3 ? 'active' : ''" @tap="selectTab">{{amount_arr[3]}}</text></view>
  22. <view><text data-index="4" :class="setIndex == 4 ? 'active' : ''" @tap="selectTab">{{amount_arr[4]}}</text></view>
  23. <view><text data-index="5" :class="setIndex == 5 ? 'active' : ''" @tap="selectTab">{{amount_arr[5]}}</text></view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="charge-footer">
  28. <view class="msg">
  29. <text>选择支付方式</text>
  30. </view>
  31. <view class="charge-channel">
  32. <view class="chanel-img">
  33. <view class="check-img">
  34. <!--<label class="radio" data-index="6" @tap="selectTab">-->
  35. <!--<radio value="6" :checked="(checked == 6) ? true : false"></radio>-->
  36. <!--<image src="../../../static/theme/default/my/weixin.png"></image>-->
  37. <!--<text>微信</text>-->
  38. <!--</label>-->
  39. <label class="radio" data-index="7" @tap="selectTab">
  40. <radio value="7" :checked="checked == 7 ? true : false"></radio>
  41. <image src="../../../static/theme/default/my/alipay.png"></image>
  42. <text>支付宝</text>
  43. </label>
  44. </view>
  45. </view>
  46. <button class="charge" type="button" @tap="charge">确认充值</button>
  47. </view>
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. import _get from '../../../common/_get';
  54. import _hook from '../../../common/_hook';
  55. import _data from '../../../common/_data';
  56. export default {
  57. data() {
  58. return {
  59. setIndex:1,
  60. checked :7,
  61. amount : 100,
  62. amount_arr:[100,200,300,400,500,600]
  63. }
  64. },
  65. onShow(){
  66. _hook.routeSonHook();
  67. },
  68. methods: {
  69. selectTab(e){
  70. let index = e.currentTarget.dataset.index;
  71. if(index == 6)return uni.showToast({
  72. title: '该支付通道暂未开放',
  73. duration: 1000,
  74. icon:"none"
  75. });
  76. if(index > 5)this.checked = index;
  77. else {
  78. this.setIndex = index;
  79. this.amount = this.amount_arr[index];
  80. }
  81. },
  82. doAmount(e){
  83. this.amount = e.detail.value;
  84. console.log(this.amount)
  85. },
  86. charge(){
  87. //1支付宝 2微信
  88. console.log(this.amount)
  89. _get.charge({amount:this.amount,charge_type:1},function (ret) {
  90. uni.requestPayment({
  91. provider: 'alipay',
  92. orderInfo: ret.orderInfo, //微信、支付宝订单数据
  93. success: function (res) {
  94. uni.showToast({
  95. title: '支付成功',
  96. duration: 1000,
  97. icon:"none"
  98. });
  99. },
  100. fail: function (err) {
  101. console.log('fail:' + JSON.stringify(err));
  102. }
  103. });
  104. },function(ret){
  105. uni.showToast({
  106. title:ret.msg,
  107. duration:1000,
  108. icon:'none'
  109. })
  110. });
  111. //微信和支付宝待
  112. //#ifdef APP-PLUS
  113. if(this.amount <= 0){
  114. uni.showToast({
  115. title: '请输入金额',
  116. duration: 1000,
  117. icon:"none"
  118. });
  119. }
  120. //1支付宝 2微信
  121. // uni.request({
  122. // url:_data.data('http_url') + '/im/pay/userCharge',
  123. // data:{amount:this.amount,charge_type:1},
  124. // header:{
  125. // /** 这里设置为简单跨域,只会请求一次 */
  126. // 'Content-Type': 'application/x-www-form-urlencoded',
  127. // },
  128. // method:'POST',
  129. // success:function (res) {
  130. // console.log(res)
  131. // }
  132. // })
  133. // _get.charge({amount:this.amount,charge_type:1},function (ret) {
  134. // console.log(ret);
  135. // uni.requestPayment({
  136. // provider: 'alipay',
  137. // orderInfo: ret, //微信、支付宝订单数据
  138. // success: function (res) {
  139. // console.log('success:' + JSON.stringify(res));
  140. // },
  141. // fail: function (err) {
  142. // console.log('fail:' + JSON.stringify(err));
  143. // }
  144. // });
  145. // });
  146. //#endif
  147. }
  148. }
  149. }
  150. </script>
  151. <style>
  152. .radio{
  153. position: relative;
  154. }
  155. .radio image{
  156. position: absolute;
  157. top: -4px;
  158. }
  159. .radio text{
  160. margin-left: 50px;
  161. }
  162. .content {
  163. display: flex;
  164. flex-direction: column;
  165. height: 100%;
  166. max-width: 100%;
  167. }
  168. .check-img{
  169. display: flex;
  170. flex-direction: row;
  171. justify-content: space-between;
  172. align-items: center;
  173. padding: 34px 37px;
  174. }
  175. .check-img image{
  176. width: 80upx;
  177. height: 80upx;
  178. }
  179. .charge-footer .msg{
  180. height: 100upx;
  181. line-height: 100upx;
  182. width: 100%;
  183. color: #aeaeb0;
  184. margin-left: 10%;
  185. font-size: 14px;
  186. }
  187. .charge-footer{
  188. padding-bottom: 80upx;
  189. }
  190. .charge-footer .charge-channel{
  191. background-color: white;
  192. padding-bottom: 180upx;
  193. }
  194. .charge-footer .charge{
  195. width: 90%;
  196. background-color: #5693ee;
  197. color: white;
  198. height: 80upx;
  199. line-height: 80upx;
  200. border-radius: 50upx;
  201. font-size: 16px;
  202. }
  203. .charge-footer{
  204. background-color: #eeeef0;
  205. }
  206. .content .charge-head{
  207. padding: 15upx 60upx;
  208. background-color: white;
  209. }
  210. .content .charge-show{
  211. margin-top: 20upx;
  212. }
  213. .content .charge-head .charge input{
  214. padding-left: 0px !important;
  215. font-size: 20px;
  216. }
  217. .content .charge-head .charge{
  218. margin: 10upx 0;
  219. }
  220. .content .charge-msg {
  221. color: #a8a8a8;
  222. }
  223. .content .charge-head .charge-cell-list{
  224. display: flex;
  225. flex-direction: column;
  226. justify-content: space-between;
  227. }
  228. .content .charge-head .charge-cell-list .charge-item{
  229. display: flex;
  230. flex-direction: row;
  231. }
  232. .charge-cell-list .charge-item view{
  233. display: flex;
  234. flex: 1;
  235. padding: 10upx;
  236. }
  237. .charge-cell-list .charge-item view text{
  238. border: 1px solid #6f6f6f;
  239. border-radius: 6px;
  240. padding: 7upx;
  241. width: 77px;
  242. height: 32px;
  243. display: flex;
  244. justify-content: center;
  245. align-items: center;
  246. font-size: 14px;
  247. }
  248. .placeholder{
  249. font-size: 20px;
  250. }
  251. .charge-item .active{
  252. background-color: #5693ee;
  253. color: white;
  254. }
  255. </style>