czjl.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <div class="knowledge-2">
  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 v-model="wpId" clearable placeholder="请选择" popper-class="select"
  9. @change="(wpId) => { getWt(wpId, true); }">
  10. <el-option v-for="item in wpArray" :key="item.id" :value="item.id" :label="item.name" />
  11. </el-select>
  12. </div>
  13. </div>
  14. <div class="query-item">
  15. <div class="lable">风机:</div>
  16. <div class="search-input">
  17. <el-select v-model="wtId" clearable placeholder="请选择" popper-class="select">
  18. <el-option v-for="item in wtArray" :key="item.id" :value="item.id" :label="item.name" />
  19. </el-select>
  20. </div>
  21. </div>
  22. <div class="query-item">
  23. <div class="query-item">
  24. <div class="lable">开始日期:</div>
  25. <div class="search-input">
  26. <el-date-picker v-model="value1" type="datetimerange" range-separator="至"
  27. start-placeholder="开始日期" end-placeholder="结束日期">
  28. </el-date-picker>
  29. </div>
  30. </div>
  31. </div>
  32. </div>
  33. <div class="query-actions" style="margin-right: 1500px">
  34. <button class="btn green" @click="requestSafeList">查询</button>
  35. <button class="btn green" @click="exportCsv">导出</button>
  36. </div>
  37. </div>
  38. <el-row :type="'flex'" class="content">
  39. <el-col :span="24">
  40. <ComTable :data="tableData" height="85vh"></ComTable>
  41. </el-col>
  42. </el-row>
  43. </div>
  44. </template>
  45. <script>
  46. import ComTable from "@com/coms/table/table.vue";
  47. import Papa from 'papaparse';
  48. export default {
  49. components: {
  50. ComTable,
  51. Papa
  52. },
  53. data() {
  54. return {
  55. value1: [],
  56. wpId: "",
  57. wpArray: [],
  58. wpName: "",
  59. wtId: "",
  60. wtIdWait:1,
  61. tableData: {
  62. column: [{
  63. name: "编号",
  64. field: "index",
  65. is_num: false,
  66. is_light: false,
  67. },
  68. {
  69. name: "转换时间",
  70. field: "zhsj",
  71. is_num: false,
  72. is_light: false,
  73. },
  74. {
  75. name: "操作类型",
  76. field: "ConversionName",
  77. is_num: false,
  78. is_light: false,
  79. }
  80. ],
  81. data: [],
  82. },
  83. };
  84. },
  85. created() {
  86. this.getWp();
  87. this.value1 = [new Date((new Date() - 3600 * 1000 * 24 * 30)).formatDate("yyyy-MM-dd"),new Date().formatDate("yyyy-MM-dd")];
  88. },
  89. methods: {
  90. exportCsv() {
  91. let data = this.tableData;
  92. let arrName = [];
  93. let dataArr = [];
  94. data.column.forEach(item =>{
  95. arrName.push(item.name)
  96. })
  97. data.data.forEach(ele=>{
  98. let i = 0;
  99. let obj = {};
  100. for(var j in ele){
  101. obj[arrName[i++]] = ele[j]
  102. }
  103. dataArr.push(obj)
  104. })
  105. var csv = Papa.unparse(dataArr);
  106. //定义文件内容,类型必须为Blob 否则createObjectURL会报错
  107. let content = new Blob([csv]);
  108. //生成url对象
  109. let urlObject = window.URL || window.webkitURL || window;
  110. let url = urlObject.createObjectURL(content);
  111. //生成<a></a>DOM元素
  112. let el = document.createElement("a");
  113. //链接赋值
  114. el.href = url;
  115. el.download = "操作类型.cvs";
  116. //必须点击否则不会下载
  117. el.click();
  118. //移除链接释放资源
  119. urlObject.revokeObjectURL(url);
  120. },
  121. formatDate(date) {
  122. var date = new Date(date);
  123. var YY = date.getFullYear() + '-';
  124. var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  125. var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  126. var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  127. var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  128. var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  129. return YY + MM + DD +" "+hh + mm + ss;
  130. },
  131. // 获取风场
  132. getWp() {
  133. let that = this;
  134. that.API.requestData({
  135. baseURL: "http://10.155.32.4:9001",
  136. subUrl: "benchmarking/wplist",
  137. success(res) {
  138. that.wpArray = res.data;
  139. that.wpId = res.data[0].id;
  140. that.wpName = res.data[0].wpName;
  141. that.getWt(that.wpId);
  142. }
  143. });
  144. },
  145. // 获取风机
  146. getWt(wpid) {
  147. let that = this;
  148. if (that.wpId) {
  149. that.API.requestData({
  150. method: "GET",
  151. baseURL: "http://10.155.32.4:9001",
  152. subUrl: "benchmarking/wtList",
  153. data: {
  154. wpid
  155. },
  156. success(res) {
  157. that.wtArray = res.data;
  158. that.wtId = res.data[0].id;
  159. }
  160. });
  161. }
  162. },
  163. // 获取停机事件
  164. requestSafeList(wpId,wtid) {
  165. let that = this;
  166. if(wpId && wtid){
  167. that.wpId = wpId;
  168. that.wtid = wtid;
  169. }
  170. if(typeof that.value1[0].valueOf() != 'string'){
  171. that.value1[0] = that.formatDate(that.value1[0].valueOf())
  172. }
  173. if(typeof that.value1[1].valueOf() != 'string'){
  174. that.value1[1] = that.formatDate(that.value1[1].valueOf())
  175. }
  176. let data = {
  177. WindPowerStation: that.wpId,
  178. wtid:that.wtid,
  179. beginDate: that.value1[0].valueOf(),
  180. endDate: that.value1[1].valueOf(),
  181. };
  182. that.API.requestData({
  183. showLoading:true,
  184. subUrl: "/operationrecord/czlb",
  185. data,
  186. success(res) {
  187. if (res.code == 200) {
  188. that.tableData.data = [];
  189. if (res.data.length) {
  190. let data = res.data;
  191. for (var i = 0; i < data.length; i++) {
  192. let obj = {
  193. index: i+1,
  194. zhsj: data[i].zhsj,
  195. ConversionName: data[i].ConversionName,
  196. };
  197. that.tableData.data.push(obj);
  198. }
  199. }
  200. }
  201. },
  202. });
  203. },
  204. },
  205. watch:{
  206. wtId(e){
  207. if(this.wtIdWait == 1){//这里只让执行一次
  208. this.requestSafeList(this.wpId,e);
  209. this.wtIdWait = 2;
  210. }
  211. }
  212. }
  213. };
  214. </script>
  215. <style lang="less" scope>
  216. @titleGray: #9ca5a8;
  217. @rowGray: #606769;
  218. @darkBack: #536268;
  219. .knowledge-2 {
  220. .el-select {
  221. width: 200px;
  222. }
  223. .el-input {
  224. width: 200px;
  225. }
  226. }
  227. </style>