tree-node.vue 9.3 KB

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