paymentMethod.vue 7.7 KB

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