Warning.vue 6.3 KB

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