tree-node.vue 8.6 KB

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