paymentMethod.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 class="subtitle">支付微信及支付宝付款</view>
  33. </view>
  34. </view>
  35. <button class="pay-way-close-btn" @click="closePaymentMethod">关闭</button>
  36. </view>
  37. </u-modal>
  38. <u-toast ref="uToast" />
  39. </view>
  40. </template>
  41. <script>
  42. import getUrlParams from "@/utils/getUrlParams.js";
  43. // import {
  44. // getEnvIsWx
  45. // } from '@/utils/judgEnvironment.js'
  46. export default {
  47. props: {
  48. // 弹框显示
  49. payWayPop: {
  50. type: Boolean,
  51. default: false
  52. },
  53. // 订单数组
  54. curOrderList: {
  55. type: Array,
  56. default: null
  57. },
  58. // 设备编号
  59. deviceNo: {
  60. type: String,
  61. default: null
  62. },
  63. // 跳转页面
  64. jumpUrl: {
  65. type: String,
  66. default: null
  67. }
  68. },
  69. data() {
  70. return {}
  71. },
  72. methods: {
  73. /**
  74. * 贵阳银行支付
  75. * @param {Array} orderList 需要支付的订单号组成的数组
  76. * @param {String} deviceNo 设备编号(只有车位锁部分有)
  77. * */
  78. gyBankPay() {
  79. uni.showLoading({
  80. title: '加载中'
  81. });
  82. const params = {
  83. orderList: this.curOrderList,
  84. deviceNo: this.deviceNo,
  85. jumpUrl: this.jumpUrl
  86. };
  87. this.$u.api.payGzbank(params).then(res=>{
  88. if (res.data.needPay) {
  89. let payUrl = res.data.url;
  90. location.href = payUrl;
  91. } else {
  92. this.$refs.uToast.show({
  93. title: '无需支付',
  94. type: 'info',
  95. });
  96. setTimeout(() => {
  97. uni.hideLoading();
  98. location.reload()
  99. }, 1000)
  100. }
  101. }).catch(err=>{
  102. this.$refs.uToast.show({
  103. title: err.msg,
  104. type: 'error',
  105. });
  106. });
  107. },
  108. /**
  109. * 微信支付
  110. * 判断vuex中是否存在openId
  111. * 存在直接调起微信支付
  112. * 不存在则通过微信登录去获取用户的code
  113. * 完成后通过code去获取用户的openId等信息
  114. * 最后再调起微信支付
  115. * */
  116. wechatPay() {
  117. uni.showLoading({
  118. title: '加载中'
  119. });
  120. // const openId = this.$store.state.vuex_wxinfo.openId
  121. // if (openId) {
  122. // this.getWXPay(this.curOrderList, this.deviceNo)
  123. // } else {
  124. // this.getCode()
  125. // }
  126. this.getWXPayByJava(this.curOrderList, this.deviceNo)
  127. },
  128. /**
  129. * 调起微信支付接口
  130. * @param {Array} list 需要支付的订单组合数组
  131. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  132. * */
  133. async getWXPay(orderList, deviceNo){
  134. let params = {
  135. orderList: orderList,
  136. openid: this.$store.state.vuex_wxinfo.openId,
  137. deviceNo: deviceNo ? deviceNo : null
  138. };
  139. await this.$wxApi.config();
  140. this.$pay.wechatPay(params).then(res =>{
  141. switch (Number(res.code)) {
  142. case 0: // 成功
  143. //#ifdef H5
  144. window.location.reload();
  145. //#endif
  146. break;
  147. case 1: // 取消
  148. this.$refs.uToast.show({
  149. title: '已取消支付',
  150. type: 'info',
  151. });
  152. break;
  153. case 2: // 支付失败
  154. this.$refs.uToast.show({
  155. title: '支付失败,请检查!',
  156. type: 'error',
  157. });
  158. break;
  159. }
  160. });
  161. },
  162. /**
  163. * 直接通过后台获取贵阳银行微信支付地址
  164. * @param {Array} list 需要支付的订单组合数组
  165. * @param {Number} deviceNo 设备编号(在停车锁部分需要)
  166. * */
  167. getWXPayByJava(orderList, deviceNo) {
  168. let params = {
  169. orderList: orderList,
  170. openid: '',
  171. jumpUrl: this.jumpUrl,
  172. deviceNo: deviceNo ? deviceNo : null
  173. };
  174. this.$u.api.ordinaryWxPay(params)
  175. .then(res => {
  176. if (res.code === 200) {
  177. // if (getEnvIsWx()) {
  178. // location.href = res.data.qrCodeUrl + '&jump_url=' + encodeURIComponent(this.jumpUrl)
  179. // } else {
  180. // location.href = res.data.qrCodeUrl
  181. // }
  182. localStorage.setItem('jumpUrl', this.jumpUrl)
  183. location.href = res.data.qrCodeUrl
  184. // this.cookie.set("jumpUrl",this.jumpUrl);
  185. } else {
  186. uni.hideLoading();
  187. }
  188. })
  189. .catch(err => {
  190. this.$refs.uToast.show({
  191. title: '无法调起微信支付!',
  192. type: 'error',
  193. });
  194. })
  195. },
  196. /**
  197. * 获取code
  198. * 1 微信登录获取code
  199. * 2 url中截取
  200. * */
  201. getCode () {
  202. // 获取页面完整url
  203. const local = window.location.href
  204. // 获取url后面的参数
  205. const locationLocaturl = window.location.search;
  206. // 截取url中的code
  207. this.code = getUrlParams(locationLocaturl, "code");
  208. // 如果没有code,则去请求
  209. if (this.code == null || this.code === '') {
  210. 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`
  211. } else {
  212. // 把code传给后台获取用户信息
  213. this.handleGetWXInfo(this.code)
  214. }
  215. },
  216. /**
  217. * 通过code获取openId等用户信息
  218. * 拿到用户信息后再调起微信支付
  219. * */
  220. handleGetWXInfo (code) {
  221. let _this = this
  222. this.$u.api.getWXInfo(code).then((res) => {
  223. if (res.code === 200 ) {
  224. this.$u.vuex('vuex_wxinfo', res.data);
  225. this.getWXPay(this.currentItem)
  226. }
  227. }).catch((err) => {
  228. this.$refs.uToast.show({
  229. title: err.msg,
  230. type: 'error',
  231. });
  232. })
  233. },
  234. /**
  235. * 关闭弹框
  236. * */
  237. closePaymentMethod() {
  238. this.$emit('closePaymentMethod')
  239. }
  240. }
  241. }
  242. </script>
  243. <style lang="scss" scoped>
  244. @import './paymentMethod.scss'
  245. </style>