index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <div class="draught-fan-list">
  3. <div class="query mg-b-8">
  4. <div class="query-items">
  5. <div class="query-item">
  6. <div class="lable">场站:</div>
  7. <div class="search-input">
  8. <el-select
  9. v-model="wpId"
  10. placeholder="请选择"
  11. popper-class="select"
  12. @change="getWt"
  13. >
  14. <el-option
  15. v-for="item in wpArray"
  16. :key="item.id"
  17. :value="item.id"
  18. :label="item.name"
  19. />
  20. </el-select>
  21. </div>
  22. </div>
  23. <!-- <div class="query-item">
  24. <div class="lable">风机:</div>
  25. <div class="search-input">
  26. <el-select
  27. v-model="wtId"
  28. placeholder="请选择"
  29. popper-class="select"
  30. >
  31. <el-option
  32. v-for="item in wtArray"
  33. :key="item.id"
  34. :value="item.id"
  35. :label="item.nemCode"
  36. />
  37. </el-select>
  38. </div>
  39. </div> -->
  40. <!-- <div class="query-item">
  41. <div class="lable">部件类型:</div>
  42. <div class="search-input">
  43. <el-select v-model="partId" placeholder="Select" size="small">
  44. <el-option
  45. v-for="item in partArray"
  46. :key="item.value"
  47. :label="item.label"
  48. :value="item.value"
  49. />
  50. </el-select>
  51. </div>
  52. </div> -->
  53. <div class="query-item">
  54. <div class="lable">日期:</div>
  55. <div class="search-input">
  56. <el-date-picker
  57. v-model="recordDate"
  58. type="date"
  59. value-format="YYYY-MM-DD"
  60. placeholder="选择日期"
  61. popper-class="date-select"
  62. >
  63. </el-date-picker>
  64. </div>
  65. </div>
  66. </div>
  67. <div class="query-actions">
  68. <button class="btn green" @click="getTableData">搜索</button>
  69. </div>
  70. </div>
  71. <el-table
  72. class="custom-table"
  73. :data="tableData"
  74. style="width: 100%"
  75. height="89vh"
  76. >
  77. <el-table-column type="index" label="序号" :width="75" align="center" />
  78. <el-table-column
  79. :label="pItem.label"
  80. v-for="(pItem, pIndex) in tableColumnList"
  81. :key="pItem.id"
  82. align="center"
  83. show-overflow-tooltip
  84. :sortable="!pItem.children?.length"
  85. :sort-by="
  86. () => {
  87. tableSort(pIndex);
  88. }
  89. "
  90. >
  91. <template v-if="pItem.children?.length">
  92. <el-table-column
  93. :label="cItem.label"
  94. v-for="cItem in pItem.children"
  95. :key="cItem.id"
  96. align="center"
  97. :sortable="!cItem.children?.length"
  98. :sort-by="
  99. () => {
  100. tableSort(cItem.index);
  101. }
  102. "
  103. >
  104. <template #default="scope">
  105. <span>{{ scope.row[cItem.index] }}</span>
  106. </template>
  107. </el-table-column>
  108. </template>
  109. <template #default="scope" v-if="!pItem.children?.length">
  110. <span>{{ scope.row[pIndex] }}</span>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. </div>
  115. </template>
  116. <script>
  117. import api from "@api/economic/index.js";
  118. import axios from "axios";
  119. export default {
  120. name:'malfunctionAnalysis',
  121. data() {
  122. return {
  123. wpId: "",
  124. wtId: "",
  125. wpArray: [],
  126. wtArray: [],
  127. partId: "fdj",
  128. partArray: [
  129. { label: "发电机", value: "fdj" },
  130. { label: "齿轮箱", value: "clx" },
  131. { label: "变桨", value: "bj" },
  132. { label: "主控", value: "zk" },
  133. ],
  134. tableData: [],
  135. recordDate: new Date().formatDate("yyyy-MM-dd"),
  136. tableColumnList: [],
  137. };
  138. },
  139. created() {
  140. this.getWp();
  141. },
  142. methods: {
  143. // 获取风场
  144. getWp() {
  145. api
  146. .getWpList({
  147. type: "-1",
  148. })
  149. .then((res) => {
  150. if (res.data.code === 200) {
  151. this.wpArray = res.data.data;
  152. this.wpId = res.data.data?.[0]?.id;
  153. this.getWt();
  154. }
  155. });
  156. },
  157. // 获取风机
  158. getWt() {
  159. api
  160. .getWtList({
  161. wpId: this.wpId,
  162. })
  163. .then((res) => {
  164. if (res.code === 200) {
  165. this.wtArray = res.data;
  166. this.wtId = res.data?.[0]?.id;
  167. this.getTableData();
  168. }
  169. });
  170. },
  171. // 获取表格数据
  172. getTableData() {
  173. this.BASE.showLoading();
  174. axios({
  175. methods: "get",
  176. baseURL: process.env.VUE_APP_NEW_WISDOM,
  177. url: `/health/getFailureStatisticMainListByWpId?wpId=${this.wpId}&recorddate=${this.recordDate}`,
  178. }).then((res) => {
  179. const title1 = res.data?.data?.title1 || [];
  180. const title2 = res.data?.data?.title2 || [];
  181. const excludeItem = /^风机编号$|^风机编码$/;
  182. let tableColumnList = [];
  183. title1?.forEach((ele, index) => {
  184. const findRes = tableColumnList.find((soleEle) => {
  185. return soleEle.label === ele;
  186. });
  187. if (!findRes) {
  188. let children = [];
  189. if (!excludeItem.test(ele)) {
  190. children.push({ id: this.getId(), label: title2[index], index });
  191. }
  192. tableColumnList.push({
  193. id: this.getId(),
  194. label: ele,
  195. children,
  196. index,
  197. });
  198. } else {
  199. findRes.children.push({
  200. id: this.getId(),
  201. label: title2[index],
  202. index,
  203. });
  204. }
  205. });
  206. this.tableData = res.data?.data?.list || [];
  207. this.tableColumnList = tableColumnList;
  208. this.BASE.closeLoading();
  209. });
  210. },
  211. // 生成随机 ID
  212. getId() {
  213. return String(
  214. new Date().getTime() + this.BASE.randomNum(1000000000, 5000000000000)
  215. );
  216. },
  217. tableSort(dataIndex) {
  218. return this.tableData.sort((a, b) => {
  219. const num1 = parseFloat(String(a[dataIndex]).replace(/^#/, ""));
  220. const num2 = parseFloat(String(b[dataIndex]).replace(/^#/, ""));
  221. return num1 - num2;
  222. });
  223. },
  224. },
  225. };
  226. </script>
  227. <style lang="less" scoped>
  228. .tableBox {
  229. width: 100%;
  230. overflow: auto;
  231. }
  232. </style>