MPayment.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="mpayment">
  3. <van-popup v-model="isShow" :close-on-click-overlay="false" close-icon-position="top-left" position="bottom" round :closeOnPopstate="true" :safe-area-inset-bottom="true" :style="{ minHeight: '30%' }" >
  4. <i @click="onClose" class="van-icon van-icon-cross van-popup__close-icon van-popup__close-icon--top-left"></i>
  5. <div class="title van-hairline--bottom">选择支付方式</div>
  6. <div class="payAmount">
  7. <p>应付金额</p>
  8. <div class="amount">{{ payAmount }}<span>元</span></div>
  9. </div>
  10. <van-radio-group v-model="payType">
  11. <div class="payment-item van-hairline--bottom" @click="payType = 'zfb'">
  12. <div class="logo-section">
  13. <img class="logo" src="@/assets/images/zfb.png" alt="">
  14. </div>
  15. <div class="title-section">支付宝支付</div>
  16. <div class="value-section"><van-radio name="zfb"></van-radio></div>
  17. </div>
  18. <div class="payment-item" @click="payType = 'wx'">
  19. <div class="logo-section">
  20. <img class="logo" src="@/assets/images/wx_icon.png" alt="">
  21. </div>
  22. <div class="title-section">微信支付</div>
  23. <div class="value-section"><van-radio name="wx"></van-radio></div>
  24. </div>
  25. </van-radio-group>
  26. <div class="blank"></div>
  27. <van-button type="primary" block @click="onSubmit">确认支付</van-button>
  28. </van-popup>
  29. </div>
  30. </template>
  31. <script>
  32. import { changeTwoDecimal, validStudentUrl } from '@/common/common'
  33. // import { executePayment } from '@/api/student'
  34. // const axios = require('@/common/axios').default
  35. export default {
  36. name: "mheader",
  37. props: {
  38. closeStatus: { // 弹窗关闭状态
  39. type: Boolean,
  40. default: false
  41. },
  42. amount: { // 支付金额
  43. type: Number,
  44. default: 0
  45. },
  46. payment: { // 支付对象
  47. type: Object
  48. }
  49. },
  50. data() {
  51. return {
  52. isShow: this.closeStatus,
  53. payAmount: this.amount,
  54. paymentObject: this.payment, // 支付对象
  55. payType: 'zfb'
  56. };
  57. },
  58. methods: {
  59. onClose() {
  60. this.$dialog.confirm({
  61. message: '是否放弃本次付款',
  62. confirmButtonText: '继续付款',
  63. cancelButtonText: '放弃'
  64. }).then(() => {
  65. // on confirm
  66. }).catch(() => {
  67. // on cancel
  68. this.isShow = false
  69. this.$emit("onChangeStatus", this.isShow);
  70. })
  71. },
  72. onSubmit() { // 提交支付
  73. // 支付...
  74. const pt = this.payType,
  75. ua = window.navigator.userAgent.toLowerCase()
  76. // 判断当前浏览器
  77. if (ua.match(/MicroMessenger/i) == 'micromessenger') {
  78. // 微信浏览器
  79. if (pt == 'zfb') {
  80. this.pay_channel = 'alipay_qr'
  81. this.getCodePay('qrCode')
  82. } else if (pt == 'wx') {
  83. this.pay_channel = 'wx_pub'
  84. this.getCodePay('pay')
  85. }
  86. } else if (ua.match(/AlipayClient/i) == 'alipayclient') {
  87. // 支付宝浏览器
  88. if (pt == 'zfb') {
  89. this.pay_channel = 'alipay_wap'
  90. // 支付宝 H5 支付
  91. this.getCodePay('pay')
  92. } else if (pt == 'wx') {
  93. this.pay_channel = 'wx_pub'
  94. this.getCodePay('qrCode')
  95. }
  96. } else {
  97. if (pt == 'zfb') {
  98. this.pay_channel = 'alipay_qr'
  99. } else if (pt == 'wx') {
  100. this.pay_channel = 'wx_pub'
  101. }
  102. this.getCodePay('qrCode')
  103. }
  104. },
  105. getCodePay(code) {
  106. // 二维码页面, 唤起支付页面
  107. let url = validStudentUrl()
  108. if(code == 'qrCode') {
  109. url += `/#/payQRCode`
  110. } else {
  111. url += `/#/payResult`
  112. }
  113. url += `?payType=${this.pay_channel}&payment=${JSON.stringify(this.paymentObject)}&platform=teacher`
  114. this.$emit("onChangeStatus", false); // 初始化弹窗状态
  115. window.location.href = url
  116. },
  117. },
  118. watch: {
  119. closeStatus(val) {
  120. this.isShow = val
  121. },
  122. amount(val) {
  123. // 强制转换金额,显示两们小数
  124. this.payAmount = changeTwoDecimal(val)
  125. },
  126. payment(val) { // 监听数据
  127. this.paymentObject = val
  128. }
  129. }
  130. };
  131. </script>
  132. <style lang="less" scoped>
  133. @import url("../assets/commonLess/variable");
  134. /deep/.van-popup__close-icon {
  135. color: #cccccc;
  136. font-size: .22rem;
  137. }
  138. // /deep/.van-popup--bottom.van-popup--round {
  139. // border-radius: .06rem .06rem 0 0;
  140. // // background-color: rgba(0, 0, 0, 0.06);
  141. // }
  142. /deep/.van-hairline--bottom::after {
  143. border-bottom-color: #F0F0F0;
  144. }
  145. .title {
  146. background-color: #ffffff;
  147. font-size: .16rem;
  148. font-weight: 400;
  149. color: #1A1A1A;
  150. padding: .14rem 0 .12rem;
  151. text-align: center;
  152. }
  153. .payAmount {
  154. background-color: #ffffff;
  155. padding: .2rem 0;
  156. text-align: center;
  157. p {
  158. font-size: .14rem;
  159. color: #666666;
  160. padding-bottom: .1rem;
  161. }
  162. .amount {
  163. font-size: .28rem;
  164. color: #000000;
  165. span {
  166. font-size: .18rem;
  167. padding-left: .03rem;
  168. }
  169. }
  170. }
  171. /deep/.van-cell {
  172. padding: .12rem .16rem;
  173. }
  174. .payment-item {
  175. background-color: #ffffff;
  176. display: flex;
  177. padding: .12rem 0;
  178. margin: 0 .16rem;
  179. align-items: center;
  180. .logo-section {
  181. width: .22rem;
  182. height: .22rem;
  183. .logo {
  184. width: .22rem;
  185. height: .22rem;
  186. }
  187. }
  188. .title-section {
  189. font-size: .16rem;
  190. padding-left: .1rem;
  191. flex: 1;
  192. }
  193. .value-section {
  194. flex: 1;
  195. .van-radio {
  196. float: right;
  197. }
  198. }
  199. }
  200. .blank {
  201. height: .65rem;
  202. background-color: #F0F0F0;
  203. }
  204. /deep/.van-button--primary {
  205. background-color: @mColor;
  206. color: #ffffff;
  207. font-size: .16rem;
  208. height: .52rem;
  209. line-height: .50rem;
  210. border-radius: 0;
  211. border-color: @mColor;
  212. }
  213. </style>