tree-node.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="tree-node ">
  3. <view class=" sum " :class="{
  4. node0:level==0
  5. }" >
  6. <view class=" meter-statistic-main" >
  7. <view class="icon" @click="toggle" v-if="node.childMeterList&&node.childMeterList.length" >
  8. <u-icon name="arrow-up" color="rgb(164 156 156)" v-show="isOpen" size="24"></u-icon>
  9. <u-icon name="arrow-down" color="rgb(164 156 156)" v-show="!isOpen" size="24"></u-icon>
  10. </view>
  11. <view class="icon" v-else >
  12. <u-icon name="arrow-rightward" v-if="level!=0" color="#fcfafa" size="24"></u-icon>
  13. </view>
  14. <view class="meter-name" :style="level==0||level==1?'font-weight: bold;':''"
  15. @click="toggle" >{{replaceLastTwoWords( node.name )}}</view>
  16. <view class="meter-number" v-if="(node.level==0&&showPark)||node.level!=0"
  17. :style="node.type==6?'padding-right: 36rpx;':''"
  18. @click="toElectronicMonitoring(node)">
  19. {{node.kwh}}度
  20. <u-icon name="arrow-right" v-if="node.type!=6"
  21. color="#d4d4d4" size="24"></u-icon>
  22. </view>
  23. </view>
  24. <view class="sum3" v-if="level==0">
  25. <template v-if="rootnode.type!='6'&&rootnode.type!='7'" >
  26. <view class="meter-state" v-if="node.online">
  27. 在线
  28. </view>
  29. <view class="meter-state meter-state2" v-else>
  30. 离线
  31. </view>
  32. </template>
  33. <view class="meter-state supplyType1" v-if="rootnode.supplyType=='1'">
  34. 转供电
  35. </view>
  36. <view class="meter-state supplyType2" v-if="rootnode.supplyType=='2'">
  37. 直供电
  38. </view>
  39. </view>
  40. <view class="sum2" v-if="childInfo.styleTemplate=='1'&&node.level==0&& node.childMeterList && node.childMeterList.length > 0" >
  41. <view class="title">
  42. 一级表计电量
  43. </view>
  44. <view class="value" :style="node.childKwh<node.kwh*0.999?'color:red!important':''">
  45. {{node.childKwh}}度
  46. </view>
  47. </view>
  48. <view class="sum2" v-if="childInfo.styleTemplate=='2'&&node.level==0&& node.childMeterList && node.childMeterList.length > 0" >
  49. <view class="title">
  50. 代缴费用户合计电量
  51. </view>
  52. <view class="value" >
  53. {{node.replaceKwh}}度
  54. </view>
  55. </view>
  56. <view class="tags" v-if="level!=0">
  57. <view class="tagsList">
  58. <template v-if="node.type!='7'" >
  59. <view class="meter-state" v-if="node.online">
  60. 在线
  61. </view>
  62. <view class="meter-state meter-state2" v-else>
  63. 离线
  64. </view>
  65. </template>
  66. <view class="meter-state " v-if="childInfo.styleTemplate=='2'&&node.type!=7"
  67. :class="'paymentMode'+node.paymentMode" >{{node.paymentMode==1?'代缴费':''}}{{node.paymentMode==2?'自缴费':''}}</view>
  68. <view class="meter-state"
  69. :style="{
  70. borderColor:colorList[node.type%colorList.length],
  71. background:colorList[node.type%colorList.length],
  72. color:'#fff',
  73. }"
  74. >
  75. {{node.typeN}}
  76. </view>
  77. <view class="icon icon2" :class="{
  78. icon6:node.type==6,
  79. iconSwitch1:node.switchStatus,
  80. iconSwitch0:!node.switchStatus,
  81. }" v-if="level!=0&&role&&node.type!=6&&node.allowSwitch" >
  82. <img src="@/assets/img/switchIcon.png"
  83. @click="switchBtn(node,0)"
  84. v-if="node.switchStatus" alt="" />
  85. <img src="@/assets/img/switchClose.png"
  86. @click="switchBtn(node,1)"
  87. v-else alt="" />
  88. </view>
  89. <view v-if="node.tag" class="meter-state" v-for="(item ,i) in getTags(node.tag)"
  90. :key="i"
  91. :style="{
  92. borderColor:item.color,
  93. background:item.color,
  94. color:'#fff',
  95. }">
  96. {{item.name}}
  97. </view>
  98. </view>
  99. <view class="operationList">
  100. <!-- <u-switch size="32" @change="switchBtn(node,$event)" v-model="node.switchStatus" inactive-color="#ff9900" ></u-switch >-->
  101. </view>
  102. </view>
  103. </view>
  104. <view class="sum first-level" :class="{
  105. 'first-level-node0':level==0
  106. }"
  107. v-if="isOpen && node.childMeterList && node.childMeterList.length > 0">
  108. <tree-node @query="query" :role="role"
  109. v-for="(child, index) in node.childMeterList"
  110. :key="index" @switchBtn="switchBtn" :level="level+1"
  111. :node="child" :rootnode="rootnode" :childInfo="childInfo"
  112. ></tree-node>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. export default {
  118. name: 'TreeNode',
  119. props: {
  120. node: Object,
  121. role:false,
  122. level:0,
  123. showPark:false,
  124. rootnode: Object, //根节点
  125. childInfo: Object, //公司属性
  126. },
  127. data() {
  128. return {
  129. isOpen: false,
  130. isInit: false,
  131. colorList:['#9C27B0',"#52b8aa","#53b56b","#ef8132",
  132. "#307af6","#52b8aa","#777777",'#f44336','#e91e63','#009688','#607d8b','#795548'],
  133. };
  134. },
  135. mounted() {
  136. //console.log("mountedmountedmounted")
  137. if(this.level==0){
  138. this.toggle()
  139. }
  140. },
  141. methods: {
  142. getTags(tag){
  143. if(!tag){
  144. return []
  145. }
  146. var sz=[]
  147. var str1=tag.split(',')
  148. for(var i in str1){
  149. if(str1[i].indexOf('#')>-1){
  150. var str2=str1[i].split('#');
  151. console.log(str2[1],typeof(str2[1]))
  152. var num =parseInt(str2[1])
  153. if(!isNaN(num)){
  154. sz.push({
  155. name:str2[0],
  156. color:this.colorList[num%this.colorList.length]
  157. })
  158. }else{
  159. sz.push({
  160. name:str2[0],
  161. color:'#'+str2[1]
  162. })
  163. }
  164. }
  165. }
  166. return sz
  167. },
  168. switchBtn(node,key){
  169. this.$emit('switchBtn',node,key)
  170. },
  171. toElectronicMonitoring(item) {
  172. if(item.type!=6){
  173. uni.navigateTo({
  174. url: '/pages/equipmentDataMonitoring/electronicMonitoring?id=' + item.id + '&name=' + item
  175. .name +
  176. '&companyId=' + item.companyId
  177. })
  178. }
  179. },
  180. query(item){
  181. this.$emit('query',item)
  182. },
  183. toggle() {
  184. this.isOpen = !this.isOpen;
  185. if(!this.isInit){
  186. this.isInit=true;
  187. this.$emit('query',this.node)
  188. }
  189. }
  190. }
  191. };
  192. </script>
  193. <style lang="scss" scoped>
  194. .tree-node {
  195. margin-top: 24rpx;
  196. ;
  197. }
  198. .meter-statistic-node {
  199. //margin-top: 32rpx;
  200. //padding-top: 12rpx;
  201. padding-bottom: 20px;
  202. background-color: #fcfafa;
  203. .meter-statistic-main{
  204. display: flex;
  205. align-items: center;
  206. }
  207. .sum {
  208. .meter-name {
  209. color: rgba(51, 51, 51, 1);
  210. font-size: 32rpx;
  211. }
  212. .icon {
  213. margin-right: 16rpx;
  214. img {
  215. width: 32rpx;
  216. height: 32rpx;
  217. vertical-align: middle;
  218. }
  219. }
  220. .icon2 {
  221. padding: 2rpx 20rpx;
  222. margin-right: 8rpx;
  223. border-radius: 8rpx;
  224. display: flex;
  225. align-items: center;
  226. }
  227. .iconSwitch1{
  228. background: #307af7;
  229. border: 1px solid #307af7;
  230. }
  231. .iconSwitch0{
  232. background: #e1e6ee;
  233. border: 1px solid #bfc4cd;
  234. }
  235. .icon6{
  236. //width: 40rpx;
  237. }
  238. .meter-state {
  239. margin:0 8rpx;
  240. //width: 64rpx;
  241. min-height: 40rpx;
  242. //line-height: 36rpx;
  243. //border-radius: 8rpx;
  244. border-radius: 4px;
  245. background-color: #fcfafa;;
  246. color: rgba(0, 185, 98, 1);
  247. font-size: 22rpx;
  248. text-align: center;
  249. padding: 0 8rpx;
  250. border: 1px solid rgba(0, 185, 98, 1);
  251. white-space: pre;
  252. display: flex;
  253. align-items: center;
  254. }
  255. .meter-state2 {
  256. border: 1px solid rgba(255, 123, 0, 1);
  257. color: rgba(255, 123, 0, 1);
  258. }
  259. .paymentMode1{
  260. color: rgba(255,255,255,1);
  261. background-color: rgba(22,119,255,1);
  262. border: 1px solid rgba(22,119,255,1);
  263. }
  264. .paymentMode2{
  265. color: rgba(255,255,255,1);
  266. background-color: rgba(129,97,255,1);
  267. border: 1px solid rgba(129,97,255,1);
  268. }
  269. .supplyType1{
  270. border: 1px solid rgba(255, 123, 0, 1);
  271. color: rgba(255, 123, 0, 1);
  272. }
  273. .supplyType2{
  274. }
  275. .meter-number {
  276. margin-left: auto;
  277. color: rgba(51, 51, 51, 1);
  278. font-size: 32rpx;
  279. white-space: pre;
  280. /deep/.u-icon--right {
  281. margin:0 8rpx;
  282. }
  283. }
  284. .tags{
  285. display: flex;
  286. padding: 0rpx 32rpx;
  287. margin-top: 8rpx;
  288. justify-content: space-between;
  289. .tagsList{
  290. display: flex;
  291. flex-wrap: wrap;
  292. .meter-state{
  293. margin-bottom: 4rpx;
  294. }
  295. }
  296. .operationList{
  297. display: flex;
  298. }
  299. }
  300. }
  301. .sum3 {
  302. padding: 0 40rpx;
  303. margin-top: 8rpx;
  304. display: flex;
  305. align-items: center;
  306. .title {
  307. color: rgba(119, 119, 119, 1);
  308. }
  309. .value {
  310. color: rgba(119, 119, 119, 1);
  311. }
  312. }
  313. .sum2 {
  314. padding: 0 40rpx;
  315. margin-top: 8rpx;
  316. display: flex;
  317. align-items: center;
  318. justify-content: space-between;
  319. .title {
  320. color: rgba(119, 119, 119, 1);
  321. }
  322. .value {
  323. color: rgba(119, 119, 119, 1);
  324. }
  325. }
  326. .first-level-list{
  327. width: 100%;
  328. display: flex;
  329. align-items: center;
  330. }
  331. // 一级表
  332. .first-level {
  333. padding-left: 32rpx;
  334. margin-top: 20rpx;
  335. .meter-name {
  336. font-size: 32rpx;
  337. overflow: hidden;
  338. white-space: nowrap;
  339. text-overflow: ellipsis;
  340. }
  341. }
  342. // 二级表
  343. .second-level {
  344. padding-left: 64rpx;
  345. margin-top: 20rpx;
  346. .meter-name {
  347. font-size: 24rpx;
  348. }
  349. }
  350. .else-switch {
  351. padding-left: 144rpx;
  352. .meter-name {
  353. font-size: 24rpx
  354. }
  355. .item {
  356. margin-top: 24rpx;
  357. }
  358. }
  359. .node0{
  360. padding:24rpx;
  361. background: linear-gradient(180deg, rgba(22,119,255,1) 0%,rgba(93,160,255,1) 100%);
  362. .meter-name,.meter-number,/deep/.u-iconfont,.title,.value{
  363. color:#fff !important;
  364. }
  365. }
  366. .first-level-node0{
  367. padding-left: 16rpx;
  368. }
  369. }
  370. </style>