index.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. <el-button class="searchColor" round size="mini" @click="getTableData"
  69. >搜 索</el-button
  70. >
  71. </div>
  72. </div>
  73. <el-table
  74. class="custom-table"
  75. :data="tableData"
  76. style="width: 100%"
  77. height="calc(100% - 35px)"
  78. >
  79. <el-table-column type="index" label="序号" :width="75" align="center" />
  80. <el-table-column
  81. :label="pItem.label"
  82. v-for="(pItem, pIndex) in tableColumnList"
  83. :key="pItem.id"
  84. align="center"
  85. show-overflow-tooltip
  86. :sortable="!pItem.children?.length"
  87. :sort-by="
  88. () => {
  89. tableSort(pIndex);
  90. }
  91. "
  92. >
  93. <template v-if="pItem.children?.length">
  94. <el-table-column
  95. :label="cItem.label"
  96. v-for="cItem in pItem.children"
  97. :key="cItem.id"
  98. align="center"
  99. :sortable="!cItem.children?.length"
  100. :sort-by="
  101. () => {
  102. tableSort(cItem.index);
  103. }
  104. "
  105. >
  106. <template #default="scope">
  107. <span>{{ scope.row[cItem.index] }}</span>
  108. </template>
  109. </el-table-column>
  110. </template>
  111. <template #default="scope" v-if="!pItem.children?.length">
  112. <span>{{ scope.row[pIndex] }}</span>
  113. </template>
  114. </el-table-column>
  115. </el-table>
  116. </div>
  117. </template>
  118. <script>
  119. import api from "@api/economic/index.js";
  120. import axios from "axios";
  121. export default {
  122. data() {
  123. return {
  124. wpId: "",
  125. wtId: "",
  126. wpArray: [],
  127. wtArray: [],
  128. partId: "clx",
  129. partArray: [
  130. { label: "齿轮箱", value: "clx" },
  131. { label: "发电机", value: "fdj" },
  132. { label: "变桨", value: "bj" },
  133. { label: "主控", value: "zk" },
  134. ],
  135. tableData: [],
  136. recordDate: new Date().formatDate("yyyy-MM-dd"),
  137. tableColumnList: [],
  138. };
  139. },
  140. created() {
  141. this.getWp();
  142. },
  143. methods: {
  144. // 获取风场
  145. getWp() {
  146. api
  147. .getWpList({
  148. type: "-1",
  149. })
  150. .then((res) => {
  151. if (res.data.code === 200) {
  152. this.wpArray = res.data.data;
  153. this.wpId = res.data.data?.[0]?.id;
  154. this.getWt();
  155. }
  156. });
  157. },
  158. // 获取风机
  159. getWt() {
  160. api
  161. .getWtList({
  162. wpId: this.wpId,
  163. })
  164. .then((res) => {
  165. if (res.code === 200) {
  166. this.wtArray = res.data;
  167. this.wtId = res.data?.[0]?.id;
  168. this.getTableData();
  169. }
  170. });
  171. },
  172. // 获取表格数据
  173. getTableData() {
  174. this.BASE.showLoading();
  175. axios({
  176. methods: "get",
  177. baseURL: process.env.VUE_APP_NEW_WISDOM,
  178. url: `/health/getParttemperaturesubListByWpId?wpId=${this.wpId}&recorddate=${this.recordDate}&partId=${this.partId}`,
  179. }).then((res) => {
  180. const title1 = res.data?.data?.title1 || [];
  181. const title2 = res.data?.data?.title2 || [];
  182. const excludeItem = /^风机编号$|^风机编码$/;
  183. let tableColumnList = [];
  184. title1?.forEach((ele, index) => {
  185. const findRes = tableColumnList.find((soleEle) => {
  186. return soleEle.label === ele;
  187. });
  188. if (!findRes) {
  189. let children = [];
  190. if (!excludeItem.test(ele)) {
  191. children.push({ id: this.getId(), label: title2[index], index });
  192. }
  193. tableColumnList.push({
  194. id: this.getId(),
  195. label: ele,
  196. children,
  197. index,
  198. });
  199. } else {
  200. findRes.children.push({
  201. id: this.getId(),
  202. label: title2[index],
  203. index,
  204. });
  205. }
  206. });
  207. this.tableData = res.data?.data?.list || [];
  208. this.tableColumnList = tableColumnList;
  209. this.BASE.closeLoading();
  210. });
  211. },
  212. // 生成随机 ID
  213. getId() {
  214. return String(
  215. new Date().getTime() + this.BASE.randomNum(1000000000, 5000000000000)
  216. );
  217. },
  218. tableSort(dataIndex) {
  219. return this.tableData.sort((a, b) => {
  220. const num1 = parseFloat(String(a[dataIndex]).replace(/^#/, ""));
  221. const num2 = parseFloat(String(b[dataIndex]).replace(/^#/, ""));
  222. return num1 - num2;
  223. });
  224. },
  225. },
  226. };
  227. </script>
  228. <style lang="less" scoped>
  229. .draught-fan-list {
  230. height: 100%;
  231. padding: 10px 20px 15px 20px;
  232. }
  233. .tableBox {
  234. width: 100%;
  235. overflow: auto;
  236. }
  237. .query-actions {
  238. margin-left: 0 !important;
  239. }
  240. button {
  241. margin-left: 10px;
  242. background: rgba(67, 81, 107, 0.3);
  243. border: 1px solid #274934;
  244. color: #b3b3b3;
  245. }
  246. .searchColor {
  247. background-color: rgba(5, 187, 76, 0.2);
  248. border: 1px solid #3b6c53;
  249. color: #b3b3b3;
  250. font-size: 14px;
  251. &:hover {
  252. background-color: rgba(5, 187, 76, 0.5);
  253. color: #ffffff;
  254. }
  255. }
  256. </style>