index.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. <u-card :show-foot="false" border-radius="16" margin="20rpx 40rpx" padding="30">
  42. <view class="pending-order-head" slot="head">
  43. <view class="pending-order-head-left"><b>P</b>甜蜜小镇D18组团停车场</view>
  44. <view class="pending-order-head-right" @click="orderDetails"><u-icon class="arrow-down" name="arrow-down" size="32"></u-icon></view>
  45. </view>
  46. <view class="pending-order-body" slot="body">
  47. <view class="pending-order-body-nav">
  48. <view class="nav-item nav-manual" @click="orderNav=0" :class="{active:orderNav==0}">手动缴费</view>
  49. <view class="nav-item nav-auto" @click="orderNav=1" :class="{active:orderNav==1}">无感支付</view>
  50. </view>
  51. <view class="pending-order-body-wrap" v-show="orderNav==0">
  52. <view class="pending-order-body-left">
  53. <view class="car-number">贵A37W45</view>
  54. <view class="duration">
  55. <span class="pending-order-body-left-label">停车时长</span>
  56. <span>01:30:25</span>
  57. </view>
  58. </view>
  59. <view class="pending-order-body-right">
  60. <view class="order">订单号:5222021022300045</view>
  61. <view class="cost">
  62. <span class="pending-order-body-left-label">停车费用</span>
  63. <span>
  64. <span class="number">10.25</span>
  65. </span>
  66. </view>
  67. </view>
  68. <view class="go-pay-wrap">
  69. <view class="go-pay" @click="handlewxpay">去支付</view>
  70. </view>
  71. </view>
  72. <view class="pending-order-body-wrap" v-show="orderNav==1">
  73. </view>
  74. </view>
  75. </u-card>
  76. <u-modal
  77. v-model="bindCarShow"
  78. title="绑定车牌号"
  79. :show-cancel-button="true"
  80. confirm-text="去绑定"
  81. content="首次使用请先绑定您的车牌"
  82. @confirm="$u.route({url:'pages/myCars/myCars'})"></u-modal>
  83. <!-- 订单细节 -->
  84. <u-modal v-model="showOrderDetails" title="停车场信息" confirm-text="知道了" :title-style="{color: '#008CFF'}">
  85. <view class="slot-content">
  86. <rich-text class="orderDetails" :nodes="content"></rich-text>
  87. </view>
  88. </u-modal>
  89. <u-toast ref="uToast" />
  90. </view>
  91. </template>
  92. <script>
  93. import getUrlParams from "../../utils/getUrlParams.js";
  94. export default {
  95. // components: {
  96. // citySelect
  97. // },
  98. data() {
  99. return {
  100. city: '贵阳市',
  101. keyword:'',
  102. bannerList:[
  103. {image: '/static/img/index-banner01.png',title: ''}
  104. ],
  105. cityOpen:false,
  106. pendingOrder:[],
  107. code:null,//微信code
  108. orderNav:0,//手动,无感
  109. bindCarShow:false,//绑定车询问弹窗
  110. showOrderDetails:false,//是否线上订单细节
  111. content:`
  112. <dl>
  113. <dt>车场名称:</dt>
  114. <dd>贵阳云岩区甜蜜小镇D18组团停车场</dd>
  115. </dl>
  116. <dl>
  117. <dt>免费时长:</dt>
  118. <dd>15分钟</dd>
  119. </dl>
  120. `,
  121. }
  122. },
  123. onLoad() {
  124. this.handleGetIndexData();
  125. let locationLocaturl = window.location.search;
  126. this.code = getUrlParams(locationLocaturl,"code");
  127. if(this.code&&!this.$store.state.vuex_wxinfo.openId){this.handleGetWXInfo(this.code)};
  128. },
  129. methods: {
  130. handleSearch(){
  131. console.log('this.keyword',this.keyword);
  132. this.$u.route({
  133. url:'pages/parkingLists/parkingLists',
  134. params: {
  135. keyword: this.keyword
  136. }
  137. })
  138. },
  139. handleCitySelect(){
  140. this.cityOpen = true;
  141. },
  142. cityChange(e){
  143. console.log('cityChange',e);
  144. this.city = e.city.label;
  145. },
  146. handleGetIndexData(){
  147. this.$u.api.getIndexData()
  148. .then(res=>{
  149. console.log('getIndexData',res);
  150. if(res.data.vehicleList.length<1){
  151. this.bindCarShow = true;
  152. }
  153. }).catch(err=>{
  154. alert(err.msg);
  155. console.log('getIndexData err',err)
  156. });
  157. },
  158. getCode () {
  159. var local = window.location.href // 获取页面url
  160. let locationLocaturl = window.location.search;
  161. this.code = getUrlParams(locationLocaturl,"code"); // 截取code
  162. if (this.code == null || this.code === '') { // 如果没有code,则去请求
  163. 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`
  164. } else {
  165. this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
  166. }
  167. },
  168. handleGetWXInfo (code) { // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
  169. let _this = this
  170. this.$u.api.getWXInfo(code).then((res) => {
  171. if (res.code === 200 ) {
  172. this.$u.vuex('vuex_wxinfo',res.data);
  173. // 继续支付
  174. }
  175. }).catch((err) => {
  176. this.$refs.uToast.show({
  177. title: err.msg,
  178. type: 'error',
  179. });
  180. })
  181. },
  182. handlewxpay(){;
  183. if(!this.$store.state.vuex_wxinfo.openId){ // 如果微信openId,则需用code去后台获取
  184. this.$refs.uToast.show({
  185. title: '请登录后重试!',
  186. type: 'info',
  187. // url: '/pages/user/index'
  188. });
  189. this.getCode();
  190. } else {
  191. // 别的业务逻辑
  192. this.getWXPay();
  193. }
  194. },
  195. async getWXPay(id){
  196. let params = {
  197. orderId:id||new Date().getTime(),
  198. openid:this.$store.state.vuex_wxinfo.openId,
  199. tradeType:"test"
  200. };
  201. await this.$wxApi.config();
  202. this.$pay.wxPay(params).then(res =>{
  203. console.log('wxPay',res.code);
  204. if(res.code == 0){
  205. // 成功
  206. // uni.reLaunch({
  207. // url: '/pages/buySuccess/buySuccess?orderId=' + params.orderId
  208. // })
  209. }else if(res.code == 1){
  210. // 取消
  211. // uni.redirectTo({
  212. // url: '/pages/userCenter/myOrder/myOrder'
  213. // })
  214. }else if(res.code == 2){
  215. this.$refs.uToast.show({
  216. title: '支付失败,请检查!',
  217. type: 'error',
  218. // url: '/pages/user/index'
  219. });
  220. }
  221. });
  222. },
  223. //
  224. orderDetails(){
  225. this.showOrderDetails = true;
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. @import "./index.scss";
  232. </style>