parkingLock.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <template>
  2. <!-- 车位锁 -->
  3. <view class="parking-lock">
  4. <!-- 车位锁支付 -->
  5. <view class="parking-lock-pay" v-if="parkingLockStatus === 1">
  6. <view class="parking-lock-title">支付停车费</view>
  7. <view class="parking-lock-tips">请您确认停车费用,确认后请支付费用,结束停车。谢谢您的使用!</view>
  8. <view class="parking-lock-info">
  9. <view class="parking-lock-info-item">
  10. <view>停车场名称</view>
  11. <view>{{orderInfo.roadName}}</view>
  12. </view>
  13. <view class="parking-lock-info-item">
  14. <view>停车泊位</view>
  15. <view>{{orderInfo.spaceName}}</view>
  16. </view>
  17. <view class="parking-lock-info-item">
  18. <view>入场时间</view>
  19. <view>{{orderInfo.inTime}}</view>
  20. </view>
  21. <view class="parking-lock-info-item">
  22. <view>出场时间</view>
  23. <view>{{orderInfo.outTime}}</view>
  24. </view>
  25. <view class="parking-lock-info-item">
  26. <view>停车时长</view>
  27. <view>{{orderInfo.duration}}</view>
  28. </view>
  29. <view class="parking-lock-info-item">
  30. <view>合计金额</view>
  31. <view>{{orderInfo.totalAmount}} 元</view>
  32. </view>
  33. <view class="parking-lock-info-item">
  34. <view>优惠金额</view>
  35. <view>{{orderInfo.preferentialAmount}} 元</view>
  36. </view>
  37. <view class="parking-lock-info-item">
  38. <view>应缴金额</view>
  39. <view class="really-money">{{orderInfo.payAmount}} 元</view>
  40. </view>
  41. </view>
  42. <view class="parking-lock-pay-btn">
  43. <button type="default" @click="payMoney">立即支付</button>
  44. </view>
  45. </view>
  46. <!-- 车位锁开始状态 -->
  47. <view class="parking-lock-begin" v-else-if="parkingLockStatus === 2">
  48. <view class="parking-lock-begin-box">
  49. <view class="parking-lock-begin-bg">
  50. <image src="../../static/img/parking-lock-bg.png" mode=""></image>
  51. </view>
  52. </view>
  53. <view class="parking-lock-begin-info">车位锁正在动作,还未到位</view>
  54. </view>
  55. <!-- 车位锁正在状态 -->
  56. <view class="parking-lock-loading" v-else-if="parkingLockStatus === 3">
  57. <view class="parking-lock-loading-box">
  58. <view class="parking-lock-loading-bg">
  59. <image src="../../static/img/parking-lock-bg.png" mode=""></image>
  60. </view>
  61. </view>
  62. <view class="parking-lock-loading-info">开锁中,请等待!</view>
  63. </view>
  64. <!-- 开锁完成 -->
  65. <view class="parking-lock-success" v-else-if="parkingLockStatus === 4">
  66. <view class="parking-lock-success-box">
  67. <image src="../../static/img/parking-lock-achieve.png" mode=""></image>
  68. </view>
  69. <view class="parking-lock-success-info">开锁已完成</view>
  70. <view class="parking-lock-success-button">
  71. <button @click="cancel">返回</button>
  72. </view>
  73. </view>
  74. <view class="parking-lock-pay" v-else-if="parkingLockStatus === 5">
  75. <view class="parking-lock-tips">{{tipsMsg}}</view>
  76. </view>
  77. <!-- 缴费方式-->
  78. <u-modal
  79. v-model="payWayPop"
  80. :title-style="{color: '#404040'}"
  81. title="缴费方式"
  82. :show-confirm-button="false"
  83. :show-cancel-button="false">
  84. <view class="slot-content">
  85. <view class="pay-way">
  86. <view class="pay-way-item" @click="gyBankPay">
  87. <image src="../../static/img/gy-bank-pay-icon.png" mode=""></image>
  88. <view>贵州银行</view>
  89. </view>
  90. <view class="pay-way-item" @click="wechatPay">
  91. <image src="../../static/img/wechat-pay-icon.png" mode=""></image>
  92. <view>微信支付</view>
  93. </view>
  94. </view>
  95. <button class="pay-way-close-btn" @click="payWayPop = false">关闭</button>
  96. </view>
  97. </u-modal>
  98. <u-toast ref="uToast" />
  99. </view>
  100. </template>
  101. <script>
  102. import { config } from './../../common/config'
  103. import getUrlParams from "../../utils/getUrlParams.js";
  104. export default {
  105. data() {
  106. return {
  107. // 车位锁状态 1:支付 2:开始开锁 3:开锁中 4:开锁完成
  108. parkingLockStatus: 1,
  109. // 支付方式选择弹框
  110. payWayPop: false,
  111. // 订单编号
  112. orderList: [],
  113. // 提示信息
  114. tipsMsg: null,
  115. // 设备编号
  116. deviceNo: null,
  117. // 轮询
  118. timer: null,
  119. // 订单信息
  120. orderInfo: {},
  121. // 订单id
  122. orderId: null
  123. }
  124. },
  125. onLoad(page) {
  126. console.log(page)
  127. if (page.orderId) {
  128. this.getOrderDetails(page.orderId)
  129. this.orderList = []
  130. this.orderId = page.orderId
  131. this.orderList.push(page.orderId)
  132. this.deviceNo = page.deviceNo
  133. } else {
  134. this.tipsMsg = page.msg
  135. this.parkingLockStatus = 5
  136. }
  137. },
  138. methods: {
  139. payMoney() {
  140. this.payWayPop = true
  141. },
  142. // 查询订单状态
  143. // getOrderStatus(orderId) {
  144. // this.$u.api.getOrderInfo({orderId: orderId})
  145. // .then(res => {
  146. // if (res.code === 200) {
  147. // if (res.data.payStatus === 0 || res.data.payStatus === 3) {
  148. // this.getOrderDetails(orderId)
  149. // } else {
  150. // this.parkingLockStatus = 2
  151. // setTimeout(() => {
  152. // this.parkingLockStatus = 3
  153. // }, 300)
  154. // this.checkEqupment()
  155. // }
  156. // }
  157. // })
  158. // },
  159. // 查询订单信息
  160. getOrderDetails(id) {
  161. this.$u.api.getOrderDetail({id: id})
  162. .then(res => {
  163. console.log(res)
  164. if (res.code === 200) {
  165. this.orderInfo = res.data
  166. if (res.data.payStatus === 1) {
  167. this.checkEqupment()
  168. }
  169. }
  170. })
  171. },
  172. // 检测设备
  173. checkEqupment() {
  174. this.timer = setInterval(() => {
  175. this.getEqumentStatus(this.deviceNo)
  176. }, 1000)
  177. },
  178. // 查询设备状态
  179. getEqumentStatus(orderNo) {
  180. console.log(orderNo)
  181. this.$u.api.getEquomentInfo({orderNo: orderNo})
  182. .then(res => {
  183. if (res.code === 200) {
  184. console.log(res.data)
  185. if (res.data.deviceStatus === 0) {
  186. this.parkingLockStatus = 4
  187. clearInterval(this.timer)
  188. } else if (res.data.deviceStatus === 1 || res.data.deviceStatus === 5) {
  189. this.parkingLockStatus = 2
  190. } else if (res.data.deviceStatus === 6) {
  191. this.parkingLockStatus = 3
  192. }
  193. }
  194. })
  195. },
  196. // 返回首页
  197. cancel() {
  198. window.location.href = config.jumpHomeUrl
  199. },
  200. // 贵阳银行支付
  201. gyBankPay() {
  202. this.$u.api.payGzbank({
  203. orderList: this.orderList,
  204. deviceNo: this.deviceNo,
  205. jumpUrl: window.location.href
  206. }).then(res=>{
  207. let payUrl = res.data.url;
  208. this.currentPayUrl=encodeURIComponent(res.data.url);
  209. this.$u.route({
  210. url: 'pages/payLists/pay',
  211. params: {
  212. currentPayUrl: this.currentPayUrl
  213. }
  214. });
  215. }).catch(err=>{
  216. this.$refs.uToast.show({
  217. title: err.msg,
  218. type: 'error',
  219. });
  220. });
  221. },
  222. // 微信支付
  223. wechatPay() {
  224. const openId = this.$store.state.vuex_wxinfo.openId
  225. if (openId) {
  226. this.getWXPay(this.orderList)
  227. } else {
  228. this.getCode()
  229. }
  230. },
  231. async getWXPay(list){
  232. let params = {
  233. orderList: list,
  234. deviceNo: this.deviceNo,
  235. openid: this.$store.state.vuex_wxinfo.openId
  236. };
  237. await this.$wxApi.config();
  238. this.$pay.wechatPay(params).then(res =>{
  239. if(res.code == 0){
  240. // 成功
  241. }else if(res.code == 1){
  242. // 取消
  243. // uni.redirectTo({
  244. // url: '/pages/userCenter/myOrder/myOrder'
  245. // })
  246. }else if(res.code == 2){
  247. this.$refs.uToast.show({
  248. title: '支付失败,请检查!',
  249. type: 'error',
  250. // url: '/pages/user/index'
  251. });
  252. }
  253. setTimeout(() => {
  254. window.location.reload()
  255. }, 1000)
  256. });
  257. },
  258. getCode () {
  259. var local = window.location.href // 获取页面url
  260. let locationLocaturl = window.location.search;
  261. this.code = getUrlParams(locationLocaturl, "code"); // 截取code
  262. if (this.code == null || this.code === '') { // 如果没有code,则去请求
  263. 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`
  264. } else {
  265. this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
  266. }
  267. },
  268. handleGetWXInfo (code) { // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
  269. this.$u.api.getWXInfo(code).then((res) => {
  270. if (res.code === 200 ) {
  271. this.$u.vuex('vuex_wxinfo', res.data);
  272. // 继续支付
  273. this.getWXPay(this.orderList)
  274. }
  275. }).catch((err) => {
  276. this.$refs.uToast.show({
  277. title: err.msg,
  278. type: 'error',
  279. });
  280. })
  281. }
  282. }
  283. }
  284. </script>
  285. <style lang="scss" scoped>
  286. @import './parkingLock.scss';
  287. </style>