index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <div class="page-container">
  3. <el-card>
  4. <div class="head-card">
  5. <div class="head-card-item">
  6. <div class="item">
  7. <div class="count" :class="{ dark: isDark }">{{ cardCount.org }}</div>
  8. <div class="label">区域统计</div>
  9. </div>
  10. <div class="logo">
  11. <img src="/@/assets/icon-org.png" class="img">
  12. </div>
  13. </div>
  14. <div class="head-card-item">
  15. <div class="item">
  16. <div class="count" :class="{ dark: isDark }">{{ cardCount.plot }}</div>
  17. <div class="label">小区统计</div>
  18. </div>
  19. <div class="logo">
  20. <img src="/@/assets/icon-plot.png" class="img">
  21. </div>
  22. </div>
  23. <div class="head-card-item">
  24. <div class="item">
  25. <div class="count" :class="{ dark: isDark }">{{ cardCount.resident }}</div>
  26. <div class="label">住户统计</div>
  27. </div>
  28. <div class="logo">
  29. <img src="/@/assets/icon-resident.png" class="img">
  30. </div>
  31. </div>
  32. </div>
  33. </el-card>
  34. <el-card class="mt-3">
  35. <div class="panel" :class="{ dark: isDark }">
  36. <div class="left-panel">
  37. <el-input v-model="filterText" size="default" placeholder="搜索区域" />
  38. <el-tree :data="treeList" node-key="id" default-expand-all :props="{
  39. children: 'children'
  40. }" @node-click="onNodeClick" :expand-on-click-node="false">
  41. <template #default="{ data }">
  42. <span class="custom-tree-node" :class="{ active: `${data.id}-${data.orgType}` === `${curNode.id}-${curNode.orgType}` }">
  43. <img src="/src/assets/icon-org.png" v-if="data.orgType === 'org'">
  44. <img src="/src/assets/icon-plot.png" v-else-if="data.orgType === 'plot'">
  45. <img src="/src/assets/icon-floor.png" v-else-if="data.orgType === 'floor'">
  46. <img src="/src/assets/icon-unit.png" v-else-if="data.orgType === 'unit'">
  47. <span class="name" :title="data.orgName">{{ data.orgName }}</span>
  48. </span>
  49. </template>
  50. </el-tree>
  51. </div>
  52. <div class="right-panel" :class="{ dark: isDark }">
  53. <!-- 小区 -->
  54. <Regional v-if="curNode.orgType === 'org'" :organizationId="curNode.id" @finish="initPage()" />
  55. <!-- 楼宇 -->
  56. <Floor v-else-if="curNode.orgType === 'plot'" :nodeId="curNode.id" @finish="initPage()" />
  57. <!-- 单元 -->
  58. <Unit v-else-if="curNode.orgType === 'floor'" :nodeId="curNode.id" @finish="initPage()" />
  59. <!-- 住户 -->
  60. <Resident v-else-if="curNode.orgType === 'unit'" :nodeId="curNode.id" @finish="initPage()" />
  61. </div>
  62. </div>
  63. </el-card>
  64. </div>
  65. </template>
  66. <script lang="ts">
  67. import { toRefs, reactive, onMounted, ref, defineComponent, watch } from 'vue';
  68. import { useStore } from '/@/store/index';
  69. import api from '/@/api/heatingDistrict';
  70. import Regional from './children/regional/index.vue'
  71. import Floor from './children/floor/index.vue'
  72. import Unit from './children/unit/index.vue'
  73. import Resident from './children/resident/index.vue'
  74. export default defineComponent({
  75. name: '',
  76. components: {
  77. Regional,
  78. Floor,
  79. Unit,
  80. Resident
  81. },
  82. setup() {
  83. const store = useStore();
  84. const treeList = ref([])
  85. const state = reactive({
  86. filterText: '',
  87. cardCount: {
  88. org: 0,
  89. plot: 0,
  90. resident: 0
  91. },
  92. curNode: {},
  93. isDark: false
  94. });
  95. // 获取区域树
  96. const getTreeData = () => {
  97. api.heatingDistrict.getTree({})
  98. .then((res: any) => {
  99. treeList.value = res || []
  100. if (!state.curNode.id) {
  101. state.curNode = treeList.value[0]
  102. }
  103. })
  104. }
  105. // 获取组织数量
  106. const getOrgCount = () => {
  107. api.heatingDistrict.getOrganizationCount({})
  108. .then((res: any) => {
  109. console.log(res)
  110. state.cardCount.org = res.Count
  111. })
  112. }
  113. // 获取小区数量
  114. const getPlotCount = () => {
  115. api.heatingDistrict.getPlotCount({})
  116. .then((res: any) => {
  117. console.log(res)
  118. state.cardCount.plot = res.Count
  119. })
  120. }
  121. // 获取组织数量
  122. const getResidentCount = () => {
  123. api.heatingDistrict.getResidentCount({})
  124. .then((res: any) => {
  125. console.log(res)
  126. state.cardCount.resident = res.Count
  127. })
  128. }
  129. const initPage = () => {
  130. getTreeData()
  131. getOrgCount()
  132. getPlotCount()
  133. getResidentCount()
  134. }
  135. const onNodeClick = (data: any, node: any) => {
  136. // console.log(data)
  137. // console.log(node)
  138. if (data.orgType === 'floor') {
  139. data.plotId = node.parent.data.id
  140. } else if (data.orgType === 'unit') {
  141. data.floorId = node.parent.data.id
  142. data.plotId = node.parent.parent.data.id
  143. }
  144. state.curNode = data
  145. }
  146. // 监听 vuex 中是否开启深色主题
  147. watch(
  148. () => store.state.themeConfig.themeConfig.isIsDark,
  149. (isIsDark) => {
  150. state.isDark = !!isIsDark;
  151. },
  152. {
  153. deep: true,
  154. immediate: true,
  155. }
  156. );
  157. // 页面加载时
  158. onMounted(() => {
  159. initPage()
  160. });
  161. return {
  162. treeList,
  163. onNodeClick,
  164. getTreeData,
  165. initPage,
  166. ...toRefs(state),
  167. };
  168. },
  169. });
  170. </script>
  171. <style lang="scss" scoped>
  172. .page-container {
  173. .panel {
  174. display: grid;
  175. grid-template-columns: 250px 1fr;
  176. border: 1px solid #ddd;
  177. &.dark {
  178. border: 1px solid rgb(51, 51, 51);
  179. }
  180. }
  181. .left-panel {
  182. padding: 20px;
  183. }
  184. .right-panel {
  185. display: flex;
  186. flex-direction: column;
  187. padding: 20px;
  188. border-left: 1px solid #ddd;
  189. position: relative;
  190. &.dark {
  191. border-left: 1px solid rgb(51, 51, 51);
  192. }
  193. }
  194. }
  195. .custom-tree-node {
  196. display: grid;
  197. grid-template-columns: 20px 1fr;
  198. align-items: center;
  199. img {
  200. width: 16px;
  201. height: 16px;
  202. }
  203. .name {
  204. overflow: hidden;
  205. text-overflow: ellipsis;
  206. }
  207. &.active {
  208. color: var(--el-color-primary);
  209. // background: var(--el-color-primary-light-9);
  210. }
  211. }
  212. .head-card {
  213. display: grid;
  214. grid-template-columns: 1fr 1fr 1fr;
  215. padding: 20px;
  216. &-item {
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. .item {
  221. text-align: center;
  222. .count {
  223. font-size: 32px;
  224. font-weight: 700;
  225. color: #101010;
  226. margin-bottom: 5px;
  227. &.dark {
  228. color: #dadada;
  229. }
  230. }
  231. }
  232. .logo {
  233. width: 72px;
  234. height: 72px;
  235. border-radius: 50%;
  236. // border: 1px solid #ddd;
  237. display: flex;
  238. align-items: center;
  239. justify-content: center;
  240. .img {
  241. width: 32px;
  242. height: 32px;
  243. }
  244. }
  245. }
  246. }
  247. :deep(.system-dic-container) {
  248. position: absolute;
  249. width: calc(100% - 40px);
  250. }
  251. </style>