terminal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <ax-body blank="0" hideIndicatorArea>
  3. <image src="@/static/img/page-bg01.png" class="page-background"></image>
  4. <view class="body" :class="{visit}">
  5. <!-- 主图 -->
  6. <view class="app-flex c-center host-graph">
  7. <image src="@/static/img/charging-01.png" mode="widthFix" class="image"></image>
  8. </view>
  9. <!-- 主参数 -->
  10. <view class="parameter">
  11. <view class="param"><view class="value">{{deviceInfo.current}}</view><view class="name">电流A</view></view>
  12. <view class="param"><view class="value">{{getVolt()}}</view><view class="name">电压V</view></view>
  13. <view class="param"><view class="value">{{deviceInfo.power}}</view><view class="name">功率KW</view></view>
  14. </view>
  15. <view class="block">
  16. <view class="card">
  17. <view class="title">终端信息</view>
  18. <view class="cell"><view class="lable">终端状态</view><view class="contet">{{getDeviceStatusLable(deviceInfo.deviceStatus)}}</view></view>
  19. <view class="cell"><view class="lable">终端编号</view><view class="contet">{{deviceInfo.deviceNo}}</view></view>
  20. <view class="cell"><view class="lable">充电电站</view><view class="contet">{{deviceInfo.thirdPartyStationName}}</view></view>
  21. <view class="cell"><view class="lable">充电终端</view><view class="contet">{{deviceInfo.deviceName}}</view></view>
  22. <view class="cell"><view class="lable">车位编号</view><view class="contet">{{deviceInfo.parkNo ? deviceInfo.parkNo : "无"}}</view></view>
  23. </view>
  24. </view>
  25. <view class="block">
  26. <view class="card">
  27. <view class="title">
  28. <text>费用信息</text>
  29. <view @click="$app.url.goto('/pages/site-more/site-more?show=1&stationId='+stationInfo.id)" class="more"><text>价格详情</text><icon class="ax-iconline i-arrow-right icon"></icon></view>
  30. </view>
  31. <view class="cell">
  32. <view class="lable">{{personal == 1?'当前电价':'集团折扣价'}}</view>
  33. <view class="contet app-flex middle">
  34. <view v-if="personal == 1"><text class="money">{{nowPriceTime.price?parseFloat(nowPriceTime.price).toFixed(4):"0.0000"}}</text><text> 元/度</text></view>
  35. <view v-else>
  36. <text class="obsolete"> {{nowPriceTime.price?parseFloat(nowPriceTime.price).toFixed(4):"0.0000"}} 元/度 </text>
  37. <text class="money">{{getCurrEcPrice()}}</text><text> 元/度</text>
  38. </view>
  39. </view>
  40. </view>
  41. <view class="cell" v-if="discountInfo&&personal == 1">
  42. <view class="lable">优惠</view>
  43. <view class="contet app-flex middle">
  44. <view>{{discountInfo.temp3}}<text class="money">{{discountInfo.discount?parseFloat(discountInfo.discount).toFixed(4):"0.0000"}}</text><text> 元/度</text></view>
  45. </view>
  46. </view>
  47. <view class="cell"><view class="lable">当前时段</view><view class="contet">{{getPriceLable(nowPriceTime.timeType)}} {{nowPriceTime.time}}</view></view>
  48. <!-- <view class="cell" style="height: auto;"><view class="lable">停车参考</view><view class="contet" style="flex: 1;padding-left: 5px;" v-html="stationInfo.parkTips"></view></view> -->
  49. <view class="cell"><view class="lable">停车参考</view><view class="contet">充电减免2小时停车费,超出时长部分计时收费</view></view>
  50. </view>
  51. </view>
  52. <view v-if="!visit" class="block">
  53. <view class="card">
  54. <view class="title">
  55. <text>我的抵扣券</text>
  56. <view class="more" v-if="isEc"><view class="switch" :class="{'personal':personal==1}"><text @click="changeAccount(1)">个人</text><text @click="changeAccount(2)">集团</text></view></view>
  57. </view>
  58. <view class="coupon" :class="{'personal':personal==1}">
  59. <view class="name">{{personal == 1?'充电抵扣券':'集团抵扣券'}}</view>
  60. <view class="feature"><view class="line"></view></view>
  61. <view class="info">
  62. <view class="value">{{accountInfo.balance}}</view>
  63. <view class="describe">剩余可抵扣充电费用 (元)</view>
  64. </view>
  65. </view>
  66. <view class="tips">
  67. <view class="li">1. 可抵扣按照当前电价进行预估计算</view>
  68. <view class="li">2. 实际结算价以具体充电时段为准</view>
  69. </view>
  70. </view>
  71. </view>
  72. <!-- 信息 -->
  73. <view class="footer">
  74. <view class="tips">账单信息可能会有所延迟,具体以实际结算为准</view>
  75. <view>
  76. <button @click="startup()" class="startup">启动终端充电</button>
  77. <ax-ios-indicator min="10"></ax-ios-indicator>
  78. </view>
  79. </view>
  80. </view>
  81. </ax-body>
  82. </template>
  83. <script>
  84. export default {
  85. onLoad(opts) {
  86. console.log("参数信息:",opts)
  87. /**
  88. * 判断终端是否占用状态
  89. * 判断占用终端设备的是不是用户自己
  90. */
  91. this.deviceId = opts.deviceId
  92. this.deviceStatus = opts.deviceStatus
  93. },
  94. onShow() {
  95. this.queryInChange(this.deviceId,this.deviceStatus);
  96. /**
  97. * 刷新用户信息
  98. */
  99. this.userInfo = this.$app.storage.get(this.$config.keyname.userInfo);
  100. if(!this.userInfo.phone){
  101. this.$app.url.goto('/pages/login/login')
  102. return;
  103. }
  104. this.$api.login({"checkStatus":1}).then(()=>{
  105. this.userInfo = this.$app.storage.get(this.$config.keyname.userInfo);
  106. if(this.userInfo.ecId){
  107. //查询该集团账户是否正常使用。
  108. this.$api.base("post","/chargeApi/queryEcInfo",{"ecId":this.userInfo.ecId},{}).then(res=>{
  109. if(res.ecInfo && res.ecInfo.ecStatus == 1){
  110. this.isEc = true;
  111. }
  112. })
  113. }
  114. })
  115. },
  116. mounted(){
  117. },
  118. data() {
  119. return {
  120. deviceId:0,
  121. deviceStatus:0,
  122. visit: '',
  123. personal: 1,// 1 个人订单 2 集团订单
  124. isEc : false,//是否集团的用户
  125. nowPriceTime : {},//当前价格时间段信息
  126. deviceInfo : {},//充电桩的信息
  127. accountInfo : {//账户信息
  128. balance : 0,//可用抵用券余额
  129. },
  130. userInfo : {},
  131. stationInfo : {},//站点信息
  132. orderInfo : {},//临时订单信息
  133. checkNum : 0,//检测订单状态次数
  134. ecInfo : {},//集团信息
  135. discountInfo:null//优惠信息
  136. }
  137. },
  138. methods: {
  139. //通过用户id查询是否还有在充电中的订单
  140. queryInChange(deviceId,deviceStatus){
  141. if(deviceStatus == 3 || deviceStatus == 4 ){
  142. //占用充电状态;终端占用且不是自己,进入访问模式
  143. this.visit = true;
  144. }
  145. this.getDeviceInfo(deviceId);//获取设备、站的详情信息
  146. this.getAccountInfo();//获取账户信息
  147. /* this.$api.base("post","/chargeApi/queryInChangeByUserId",{},{}).then(res=>{
  148. if(res.isChange == 1){
  149. this.orderInfo = res.orderInfo;
  150. //用户有充电中的订单
  151. //if(res.orderInfo.deviceId == deviceId){
  152. // 跳转
  153. this.$app.url.goto('/pages/charging/charging?orderId='+this.orderInfo.id+"&deviceId="+deviceId,false);
  154. //}
  155. }else{
  156. }
  157. }) */
  158. },
  159. //获取设备的详情信息
  160. getDeviceInfo(deviceId){
  161. this.$api.base("post","/chargeApi/getDevicesDetial",{"deviceId":deviceId},{}).then(res=>{
  162. this.deviceInfo = res.device;
  163. this.nowPriceTime = res.nowPriceTime;
  164. this.stationInfo = res.stationInfo;
  165. if(res.discountInfo){
  166. this.discountInfo = res.discountInfo
  167. }
  168. if(this.deviceInfo.tipsStatus==1){
  169. this.$app.popup.alert(this.deviceInfo.tipsContent,"温馨提示");
  170. }
  171. })
  172. },
  173. //获取账户信息
  174. getAccountInfo(){
  175. if(this.personal == 1){
  176. //获取个人账户信息
  177. this.$api.base("post","/chargeApi/getUserAccount",{},{}).then(res=>{
  178. this.accountInfo.balance = res.userAccount.balance;
  179. })
  180. }else{
  181. //获取集团账户信息
  182. this.$api.base("post","/chargeApi/getEcUserAccount",{},{error:false}).then(res=>{
  183. this.ecInfo = res.ecInfo;
  184. this.accountInfo.balance = res.ecUserAccount.balance;
  185. }).catch(err=>{
  186. this.accountInfo.balance = 0;
  187. this.$app.popup.alert(err.msg,"温馨提示");
  188. })
  189. }
  190. },
  191. //切换账户
  192. changeAccount(type){
  193. if(this.personal == type){
  194. return;
  195. }
  196. this.personal = type;
  197. this.getAccountInfo();
  198. },
  199. //当前集团折扣价
  200. getCurrEcPrice(){
  201. if(!this.nowPriceTime){
  202. return 0;
  203. }
  204. var currEcP = this.nowPriceTime.price;
  205. if(this.ecInfo && this.ecInfo.ecDiscount){
  206. var realServicePrice = this.nowPriceTime.servicePrice
  207. if(this.stationInfo.contractServicePrice){
  208. realServicePrice = this.stationInfo.contractServicePrice
  209. }
  210. currEcP = (this.nowPriceTime.electrovalence + realServicePrice + this.nowPriceTime.addServicePrice * this.ecInfo.ecDiscount/100);
  211. }
  212. console.log("dddd",currEcP)
  213. if(currEcP){
  214. currEcP = currEcP.toFixed(2);
  215. }
  216. return Number(currEcP).toFixed(4);
  217. },
  218. //转换出电压值
  219. getVolt(){
  220. if(!this.deviceInfo.power){
  221. return 0;
  222. }
  223. var v = this.deviceInfo.power/this.deviceInfo.current * 1000;
  224. return v;
  225. },
  226. //映射 峰 平 谷
  227. getPriceLable(type){
  228. //时间类型 1 谷 2 平 3 峰
  229. var str = "";
  230. switch (type){
  231. case 1:
  232. str = "谷";
  233. break;
  234. case 2:
  235. str = "平";
  236. break;
  237. case 3:
  238. str = "峰";
  239. break;
  240. }
  241. return str;
  242. },
  243. //映射订单状态名称()
  244. getDeviceStatusLable(status){
  245. //设备状态 0:离网1:空闲2:占用(未充电)3:占用(充电中)4:占用(预约锁定)255:故障
  246. var str = "";
  247. switch (status){
  248. case 0:
  249. str = "离网";
  250. break;
  251. case 1:
  252. str = "空闲";
  253. break;
  254. case 2:
  255. str = "占用";
  256. break;
  257. case 3:
  258. str = "占用";
  259. break;
  260. case 4:
  261. str = "占用";
  262. break;
  263. case 255:
  264. str = "故障";
  265. break;
  266. }
  267. return str;
  268. },
  269. startup(){
  270. if(this.visit){
  271. this.$app.popup.alert("该充电枪被占用或存在异常,请重新尝试或更换其他充电枪。","温馨提示");
  272. return;
  273. }
  274. //判断账户余额是否大于两元
  275. if((this.accountInfo.balance - 2) <= 0){
  276. return this.$app.popup.confirm("无法启动充电,抵扣余量需大于2元,请先购买充电券!","温馨提示!",{confirmText:"立即购券"}).then(confirm=>{
  277. if(confirm){
  278. this.$app.url.goto('/pages/coupon-buy/coupon-buy',true);
  279. }
  280. });
  281. }
  282. //统一下单并启动接口
  283. this.startChangeAndOrder();
  284. },
  285. //统一下单并启动接口
  286. startChangeAndOrder(){
  287. var obj = {
  288. userId : this.userInfo.id,
  289. deviceId : this.deviceInfo.id,
  290. orderType : this.personal == 2 ? 2 : 1,//订单类型 1 个人订单 2 集团订单
  291. }
  292. this.$api.base("post","/chargeApi/startChangeAndOrder",obj,{}).then(res=>{
  293. //下单成功,并进行了订单预充值
  294. this.orderInfo = res.orderInfo;
  295. if(res.flg && res.flg == 1){
  296. //用户有充电中的订单
  297. this.$app.popup.confirm("您有一个进行中充电订单,不可再次启动。",null,{showCancel:false,confirmText:"查看订单"}).then(cres=>{
  298. this.$app.url.goto('/pages/charging/charging?orderId='+this.orderInfo.id+"&deviceId="+this.deviceInfo.id,false);
  299. });
  300. }else{
  301. //正常启动充电订单
  302. this.$app.url.goto('/pages/charging/charging?orderId='+this.orderInfo.id+"&deviceId="+this.deviceInfo.id,false);
  303. }
  304. //this.$app.popup.loading(true,{title:"启动中...."})
  305. //延迟5s查询一下订单,看看是否真的启动成功
  306. //setTimeout(()=>this.checkedStartStatus(),5000);
  307. })
  308. },
  309. /* // 通过充电桩编号(sn)检测该设备是否插枪,是否可以进行后续的下单,启动操作
  310. checkDeviceReady(){
  311. this.$api.base("post","/chargeApi/checkDeviceReady",{"sn":this.deviceInfo.deviceNo},{}).then(res=>{
  312. if(res.code == 0){
  313. //充电桩已经插枪准备好了,可以进行下单充值操作
  314. this.chargeAndOrder();
  315. }
  316. })
  317. },
  318. // 进行下单,并进行接口充值,准备启动充电
  319. chargeAndOrder(){
  320. var obj = {
  321. userId : this.userInfo.id,
  322. deviceId : this.deviceInfo.id,
  323. orderType : this.personal == 2 ? 2 : 1,//订单类型 1 个人订单 2 集团订单
  324. }
  325. this.$api.base("post","/chargeApi/chargeAndOrder",obj,{}).then(res=>{
  326. if(res.code == 0){
  327. //下单成功,并进行了订单预充值
  328. this.orderInfo = res.orderInfo;
  329. //通知已经充值成功,可以进行设备充电的启动
  330. this.changePayAndStart();
  331. }
  332. })
  333. },
  334. // 支付成功启动充电通知
  335. changePayAndStart(){
  336. this.$api.base("post","/chargeApi/changePayAndStart",{"id":this.orderInfo.id},{}).then(res=>{
  337. if(res.code == 0){
  338. this.$app.popup.loading(ture,{title:"启动中...."})
  339. //延迟5s查询一下订单,看看是否真的启动成功
  340. setTimeout(()=>this.checkedStartStatus(),5000);
  341. }
  342. })
  343. }, */
  344. // 延迟5s查询一下订单,看看是否真的启动成功
  345. checkedStartStatus(){
  346. this.$api.base("post","/chargeApi/checkedStartStatus",{"id":this.orderInfo.id},{}).then(res=>{
  347. if(res.code == 0){
  348. var respObj = res.obj;
  349. if(respObj.code == 200){
  350. if(respObj.status == 1){
  351. uni.hideLoading();
  352. //状态为1说明正常启动
  353. this.$app.url.goto('/pages/charging/charging?orderId='+this.orderInfo.id+"&deviceId="+this.deviceInfo.id,false);
  354. }else{
  355. //其他状态,说明充电桩,未启动。或其他问题,需要再次进行进行验证
  356. if(this.checkNum < 20){
  357. this.checkNum = this.checkNum + 1;
  358. //延迟2s查询一下订单,看看是否真的启动成功
  359. setTimeout(()=>this.checkedStartStatus(),2000);
  360. }
  361. }
  362. }else{
  363. uni.hideLoading();
  364. this.$app.popup.alert(respObj.msg,"温馨提示");
  365. }
  366. }else{
  367. uni.hideLoading();
  368. }
  369. })
  370. },
  371. }
  372. }
  373. </script>
  374. <style scoped>
  375. @import url("terminal.css");
  376. </style>