paymentMethod.vue 7.3 KB

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