chargeDetail.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <script setup lang="ts">
  2. import { ScanCodeUtil, formatStatusName } from '../utils/index'
  3. import router from '@/router'
  4. import { StaticUrl } from '@/config'
  5. const { statusBarHeight, MenuButtonHeight } = storeToRefs(useSysStore())
  6. const activeTab = ref('price')
  7. definePage({
  8. name: 'charge-detail',
  9. islogin: false,
  10. style: {
  11. navigationBarTitleText: '充电详情',
  12. navigationStyle: 'custom',
  13. },
  14. })
  15. const stationId = ref()
  16. onLoad((options: any) => {
  17. stationId.value = Number(options.stationId)
  18. activeTab.value = options.type
  19. })
  20. onMounted(() => {
  21. getPricesList()
  22. getConnectorsList()
  23. })
  24. const priceDetail = ref<Api.chargeStationPrices>()
  25. async function getPricesList() {
  26. const res = await Apis.charge.prices({ data: { stationId: stationId.value } })
  27. priceDetail.value = res.data
  28. }
  29. const connectorsDetail = ref<Api.chargeStationConnectors>()
  30. async function getConnectorsList() {
  31. const res = await Apis.charge.connectors({ data: { stationId: stationId.value } })
  32. connectorsDetail.value = res.data
  33. }
  34. /**
  35. * 处理站点设备状态
  36. *status 状态:0-离线 1-空闲 2-占用
  37. */
  38. function getStatusImageByStatus(deviceStatus: number) {
  39. switch (deviceStatus) {
  40. case 1: // 空闲
  41. return 'kx'
  42. case 2: // 占用
  43. return 'zy'
  44. case 3: // 占用
  45. return 'zy'
  46. case 0: // 离线
  47. return 'lx'
  48. default:
  49. return 'unknown'
  50. }
  51. }
  52. // 切换选项卡的方法
  53. function switchTab(tab: string) {
  54. activeTab.value = tab
  55. }
  56. // 计算样式的方法
  57. function getTabStyle(tab: string) {
  58. return activeTab.value === tab
  59. ? { background: '#9ED605', color: '#FFF' }
  60. : {}
  61. }
  62. async function getDeviceInfo(connectorCode: string) {
  63. useGlobalLoading().loading({})
  64. const res = await Apis.charge.connectorDetail({ data: { connectorCode } })
  65. useGlobalLoading().close()
  66. if (res.data.status === 0 || res.data.status === 255) {
  67. useGlobalMessage().alert('此设备异常或被占用,请更换其他设备')
  68. }
  69. else {
  70. router.push({ name: 'charge-start', params: { connectorCode } })
  71. }
  72. }
  73. async function scanCode() {
  74. try {
  75. const connectorCode = await ScanCodeUtil.scanAndGetConnectorCode()
  76. if (!connectorCode) {
  77. useGlobalMessage().alert('二维码不正确')
  78. return
  79. }
  80. // 获取设备信息
  81. getDeviceInfo(connectorCode)
  82. }
  83. catch (error) {
  84. console.error('扫码失败:', error)
  85. }
  86. }
  87. </script>
  88. <template>
  89. <view class="charge-detail-page min-h-screen bg-[linear-gradient(90deg,#F1FECC_0%,#EAFEFA_100%)]">
  90. <wd-navbar
  91. title="充电详情" custom-style="background: linear-gradient(90deg, #F1FECC 0%, #EAFEFA 100%);"
  92. :bordered="false" :z-index="999" safe-area-inset-top left-arrow fixed @click-left="router.back()"
  93. />
  94. <view :style="{ paddingTop: `${(Number(statusBarHeight) || 44) + MenuButtonHeight + 12}px` }" />
  95. <view class="content-page box-border px24rpx">
  96. <view class="flex items-center justify-between">
  97. <view>
  98. <view class="text-32rpx font-bold">
  99. {{ priceDetail?.stationName }}
  100. </view>
  101. <view class="mt-16rpx text-24rpx text-#AAA">
  102. {{ priceDetail?.tips || '--' }}
  103. </view>
  104. </view>
  105. <view>
  106. <image class="h-132rpx w-140rpx" :src="`${StaticUrl}/site-name-icon.png`" />
  107. </view>
  108. </view>
  109. <view class="items-centerrounded-16rpx mt-20rpx flex bg-#FFF p-20rpx">
  110. <view class="w-230rpx text-center">
  111. <view class="text-32rpx text-#9ED605 font-bold">
  112. {{ connectorsDetail?.idleCount }}
  113. </view>
  114. <view class="text-24rpx font-500">
  115. 空闲
  116. </view>
  117. </view>
  118. <view class="h-76rpx w-2rpx bg-#F0F0F0" />
  119. <view class="w-230rpx text-center">
  120. <view class="text-32rpx text-#9ED605 font-bold">
  121. {{ connectorsDetail?.occupiedCount }}
  122. </view>
  123. <view class="text-24rpx font-500">
  124. 占用
  125. </view>
  126. </view>
  127. <view class="h-76rpx w-2rpx bg-#F0F0F0" />
  128. <view class="w-230rpx text-center">
  129. <view class="text-32rpx text-#9ED605 font-bold">
  130. {{ connectorsDetail?.offlineCount }}
  131. </view>
  132. <view class="text-24rpx font-500">
  133. 离线
  134. </view>
  135. </view>
  136. </view>
  137. <view class="mt-28rpx">
  138. <view class="flex items-center justify-between rounded-42rpx bg-#FFF p-6rpx">
  139. <view
  140. class="h-80rpx w-348rpx rounded-60rpx text-center line-height-[80rpx]" :style="getTabStyle('price')"
  141. @click="switchTab('price')"
  142. >
  143. 电站价格
  144. </view>
  145. <view
  146. class="h-80rpx w-348rpx rounded-60rpx text-center line-height-[80rpx]" :style="getTabStyle('terminal')"
  147. @click="switchTab('terminal')"
  148. >
  149. 充电终端
  150. </view>
  151. </view>
  152. </view>
  153. <view v-if="activeTab == 'price'">
  154. <view
  155. v-for="item in priceDetail?.priceList" :key="item.timePeriod"
  156. class="mt-20rpx rounded-16rpx bg-#FFF p-24rpx"
  157. :style="{ border: item.currentPeriod ? '2rpx solid #9ED605' : '' }"
  158. >
  159. <view class="relative flex items-center justify-between">
  160. <view class="flex items-center gap-20rpx">
  161. <view
  162. class="h-40rpx w-40rpx rounded-8rpx bg-#CCC text-center text-28rpx text-#FFF font-bold line-height-[40rpx]"
  163. >
  164. {{ item.periodFlagName }}
  165. </view>
  166. <view class="text-28rpx font-bold">
  167. {{ item.timePeriod }}
  168. </view>
  169. </view>
  170. <view
  171. v-if="item.currentPeriod"
  172. class="absolute h-40rpx w-152rpx rounded-[0_16rpx_0_16rpx] bg-[linear-gradient(99deg,#D2F670_0%,#9ED605_100%)] text-center text-28rpx text-#FFF font-600 -right-24rpx -top-24rpx"
  173. >
  174. 当前时段
  175. </view>
  176. </view>
  177. <view class="mt-24rpx rounded-16rpx bg-#F6F6F6 p-20rpx">
  178. <view class="flex items-center justify-between">
  179. <view class="text-24rpx text-#222222">
  180. 抵扣券电价
  181. </view>
  182. <view
  183. class="text-24rpx"
  184. :style="{ color: item.currentPeriod ? '#FF6464' : '', fontWeight: item.currentPeriod ? '800' : '' }"
  185. >
  186. <text>{{ item.totalPrice }}</text>
  187. <text class="text-#AAA">
  188. 元/度
  189. </text>
  190. </view>
  191. </view>
  192. </view>
  193. </view>
  194. </view>
  195. <view v-if="activeTab == 'terminal'">
  196. <view
  197. v-for="item in connectorsDetail?.connectorList" :key="item.connectorId"
  198. class="mt-20rpx flex items-center gap-20rpx rounded-16rpx bg-#FFF p-20rpx"
  199. @click="router.push({ name: 'charge-start', params: { connectorCode: item.connectorCode } })"
  200. >
  201. <view
  202. class="h-116rpx w-116rpx text-center"
  203. :style="{ backgroundImage: `url(${StaticUrl}/site-status-${getStatusImageByStatus(item.status)}.png)`, backgroundSize: 'cover', backgroundPosition: 'center' }"
  204. >
  205. <image class="mt-20rpx h-38rpx w-27.18rpx" :src="`${StaticUrl}/terminal-icon.png`" />
  206. <view class="text-24rpx font-bold">
  207. {{ formatStatusName(item.statusName) }}
  208. </view>
  209. </view>
  210. <view>
  211. <view class="text-bold text-28rpx">
  212. {{ item.connectorName }}
  213. </view>
  214. <view class="mt-4rpx text-24rpx text-#AAA">
  215. 电类分类:{{ item.equipmentType }}
  216. </view>
  217. <view class="mt-4rpx w-400rpx overflow-hidden truncate whitespace-nowrap text-24rpx text-#AAA">
  218. 终端编号:{{ item.connectorCode }}
  219. </view>
  220. </view>
  221. </view>
  222. </view>
  223. </view>
  224. <view class="h-180rpx" />
  225. <view
  226. class="fixed bottom-66rpx left-24rpx h-100rpx w-702rpx rounded-16rpx bg-[linear-gradient(90deg,#DBFC81_0%,#9ED605_100%)] text-center text-28rpx font-800 line-height-[100rpx] shadow-[inset_0rpx_6rpx_20rpx_2rpx_#FFFFFF]"
  227. @click="scanCode"
  228. >
  229. 扫码充电
  230. </view>
  231. </view>
  232. </template>
  233. <style lang="scss" scoped></style>