index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <view>
  3. <view class="payment" :class="pay_close ? 'on' : ''">
  4. <view class="title acea-row row-center-wrapper">
  5. 选择付款方式<text class="iconfont icon-guanbi" @click='close'></text>
  6. </view>
  7. <view class="item acea-row row-between-wrapper" @click='goPay(item.number || 0 , item.value)' v-for="(item,index) in payMode"
  8. :key="index">
  9. <view class="left acea-row row-between-wrapper">
  10. <view class="iconfont" :class="item.icon"></view>
  11. <view class="text">
  12. <view class="name">{{item.name}}</view>
  13. <view class="info" v-if="item.number">
  14. {{item.title}} <span class="money">¥{{ item.number }}</span>
  15. </view>
  16. <view class="info" v-else>{{item.title}}</view>
  17. </view>
  18. </view>
  19. <view class="iconfont icon-xiangyou"></view>
  20. </view>
  21. </view>
  22. <view class="mask" @click='close' v-if="pay_close"></view>
  23. </view>
  24. </template>
  25. <script>
  26. import {
  27. balancePay,
  28. wxPay
  29. } from '@/api/api.js';
  30. export default {
  31. props: {
  32. payMode: {
  33. type: Array,
  34. default: function() {
  35. return [];
  36. }
  37. },
  38. pay_close: {
  39. type: Boolean,
  40. default: false,
  41. },
  42. order_id: {
  43. type: String,
  44. default: ''
  45. },
  46. totalPrice: {
  47. type: String,
  48. default: '0'
  49. }
  50. },
  51. data() {
  52. return {
  53. };
  54. },
  55. methods: {
  56. close: function() {
  57. this.$emit('onChangeFun', {
  58. action: 'payClose'
  59. });
  60. },
  61. goPay: function(number, paytype) {
  62. let that = this;
  63. if (!that.order_id) return that.$util.Tips({
  64. title: '请选择要支付的订单'
  65. });
  66. if (paytype == 'yue' && parseFloat(number) < parseFloat(that.totalPrice)) return that.$util.Tips({
  67. title: '余额不足!'
  68. });
  69. uni.showLoading({
  70. title: '支付中'
  71. });
  72. if(paytype == 'yue'){
  73. balancePay({'order_id':that.order_id}).then(res => {
  74. uni.hideLoading();
  75. return that.$util.Tips({
  76. title: res.data.msg,
  77. icon: 'success'
  78. }, () => {
  79. that.$emit('onChangeFun', {
  80. action: 'pay_complete'
  81. });
  82. });
  83. }).catch(err => {
  84. uni.hideLoading();
  85. return that.$util.Tips({
  86. title: err
  87. }, () => {
  88. that.$emit('onChangeFun', {
  89. action: 'pay_fail'
  90. });
  91. });
  92. })
  93. }else{
  94. wxPay({
  95. order_id: that.order_id,
  96. from: this.$wechat.isWeixin() ? 'weixin' : 'h5'
  97. }).then(res => {
  98. if (res.data.result === undefined) return that.$util.Tips({
  99. title: '缺少支付参数'
  100. });
  101. if (res.data.type == "WECHAT_H5_PAY") {
  102. uni.hideLoading();
  103. location.replace(res.data.result.mweb_url);
  104. return that.$util.Tips({
  105. title: "支付成功",
  106. icon: 'success'
  107. }, () => {
  108. that.$emit('onChangeFun', {
  109. action: 'pay_complete'
  110. });
  111. });
  112. } else {
  113. let response = res.data.result;
  114. if (typeof WeixinJSBridge == "undefined") {
  115. if (document.addEventListener) {
  116. document.addEventListener('WeixinJSBridgeReady', this.onBridgeReady(response), false);
  117. } else if (document.attachEvent) {
  118. document.attachEvent('WeixinJSBridgeReady', this.onBridgeReady(response));
  119. document.attachEvent('onWeixinJSBridgeReady', this.onBridgeReady(response));
  120. }
  121. } else {
  122. this.onBridgeReady(response);
  123. }
  124. }
  125. }).catch(err => {
  126. uni.hideLoading();
  127. return that.$util.Tips({
  128. title: err
  129. }, () => {
  130. that.$emit('onChangeFun', {
  131. action: 'pay_fail'
  132. });
  133. });
  134. })
  135. }
  136. },
  137. onBridgeReady: function(response) {
  138. WeixinJSBridge.invoke(
  139. 'getBrandWCPayRequest', {
  140. "appId": response.appId, //公众号名称,由商户传入
  141. "timeStamp": response.timeStamp, //时间戳,自1970年以来的秒数
  142. "nonceStr": response.nonceStr, //随机串
  143. "package": response.package,
  144. "signType": response.signType, //微信签名方式
  145. "paySign": response.paySign //微信签名
  146. },
  147. function(res) {
  148. if (res.err_msg == "get_brand_wcpay_request:ok") {
  149. uni.hideLoading();
  150. return that.$util.Tips({
  151. title: "支付成功",
  152. icon: 'success'
  153. }, () => {
  154. that.$emit('onChangeFun', {
  155. action: 'pay_complete'
  156. });
  157. });
  158. } else {
  159. uni.hideLoading();
  160. return that.$util.Tips({
  161. title: '支付失败'
  162. });
  163. }
  164. WeixinJSBridge.log(res.err_msg);
  165. }
  166. );
  167. }
  168. }
  169. }
  170. </script>
  171. <style scoped lang="scss">
  172. .payment {
  173. position: fixed;
  174. bottom: 0;
  175. left: 0;
  176. width: 100%;
  177. border-radius: 16rpx 16rpx 0 0;
  178. background-color: #fff;
  179. padding-bottom: 60rpx;
  180. z-index: 99;
  181. transition: all 0.3s cubic-bezier(0.25, 0.5, 0.5, 0.9);
  182. transform: translate3d(0, 100%, 0);
  183. }
  184. .payment.on {
  185. transform: translate3d(0, 0, 0);
  186. }
  187. .payment .title {
  188. text-align: center;
  189. height: 123rpx;
  190. font-size: 32rpx;
  191. color: #282828;
  192. font-weight: bold;
  193. padding-right: 30rpx;
  194. margin-left: 30rpx;
  195. position: relative;
  196. border-bottom: 1rpx solid #eee;
  197. }
  198. .payment .title .iconfont {
  199. position: absolute;
  200. right: 30rpx;
  201. top: 50%;
  202. transform: translateY(-50%);
  203. font-size: 43rpx;
  204. color: #8a8a8a;
  205. font-weight: normal;
  206. }
  207. .payment .item {
  208. border-bottom: 1rpx solid #eee;
  209. height: 130rpx;
  210. margin-left: 30rpx;
  211. padding-right: 30rpx;
  212. }
  213. .payment .item .left {
  214. width: 610rpx;
  215. }
  216. .payment .item .left .text {
  217. width: 540rpx;
  218. }
  219. .payment .item .left .text .name {
  220. font-size: 32rpx;
  221. color: #282828;
  222. }
  223. .payment .item .left .text .info {
  224. font-size: 24rpx;
  225. color: #999;
  226. }
  227. .payment .item .left .text .info .money {
  228. color: #ff9900;
  229. }
  230. .payment .item .left .iconfont {
  231. font-size: 45rpx;
  232. color: #09bb07;
  233. }
  234. .payment .item .left .iconfont.icon-zhifubao {
  235. color: #00aaea;
  236. }
  237. .payment .item .left .iconfont.icon-yuezhifu {
  238. color: #ff9900;
  239. }
  240. .payment .item .left .iconfont.icon-yuezhifu1 {
  241. color: #eb6623;
  242. }
  243. .payment .item .iconfont {
  244. font-size: 0.3rpx;
  245. color: #999;
  246. }
  247. </style>