MPayment.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. this.paymentObject = val;
  160. },
  161. },
  162. };
  163. </script>
  164. <style lang="less" scoped>
  165. @import url("../assets/commonLess/variable");
  166. /deep/.van-popup__close-icon {
  167. color: #cccccc;
  168. font-size: 0.22rem;
  169. }
  170. // /deep/.van-popup--bottom.van-popup--round {
  171. // border-radius: .06rem .06rem 0 0;
  172. // // background-color: rgba(0, 0, 0, 0.06);
  173. // }
  174. /deep/.van-hairline--bottom::after {
  175. border-bottom-color: #f0f0f0;
  176. }
  177. .title {
  178. background-color: #ffffff;
  179. font-size: 0.16rem;
  180. font-weight: 400;
  181. color: #1a1a1a;
  182. padding: 0.14rem 0 0.12rem;
  183. text-align: center;
  184. }
  185. .payAmount {
  186. background-color: #ffffff;
  187. padding: 0.2rem 0;
  188. text-align: center;
  189. p {
  190. font-size: 0.14rem;
  191. color: #666666;
  192. padding-bottom: 0.1rem;
  193. }
  194. .amount {
  195. font-size: 0.28rem;
  196. color: #000000;
  197. span {
  198. font-size: 0.18rem;
  199. padding-left: 0.03rem;
  200. }
  201. }
  202. }
  203. /deep/.van-cell {
  204. padding: 0.12rem 0.16rem;
  205. }
  206. .payment-item {
  207. background-color: #ffffff;
  208. display: flex;
  209. padding: 0.12rem 0;
  210. margin: 0 0.16rem;
  211. align-items: center;
  212. .logo-section {
  213. width: 0.22rem;
  214. height: 0.22rem;
  215. .logo {
  216. width: 0.22rem;
  217. height: 0.22rem;
  218. }
  219. }
  220. .title-section {
  221. font-size: 0.16rem;
  222. padding-left: 0.1rem;
  223. flex: 1;
  224. }
  225. .value-section {
  226. flex: 1;
  227. .van-radio {
  228. float: right;
  229. }
  230. }
  231. }
  232. .blank {
  233. height: 0.65rem;
  234. background-color: #f0f0f0;
  235. }
  236. /deep/.van-button--primary {
  237. background-color: @mColor;
  238. color: #ffffff;
  239. font-size: 0.16rem;
  240. height: 0.52rem;
  241. line-height: 0.5rem;
  242. border-radius: 0;
  243. border-color: @mColor;
  244. }
  245. </style>