switchDetail.vue 7.2 KB

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