switchDetail.vue 6.8 KB

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