payLists.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view>
  3. <u-navbar title-color="#fff" :custom-back="customBack" :bpay-bottom="false" back-icon-color="#CCE8FF" :background="{background: '#008CFF' }" title="停车缴费"></u-navbar>
  4. <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" >
  5. <scroll-view scroll-y style="height: 100%; width: 100%;" >
  6. <view class="page-box">
  7. <view class="pay" v-for="(payItem, index) in payList" :key="payItem.id">
  8. <view class="pay-top u-flex">
  9. <view class="pay-top-left u-flex-1">
  10. <view class="car">{{payItem.vehicleNo}}</view>
  11. <view class="addr">{{payItem.roadName}}</view>
  12. </view>
  13. <view class="pay-top-right">{{payItem.orderStatus | filterOrderStatus}}</view>
  14. </view>
  15. <view class="pay-center">
  16. <view class="pay-center-item">停车泊位:{{payItem.spaceName}}</view>
  17. <view class="pay-center-item">入场时间:{{payItem.inTime}}</view>
  18. <view class="pay-center-item">出场时间:{{payItem.outTime}}</view>
  19. <view class="pay-center-item">停留时间:{{payItem.duration}}</view>
  20. <view class="pay-center-item">应付金额:<span class="pay-amount">{{payItem.payAmount}}</span></view>
  21. </view>
  22. <view class="pay-bottom">
  23. <!-- <u-cell-item title="去支付" @click="paythis(payItem.orderId)" style="color: #008CFF;"></u-cell-item> -->
  24. <u-cell-item title="去支付" @click="choosePayWay(payItem.orderId)" style="color: #008CFF;"></u-cell-item>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. </mescroll-body>
  30. <view class="button-wrap" v-if="payList.length&&payList.length>=1">
  31. <!-- <button class="button" type="primary" @click="all()">全部缴费</button> -->
  32. <button class="button" type="primary" @click="confirmPrice()">全部缴费</button>
  33. </view>
  34. <!-- 缴费提示-->
  35. <u-modal
  36. v-model="payTipsPop"
  37. :title-style="{color: '#404040'}"
  38. title="缴费提示"
  39. :show-confirm-button="true"
  40. confirm-text="立即缴费"
  41. :confirm-style="{backgroundColor: '#3397FA', color: '#fff'}"
  42. :show-cancel-button="true"
  43. cancel-text="取消"
  44. :cancel-style="{backgroundColor: '#EBF1FF', color: '#3397FA'}"
  45. @confirm="payTipsPopConfirm">
  46. <view class="slot-content">
  47. <view class="pay-tips">
  48. <text>{{payTipsItem.num}}</text>场停车欠费,共
  49. <text>{{payTipsItem.price}}</text>元
  50. </view>
  51. </view>
  52. </u-modal>
  53. <!-- 缴费方式-->
  54. <u-modal
  55. v-model="payWayPop"
  56. :title-style="{color: '#404040'}"
  57. title="缴费方式"
  58. :show-confirm-button="false"
  59. :show-cancel-button="false">
  60. <view class="slot-content">
  61. <view class="pay-way">
  62. <view class="pay-way-item" @click="gyBankPay">
  63. <image src="../../static/img/gy-bank-pay-icon.png" mode=""></image>
  64. <view>贵州银行</view>
  65. </view>
  66. <view class="pay-way-item" @click="wechatPay">
  67. <image src="../../static/img/wechat-pay-icon.png" mode=""></image>
  68. <view>微信支付</view>
  69. </view>
  70. </view>
  71. <button class="pay-way-close-btn" @click="payWayPop = false">关闭</button>
  72. </view>
  73. </u-modal>
  74. <u-toast ref="uToast" />
  75. </view>
  76. </template>
  77. <script>
  78. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  79. import getUrlParams from "../../utils/getUrlParams.js";
  80. export default {
  81. mixins: [MescrollMixin], // 使用mixin
  82. data() {
  83. return {
  84. currentPayUrl: "",
  85. payList: [],
  86. list: [
  87. {index:0,name: '未缴费',orderStatu:3,pageNum:1,total:null}
  88. ],
  89. orderList: [],
  90. PayUrl: "",
  91. payTipsPop: false,
  92. payWayPop: false,
  93. // 选中去支付的单条条目
  94. currentItem: [],
  95. // 缴费提示类目
  96. payTipsItem: {
  97. num: '',
  98. price: ''
  99. },
  100. code: null,
  101. };
  102. },
  103. computed: {
  104. // 价格小数
  105. priceDecimal() {
  106. return val => {
  107. if (val !== parseInt(val)) return val.slice(-2);
  108. else return '00';
  109. };
  110. },
  111. // 价格整数
  112. priceInt() {
  113. return val => {
  114. if (val !== parseInt(val)) return val.split('.')[0];
  115. else return val;
  116. };
  117. }
  118. },
  119. onLoad(){
  120. // let locationLocaturl = window.location.hash;
  121. // this.orderId = getUrlParams(locationLocaturl,"orderId"); // 截取orderId
  122. // console.log('this.orderId',this.orderId);
  123. // if (this.orderId) {
  124. // this.handleGetOrderinfo(this.orderId);
  125. // }
  126. // this.code = getUrlParams(locationLocaturl,"code");
  127. // if (this.code) {
  128. // this.handleGetWXInfo(this.code)
  129. // }
  130. },
  131. methods: {
  132. customBack(){
  133. this.$u.route({
  134. type:'switchTab',
  135. url: 'pages/index/index'
  136. });
  137. },
  138. /*下拉刷新的回调*/
  139. downCallback(){
  140. // 第2种: 下拉刷新和上拉加载调同样的接口, 则不用第1种, 直接mescroll.resetUpScroll()即可
  141. this.mescroll.resetUpScroll(); // 重置列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  142. },
  143. /*上拉加载的回调*/
  144. upCallback(page) {
  145. let pageNum = page.num; // 页码, 默认从1开始
  146. let pageSize = page.size; // 页长, 默认每页10条
  147. // this.getMessageList()
  148. this.$u.api.getOrderList({pageSize:pageSize ,pageNum: pageNum, paying: true})
  149. .then(res=>{
  150. // 接口返回的当前页数据列表 (数组)
  151. let curPageData = res.data.rows;
  152. // 接口返回的当前页数据长度 (如列表有26个数据,当前页返回8个,则curPageLen=8)
  153. let curPageLen = curPageData.length;
  154. // 接口返回的总页数 (如列表有26个数据,每页10条,共3页; 则totalPage=3)
  155. let totalPage = res.data.pages;
  156. // 接口返回的总数据量(如列表有26个数据,每页10条,共3页; 则totalSize=26)
  157. let totalSize = res.data.total;
  158. // 接口返回的是否有下一页 (true/false)
  159. // let hasNext = data.pages;
  160. //设置列表数据
  161. if(page.num == 1) this.payList = []; //如果是第一页需手动置空列表
  162. this.payList = this.payList.concat(curPageData); //追加新数据
  163. // 请求成功,隐藏加载状态
  164. //方法一(推荐): 后台接口有返回列表的总页数 totalPage
  165. this.mescroll.endByPage(curPageLen, totalPage);
  166. setTimeout(()=>{
  167. this.mescroll.endSuccess(curPageLen)
  168. },20)
  169. }).catch(err=>{
  170. this.$refs.uToast.show({
  171. title: err.msg,
  172. type: 'error',
  173. });
  174. });
  175. },
  176. paythis(orderId){
  177. let orderList=[];
  178. orderList.push(orderId);
  179. this.$u.api.payGzbank({orderList: orderList}).then(res=>{
  180. let payUrl = res.data.url;
  181. this.currentPayUrl=encodeURIComponent(res.data.url);
  182. // return;
  183. this.$u.route({
  184. url: 'pages/payLists/pay',
  185. params: {
  186. currentPayUrl:this.currentPayUrl
  187. }
  188. });
  189. }).catch(err=>{
  190. this.$refs.uToast.show({
  191. title: err.msg,
  192. type: 'error',
  193. });
  194. });
  195. },
  196. all(){
  197. this.payList.forEach((item, index, arr)=>{
  198. console.log(item)
  199. if(item.orderId){
  200. this.orderList.push(item.orderId)
  201. }
  202. });
  203. this.$u.api.payGzbank({orderList: this.orderList}).then(res=>{
  204. let payUrl = res.data.url;
  205. this.currentPayUrl=encodeURIComponent(res.data.url);
  206. // console.log('this.currentPayUrl',this.currentPayUrl);
  207. // return;
  208. this.$u.route({
  209. url: 'pages/payLists/pay',
  210. params: {
  211. currentPayUrl:this.currentPayUrl
  212. }
  213. });
  214. }).catch(err=>{
  215. this.$refs.uToast.show({
  216. title: err.msg,
  217. type: 'error',
  218. });
  219. });
  220. },
  221. // 去支付,选择支付方式
  222. choosePayWay(item) {
  223. console.log(item)
  224. this.currentItem = []
  225. this.currentItem.push(item)
  226. this.payWayPop = true
  227. },
  228. // 贵阳银行支付
  229. gyBankPay(list) {
  230. this.$u.api.payGzbank({orderList: this.currentItem}).then(res=>{
  231. let payUrl = res.data.url;
  232. this.currentPayUrl=encodeURIComponent(res.data.url);
  233. // console.log('this.currentPayUrl',this.currentPayUrl);
  234. // return;
  235. this.$u.route({
  236. url: 'pages/payLists/pay',
  237. params: {
  238. currentPayUrl:this.currentPayUrl
  239. }
  240. });
  241. }).catch(err=>{
  242. this.$refs.uToast.show({
  243. title: err.msg,
  244. type: 'error',
  245. });
  246. });
  247. },
  248. // 微信支付
  249. wechatPay() {
  250. const openId = this.$store.state.vuex_wxinfo.openId
  251. if (openId) {
  252. this.getWXPay(this.currentItem)
  253. } else {
  254. this.getCode()
  255. }
  256. },
  257. // 全部缴费确认
  258. confirmPrice() {
  259. let orderNum = 0, price = 0
  260. this.currentItem = []
  261. this.payList.forEach(item => {
  262. console.log(item)
  263. if (item.orderStatus !== 2 && item.payStatus !== 1 ) {
  264. price += item.payAmount
  265. orderNum ++
  266. this.currentItem.push(item.orderId)
  267. }
  268. })
  269. this.payTipsItem.num = orderNum
  270. this.payTipsItem.price = price
  271. if (orderNum !== 0 && price !== 0) {
  272. this.payTipsPop = true
  273. } else {
  274. this.$refs.uToast.show({
  275. title: '没有需要支付的订单',
  276. type: 'warning'
  277. })
  278. }
  279. },
  280. // 缴费提示弹框确认
  281. payTipsPopConfirm() {
  282. this.payWayPop = true
  283. },
  284. getCode () {
  285. var local = window.location.href // 获取页面url
  286. let locationLocaturl = window.location.search;
  287. this.code = getUrlParams(locationLocaturl,"code"); // 截取code
  288. if (this.code == null || this.code === '') { // 如果没有code,则去请求
  289. 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`
  290. } else {
  291. this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
  292. }
  293. },
  294. handleGetWXInfo (code) { // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
  295. let _this = this
  296. this.$u.api.getWXInfo(code).then((res) => {
  297. if (res.code === 200 ) {
  298. this.$u.vuex('vuex_wxinfo', res.data);
  299. // 继续支付
  300. this.getWXPay(this.currentItem)
  301. }
  302. }).catch((err) => {
  303. this.$refs.uToast.show({
  304. title: err.msg,
  305. type: 'error',
  306. });
  307. })
  308. },
  309. async getWXPay(list){
  310. let params = {
  311. orderList: list,
  312. openid:this.$store.state.vuex_wxinfo.openId
  313. };
  314. await this.$wxApi.config();
  315. this.$pay.wechatPay(params).then(res =>{
  316. if(res.code == 0){
  317. // 成功
  318. this.$u.route({
  319. url:'pages/payLists/payLists',
  320. });
  321. }else if(res.code == 1){
  322. // 取消
  323. // uni.redirectTo({
  324. // url: '/pages/userCenter/myOrder/myOrder'
  325. // })
  326. }else if(res.code == 2){
  327. this.$refs.uToast.show({
  328. title: '支付失败,请检查!',
  329. type: 'error',
  330. // url: '/pages/user/index'
  331. });
  332. }
  333. });
  334. },
  335. handleGetOrderinfo(orderId){
  336. this.$u.api.getOrderinfo({id:orderId})
  337. .then(res=>{
  338. // this.$refs.uToast.show({
  339. // title: res.msg,
  340. // type: 'success',
  341. // });
  342. this.orderInfo = res.data;
  343. console.log('handleGetOrderinfo',JSON.parse(JSON.stringify(res)));
  344. }).catch(err=>{
  345. this.$refs.uToast.show({
  346. title: err.msg,
  347. type: 'error',
  348. });
  349. console.log('handleGetOrderinfo ',err)
  350. });
  351. },
  352. }
  353. };
  354. </script>
  355. <style>
  356. /* #ifndef H5 */
  357. page {
  358. height: 100%;
  359. background-color: #F6F6FF;
  360. }
  361. /* #endif */
  362. </style>
  363. <style lang="scss" scoped>
  364. @import "./payLists.scss";
  365. </style>