index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. <template>
  2. <ax-body hide-indicator-area :style="[StyleSheet]">
  3. <!-- 标题栏 -->
  4. <template #title>
  5. <view class="titlebar">
  6. <image src="@/static/img/title.png" class="page-title"></image>
  7. <!-- <text class="page-subtitle">“特惠充电享不停”</text> -->
  8. </view>
  9. </template>
  10. <view class="base">
  11. <!-- 搜索块 -->
  12. <view id="search" class="app-flex search-view">
  13. <view class="locate-city">
  14. <image src="@/static/img/locate.svg" class="_icon"></image>
  15. <text class="__name">{{city.data[city.index].text}}</text>
  16. </view>
  17. <label class="search-bar" @click="$app.url.goto('/pages/search/search')">
  18. <input placeholder-class="app-placeholder" placeholder="输入目的地/电站名" />
  19. <image src="@/static/img/search.svg" class="_icon-search"></image>
  20. </label>
  21. </view>
  22. </view>
  23. <view class="arrears-tips" v-if="payment_msg!=null">
  24. <view class="arrears-left">
  25. <image class="arrears-icon" src="@/static/img/arrears-icon.svg" mode=""></image>
  26. <view class="arrears-text">您有一笔超充订单{{(payment_msg.maspAmount+payment_msg.maspRealAmount).toFixed(2)}}元待补缴</view>
  27. </view>
  28. <view class="arrears-btn" @click="topage_coupon">去补缴</view>
  29. </view>
  30. <!-- 主滚动 -->
  31. <view class="main-scroll-wrap">
  32. <scroll-view class="root-scroll app-hide-scrollbar" @scrolltolower="scrollLock=true" @scrolltoupper="scrollLock=false" scroll-y>
  33. <view class="contet-root">
  34. <!-- 内容顶部 -->
  35. <view id="roller" class="base">
  36. <!-- 快捷栏 -->
  37. <view class="shortcut-bar">
  38. <view class="_item" @click="$app.url.goto('/pages/order/order')">
  39. <image src="@/static/img/shortcut1.png" class="_icon"></image>
  40. <view class="_name">订单中心</view>
  41. </view>
  42. <view class="_item" @click="$app.url.goto('/pages/coupon-buy/coupon-buy')">
  43. <image src="@/static/img/shortcut2.png" class="_icon"></image>
  44. <view class="_name">购充电券</view>
  45. </view>
  46. <view class="_item" @click="customerService()">
  47. <image src="@/static/img/shortcut3.png" class="_icon"></image>
  48. <view class="_name">在线客服</view>
  49. </view>
  50. <view class="_item" @click="$app.url.goto('/pages/feedback/feedback')">
  51. <image src="@/static/img/shortcut4.png" class="_icon"></image>
  52. <view class="_name">意见反馈</view>
  53. </view>
  54. </view>
  55. <!-- 版头广告 -->
  56. <swiper class="banner" v-if="banners.length>0" autoplay="true" >
  57. <swiper-item v-for="(item,index) in banners" :key="index" @click="$app.url.goto(item.jumpPage)">
  58. <view class="swiper-item">
  59. <image @load="bannerLoadCompleted()" :src="showImg(item.pic)" class="swiper-item-image" mode="widthFix"></image>
  60. </view>
  61. </swiper-item>
  62. </swiper>
  63. </view>
  64. <view id="fixed" class="base">
  65. <!-- 选项条 -->
  66. <view class="app-flex options-bar">
  67. <view class="app-flex middle option-wrap">
  68. <view v-for="(item,index) in sorts.data" :key="index" @click="changeSort(index)"
  69. class="option-item" :class="{active:sorts.index==index}">{{item.name}}</view>
  70. </view>
  71. <view class="app-flex c-center separ"></view>
  72. <view @click="$app.url.goto('/pages/map/map',false)" class="app-flex middle map-mode">
  73. <image src="@/static/img/map.svg" class="_icon"></image>
  74. <text>地图模式</text>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 电站列表 -->
  79. <view id="list-box" class="list-scroll-wrap">
  80. <scroll-view class="list-scroll" :scroll-y="scrollLock">
  81. <view class="list">
  82. <view v-for="(item,index) in list.data" :key="index" @click="gotoSiteDetail(item)" class="item">
  83. <view class="contet">
  84. <view class="name">
  85. <view class="icon"><image src="@/static/img/plug.svg" mode="widthFix"></image></view>
  86. <view class="txt">{{item.name}}</view>
  87. </view>
  88. <view class="parkade">
  89. <view class="icon"><image src="@/static/img/parkade.svg" mode="widthFix"></image></view>
  90. <!-- <view class="txt"><rich-text :nodes="item.parkTips"></rich-text></view> -->
  91. <view class="txt">充电减免2小时停车费,超出时长部分计时收费</view>
  92. </view>
  93. <view class="app-flex c-between info">
  94. <view class="app-flex middle">
  95. <view class="charge"><text class="icon">快</text><text class="value">{{item.params.emptyFast}}</text><text class="max">{{item.params.totalFast}}</text></view>
  96. <view class="charge"><text class="icon blue">慢</text><text class="value">{{item.params.emptySlow}}</text><text class="max">{{item.params.totalSlow}}</text></view>
  97. </view>
  98. <view class="discount" v-if="discountInfo">
  99. <view>
  100. {{discountInfo.temp2}}
  101. </view>
  102. </view>
  103. <view class="distance">
  104. <view class="icon"><image src="@/static/img/distance.svg" mode="widthFix"></image></view>
  105. <text>{{item.params.rangeShow}}</text>
  106. </view>
  107. </view>
  108. </view>
  109. <view class="price">
  110. <!-- v-if="user_info.firmId===null" -->
  111. <view class="app-flex middle" style="color: #FF5D50;" v-if="user_info.firmType===0||user_info.firmId===null||user_info===null">
  112. <text class="value">{{item.params.nowPrice?item.params.nowPrice.toFixed(4):"0.0000"}}</text>
  113. <text class="unit">元/度</text>
  114. </view>
  115. <view class="app-flex middle" v-else>
  116. <view class="card-bottom-text">
  117. <text>{{item.params.firmPrice.toFixed(4)}}</text>
  118. <text class="mini-text">元/度</text>
  119. </view>
  120. <view class="operation-price-btn">
  121. 企业专享价
  122. </view>
  123. <view class="ordinary-price">{{item.params.nowPrice?item.params.nowPrice.toFixed(4):"0.0000"}}</view>
  124. </view>
  125. <view>{{item.params.priceShow}}</view>
  126. </view>
  127. </view>
  128. </view>
  129. </scroll-view>
  130. </view>
  131. <!-- <view style="height: 158px;"></view> -->
  132. </view>
  133. </scroll-view>
  134. </view>
  135. <ax-popup ref="filter" position="" maskType="black" maskEnable maskClose>
  136. <view class="ad-popup">
  137. <view class="close-get" @click="$refs.filter.close()">X</view>
  138. <swiper class="ad-swiper" :autoplay="true" :interval="3000" :duration="1000">
  139. <swiper-item class="ad-swiper-item" v-for="(item,index) in adBanner" :key="index">
  140. <image class="ad-image" :src="showImg(item.picture)" mode="widthFix"></image>
  141. </swiper-item>
  142. </swiper>
  143. </view>
  144. </ax-popup>
  145. <app-navigation id="app-navigation" active="home"></app-navigation>
  146. </ax-body>
  147. </template>
  148. <script>
  149. var bmap = require('static/js/bmap-wx.js');
  150. export default {
  151. async onLoad(options) {
  152. const permit = await this.queryPermit();
  153. if(permit.privacy){
  154. // 没有通过隐私协议
  155. this.privacy.visible = true;
  156. }else{
  157. // 已通过隐私协议
  158. if(permit.location===true){
  159. // 可以调用定位能力
  160. this.updateLocation();
  161. }else if(permit.location===false){
  162. // 通过了隐私协议,但是定位被拒绝
  163. this.location.visible = true;
  164. this.updateLocation();
  165. }else if(permit.location===undefined){
  166. // 没有申请过定位能力
  167. this.updateLocation();
  168. }
  169. }
  170. if (options.hasOwnProperty('q') && options.q) {
  171. // 通过下面这步解码,可以拿到url的值
  172. const url = decodeURIComponent(options.q)
  173. // 对url中携带的参数提取处理
  174. console.log("url:"+url)
  175. var device_no = this.getQueryParams(url,"connectorCode")
  176. console.log("device_no:"+device_no)
  177. if(device_no){
  178. this.getDeviceInfo(device_no)
  179. }
  180. }
  181. // this.user_info=this.$app.storage.get('USER_INFO')
  182. },
  183. mounted() {
  184. if(this.adBanner.length>0){
  185. this.$refs.filter.open();
  186. }
  187. this.setListHeight();
  188. this.setAppNavigationHeight();
  189. this.get_frimid()
  190. this.get_userinfo()
  191. this.get_paymentMsg()
  192. },
  193. data() {
  194. return {
  195. payment_msg:null,
  196. user_info:{},
  197. // 导航栏高度
  198. appNavigationHeight: 0,
  199. // 页面滚动锁
  200. scrollLock: true,
  201. sorts:{
  202. index: 0,
  203. data: [{name:'离我最近',code:"range"},{name:'空闲最多',code:"device"},{name:'电费最低',code:"price"}]
  204. },
  205. list:{
  206. height: 0,
  207. data: []
  208. },
  209. banners:[],
  210. adBanner:[],
  211. location:{
  212. visible: false,
  213. value: '',
  214. },
  215. privacy:{
  216. visible: false,
  217. },
  218. city:{
  219. index: 0,
  220. data:[
  221. {text:'贵阳',areaCode:"5201"},
  222. {text:'六盘水',areaCode:"5202"},
  223. {text:'遵义',areaCode:"5203"},
  224. {text:'安顺',areaCode:"5204"},
  225. {text:'毕节',areaCode:"5205"},
  226. {text:'铜仁',areaCode:"5206"},
  227. {text:'黔东南',areaCode:"5226"},
  228. {text:'黔南',areaCode:"5227"},
  229. {text:'黔西南',areaCode:"5223"},
  230. ]
  231. },
  232. discountInfo:null
  233. }
  234. },
  235. onShow() {
  236. this.getBanners()
  237. this.getAdswiper()
  238. },
  239. computed:{
  240. StyleSheet(){
  241. return {
  242. '--app-navigation-heiht': `${this.appNavigationHeight}px`,
  243. '--list-heiht': `${this.list.height}px`
  244. }
  245. }
  246. },
  247. onShareAppMessage(res) {
  248. if (res.from === 'button') {
  249. // 来自页面内分享按钮
  250. console.log(res.target);
  251. }
  252. return {
  253. title: "用券充天天都享会员价", // 标题
  254. path: "/pages/index/index", // 分享路径
  255. imageUrl: '../../static/img/share.jpg', // 分享图
  256. desc: '用券充天天都享会员价'
  257. };
  258. },
  259. onShareTimeline() {
  260. return {
  261. title: "用券充天天都享会员价", // 标题
  262. path: "/pages/index/index", // 分享路径
  263. imageUrl: '../../static/img/share.jpg'// 分享图
  264. };
  265. },
  266. methods: {
  267. get_userinfo(){
  268. this.$api.base("post", "/userApi/getUserAccount", {}, {error:false}).then(res => {
  269. this.user_info = res.accountInfo
  270. this.$app.storage.set('USER_INFO', res.accountInfo);
  271. })
  272. },
  273. // 企业用户扫码进入
  274. get_frimid(){
  275. if(this.$app.storage.get('FRIM_ID')){
  276. if(this.$app.storage.get('USER_TOKEN')){
  277. this.$api.base("post","/userApi/add-firm-user?firmId="+parseInt(this.$app.storage.get('FRIM_ID')),{},{error: false}).then(res=>{
  278. this.get_userinfo()
  279. setTimeout(()=>{
  280. this.$app.storage.remove('FRIM_ID')
  281. },500)
  282. this.$app.popup.alert(res.msg);
  283. }).catch(err=>{
  284. setTimeout(()=>{
  285. this.$app.storage.remove('FRIM_ID')
  286. },500)
  287. // this.$app.popup.alert(err.msg)
  288. })
  289. }else{
  290. uni.showModal({
  291. title:'未登录',
  292. content:'你还未进行登录,请去登录',
  293. showCancel:false,
  294. success:function(res) {
  295. if(res.confirm){
  296. uni.navigateTo({
  297. url:'/pages/login/login'
  298. })
  299. }
  300. }
  301. })
  302. }
  303. }
  304. },
  305. getDeviceInfo(sn){
  306. this.$api.base("post","/chargeApi/checkDevicesBySn",{"sn":sn},{}).then(res=>{
  307. var item = res.device;
  308. //设备状态 0:离网1:空闲2:占用(未充电)3:占用(充电中)4:占用(预约锁定)255:故障
  309. if(item.deviceStatus == 0 || item.deviceStatus == 255 ){
  310. return;
  311. }
  312. this.$app.url.goto('/pages/terminal/terminal?deviceId='+item.id+"&deviceStatus="+item.deviceStatus);
  313. })
  314. },
  315. getQueryParams(url,key) {
  316. const queryString = url.split('?')[1] || '';
  317. const params = {};
  318. const pairs = queryString.split('&');
  319. pairs.forEach(pair => {
  320. const [key, value] = pair.split('=');
  321. params[decodeURIComponent(key)] = decodeURIComponent(value || '');
  322. });
  323. return params[key];
  324. },
  325. showImg(img){
  326. return this.$config.url.request+img
  327. },
  328. // 打开客服
  329. customerService(){
  330. const cs = this.$config.customerService;
  331. this.$app.act.customerService(cs.id,cs.url).catch(err=>{
  332. console.log(err);
  333. this.$app.popup.alert('客服中心失联啦,请联系管理员!');
  334. });
  335. },
  336. // 查询许可
  337. queryPermit(){
  338. return new Promise((resolve,reject)=>{
  339. const data = {};
  340. const check = ()=>{
  341. if( Object.keys(data).length == 2 ) resolve(data);
  342. }
  343. if(uni.getPrivacySetting){
  344. uni.getPrivacySetting({
  345. success: res => {
  346. data.privacy = res.needAuthorization;
  347. },
  348. complete: () => {
  349. if(typeof data.privacy !='boolean' && typeof data.privacy !='undefined') data.privacy = null;
  350. check();
  351. },
  352. });
  353. }else{
  354. data.privacy = false;
  355. }
  356. uni.getSetting({
  357. success: res => {
  358. data.location = uni.getLocation ? res.authSetting['scope.userLocation'] : undefined;
  359. },
  360. complete: () => {
  361. if(typeof data.location !='boolean' && typeof data.location !='undefined') data.location = null;
  362. check();
  363. },
  364. })
  365. });
  366. },
  367. // 更新位置
  368. updateLocation(){
  369. this.getLocation().then(res=>{
  370. this.location.value = [res.longitude,res.latitude].join(',');
  371. this.getStations(res.longitude,res.latitude)
  372. this.$app.storage.set('USER_LOCATION',this.location.value);
  373. return this.reverseGeocoder([res.latitude,res.longitude].join(','))
  374. });
  375. },
  376. // 获取定位
  377. getLocation(){
  378. return new Promise((resolve,reject)=>{
  379. // this.loading.visible = true;
  380. if(uni.getLocation){
  381. uni.getLocation({
  382. success: res => resolve(res),
  383. fail: err => {
  384. console.log(err)
  385. console.log('定位失败');
  386. // this.location.visible = true;
  387. this.getStations("","")
  388. },
  389. complete: () => {
  390. }
  391. })
  392. }else{
  393. console.log('微信版本太低,无定位接口可用');
  394. resolve({longitude:'',latitude:''});
  395. }
  396. });
  397. },
  398. reverseGeocoder(latlon){
  399. console.log(latlon)
  400. let lat = latlon.split(",")[0]
  401. let lng = latlon.split(",")[1]
  402. let baiduLoc = this.convertGcj02ToBd09(lng,lat)
  403. latlon = baiduLoc.lat+","+baiduLoc.lng
  404. console.log(latlon)
  405. return new Promise((resolve,reject)=>{
  406. var BMap = new bmap.BMapWX({
  407. ak: 'vtQgaPzonb3H4qeUOWGr53ePcNCsmdMj'
  408. });
  409. BMap.regeocoding({
  410. location:latlon,
  411. success:res=>{
  412. let code = res.originalData.result.addressComponent.adcode.substr(0,4)
  413. for (var i = 0; i < this.city.data.length; i++) {
  414. if(this.city.data[i].areaCode==code){
  415. this.city.index = i
  416. break;
  417. }
  418. }
  419. console.log(res)
  420. },
  421. fail:err=>{
  422. console.log(err)
  423. }
  424. })
  425. });
  426. },
  427. get_paymentMsg(){
  428. // maspStatus(1:待补缴,2:已补缴)realPredictServiceCost平台;maspAmount第三方
  429. this.$api.base("post","/chargeApi/queryOrderList-arrearage",{},{}).then(res=>{
  430. this.payment_msg=res.data
  431. })
  432. },
  433. getBanners(){
  434. this.$api.base("post","/userApi/getBanners",{},{}).then(res=>{
  435. this.banners = res.banners
  436. })
  437. },
  438. getAdswiper(){
  439. this.$api.base("post","/userApi/getAdvertising",{},{}).then(res=>{
  440. this.adBanner = res.banners
  441. })
  442. },
  443. convertBdToTx(lng, lat) {
  444. // 百度坐标系(BD09)转火星坐标系(GCJ-02,即腾讯地图使用的坐标系)
  445. // 这里的转换公式是基于经验公式,可能存在一定的误差
  446. let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  447. let x = lng - 0.0065;
  448. let y = lat - 0.006;
  449. let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  450. let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  451. let lngs = z * Math.cos(theta);
  452. let lats = z * Math.sin(theta);
  453. return { lng: lngs, lat: lats };
  454. },
  455. getStations(lng,lat){
  456. this.$api.base("post","/chargeApi/getStations",{order:this.sorts.index,lat,lng},{}).then(res=>{
  457. res.stationList.forEach(i=>{
  458. var txPoint = this.convertBdToTx(i.lng,i.lat)
  459. i.lng = txPoint.lng
  460. i.lat = txPoint.lat
  461. })
  462. this.list.data = res.stationList
  463. if(res.discountInfo){
  464. this.discountInfo = res.discountInfo
  465. }
  466. })
  467. },
  468. // 设定导航栏高度
  469. setAppNavigationHeight(){
  470. this.$nextTick(()=>{
  471. uni.createSelectorQuery().in(this).select("#app-navigation").boundingClientRect(data=>{
  472. this.appNavigationHeight = data.height;
  473. }).exec();
  474. });
  475. },
  476. // 设置列表高度
  477. setListHeight(){
  478. this.$app.act.selectorQuery(this,"#list-box,#roller",true).then(res=>{
  479. const win = uni.getWindowInfo();
  480. const roller = res.find(i=>i.id=='roller');
  481. const list = res.find(i=>i.id=='list-box');
  482. this.list.height = win.windowHeight - list.top - this.appNavigationHeight + roller.height;
  483. });
  484. },
  485. // 版头加载完成
  486. bannerLoadCompleted(){
  487. this.setListHeight();
  488. },
  489. changeSort(index){
  490. this.sorts.index = index;
  491. switch(index){
  492. case 0:
  493. this.list.data.sort((a,b)=>a.params.range-b.params.range)
  494. break;
  495. case 1:
  496. this.list.data.sort((a,b)=>b.params.totalEmpty-a.params.totalEmpty)
  497. break;
  498. case 2:
  499. this.list.data.sort((a,b)=>a.params.nowPrice-b.params.nowPrice)
  500. break;
  501. }
  502. },
  503. scrolltolower(){
  504. console.log('到底')
  505. },
  506. gotoSiteDetail(item){
  507. this.$app.url.goto('/pages/site/site?item='+JSON.stringify(item));
  508. },
  509. topage_coupon(){
  510. let payment=this.payment_msg.realPredictServiceCost+this.payment_msg.maspAmount
  511. this.$app.url.goto('/pages/coupon-buy/coupon-buy?payment='+payment)
  512. },
  513. // 确认隐私协议
  514. agreePrivacyAuthorization(){
  515. this.privacy.visible = false;
  516. this.updateLocation();
  517. },
  518. // 打开隐私协议
  519. openPrivacyContract(){
  520. uni.openPrivacyContract();
  521. },
  522. // 拒绝隐私协议
  523. refusePrivacy(){
  524. this.privacy.visible = false;
  525. },
  526. convertGcj02ToBd09(lng, lat) {
  527. const x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  528. const z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
  529. const theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
  530. const bd_lng = z * Math.cos(theta) + 0.0065;
  531. const bd_lat = z * Math.sin(theta) + 0.006;
  532. return {
  533. lng: bd_lng,
  534. lat: bd_lat
  535. };
  536. }
  537. }
  538. }
  539. </script>
  540. <style>
  541. @import url('index.css');
  542. .discount{
  543. flex: 1;
  544. text-align: right;
  545. padding-right: 5px;
  546. }
  547. .discount view{
  548. display: inline-flex;
  549. align-items: center;
  550. height: 22px;
  551. border: 1px solid #ccc;
  552. border-radius: 5px;
  553. font-size: 12px;
  554. color: #F59C79;
  555. padding: 0 7px;
  556. overflow: hidden;
  557. }
  558. </style>