switchCharge.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  1. <template>
  2. <view>
  3. <ujp-navbar title="选择充电桩" :autoBack="false" :customBack="customBack">
  4. <!-- <view class="slot-wrap">
  5. <view class="navbar-left"></view>
  6. <view class="navbar-right" @click="selectBtn"><span>确定选择</span></view>
  7. </view> -->
  8. </ujp-navbar>
  9. <u-select ref="refselect" title="" v-model="tabsFrom.show1" :defaultValue="current"
  10. :list="selectList" value-name="id" label-name="name"
  11. @confirm="selector1confirm" >
  12. </u-select>
  13. <view class="head-head" style="background: #fff;" v-show="stationShow" >
  14. <view style="
  15. text-align: center;
  16. display: flex;
  17. align-items: center;
  18. " >
  19. <view style="width: 30%;" @click="tabsFrom.show1=true">
  20. {{tabsFrom.show1Text}} <u-icon name="arrow-down" color="#999999"></u-icon>
  21. </view>
  22. <view style="width: 70%;">
  23. <u-search placeholder="搜索站点名称或地址" :show-action="false"
  24. @change="searchStationData(1)" @search="searchStationData(1)" @click="searchStationData(1)"
  25. @custom='searchStationData(1)'
  26. v-model="keyword"></u-search>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="head-head-placeholder " v-show="stationShow">
  31. </view>
  32. <view class="chargeListStation" v-show="stationShow">
  33. <view style="text-align: center;margin-top: 100px" v-if="!stationList.length">
  34. <img src="@/assets/img/blankpage.png">
  35. <p v-if="isPoint">暂无充电站</p>
  36. <p v-else >暂无充电站</p>
  37. <p><span style="color: #1677ff;" @click="getPoint()">重新定位?</span></p>
  38. </view>
  39. <view class="chargeHead" v-if="stationList.length" >已为您查询附近的充电站</view>
  40. <template v-for="(item,i) in stationList">
  41. <view class="chargeList-item " @click="selectStationBtn(item)" :class="{
  42. }" :key="i">
  43. <view class="chargeList-item-row">
  44. <u-icon name="qichexiangguan-chongdianzhan" custom-prefix="custom-icon" color="#1677ff"
  45. size="40"></u-icon>
  46. <p>名称</p>
  47. <span> {{item.name}}</span>
  48. </view>
  49. <!-- <view class="chargeList-item-row">
  50. <u-icon name="juli" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  51. <p>位置</p>
  52. </view> -->
  53. <view class="chargeList-item-row">
  54. <u-icon name="dizhi" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  55. <p>地址</p>
  56. <span>{{item.address}}</span>
  57. </view>
  58. </view>
  59. </template>
  60. <u-divider bg-color="#F2F4F4" v-if="recordsTotal&&stationList.length==recordsTotal" border-color="#CFD2D5">已经到底了</u-divider>
  61. </view>
  62. <view class="chargeList" v-show="!stationShow">
  63. <view style="text-align: center;margin-top: 100px" v-if="!list.length">
  64. <img src="@/assets/img/blankpage.png">
  65. <p>暂无充电桩</p>
  66. <p><span style="color: #1677ff;" @click="getPoint()">查询附近站点</span></p>
  67. </view>
  68. <view class="chargeHead2" v-if="list.length" >
  69. <view>{{stationName}}</view>
  70. <view class="chargeHead2span" @click="getPoint()">查询附近站点</view></view>
  71. <template v-for="(item,i) in list">
  72. <view class="chargeList-item " @click="select=item.id,selectBtn()" :class="{
  73. 'active':item.id==select,
  74. }" :key="i">
  75. <view class="chargeList-item-row">
  76. <u-icon name="qichexiangguan-chongdianzhan" custom-prefix="custom-icon" color="#1677ff"
  77. size="40"></u-icon>
  78. <p>名称</p>
  79. <span> {{item.name}}</span>
  80. </view>
  81. <view class="chargeList-item-row">
  82. <u-icon name="shoujichongdian" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  83. <p>通道数</p>
  84. <span>{{item.numOfChannel}}</span>
  85. <p>空闲</p>
  86. <span>{{item.availableNumOfChannel}}</span>
  87. </view>
  88. <!-- <view class="chargeList-item-row">
  89. <u-icon name="juli" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  90. <p>距离</p>
  91. <span>荆鹏软件园1号充电桩</span>
  92. </view>
  93. <view class="chargeList-item-row">
  94. <u-icon name="dizhi" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  95. <p>地址</p>
  96. <span>荆鹏软件园1号充电桩</span>
  97. </view> -->
  98. </view>
  99. </template>
  100. <view style="
  101. display: flex;
  102. " >
  103. <u-button type="success" size="medium" @click="navigate" v-if="selectStation.id&&selectStation.latitude&&selectStation.longitude" >点击查看地图导航</u-button>
  104. </view>
  105. </view>
  106. </view>
  107. </template>
  108. <script>
  109. import * as API from '@/apis/index.js'
  110. import * as WxJsApi from '@/utils/wxJsApi.js'
  111. export default {
  112. data() {
  113. return {
  114. list: [
  115. ],
  116. stationList:[],
  117. stationId: '',
  118. stationIdSelect: '',
  119. stationShow: false,
  120. select: '',
  121. selectBtnId: '',
  122. selectStation:{},
  123. index: false,
  124. stationName:'',
  125. isReady:false,
  126. isPoint:true,
  127. longitude: 0,
  128. latitude: 0,
  129. pageIndex: 1,
  130. recordsTotal: 0,
  131. keyword:"",
  132. selectList:[
  133. {id:0,name:"全部"},
  134. {id:2,name:"附近2公里"},
  135. {id:5,name:"附近5公里"},
  136. {id:10,name:"附近10公里"},
  137. {id:20,name:"附近20公里"},
  138. {id:50,name:"附近50公里"},
  139. ],
  140. current:[1],
  141. tabsFrom: {
  142. show1: false,
  143. show1Index: 2,
  144. show2Index: '',
  145. show2: false,
  146. show1Text: "附近2公里",
  147. show2Text: "全部时间",
  148. },
  149. }
  150. },
  151. onLoad(op) {
  152. if (op.id) {
  153. this.select = op.id;
  154. }
  155. if (op.stationId) {
  156. this.stationId = op.stationId;
  157. }
  158. if (op.index) {
  159. this.index = true;
  160. }
  161. WxJsApi.getWxConfig(['getLocation', 'addEventListener', 'scanQRCode', 'openLocation']).then((res) => {
  162. // //(res)
  163. this.isReady=true;
  164. }).catch(error => {
  165. //(res)
  166. })
  167. },
  168. onReachBottom() {
  169. if (this.stationList.length < this.recordsTotal) {
  170. this.myLoadmore();
  171. }
  172. },
  173. methods: {
  174. selector1confirm(e){
  175. console.log(e)
  176. var value = e[0].value
  177. var index=this.selectList.findIndex(item=>{
  178. return item.id==value
  179. })
  180. this.current=[index]
  181. this.tabsFrom.show1Index=e[0].value
  182. this.tabsFrom.show1Text=e[0].label
  183. this.searchStationData(1)
  184. },
  185. navigate() {
  186. // x
  187. // :
  188. // "112.276527"
  189. // y
  190. // :
  191. // "30.306427"
  192. //console.log(item)
  193. uni.showLoading({
  194. })
  195. WxJsApi.openLocation({
  196. latitude: this.selectStation.latitude, //目的地latitude
  197. longitude: this.selectStation.longitude, //目的地longitude
  198. name: this.selectStation.name,
  199. address: this.selectStation.address,
  200. scale: 15, //地图缩放大小,可根据情况具体调整
  201. success(res) {
  202. uni.hideLoading()
  203. },
  204. complete() {
  205. // uni.hideLoading()
  206. }
  207. });
  208. // //('station'+JSON.stringify(_self.stationDetail.station))
  209. // window.location.href = "https://uri.amap.com/marker?position=" + _self.stationDetail.station.longitude +
  210. // "," + _self.stationDetail.station.latitude + "&name=" + _self.stationDetail.station.name;
  211. },
  212. myLoadmore() {
  213. this.pageIndex += 1;
  214. this.searchStationData()
  215. },
  216. getPoint() {
  217. uni.showToast({
  218. title: "定位中...请打开定位设置",
  219. icon: "none"
  220. })
  221. WxJsApi.getLocation().then((res) => {
  222. this.isPoint=true;
  223. this.latitude = parseFloat(res.latitude);
  224. this.longitude = parseFloat(res.longitude);
  225. if (res.errMsg != 'getLocation:ok') {
  226. uni.showToast({
  227. title: res
  228. })
  229. } else {
  230. this.searchStationData()
  231. }
  232. }).catch(error => {
  233. this.isPoint=false;
  234. uni.showToast({
  235. title: error,
  236. icon: "none"
  237. })
  238. })
  239. },
  240. searchStationData(bl){
  241. if (bl) {
  242. this.stationList = [];
  243. this.pageIndex = 1;
  244. }
  245. uni.showLoading({
  246. title: "加载中",
  247. mask: true,
  248. })
  249. var data={
  250. longitude: this.longitude,
  251. latitude: this.latitude,
  252. pageIndex:this.pageIndex,
  253. pageSize:20,
  254. stationName:this.keyword
  255. }
  256. if(this.tabsFrom.show1Index){
  257. data.radius=this.tabsFrom.show1Index
  258. }
  259. API.chargingStationData(data).then((res) => {
  260. //this.stationList = res.data.data;
  261. this.stationList = [
  262. ...this.stationList,
  263. ...res.data.data
  264. ];
  265. this.stationShow = true;
  266. this.recordsTotal = res.data.recordsTotal
  267. uni.hideLoading()
  268. }).catch(error => {
  269. uni.showToast({
  270. title: error
  271. })
  272. })
  273. },
  274. customBack() {
  275. if(this.stationShow){
  276. try{
  277. this.stationShow=false
  278. //this.stationIdSelect=this.stationId
  279. this.getList()
  280. }catch(e){
  281. //TODO handle the exception
  282. uni.redirectTo({
  283. url: '/pages/charge/index'
  284. })
  285. }
  286. }else{
  287. uni.redirectTo({
  288. url: '/pages/charge/index'
  289. })
  290. }
  291. },
  292. selectStationBtn(item){
  293. this.stationIdSelect=item.id
  294. this.stationShow=false
  295. this.selectStation=item
  296. this.getList()
  297. },
  298. selectBtn() {
  299. this.selectBtnId = this.select;
  300. this.carhelp.set("qr-default-id", this.selectBtnId);
  301. uni.redirectTo({
  302. url: '/pages/charge/index?id=' + this.selectBtnId
  303. })
  304. },
  305. getList() {
  306. uni.showLoading({
  307. title: "加载中",
  308. mask: true,
  309. })
  310. var data = {
  311. //deviceId: this.select,
  312. pageIndex:this.pageIndex,
  313. stationId: this.stationIdSelect,
  314. pageSize: 50,
  315. };
  316. API.chargingDeviceData(data).then((res) => {
  317. console.log(res)
  318. this.list =res.data.data;
  319. if(this.list.length){
  320. this.stationName=this.list[0].stationName
  321. }
  322. uni.hideLoading()
  323. }).catch(error => {
  324. uni.showToast({
  325. title: error
  326. })
  327. })
  328. }
  329. },
  330. onReady() {
  331. if(this.stationId){
  332. this.stationIdSelect=this.stationId
  333. this.getList()
  334. }else{
  335. this.stationShow = true;
  336. this.getPoint()
  337. }
  338. },
  339. }
  340. </script>
  341. <style>
  342. page {
  343. background-color: #f7f7f7;
  344. }
  345. </style>
  346. <style lang="scss" scoped>
  347. .slot-wrap {
  348. display: flex;
  349. align-items: center;
  350. justify-content: space-between;
  351. flex: 1;
  352. }
  353. .navbar-right {
  354. display: flex;
  355. margin-right: 20rpx;
  356. align-items: center;
  357. color: #1677ff;
  358. }
  359. .chargeHead{
  360. padding:0 15px ;
  361. margin-top: 10px;
  362. span{
  363. float: right;
  364. color: #1677ff;
  365. }
  366. }
  367. .chargeHead2{
  368. padding:0 15px ;
  369. margin-top: 10px;
  370. justify-content: space-between;
  371. display: flex;
  372. .chargeHead2span{
  373. float: right;
  374. white-space: pre;
  375. color: #1677ff;
  376. margin-left: 20px;
  377. }
  378. }
  379. .chargeList-item {
  380. background-color: #fff;
  381. padding: 15px;
  382. margin: 10px;
  383. border-radius: 10px;
  384. .chargeList-item-row {
  385. display: flex;
  386. align-items: center;
  387. margin-bottom: 10px;
  388. &:last-child {
  389. margin-bottom: 0;
  390. }
  391. p {
  392. color: #999;
  393. white-space: pre;
  394. margin: 0 10px;
  395. }
  396. }
  397. }
  398. .chargeList-item.active {
  399. border: 1px solid #1677ff;
  400. }
  401. .head-head-placeholder{
  402. height: 100rpx;
  403. }
  404. .head-head{
  405. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.15);
  406. padding:24rpx;
  407. position: fixed;
  408. left: 0;
  409. right: 0;
  410. top: 80rpx;
  411. z-index: 991;
  412. .head-body{
  413. margin-top: 32rpx;
  414. display: flex;
  415. justify-content: space-around;
  416. .head-btn{
  417. text-align: center;
  418. width: 31%;
  419. padding: 12rpx;
  420. border: 1px solid #f2f2f2;
  421. background-color:#f2f2f2 ;
  422. border-radius: 6px;
  423. span{
  424. margin-left: 4rpx;
  425. }
  426. }
  427. .head-select{
  428. border: 1px solid #1677FF;
  429. background-color:#1677FF ;
  430. color: #fff;
  431. }
  432. }
  433. }
  434. </style>