paymentMethod.vue 7.4 KB

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