LineTree.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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;font-size: 16px;font-weight: 500;">一次性接线方式</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. moduleSize: {
  47. type: Number,
  48. required: true
  49. },
  50. moduleIndex: {
  51. type: Number,
  52. required: true
  53. }
  54. },
  55. setup(props, { emit }) {
  56. let lineData = ref([])//树形数据
  57. let defaultProps = ref({
  58. children: "children",
  59. label: "name",
  60. id: 'id'
  61. })
  62. let pushList = ref([])
  63. let result = ref(0)
  64. let pList = ref([])
  65. let selectIndex = ref(null)
  66. let vif = ref(true)
  67. let loading = ref(false)
  68. let counts = ref(0)//总条数
  69. let size = ref(0)
  70. let index = ref(10)
  71. let intE = ref("")
  72. watch(() => props.selectIndex, (newVal) => {
  73. result.value = newVal
  74. searchFlashLel()
  75. })
  76. watch(() => props.moduleIndex, (newVal) => {
  77. size.value = newVal
  78. litLine.getAllm({ pageno: index.value, pagesize: size.value, vol_id: intE.value - 0 }).then(res => {
  79. if (res.code == 0) {
  80. loading.value = true
  81. counts.value = res.count
  82. console.log(counts.value, 'linetree');
  83. emit("lineBack", loading.value)
  84. emit("volBack", res.data, intE.value - 0, counts.value)
  85. } else {
  86. ElMessage({
  87. message: res.msg,
  88. type: "error"
  89. })
  90. }
  91. })
  92. })
  93. watch(() => props.moduleSize, (newVal) => {
  94. index.value = newVal
  95. litLine.getAllm({ pageno: index.value, pagesize: size.value, vol_id: intE.value - 0 }).then(res => {
  96. if (res.code == 0) {
  97. loading.value = true
  98. counts.value = res.count
  99. console.log(counts.value, 'linetree');
  100. emit("lineBack", loading.value)
  101. emit("volBack", res.data, intE.value - 0, counts.value)
  102. } else {
  103. ElMessage({
  104. message: res.msg,
  105. type: "error"
  106. })
  107. }
  108. })
  109. })
  110. function searchLine() {
  111. size.value = props.moduleIndex
  112. index.value = props.moduleSize
  113. }
  114. function searchFlashLel() {//拿到电压等级
  115. systemRow.getChildren({ code: "voltage_level" }).then(res => {
  116. vif.value = true
  117. if (props.selectIndex == 1) {
  118. vif.value = false
  119. // 获取每个电压等级下的接线方式
  120. litLine.getAllLine({ pageno: 1, pagesize: 20 }).then(res2 => {
  121. for (let i = 0; i < res2.data.length; i++) {
  122. const vol_level_id = res2.data[i].vol_level_id
  123. res.data.filter((item) => {
  124. if (item.id == vol_level_id) {
  125. res2.data[i]['datatype'] = 'linkstyle'
  126. item['children'] == null ? item['children'] = [res2.data[i]] : item['children'].push(res2.data[i])
  127. return item
  128. }
  129. })
  130. }
  131. lineData.value = res.data
  132. })
  133. } else {
  134. lineData.value = res.data
  135. }
  136. })
  137. }
  138. function handleNodeClick(e) {
  139. litLine.getAllLine({ pageno: 1, pagesize: 20, vol_id: e.id - 0 }).then(res => {
  140. if (res.code == 0) {
  141. loading.value = true
  142. emit("lineBack", loading.value)
  143. pushList.value = res.data
  144. emit("listBack", res.data)
  145. } else {
  146. ElMessage({
  147. message: res.msg,
  148. type: "error"
  149. })
  150. }
  151. })
  152. }
  153. function handleModelNodeClick(e) {
  154. // 模型管理
  155. if (e.datatype === 'linkstyle') {
  156. // 接线方式
  157. litLine.getAllm({ pageno: 1, pagesize: 20, line_link_style: e.id }).then(res => {
  158. if (res.code == 0) {
  159. loading.value = true
  160. emit("lineBack", loading.value)
  161. emit("listBack", res.data, e.id)
  162. } else {
  163. ElMessage({
  164. message: res.msg,
  165. type: "error"
  166. })
  167. }
  168. })
  169. } else {
  170. // 电压等级
  171. intE.value = e.id
  172. litLine.getAllm({ pageno: 1, pagesize: 20, vol_id: intE.value - 0 }).then(res => {
  173. if (res.code == 0) {
  174. loading.value = true
  175. counts.value = res.count
  176. console.log(counts.value, 'linetree');
  177. emit("lineBack", loading.value)
  178. emit("volBack", res.data, e.id, counts.value)
  179. } else {
  180. ElMessage({
  181. message: res.msg,
  182. type: "error"
  183. })
  184. }
  185. })
  186. }
  187. }
  188. function pClick(row, num) {
  189. selectIndex.value = num
  190. litLine.getAllLine({ pageno: 1, pagesize: 20, vol_id: row.id - 0 }).then(res => {
  191. if (res.code == 0) {
  192. pushList.value = res.data
  193. emit("listBack", pushList.value, row.id)
  194. }
  195. })
  196. }
  197. onMounted(() => {
  198. searchLine()
  199. searchFlashLel()
  200. })
  201. return {
  202. lineData,//树形数据
  203. searchLine,//获取数据
  204. defaultProps,
  205. searchFlashLel,
  206. handleNodeClick,
  207. handleModelNodeClick,
  208. pushList,
  209. result,
  210. pList,
  211. selectIndex,
  212. pClick,
  213. vif,
  214. loading,
  215. counts,//总条数
  216. size,
  217. index,
  218. intE,
  219. }
  220. },
  221. components: {
  222. LitLine
  223. }
  224. }
  225. </script>
  226. <style scoped>
  227. .traBox {
  228. text-align: center;
  229. }
  230. .result {
  231. font-size: 12px;
  232. color: #5D7FDA;
  233. }
  234. .chooseP {
  235. font-size: 12px;
  236. }
  237. .el-tree {
  238. --el-tree-node-content-height: 32px;
  239. --el-tree-node-hover-bg-color: #b2b4ef80 !important;
  240. }
  241. .el-tree-node:hover {
  242. background-color: #b2b4ef80 !important;
  243. color: #fff;
  244. }
  245. .is-current {
  246. background: #b2b4ef !important;
  247. color: #fff !important;
  248. font-weight: bold;
  249. }
  250. </style>