paymentMethod.vue 7.4 KB

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