switchCharge.vue 9.2 KB

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