equip.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <div>
  3. <el-row>
  4. <el-col class="btn-top" :span="12">
  5. <el-button type="primary" @click="saveData">设置范围</el-button>
  6. <el-button @click="clearData">清空</el-button>
  7. </el-col>
  8. </el-row>
  9. <el-tree
  10. :data="eqList"
  11. show-checkbox
  12. ref="tree"
  13. node-key="aliasCode"
  14. @check="checkChange"
  15. :default-checked-keys="choiceCheckList"
  16. :default-expanded-keys="choiceCheckList"
  17. :props="defaultProps"
  18. >
  19. </el-tree>
  20. </div>
  21. </template>
  22. <script>
  23. import {
  24. sys_eq,
  25. set_scope,
  26. get_scope,
  27. sys_eq_for_scope,
  28. } from "@/api/workScope.js";
  29. export default {
  30. data() {
  31. return {
  32. eqList: [],
  33. defaultProps: {
  34. children: "children",
  35. label: "aliasName",
  36. },
  37. choiceCheckList: [],
  38. };
  39. },
  40. methods: {
  41. checkChange(node, choiceKey, v) {
  42. const list = [];
  43. choiceKey.checkedKeys.forEach((msg) => {
  44. if (msg != undefined) {
  45. list.push(msg);
  46. }
  47. });
  48. this.choiceCheckList = list;
  49. },
  50. // 专业系统设备树
  51. getSys_eq_tree() {
  52. sys_eq_for_scope({ target: "rtn" }).then((res) => {
  53. this.eqList = res.rtn;
  54. this.readData();
  55. });
  56. },
  57. readData() {
  58. const data = { type: "device", target: "rtn" };
  59. get_scope(data).then((res) => {
  60. this.choiceCheckList = res.rtn.map((a) => {
  61. return a.code;
  62. });
  63. });
  64. },
  65. // 保存数据
  66. saveData() {
  67. let data = {
  68. type: "device",
  69. target: "action",
  70. codes: this.choiceCheckList,
  71. };
  72. set_scope(data).then(() => {
  73. this.readData();
  74. });
  75. },
  76. //清空
  77. clearData() {
  78. this.$confirm("是否继续?", "提示", {
  79. confirmButtonText: "确定",
  80. cancelButtonText: "取消",
  81. type: "warning",
  82. })
  83. .then(() => {
  84. this.choiceCheckList = [];
  85. this.$refs.tree.setCheckedKeys([]);
  86. this.saveData();
  87. this.$message({
  88. type: "success",
  89. message: "删除成功!",
  90. });
  91. })
  92. .catch(() => {
  93. this.$message({
  94. type: "info",
  95. message: "已取消删除",
  96. });
  97. });
  98. },
  99. },
  100. created() {
  101. this.getSys_eq_tree();
  102. },
  103. };
  104. </script>
  105. <style lang="less" scoped>
  106. .btn-top {
  107. margin-bottom: 12px;
  108. display: flex;
  109. justify-content: flex-end;
  110. }
  111. </style>