Warning.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="wind-site-warning">
  3. <div class="search pd-16 pd-b-8">
  4. <el-row>
  5. <div class="query">
  6. <input class="search-input" name="query" v-model="query" />
  7. </div>
  8. <button class="btn search" @click="search">搜 索</button>
  9. <div class="empty"></div>
  10. <button class="btn empty-btn" @click="reset">重置</button>
  11. </el-row>
  12. <el-row class="options">
  13. <el-col
  14. class="option-item"
  15. :span="8"
  16. v-for="(option, index) in options"
  17. :key="option"
  18. @click="onOptionClick(option, index)"
  19. :class="{ active: option.isActive }"
  20. >
  21. <div class="count">{{ option.count }}</div>
  22. <div class="text">{{ option.text }}</div>
  23. </el-col>
  24. </el-row>
  25. </div>
  26. <div class="warning-list">
  27. <Table
  28. :data="warning"
  29. :canScroll="true"
  30. :height="'calc(100vh - 560px)'"
  31. />
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import Table from "../../../../components/coms/table/table.vue";
  37. export default {
  38. components: {
  39. Table,
  40. },
  41. data() {
  42. return {
  43. query: "",
  44. options: [],
  45. ackupData: {},
  46. warning: {
  47. column: [
  48. // {
  49. // name: "报警编号",
  50. // field: "Code",
  51. // is_num: true, // 是否为数字
  52. // },
  53. {
  54. name: "PLC变量名",
  55. field: "name",
  56. },
  57. {
  58. name: "报警信息",
  59. field: "value",
  60. },
  61. {
  62. name: "报警状态",
  63. field: "data1",
  64. template: function (data) {
  65. if (data === 1) return "<div class='error-state'></div>";
  66. else return "正常";
  67. },
  68. },
  69. ],
  70. data: [],
  71. },
  72. activeArray: [],
  73. isSearch: false,
  74. };
  75. },
  76. props: {
  77. data: {
  78. type: Object,
  79. default: () => {},
  80. },
  81. },
  82. mounted() {
  83. this.backupData = this.BASE.deepCopy(this.data);
  84. this.riseData(this.data);
  85. },
  86. methods: {
  87. onOptionClick(option, index) {
  88. option.isActive = !option.isActive;
  89. this.activeArray[index] = !this.activeArray[index];
  90. let warningData = [];
  91. this.activeArray.forEach((bool, index) => {
  92. if (bool) {
  93. this.options[index].vos.forEach((ele) => {
  94. warningData.push(ele);
  95. });
  96. }
  97. });
  98. this.warning.data = warningData;
  99. this.isSearch = false;
  100. this.query = "";
  101. },
  102. // 格式化数据
  103. riseData(data) {
  104. let options = [];
  105. let warningData = [];
  106. let index = 0;
  107. for (let key in data) {
  108. data.index = index;
  109. if (this.activeArray.length < index + 1) {
  110. this.activeArray.push(!index ? true : false);
  111. }
  112. options.push({
  113. id: data[key].id,
  114. text: data[key].name,
  115. vos: data[key].vos,
  116. count: data[key].vos.length,
  117. isActive: this.activeArray[index],
  118. });
  119. if (this.activeArray[index]) {
  120. data[key].vos.forEach((ele) => {
  121. warningData.push(ele);
  122. });
  123. }
  124. index++;
  125. }
  126. this.options = options;
  127. this.warning.data = warningData;
  128. if (this.isSearch) {
  129. this.search();
  130. }
  131. },
  132. search() {
  133. // 压器类总
  134. this.isSearch = true;
  135. if (this.query) {
  136. let warningData = [];
  137. this.BASE.deepCopy(this.warning.data).forEach((ele) => {
  138. if (ele.name.indexOf(this.query) !== -1) {
  139. warningData.push(ele);
  140. }
  141. });
  142. this.warning.data = warningData;
  143. } else {
  144. this.riseData(this.data);
  145. }
  146. },
  147. reset() {
  148. for (let i = 0; i < this.activeArray.length; i++) {
  149. this.activeArray[i] = false;
  150. }
  151. this.isSearch = false;
  152. this.query = "";
  153. let sourceMap = this.BASE.deepCopy(this.backupData);
  154. this.riseData(sourceMap, true);
  155. },
  156. },
  157. watch: {
  158. data(res) {
  159. this.backupData = this.BASE.deepCopy(res);
  160. this.riseData(res);
  161. },
  162. },
  163. };
  164. </script>
  165. <style lang="less">
  166. .wind-site-warning {
  167. border: 1px solid @darkgray;
  168. .search {
  169. .query {
  170. height: 100%;
  171. flex: 0 0 200px;
  172. margin-right: 8px;
  173. .search-input {
  174. background: transparent;
  175. border: 1px solid @darkgray;
  176. padding: 10px;
  177. color: @gray;
  178. outline: unset;
  179. border-radius: 0%;
  180. margin-right: 10px;
  181. height: 28px;
  182. line-height: 28px;
  183. }
  184. }
  185. button {
  186. height: 100%;
  187. flex: 0 0 auto;
  188. background: transparent;
  189. border: 1px solid @darkgray;
  190. // padding: 10px 1.481vh;
  191. color: @gray;
  192. font-size: 14px;
  193. cursor: pointer;
  194. height: 28px;
  195. line-height: 28px;
  196. }
  197. .empty {
  198. flex: auto;
  199. }
  200. .options {
  201. margin-top: 8px;
  202. .option-item {
  203. display: flex;
  204. color: @gray;
  205. cursor: pointer;
  206. font-size: 12px;
  207. margin-bottom: 2px;
  208. .count {
  209. flex: 0 0 3.704vh;
  210. text-align: center;
  211. border: 1px solid @darkgray;
  212. margin-right: 0.37vh;
  213. height: 28px;
  214. line-height: 28px;
  215. }
  216. .text {
  217. flex: 1 0 auto;
  218. border: 1px solid @darkgray;
  219. height: 28px;
  220. line-height: 28px;
  221. padding: 0 8px;
  222. }
  223. & + .option-item {
  224. padding-left: 10px;
  225. }
  226. &:nth-child(3n + 1) {
  227. padding-left: 0px;
  228. }
  229. &.purple {
  230. .text,
  231. .count {
  232. border-color: @purple;
  233. color: @purple;
  234. }
  235. }
  236. &.active,
  237. &:hover {
  238. .text,
  239. .count {
  240. border-color: @green;
  241. color: @green;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. .warning-list {
  248. height: 61.5vh;
  249. .error-state {
  250. width: 10px;
  251. height: 10px;
  252. border-radius: 50%;
  253. background-color: @red;
  254. margin: auto;
  255. }
  256. thead tr th {
  257. padding: 0;
  258. font-size: 12px;
  259. }
  260. }
  261. }
  262. </style>