LineTree.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <template>
  2. <div>
  3. <div class="traBox">
  4. <span
  5. style="line-height: 22px;height: 22px;float: left;width: 92%;margin: 4%;font-weight: bold;border-bottom: 1px solid #e4e2e2;">
  6. <img style="width: 20px;height: 20px;margin-right: 5px;float: left;" src="../../../assets/icon/pice_set.png"
  7. alt="">
  8. <span style="float: left;">接线方式</span>
  9. </span>
  10. <el-tree v-if="vif" node-key="id" style="float: left;width: 100%;margin: 0 auto;background-color: #F7F8FB;"
  11. :data="lineData" :props="defaultProps" @node-click="handleNodeClick" />
  12. <el-tree v-else node-key="id" style="float: left;width: 100%;margin: 0 auto;background-color: #F7F8FB;"
  13. :data="lineData" :props="defaultProps" @node-click="handleModelNodeClick" ref="tree2">
  14. <template #default="{ node, data }">
  15. <span>
  16. <!-- 正常情况 -->
  17. <span v-if="data.datatype == 'linkstyle'"><img
  18. style="width: 20px;height: 20px;margin-right: 5px;float: left;"
  19. src="../../../assets/icon/pice_set.png" alt="" /></span>
  20. <span>
  21. {{ node.label }}
  22. </span>
  23. </span>
  24. </template>
  25. </el-tree>
  26. <!--
  27. <p v-else v-for="(item,index) in pList" :class="selectIndex == index?'result':'chooseP'" @click="pClick(item,index)">
  28. {{ item.name }}
  29. </p>
  30. -->
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { ref, onMounted, toRefs, watch } from 'vue'
  36. import litLine from '@/api/litLine'
  37. import systemRow from '@/api/systemRow';
  38. import LitLine from './LitLine.vue';
  39. import { ElMessage } from 'element-plus';
  40. export default {
  41. props: {
  42. selectIndex: {
  43. type: Number,
  44. required: true
  45. }
  46. },
  47. setup(props, { emit }) {
  48. let lineData = ref([])//树形数据
  49. let defaultProps = ref({
  50. children: "children",
  51. label: "name",
  52. id: 'id'
  53. })
  54. let pushList = ref([])
  55. let result = ref(0)
  56. let pList = ref([])
  57. let selectIndex = ref(null)
  58. let vif = ref(true)
  59. let loading = ref(false)
  60. watch(() => props.selectIndex, (newVal) => {
  61. result.value = newVal
  62. searchFlashLel()
  63. })
  64. function searchLine() {
  65. if (props.selectIndex == 0) {
  66. litLine.getLineModel({ pageno: 1, pagesize: 99999 }).then(res => {
  67. // console.log(res, '987res');
  68. })
  69. }
  70. }
  71. function searchFlashLel() {//拿到电压等级
  72. systemRow.getChildren({ code: "voltage_level" }).then(res => {
  73. vif.value = true
  74. if (props.selectIndex == 1) {
  75. vif.value = false
  76. // 获取每个电压等级下的接线方式
  77. litLine.getAllLine({ pageno: 1, pagesize: 99999 }).then(res2 => {
  78. for (let i = 0; i < res2.data.length; i++) {
  79. const vol_level_id = res2.data[i].vol_level_id
  80. res.data.filter((item) => {
  81. if (item.id == vol_level_id) {
  82. res2.data[i]['datatype'] = 'linkstyle'
  83. item['children'] == null ? item['children'] = [res2.data[i]] : item['children'].push(res2.data[i])
  84. return item
  85. }
  86. })
  87. }
  88. lineData.value = res.data
  89. })
  90. } else {
  91. lineData.value = res.data
  92. }
  93. })
  94. }
  95. function handleNodeClick(e) {
  96. litLine.getAllLine({ pageno: 1, pagesize: 99999, vol_id: e.id - 0 }).then(res => {
  97. // console.log(res, 'asdasdasd');
  98. if (res.code == 0) {
  99. loading.value = true
  100. emit("lineBack", loading.value)
  101. pushList.value = res.data
  102. emit("listBack", res.data)
  103. } else {
  104. ElMessage({
  105. message: res.msg,
  106. type: "error"
  107. })
  108. }
  109. })
  110. }
  111. function handleModelNodeClick(e) {
  112. // 模型管理
  113. if (e.datatype === 'linkstyle') {
  114. // 接线方式
  115. litLine.getAllm({ pageno: 1, pagesize: 99999, line_link_style: e.id }).then(res => {
  116. if (res.code == 0) {
  117. loading.value = true
  118. emit("lineBack", loading.value)
  119. emit("listBack", res.data, e.id)
  120. } else {
  121. ElMessage({
  122. message: res.msg,
  123. type: "error"
  124. })
  125. }
  126. })
  127. } else {
  128. // 电压等级
  129. litLine.getAllm({ pageno: 1, pagesize: 99999, vol_id: e.id }).then(res => {
  130. if (res.code == 0) {
  131. loading.value = true
  132. emit("lineBack", loading.value)
  133. emit("volBack", res.data, e.id)
  134. } else {
  135. ElMessage({
  136. message: res.msg,
  137. type: "error"
  138. })
  139. }
  140. })
  141. }
  142. }
  143. function pClick(row, num) {
  144. selectIndex.value = num
  145. litLine.getAllLine({ pageno: 1, pagesize: 99999, vol_id: row.id - 0 }).then(res => {
  146. if (res.code == 0) {
  147. pushList.value = res.data
  148. emit("listBack", pushList.value, row.id)
  149. }
  150. })
  151. }
  152. onMounted(() => {
  153. searchLine()
  154. searchFlashLel()
  155. })
  156. return {
  157. lineData,//树形数据
  158. searchLine,//获取数据
  159. defaultProps,
  160. searchFlashLel,
  161. handleNodeClick,
  162. handleModelNodeClick,
  163. pushList,
  164. result,
  165. pList,
  166. selectIndex,
  167. pClick,
  168. vif,
  169. loading,
  170. }
  171. },
  172. components: {
  173. LitLine
  174. }
  175. }
  176. </script>
  177. <style scoped>
  178. .traBox {
  179. text-align: center;
  180. }
  181. .result {
  182. font-size: 12px;
  183. color: #5D7FDA;
  184. }
  185. .chooseP {
  186. font-size: 12px;
  187. }
  188. .el-tree {
  189. --el-tree-node-content-height: 32px;
  190. --el-tree-node-hover-bg-color: #b2b4ef80 !important;
  191. }
  192. .el-tree-node:hover {
  193. background-color: #b2b4ef80 !important;
  194. color: #fff;
  195. }
  196. .is-current {
  197. background: #b2b4ef !important;
  198. color: #fff !important;
  199. font-weight: bold;
  200. }
  201. </style>