MPayment.vue 6.3 KB

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