MPayment.vue 6.2 KB

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