index.vue 17 KB

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