paymentMethod.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <!--
  3. 支付方式选择 微信or贵阳银行
  4. -->
  5. <view>
  6. <u-modal
  7. v-model="payWayPop"
  8. :title-style="{color: '#404040'}"
  9. title="缴费方式"
  10. :show-confirm-button="false"
  11. :show-cancel-button="false">
  12. <view class="slot-content">
  13. <!-- <view class="pay-way">
  14. <view class="pay-way-item" @click="gyBankPay">
  15. <image src="../../static/img/gy-bank-pay-icon.png" mode=""></image>
  16. <view>贵州银行</view>
  17. </view>
  18. <view class="pay-way-item" @click="wechatPay">
  19. <image src="../../static/img/wechat-pay-icon.png" mode=""></image>
  20. <view>微信支付</view>
  21. </view>
  22. </view> -->
  23. <view class="pay-way-new">
  24. <view class="pay-way-item pay-way-item-hy" @click="gyBankPay">
  25. <image src="../../static/img/guiyang-bank-icon.png" mode=""></image>
  26. <view class="title">贵州银行</view>
  27. <view class="subtitle">前三个月每天首次一分钱<br/>长期八折优惠</view>
  28. </view>
  29. <view class="pay-way-item pay-way-item-jh" @click="wechatPay">
  30. <image src="../../static/img/juhe-icon.png" mode=""></image>
  31. <view class="title">聚合支付</view>
  32. </view>
  33. </view>
  34. <button class="pay-way-close-btn" @click="closePaymentMethod">关闭</button>
  35. </view>
  36. </u-modal>
  37. <u-toast ref="uToast" />
  38. </view>
  39. </template>
  40. <script>
  41. import getUrlParams from "@/utils/getUrlParams.js";
  42. export default {
  43. props: {
  44. // 弹框显示
  45. payWayPop: {
  46. type: Boolean,
  47. default: false
  48. },
  49. // 订单数组
  50. curOrderList: {
  51. type: Array,
  52. default: null
  53. },
  54. // 设备编号
  55. deviceNo: {
  56. type: String,
  57. default: null
  58. }
  59. },
  60. data() {
  61. return {}
  62. },
  63. methods: {
  64. /**
  65. * 贵阳银行支付
  66. * @param {Array} orderList 需要支付的订单号组成的数组
  67. * @param {String} deviceNo 设备编号(只有车位锁部分有)
  68. * */
  69. gyBankPay() {
  70. const params = {
  71. orderList: this.curOrderList,
  72. deviceNo: this.deviceNo,
  73. jumpUrl: window.location.href
  74. };
  75. this.$u.api.payGzbank(params).then(res=>{
  76. if (res.data.needPay) {
  77. let payUrl = res.data.url;
  78. window.location.href = payUrl;
  79. } else {
  80. this.$refs.uToast.show({
  81. title: '无需支付',
  82. type: 'info',
  83. });
  84. setTimeout(() => {
  85. location.reload()
  86. }, 1000)
  87. }
  88. }).catch(err=>{
  89. this.$refs.uToast.show({
  90. title: err.msg,
  91. type: 'error',
  92. });
  93. });
  94. },
  95. /**
  96. * 微信支付
  97. * 判断vuex中是否存在openId
  98. * 存在直接调起微信支付
  99. * 不存在则通过微信登录去获取用户的code
  100. * 完成后通过code去获取用户的openId等信息
  101. * 最后再调起微信支付
  102. * */
  103. wechatPay() {
  104. // const openId = this.$store.state.vuex_wxinfo.openId
  105. // if (openId) {
  106. // this.getWXPay(this.curOrderList, this.deviceNo)
  107. // } else {
  108. // this.getCode()
  109. // }
  110. this.getWXPayByJava(this.curOrderList, this.deviceNo)
  111. },
  112. /**
  113. * 调起微信支付接口
  114. * @param {Array} list 需要支付的订单组合数组
  115. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  116. * */
  117. async getWXPay(orderList, deviceNo){
  118. let params = {
  119. orderList: orderList,
  120. openid: this.$store.state.vuex_wxinfo.openId,
  121. deviceNo: deviceNo ? deviceNo : null
  122. };
  123. await this.$wxApi.config();
  124. this.$pay.wechatPay(params).then(res =>{
  125. switch (Number(res.code)) {
  126. case 0: // 成功
  127. //#ifdef H5
  128. window.location.reload();
  129. //#endif
  130. break;
  131. case 1: // 取消
  132. this.$refs.uToast.show({
  133. title: '已取消支付',
  134. type: 'info',
  135. });
  136. break;
  137. case 2: // 支付失败
  138. this.$refs.uToast.show({
  139. title: '支付失败,请检查!',
  140. type: 'error',
  141. });
  142. break;
  143. }
  144. });
  145. },
  146. /**
  147. * 直接通过后台获取贵阳银行微信支付地址
  148. * @param {Array} list 需要支付的订单组合数组
  149. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  150. * */
  151. getWXPayByJava(orderList, deviceNo) {
  152. let params = {
  153. orderList: orderList,
  154. openid: '',
  155. jumpUrl: window.location.href,
  156. deviceNo: deviceNo ? deviceNo : null
  157. };
  158. this.$u.api.ordinaryWxPay(params)
  159. .then(res => {
  160. if (res.code === 200) {
  161. location.href = res.data.qrCodeUrl
  162. } else {
  163. this.$refs.uToast.show({
  164. title: res.msg,
  165. type: 'error',
  166. });
  167. }
  168. })
  169. .catch(err => {
  170. this.$refs.uToast.show({
  171. title: '无法调起微信支付!',
  172. type: 'error',
  173. });
  174. })
  175. },
  176. /**
  177. * 获取code
  178. * 1 微信登录获取code
  179. * 2 url中截取
  180. * */
  181. getCode () {
  182. // 获取页面完整url
  183. const local = window.location.href
  184. // 获取url后面的参数
  185. const locationLocaturl = window.location.search;
  186. // 截取url中的code
  187. this.code = getUrlParams(locationLocaturl, "code");
  188. // 如果没有code,则去请求
  189. if (this.code == null || this.code === '') {
  190. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wxAppid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`
  191. } else {
  192. // 把code传给后台获取用户信息
  193. this.handleGetWXInfo(this.code)
  194. }
  195. },
  196. /**
  197. * 通过code获取openId等用户信息
  198. * 拿到用户信息后再调起微信支付
  199. * */
  200. handleGetWXInfo (code) {
  201. let _this = this
  202. this.$u.api.getWXInfo(code).then((res) => {
  203. if (res.code === 200 ) {
  204. this.$u.vuex('vuex_wxinfo', res.data);
  205. this.getWXPay(this.currentItem)
  206. }
  207. }).catch((err) => {
  208. this.$refs.uToast.show({
  209. title: err.msg,
  210. type: 'error',
  211. });
  212. })
  213. },
  214. /**
  215. * 关闭弹框
  216. * */
  217. closePaymentMethod() {
  218. this.$emit('closePaymentMethod')
  219. }
  220. }
  221. }
  222. </script>
  223. <style lang="scss" scoped>
  224. @import './paymentMethod.scss'
  225. </style>