czjl.vue 5.8 KB

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