switchCharge.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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="stationIdSelect=item.id,stationShow=false,getList()" :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" v-if="false">
  27. <u-icon name="shoujichongdian" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  28. <p>空闲</p>
  29. <span>{{item.availableNumOfChannel}}</span>
  30. </view>
  31. <!-- <view class="chargeList-item-row">
  32. <u-icon name="juli" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  33. <p>位置</p>
  34. </view> -->
  35. <view class="chargeList-item-row">
  36. <u-icon name="dizhi" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  37. <p>地址</p>
  38. <span>{{item.address}}</span>
  39. </view>
  40. </view>
  41. </template>
  42. </view>
  43. <view class="chargeList" v-show="!stationShow">
  44. <view style="text-align: center;margin-top: 100px" v-if="!list.length">
  45. <img src="@/assets/img/blankpage.png">
  46. <p>暂无充电桩</p>
  47. <p><span style="color: #1677ff;" @click="getPoint()">查询附近站点</span></p>
  48. </view>
  49. <view class="chargeHead" v-if="list.length" >{{stationName}}<span @click="getPoint()">查询附近站点</span></view>
  50. <template v-for="(item,i) in list">
  51. <view class="chargeList-item " @click="select=item.id,selectBtn()" :class="{
  52. 'active':item.id==select,
  53. }" :key="i">
  54. <view class="chargeList-item-row">
  55. <u-icon name="qichexiangguan-chongdianzhan" custom-prefix="custom-icon" color="#1677ff"
  56. size="40"></u-icon>
  57. <p>名称</p>
  58. <span> {{item.name}}</span>
  59. </view>
  60. <view class="chargeList-item-row">
  61. <u-icon name="shoujichongdian" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  62. <p>通道数</p>
  63. <span>{{item.numOfChannel}}</span>
  64. <p>空闲</p>
  65. <span>{{item.availableNumOfChannel}}</span>
  66. </view>
  67. <!-- <view class="chargeList-item-row">
  68. <u-icon name="juli" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  69. <p>距离</p>
  70. <span>荆鹏软件园1号充电桩</span>
  71. </view>
  72. <view class="chargeList-item-row">
  73. <u-icon name="dizhi" custom-prefix="custom-icon" color="#1677ff" size="40"></u-icon>
  74. <p>地址</p>
  75. <span>荆鹏软件园1号充电桩</span>
  76. </view> -->
  77. </view>
  78. </template>
  79. </view>
  80. </view>
  81. </template>
  82. <script>
  83. import * as API from '@/apis/index.js'
  84. import * as WxJsApi from '@/utils/wxJsApi.js'
  85. export default {
  86. data() {
  87. return {
  88. list: [
  89. ],
  90. stationList:[],
  91. stationId: '',
  92. stationIdSelect: '',
  93. stationShow: false,
  94. select: '',
  95. selectBtnId: '',
  96. index: false,
  97. stationName:'',
  98. isReady:false,
  99. isPoint:true,
  100. longitude: 0,
  101. latitude: 0,
  102. }
  103. },
  104. onLoad(op) {
  105. if (op.id) {
  106. this.select = op.id;
  107. }
  108. if (op.stationId) {
  109. this.stationId = op.stationId;
  110. }
  111. if (op.index) {
  112. this.index = true;
  113. }
  114. WxJsApi.getWxConfig(['getLocation', 'addEventListener', 'scanQRCode']).then((res) => {
  115. // //(res)
  116. this.isReady=true;
  117. }).catch(error => {
  118. //(res)
  119. })
  120. },
  121. methods: {
  122. getPoint() {
  123. uni.showToast({
  124. title: "定位中...请打开定位设置",
  125. icon: "none"
  126. })
  127. WxJsApi.getLocation().then((res) => {
  128. this.isPoint=true;
  129. this.latitude = parseFloat(res.latitude);
  130. this.longitude = parseFloat(res.longitude);
  131. if (res.errMsg != 'getLocation:ok') {
  132. uni.showToast({
  133. title: res
  134. })
  135. } else {
  136. this.searchStationData()
  137. }
  138. }).catch(error => {
  139. this.isPoint=false;
  140. uni.showToast({
  141. title: error,
  142. icon: "none"
  143. })
  144. })
  145. },
  146. searchStationData(){
  147. uni.showLoading({
  148. title: "加载中",
  149. mask: true,
  150. })
  151. var data={
  152. longitude: this.longitude,
  153. latitude: this.latitude,
  154. pageSize:50,
  155. raidus:2,
  156. }
  157. API.chargingStationData(data).then((res) => {
  158. this.stationList = res.data.data;
  159. this.stationShow = true;
  160. uni.hideLoading()
  161. }).catch(error => {
  162. uni.showToast({
  163. title: error
  164. })
  165. })
  166. },
  167. customBack() {
  168. if(this.stationShow&&this.stationId){
  169. this.stationShow=false
  170. this.stationIdSelect=stationId
  171. this.getList()
  172. }else{
  173. uni.redirectTo({
  174. url: '/pages/charge/index'
  175. })
  176. }
  177. },
  178. selectBtn() {
  179. this.selectBtnId = this.select;
  180. this.carhelp.set("qr-default-id", this.selectBtnId);
  181. uni.redirectTo({
  182. url: '/pages/charge/index?id=' + this.selectBtnId
  183. })
  184. },
  185. getList() {
  186. uni.showLoading({
  187. title: "加载中",
  188. mask: true,
  189. })
  190. var data = {
  191. //deviceId: this.select,
  192. stationId: this.stationIdSelect,
  193. pageSize: 50,
  194. };
  195. API.chargingDeviceData(data).then((res) => {
  196. console.log(res)
  197. this.list =res.data.data;
  198. if(this.list.length){
  199. this.stationName=this.list[0].stationName
  200. }
  201. this.recordsTotal = res.data.recordsTotal
  202. uni.hideLoading()
  203. }).catch(error => {
  204. uni.showToast({
  205. title: error
  206. })
  207. })
  208. }
  209. },
  210. onReady() {
  211. if(this.stationId){
  212. this.stationIdSelect=this.stationId
  213. this.getList()
  214. }else{
  215. this.stationShow = true;
  216. this.getPoint()
  217. }
  218. },
  219. }
  220. </script>
  221. <style>
  222. page {
  223. background-color: #f7f7f7;
  224. }
  225. </style>
  226. <style lang="scss" scoped>
  227. .slot-wrap {
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-between;
  231. flex: 1;
  232. }
  233. .navbar-right {
  234. display: flex;
  235. margin-right: 20rpx;
  236. align-items: center;
  237. color: #1677ff;
  238. }
  239. .chargeHead{
  240. padding:0 15px ;
  241. margin-top: 10px;
  242. span{
  243. float: right;
  244. color: #1677ff;
  245. }
  246. }
  247. .chargeList-item {
  248. background-color: #fff;
  249. padding: 15px;
  250. margin: 10px;
  251. border-radius: 10px;
  252. .chargeList-item-row {
  253. display: flex;
  254. align-items: center;
  255. margin-bottom: 10px;
  256. &:last-child {
  257. margin-bottom: 0;
  258. }
  259. p {
  260. color: #999;
  261. margin: 0 10px;
  262. }
  263. }
  264. }
  265. .chargeList-item.active {
  266. border: 1px solid #1677ff;
  267. }
  268. </style>