switchDetail.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <view>
  3. <u-navbar :title="title" title-color="#101010"></u-navbar>
  4. <view class="control-group" v-if="role">
  5. <view class="control">
  6. <view class="text">
  7. 电源状态
  8. </view>
  9. <view class="icon" style=" display: flex;">
  10. <u-switch-jp size="42"
  11. :obj="{
  12. width: '4em',
  13. transform:'translateX(300%)',
  14. sz:['已关闭','已开启'],
  15. fontSize:'32rpx'
  16. }"
  17. @change="switchBtnApi(meterDetails.meter,$event)"
  18. v-model="meterDetails.meter.switchStatus" inactive-color="#ff9900" ></u-switch-jp >
  19. <!--
  20. <img src="@/assets/img/switchIcon.png"
  21. @tap.stop="switchBtnApi(meterDetails.meter,0)" class="img"
  22. v-if="meterDetails.meter.switchStatus" alt="" ></img >
  23. <img src="@/assets/img/switchClose.png"
  24. @tap.stop="switchBtnApi(meterDetails.meter,1)" class="img"
  25. v-else alt="" ></img > -->
  26. <!-- <img src="@/assets/img/control.png" alt="" /> -->
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 用电信息 -->
  31. <view class="electricity-information">
  32. <view class="title">
  33. <view class="text">
  34. 用电信息
  35. </view>
  36. <!-- <view class="more" @click="gotoUrl('/pages/tenantList/electricityInformation')">
  37. <u-icon name="arrow-right" size="24" color="#d4d4d4"></u-icon>
  38. </view> -->
  39. </view>
  40. <view class="infos">
  41. <view class="item" style="width: 30%;">
  42. <view class="item-value">
  43. {{meterDetails.thisDayKwh}}
  44. </view>
  45. <view class="item-title">
  46. 今日用电量(度)
  47. </view>
  48. </view>
  49. <view class="item" style="width: 30%;">
  50. <view class="item-value">
  51. {{meterDetails.thisMonthKwh}}
  52. </view>
  53. <view class="item-title">
  54. 当月用电量(度)
  55. </view>
  56. </view>
  57. <view class="item" style="width: 30%;">
  58. <view class="item-value" v-if="meterDetails.nowRecord">
  59. {{meterDetails.nowRecord.totalPower}}
  60. </view>
  61. <view class="item-title">
  62. 当前功率(千瓦)
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- 日志
  68. source=2 由他人分配的不能操作定时
  69. -->
  70. <view class="log" v-if="source!='2'" @click="gotoUrl('/pages/timing/timing?id='+meterId+'&title='+title)">
  71. <view class="icon">
  72. <u-icon name="clock" color="#fff" size="40" ></u-icon>
  73. </view>
  74. <view class="text">
  75. 供电管理
  76. </view>
  77. <view class="more">
  78. <u-icon name="arrow-right" size="32" color="#bbbbbb" ></u-icon>
  79. </view>
  80. </view>
  81. <view class="log" @click="gotoUrl('/pages/tenantList/operationLog?id='+meterId)">
  82. <view class="icon">
  83. <img src="@/assets/img/riLine-file-list-2-line.svg" alt="" />
  84. </view>
  85. <view class="text">
  86. 操作日志
  87. </view>
  88. <view class="more">
  89. <u-icon name="arrow-right" size="32" color="#bbbbbb" ></u-icon>
  90. </view>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. import * as API from '@/apis/pagejs/energyManage.js'
  96. import * as API_meterTimer from '@/apis/pagejs/meterTimer.js'
  97. export default {
  98. data() {
  99. return {
  100. codes:"",
  101. meterId:"",
  102. meterDetails:{},
  103. role:false,
  104. title:"",
  105. intervalId:"",
  106. getMeterReady:false,
  107. source:"",
  108. }
  109. },
  110. onLoad(op) {
  111. if(op.id){
  112. this.meterId=op.id;
  113. this.getMeter()
  114. }
  115. },
  116. onShow() {
  117. if(this.meterId&&this.getMeterReady){
  118. this.startInterval()
  119. }
  120. },
  121. onHide() {
  122. this.clearTimer()
  123. },
  124. methods: {
  125. clearTimer() {
  126. if (this.intervalId) {
  127. clearInterval(this.intervalId); // 清除定时器
  128. this.intervalId = null; // 重置定时器ID
  129. }
  130. },
  131. startInterval() {
  132. this.clearTimer(); // 组件销毁前清除定时器
  133. this.intervalId = setInterval(() => {
  134. this.getMeter(true)
  135. }, 60000);
  136. },
  137. switchBtnApiMethod(node,key){
  138. uni.showLoading({
  139. title: "加载中",
  140. mask: true,
  141. })
  142. API.remoteSwitch({
  143. meterId:node.id,
  144. enabled:key
  145. }).then((res) => {
  146. uni.hideLoading();
  147. node.switchStatus=key
  148. }).catch(error => {
  149. uni.showToast({
  150. title: error,
  151. icon: "none"
  152. })
  153. })
  154. },
  155. switchBtnApi(node,key){
  156. uni.showModal({
  157. confirmColor:`${key?'#3CC51F':'red'}`,
  158. confirmText:`${key?'开启':'关闭'}`,
  159. content: `确认是否要"${key?'开启':'关闭'}"${this.replaceLastTwoWords(node.name)}`,
  160. title: "提示",
  161. success:res=> {
  162. if(res.confirm){
  163. //this.switchBtnApiMethod(node,key);
  164. }else{
  165. node.switchStatus=!key
  166. }
  167. }
  168. })
  169. console.log(node,key)
  170. },
  171. getMeter(bl){
  172. if(!bl){
  173. uni.showLoading({
  174. title: "加载中",
  175. mask: true,
  176. })
  177. }
  178. API_meterTimer.meterDetails({
  179. meterId:this.meterId
  180. }).then((response) => {
  181. this.codes =this.carhelp.getPersonInfo().codes;
  182. this.role=this.codes&&this.codes.indexOf('switch')!=-1;
  183. this.meterDetails=response.data
  184. if(!bl){
  185. uni.hideLoading();
  186. }
  187. this.getMeterReady=true;
  188. if(this.meterDetails.meter){
  189. this.title=this.replaceLastTwoWords(this.meterDetails.meter.name)
  190. this.source=this.meterDetails.meter.source
  191. }
  192. }).catch(error => {
  193. uni.showToast({
  194. title: error,
  195. icon: "none"
  196. })
  197. })
  198. },
  199. }
  200. }
  201. </script>
  202. <style lang="scss" scoped>
  203. .control-group{
  204. margin: 24rpx 32rpx;
  205. padding: 40rpx 32rpx;
  206. background-color: #fff;
  207. border-radius: 8px;
  208. .control:first-of-type{
  209. margin-top: 0;
  210. }
  211. .control{
  212. display: flex;
  213. align-items: center;
  214. justify-content: space-between;
  215. margin-top: 56rpx;
  216. .text{
  217. color: rgba(51,51,51,1);
  218. font-size: 32rpx;
  219. font-weight: bold;
  220. }
  221. .icon{
  222. img{
  223. width: 64rpx;
  224. height: 64rpx;
  225. }
  226. }
  227. }
  228. }
  229. .electricity-information {
  230. margin: 24rpx 32rpx;
  231. padding: 40rpx 0rpx;
  232. background-color: #fff;
  233. border-radius: 8px;
  234. .title {
  235. display: flex;
  236. align-items: center;
  237. padding: 0 32rpx;
  238. margin-bottom: 40rpx;
  239. .text {
  240. display: flex;
  241. align-items: center;
  242. color: rgba(51, 51, 51, 1);
  243. font-size: 36rpx;
  244. margin-left: 16rpx;
  245. font-weight: bold;
  246. }
  247. .date {
  248. margin-left: auto;
  249. }
  250. .more {
  251. color: #838383;
  252. font-size: 24rpx;
  253. margin-left: auto;
  254. }
  255. }
  256. .chart {
  257. width: 100%;
  258. height: 440rpx;
  259. .img {
  260. width: 100%;
  261. height: 440rpx;
  262. }
  263. }
  264. .infos {
  265. padding: 0 32rpx;
  266. display: flex;
  267. justify-content: space-between;
  268. text-align: center;
  269. .item-title {
  270. color: rgba(119,119,119,1);
  271. font-size: 24rpx;
  272. margin-top: 8rpx;
  273. }
  274. .item-value {
  275. color: rgba(16, 16, 16, 1);
  276. font-size: 56rpx;
  277. margin-top: 16rpx;
  278. }
  279. }
  280. }
  281. .log{
  282. margin: 24rpx 32rpx;
  283. padding: 40rpx 32rpx;
  284. background-color: #fff;
  285. border-radius: 8px;
  286. display: flex;
  287. align-items: center;
  288. .icon{
  289. width: 88rpx;
  290. height: 88rpx;
  291. border-radius: 999px;
  292. background-color: rgba(22,119,255,1);
  293. display: flex;
  294. align-items: center;
  295. justify-content: center;
  296. img{
  297. width: 48rpx;
  298. height: 48rpx;
  299. }
  300. }
  301. .text{
  302. color: rgba(51,51,51,1);
  303. font-size: 32rpx;
  304. margin-left: 24rpx;
  305. font-weight: bold;
  306. }
  307. .more{
  308. margin-left: auto;
  309. }
  310. }
  311. </style>