index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. <view class="app-flex middle" style="color: #FF5D50;" v-if="!isOperation">
  104. <text class="value">{{item.params.nowPrice?item.params.nowPrice.toFixed(4):"0.0000"}}</text>
  105. <text class="unit">元/度</text>
  106. </view>
  107. <view class="app-flex middle" v-else>
  108. <view class="card-bottom-text">
  109. <text>1.0026</text>
  110. <text class="mini-text">元/度</text>
  111. </view>
  112. <view class="operation-price-btn">
  113. 企业专享价
  114. </view>
  115. <view class="ordinary-price">{{item.params.nowPrice?item.params.nowPrice.toFixed(4):"0.0000"}}</view>
  116. </view>
  117. <view>{{item.params.priceShow}}</view>
  118. </view>
  119. </view>
  120. </view>
  121. </scroll-view>
  122. </view>
  123. <!-- <view style="height: 158px;"></view> -->
  124. </view>
  125. </scroll-view>
  126. </view>
  127. <app-navigation id="app-navigation" active="home"></app-navigation>
  128. </ax-body>
  129. </template>
  130. <script>
  131. var bmap = require('static/js/bmap-wx.js');
  132. export default {
  133. async onLoad(options) {
  134. const permit = await this.queryPermit();
  135. if(permit.privacy){
  136. // 没有通过隐私协议
  137. this.privacy.visible = true;
  138. }else{
  139. // 已通过隐私协议
  140. if(permit.location===true){
  141. // 可以调用定位能力
  142. this.updateLocation();
  143. }else if(permit.location===false){
  144. // 通过了隐私协议,但是定位被拒绝
  145. this.location.visible = true;
  146. this.updateLocation();
  147. }else if(permit.location===undefined){
  148. // 没有申请过定位能力
  149. this.updateLocation();
  150. }
  151. }
  152. if (options.hasOwnProperty('q') && options.q) {
  153. // 通过下面这步解码,可以拿到url的值
  154. const url = decodeURIComponent(options.q)
  155. // 对url中携带的参数提取处理
  156. console.log("url:"+url)
  157. var device_no = this.getQueryParams(url,"connectorCode")
  158. console.log("device_no:"+device_no)
  159. if(device_no){
  160. this.getDeviceInfo(device_no)
  161. }
  162. }
  163. },
  164. mounted() {
  165. this.setListHeight();
  166. this.setAppNavigationHeight();
  167. },
  168. data() {
  169. return {
  170. isOperation:false,
  171. // 导航栏高度
  172. appNavigationHeight: 0,
  173. // 页面滚动锁
  174. scrollLock: true,
  175. sorts:{
  176. index: 0,
  177. data: [{name:'离我最近',code:"range"},{name:'空闲最多',code:"device"},{name:'电费最低',code:"price"}]
  178. },
  179. list:{
  180. height: 0,
  181. data: []
  182. },
  183. banners:[],
  184. location:{
  185. visible: false,
  186. value: '',
  187. },
  188. privacy:{
  189. visible: false,
  190. },
  191. city:{
  192. index: 0,
  193. data:[
  194. {text:'贵阳',areaCode:"5201"},
  195. {text:'六盘水',areaCode:"5202"},
  196. {text:'遵义',areaCode:"5203"},
  197. {text:'安顺',areaCode:"5204"},
  198. {text:'毕节',areaCode:"5205"},
  199. {text:'铜仁',areaCode:"5206"},
  200. {text:'黔东南',areaCode:"5226"},
  201. {text:'黔南',areaCode:"5227"},
  202. {text:'黔西南',areaCode:"5223"},
  203. ]
  204. },
  205. discountInfo:null
  206. }
  207. },
  208. onShow() {
  209. this.getBanners()
  210. },
  211. computed:{
  212. StyleSheet(){
  213. return {
  214. '--app-navigation-heiht': `${this.appNavigationHeight}px`,
  215. '--list-heiht': `${this.list.height}px`
  216. }
  217. }
  218. },
  219. onShareAppMessage(res) {
  220. if (res.from === 'button') {
  221. // 来自页面内分享按钮
  222. console.log(res.target);
  223. }
  224. return {
  225. title: "用券充天天都享会员价", // 标题
  226. path: "/pages/index/index", // 分享路径
  227. imageUrl: '../../static/img/share.jpg', // 分享图
  228. desc: '用券充天天都享会员价'
  229. };
  230. },
  231. onShareTimeline() {
  232. return {
  233. title: "用券充天天都享会员价", // 标题
  234. path: "/pages/index/index", // 分享路径
  235. imageUrl: '../../static/img/share.jpg'// 分享图
  236. };
  237. },
  238. methods: {
  239. getDeviceInfo(sn){
  240. this.$api.base("post","/chargeApi/checkDevicesBySn",{"sn":sn},{}).then(res=>{
  241. console.log("设备信息:",res)
  242. var item = res.device;
  243. //设备状态 0:离网1:空闲2:占用(未充电)3:占用(充电中)4:占用(预约锁定)255:故障
  244. if(item.deviceStatus == 0 || item.deviceStatus == 255 ){
  245. return;
  246. }
  247. this.$app.url.goto('/pages/terminal/terminal?deviceId='+item.id+"&deviceStatus="+item.deviceStatus);
  248. })
  249. },
  250. getQueryParams(url,key) {
  251. const queryString = url.split('?')[1] || '';
  252. const params = {};
  253. const pairs = queryString.split('&');
  254. pairs.forEach(pair => {
  255. const [key, value] = pair.split('=');
  256. params[decodeURIComponent(key)] = decodeURIComponent(value || '');
  257. });
  258. return params[key];
  259. },
  260. showImg(img){
  261. return this.$config.url.request+img
  262. },
  263. // 打开客服
  264. customerService(){
  265. const cs = this.$config.customerService;
  266. this.$app.act.customerService(cs.id,cs.url).catch(err=>{
  267. console.log(err);
  268. this.$app.popup.alert('客服中心失联啦,请联系管理员!');
  269. });
  270. },
  271. // 查询许可
  272. queryPermit(){
  273. return new Promise((resolve,reject)=>{
  274. const data = {};
  275. const check = ()=>{
  276. if( Object.keys(data).length == 2 ) resolve(data);
  277. }
  278. if(uni.getPrivacySetting){
  279. uni.getPrivacySetting({
  280. success: res => {
  281. data.privacy = res.needAuthorization;
  282. },
  283. complete: () => {
  284. if(typeof data.privacy !='boolean' && typeof data.privacy !='undefined') data.privacy = null;
  285. check();
  286. },
  287. });
  288. }else{
  289. data.privacy = false;
  290. }
  291. uni.getSetting({
  292. success: res => {
  293. data.location = uni.getLocation ? res.authSetting['scope.userLocation'] : undefined;
  294. },
  295. complete: () => {
  296. if(typeof data.location !='boolean' && typeof data.location !='undefined') data.location = null;
  297. check();
  298. },
  299. })
  300. });
  301. },
  302. // 更新位置
  303. updateLocation(){
  304. this.getLocation().then(res=>{
  305. this.location.value = [res.longitude,res.latitude].join(',');
  306. this.getStations(res.longitude,res.latitude)
  307. this.$app.storage.set('USER_LOCATION',this.location.value);
  308. return this.reverseGeocoder([res.latitude,res.longitude].join(','))
  309. });
  310. },
  311. // 获取定位
  312. getLocation(){
  313. return new Promise((resolve,reject)=>{
  314. // this.loading.visible = true;
  315. if(uni.getLocation){
  316. uni.getLocation({
  317. success: res => resolve(res),
  318. fail: err => {
  319. console.log(err)
  320. console.log('定位失败');
  321. // this.location.visible = true;
  322. this.getStations("","")
  323. },
  324. complete: () => {
  325. }
  326. })
  327. }else{
  328. console.log('微信版本太低,无定位接口可用');
  329. resolve({longitude:'',latitude:''});
  330. }
  331. });
  332. },
  333. reverseGeocoder(latlon){
  334. console.log(latlon)
  335. let lat = latlon.split(",")[0]
  336. let lng = latlon.split(",")[1]
  337. let baiduLoc = this.convertGcj02ToBd09(lng,lat)
  338. latlon = baiduLoc.lat+","+baiduLoc.lng
  339. console.log(latlon)
  340. return new Promise((resolve,reject)=>{
  341. var BMap = new bmap.BMapWX({
  342. ak: 'vtQgaPzonb3H4qeUOWGr53ePcNCsmdMj'
  343. });
  344. BMap.regeocoding({
  345. location:latlon,
  346. success:res=>{
  347. let code = res.originalData.result.addressComponent.adcode.substr(0,4)
  348. for (var i = 0; i < this.city.data.length; i++) {
  349. if(this.city.data[i].areaCode==code){
  350. this.city.index = i
  351. break;
  352. }
  353. }
  354. console.log(res)
  355. },
  356. fail:err=>{
  357. console.log(err)
  358. }
  359. })
  360. });
  361. },
  362. getBanners(){
  363. this.$api.base("post","/userApi/getBanners",{},{}).then(res=>{
  364. this.banners = res.banners
  365. })
  366. },
  367. convertBdToTx(lng, lat) {
  368. // 百度坐标系(BD09)转火星坐标系(GCJ-02,即腾讯地图使用的坐标系)
  369. // 这里的转换公式是基于经验公式,可能存在一定的误差
  370. let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  371. let x = lng - 0.0065;
  372. let y = lat - 0.006;
  373. let z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  374. let theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  375. let lngs = z * Math.cos(theta);
  376. let lats = z * Math.sin(theta);
  377. return { lng: lngs, lat: lats };
  378. },
  379. getStations(lng,lat){
  380. this.$api.base("post","/chargeApi/getStations",{order:this.sorts.index,lat,lng},{}).then(res=>{
  381. res.stationList.forEach(i=>{
  382. var txPoint = this.convertBdToTx(i.lng,i.lat)
  383. i.lng = txPoint.lng
  384. i.lat = txPoint.lat
  385. })
  386. this.list.data = res.stationList
  387. if(res.discountInfo){
  388. this.discountInfo = res.discountInfo
  389. }
  390. })
  391. },
  392. // 设定导航栏高度
  393. setAppNavigationHeight(){
  394. this.$nextTick(()=>{
  395. uni.createSelectorQuery().in(this).select("#app-navigation").boundingClientRect(data=>{
  396. this.appNavigationHeight = data.height;
  397. }).exec();
  398. });
  399. },
  400. // 设置列表高度
  401. setListHeight(){
  402. this.$app.act.selectorQuery(this,"#list-box,#roller",true).then(res=>{
  403. const win = uni.getWindowInfo();
  404. const roller = res.find(i=>i.id=='roller');
  405. const list = res.find(i=>i.id=='list-box');
  406. this.list.height = win.windowHeight - list.top - this.appNavigationHeight + roller.height;
  407. });
  408. },
  409. // 版头加载完成
  410. bannerLoadCompleted(){
  411. this.setListHeight();
  412. },
  413. changeSort(index){
  414. this.sorts.index = index;
  415. switch(index){
  416. case 0:
  417. this.list.data.sort((a,b)=>a.params.range-b.params.range)
  418. break;
  419. case 1:
  420. this.list.data.sort((a,b)=>b.params.totalEmpty-a.params.totalEmpty)
  421. break;
  422. case 2:
  423. this.list.data.sort((a,b)=>a.params.nowPrice-b.params.nowPrice)
  424. break;
  425. }
  426. },
  427. scrolltolower(){
  428. console.log('到底')
  429. },
  430. gotoSiteDetail(item){
  431. this.$app.url.goto('/pages/site/site?item='+JSON.stringify(item));
  432. },
  433. // 确认隐私协议
  434. agreePrivacyAuthorization(){
  435. this.privacy.visible = false;
  436. this.updateLocation();
  437. },
  438. // 打开隐私协议
  439. openPrivacyContract(){
  440. uni.openPrivacyContract();
  441. },
  442. // 拒绝隐私协议
  443. refusePrivacy(){
  444. this.privacy.visible = false;
  445. },
  446. convertGcj02ToBd09(lng, lat) {
  447. const x_pi = 3.14159265358979324 * 3000.0 / 180.0;
  448. const z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
  449. const theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
  450. const bd_lng = z * Math.cos(theta) + 0.0065;
  451. const bd_lat = z * Math.sin(theta) + 0.006;
  452. return {
  453. lng: bd_lng,
  454. lat: bd_lat
  455. };
  456. }
  457. }
  458. }
  459. </script>
  460. <style>
  461. @import url('index.css');
  462. .discount{
  463. flex: 1;
  464. text-align: right;
  465. padding-right: 5px;
  466. }
  467. .discount view{
  468. display: inline-flex;
  469. align-items: center;
  470. height: 22px;
  471. border: 1px solid #ccc;
  472. border-radius: 5px;
  473. font-size: 12px;
  474. color: #F59C79;
  475. padding: 0 7px;
  476. overflow: hidden;
  477. }
  478. </style>