index.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <view>
  3. <u-navbar :is-back='false' :border-bottom="false" :background="{ background: '#008CFF' }" title=""></u-navbar>
  4. <view class="header-bar">
  5. <view class="city" @click="handleCitySelect">
  6. {{city}}<u-icon name="arrow-down" color="#fff" size="32"></u-icon>
  7. </view>
  8. <u-search placeholder="搜索发票、停车场" :show-action="false" @search="handleSearch" v-model="keyword"></u-search>
  9. <u-icon class="scan" name="scan" color="#fff" size="48"></u-icon>
  10. </view>
  11. <u-swiper :list="bannerList" border-radius="0"></u-swiper>
  12. <u-city-select v-model="cityOpen" @city-change="cityChange" :areaCode='["52", "5201"]' ></u-city-select>
  13. <u-card :show-head="false" :show-foot="false" border-radius="16" margin="20rpx 40rpx" padding="30">
  14. <view class="content-nav" slot="body">
  15. <view class="content-nav-item">
  16. <view class="content-nav-item-icon-wrap">
  17. <u-image src="../../static/img/index-content-nav-01.png" width="77rpx" height="75rpx" mode="heightFix"></u-image>
  18. </view>
  19. <view class="content-nav-item-icon-text">停车缴费</view>
  20. </view>
  21. <view class="content-nav-item">
  22. <view class="content-nav-item-icon-wrap">
  23. <u-image src="../../static/img/index-content-nav-02.png" width="77rpx" height="75rpx" mode="heightFix"></u-image>
  24. </view>
  25. <view class="content-nav-item-icon-text">优惠活动</view>
  26. </view>
  27. <view class="content-nav-item">
  28. <view class="content-nav-item-icon-wrap">
  29. <u-image src="../../static/img/index-content-nav-03.png" width="77rpx" height="75rpx" mode="heightFix"></u-image>
  30. </view>
  31. <view class="content-nav-item-icon-text">车辆管理</view>
  32. </view>
  33. <view class="content-nav-item">
  34. <view class="content-nav-item-icon-wrap">
  35. <u-image src="../../static/img/index-content-nav-04.png" width="77rpx" height="75rpx" mode="heightFix"></u-image>
  36. </view>
  37. <view class="content-nav-item-icon-text">我的停车</view>
  38. </view>
  39. </view>
  40. </u-card>
  41. <template v-for="(item, index) in orderList">
  42. <u-card :show-foot="false" border-radius="16" margin="20rpx 40rpx" padding="30">
  43. <view class="pending-order-head" slot="head">
  44. <view class="pending-order-head-left"><b>P</b>{{item.roadName}}</view>
  45. <view class="pending-order-head-right" @click="onRoadInfo(item)"><u-icon class="arrow-down" name="arrow-down" size="32"></u-icon></view>
  46. </view>
  47. <view class="pending-order-body" slot="body">
  48. <!-- <view class="pending-order-body-nav">
  49. <view class="nav-item nav-manual" @click="orderNav=0" :class="{active:orderNav==0}">手动缴费</view>
  50. <view class="nav-item nav-auto" @click="orderNav=1" :class="{active:orderNav==1}">无感支付</view>
  51. </view> -->
  52. <view class="pending-order-body-wrap" v-show="orderNav==0">
  53. <view class="pending-order-body-left">
  54. <view class="car-number">{{item.vehicleNo}}</view>
  55. <view class="duration">
  56. <span class="pending-order-body-left-label">停车时长:</span>
  57. <span>{{item.duration}}</span>
  58. </view>
  59. </view>
  60. <view class="pending-order-body-right">
  61. <view class="order">订单号:{{item.id}}</view>
  62. <view class="cost">
  63. <span class="pending-order-body-left-label">停车费用:</span>
  64. <span>
  65. <span class="number">¥{{item.payAmount}}</span>
  66. </span>
  67. </view>
  68. </view>
  69. <view class="go-pay-wrap">
  70. <view class="go-pay" @click="handlewxpay">去支付</view>
  71. </view>
  72. </view>
  73. <view class="pending-order-body-wrap" v-show="orderNav==1">
  74. </view>
  75. </view>
  76. </u-card>
  77. </template>
  78. <u-modal
  79. v-model="bindCarShow"
  80. title="绑定车牌号"
  81. :show-cancel-button="true"
  82. confirm-text="去绑定"
  83. content="首次使用请先绑定您的车牌"
  84. @confirm="$u.route({url:'pages/myCars/myCars'})"></u-modal>
  85. <!-- 订单细节 -->
  86. <u-modal v-model="showOrderDetails" title="停车场信息" confirm-text="知道了" :title-style="{color: '#008CFF'}">
  87. <view class="slot-content">
  88. <rich-text class="orderDetails" :nodes="content"></rich-text>
  89. </view>
  90. </u-modal>
  91. <u-toast ref="uToast" />
  92. </view>
  93. </template>
  94. <script>
  95. import getUrlParams from "../../utils/getUrlParams.js";
  96. export default {
  97. // components: {
  98. // citySelect
  99. // },
  100. data() {
  101. return {
  102. city: '贵阳市',
  103. keyword:'',
  104. bannerList:[
  105. {image: '/static/img/index-banner01.png',title: ''}
  106. ],
  107. orderList:[],
  108. cityOpen:false,
  109. pendingOrder:[],
  110. code:null,//微信code
  111. orderNav:0,//手动,无感
  112. bindCarShow:false,//绑定车询问弹窗
  113. showOrderDetails:false,//是否线上订单细节
  114. content:`
  115. <dl>
  116. <dt>车场名称:</dt>
  117. <dd>贵阳云岩区甜蜜小镇D18组团停车场</dd>
  118. </dl>
  119. <dl>
  120. <dt>免费时长:</dt>
  121. <dd>15分钟</dd>
  122. </dl>
  123. `,
  124. }
  125. },
  126. onLoad() {
  127. this.handleGetIndexData();
  128. // this.getLocation();
  129. let locationLocaturl = window.location.search;
  130. this.code = getUrlParams(locationLocaturl,"code");
  131. if(this.code&&!this.$store.state.vuex_wxinfo.openId){this.handleGetWXInfo(this.code)};
  132. },
  133. methods: {
  134. // getLocation(){
  135. // console.log("请求定位")
  136. // uni.getLocation({
  137. // type:"gcj02",
  138. // success : function (res) {
  139. // console.log("定位返回信息:", res)
  140. // alert(res.longitude + "," + res.latitude )
  141. // },
  142. // fail: function(res){
  143. // console.log("请求错误:", res)
  144. // }
  145. // })
  146. // },
  147. handleSearch(){
  148. console.log('this.keyword',this.keyword);
  149. this.$u.route({
  150. url:'pages/parkingLists/parkingLists',
  151. params: {
  152. keyword: this.keyword
  153. }
  154. })
  155. },
  156. handleCitySelect(){
  157. this.cityOpen = true;
  158. },
  159. cityChange(e){
  160. console.log('cityChange',e);
  161. this.city = e.city.label;
  162. },
  163. handleGetIndexData(){
  164. this.$u.api.getIndexData()
  165. .then(res=>{
  166. if(res.data.vehicleList.length<1){
  167. this.bindCarShow = true;
  168. }
  169. this.orderList = res.data.orderList;
  170. }).catch(err=>{
  171. alert(err.msg);
  172. console.log('getIndexData err',err)
  173. });
  174. },
  175. getCode () {
  176. var local = window.location.href // 获取页面url
  177. let locationLocaturl = window.location.search;
  178. this.code = getUrlParams(locationLocaturl,"code"); // 截取code
  179. if (this.code == null || this.code === '') { // 如果没有code,则去请求
  180. 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`
  181. } else {
  182. this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
  183. }
  184. },
  185. handleGetWXInfo (code) { // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
  186. let _this = this
  187. this.$u.api.getWXInfo(code).then((res) => {
  188. if (res.code === 200 ) {
  189. this.$u.vuex('vuex_wxinfo',res.data);
  190. // 继续支付
  191. }
  192. }).catch((err) => {
  193. this.$refs.uToast.show({
  194. title: err.msg,
  195. type: 'error',
  196. });
  197. })
  198. },
  199. handlewxpay(){;
  200. if(!this.$store.state.vuex_wxinfo.openId){ // 如果微信openId,则需用code去后台获取
  201. this.$refs.uToast.show({
  202. title: '请登录后重试!',
  203. type: 'info',
  204. // url: '/pages/user/index'
  205. });
  206. this.getCode();
  207. } else {
  208. // 别的业务逻辑
  209. this.getWXPay();
  210. }
  211. },
  212. async getWXPay(id){
  213. let params = {
  214. orderId:id||new Date().getTime(),
  215. openid:this.$store.state.vuex_wxinfo.openId,
  216. tradeType:"test"
  217. };
  218. await this.$wxApi.config();
  219. this.$pay.wxPay(params).then(res =>{
  220. console.log('wxPay',res.code);
  221. if(res.code == 0){
  222. // 成功
  223. // uni.reLaunch({
  224. // url: '/pages/buySuccess/buySuccess?orderId=' + params.orderId
  225. // })
  226. }else if(res.code == 1){
  227. // 取消
  228. // uni.redirectTo({
  229. // url: '/pages/userCenter/myOrder/myOrder'
  230. // })
  231. }else if(res.code == 2){
  232. this.$refs.uToast.show({
  233. title: '支付失败,请检查!',
  234. type: 'error',
  235. // url: '/pages/user/index'
  236. });
  237. }
  238. });
  239. },
  240. //
  241. onRoadInfo(item){
  242. this.$u.api.roadInfoById({id:item.roadId})
  243. .then(res=>{
  244. this.content = `
  245. <dl><dt>路段名称:</dt> <dd>` + res.data.roadName + `</dd></dl>`
  246. + `<dl><dt>路段编码:</dt><dd>` + res.data.roadNo + `</dd></dl>`
  247. + `<dl><dt>联系人:</dt><dd>` + res.data.manager + `</dd></dl>`
  248. + `<dl><dt>联系电话:</dt><dd>` + res.data.telephone + `</dd></dl>`;
  249. this.showOrderDetails = true;
  250. }).catch(err=>{
  251. alert(err.msg);
  252. console.log('getIndexData err',err)
  253. });
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. @import "./index.scss";
  260. </style>