ztzhjl.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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: "time",
  69. is_num: false,
  70. is_light: false,
  71. },
  72. {
  73. name: "转换前类型",
  74. field: "qType",
  75. is_num: false,
  76. is_light: false,
  77. },
  78. {
  79. name: "转换后类型",
  80. field: "hType",
  81. is_num: false,
  82. is_light: false,
  83. }, {
  84. name: "关联风机",
  85. field: "glfj",
  86. is_num: false,
  87. is_light: false,
  88. }
  89. ],
  90. data: [],
  91. },
  92. };
  93. },
  94. created() {
  95. this.getWp();
  96. this.value1 = [new Date((new Date() - 3600 * 1000 * 24 * 30)).formatDate("yyyy-MM-dd"),new Date().formatDate("yyyy-MM-dd")];
  97. },
  98. methods: {
  99. exportCsv() {
  100. let data = this.tableData;
  101. let arrName = [];
  102. let dataArr = [];
  103. data.column.forEach(item =>{
  104. arrName.push(item.name)
  105. })
  106. data.data.forEach(ele=>{
  107. let i = 0;
  108. let obj = {};
  109. for(var j in ele){
  110. obj[arrName[i++]] = ele[j]
  111. }
  112. dataArr.push(obj)
  113. })
  114. var csv = Papa.unparse(dataArr);
  115. //定义文件内容,类型必须为Blob 否则createObjectURL会报错
  116. let content = new Blob([csv]);
  117. //生成url对象
  118. let urlObject = window.URL || window.webkitURL || window;
  119. let url = urlObject.createObjectURL(content);
  120. //生成<a></a>DOM元素
  121. let el = document.createElement("a");
  122. //链接赋值
  123. el.href = url;
  124. el.download = "状态转换记录.cvs";
  125. //必须点击否则不会下载
  126. el.click();
  127. //移除链接释放资源
  128. urlObject.revokeObjectURL(url);
  129. },
  130. formatDate(date) {
  131. var date = new Date(date);
  132. var YY = date.getFullYear() + '-';
  133. var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
  134. var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
  135. var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
  136. var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
  137. var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
  138. return YY + MM + DD +" "+hh + mm + ss;
  139. },
  140. // 获取风场
  141. getWp() {
  142. let that = this;
  143. that.API.requestData({
  144. baseURL: "http://10.155.32.4:9001",
  145. subUrl: "benchmarking/wplist",
  146. success(res) {
  147. that.wpArray = res.data;
  148. that.wpId = res.data[0].id;
  149. that.wpName = res.data[0].wpName;
  150. that.getWt(that.wpId);
  151. }
  152. });
  153. },
  154. // 获取风机
  155. getWt(wpid) {
  156. let that = this;
  157. if (that.wpId) {
  158. that.API.requestData({
  159. method: "GET",
  160. baseURL: "http://10.155.32.4:9001",
  161. subUrl: "benchmarking/wtList",
  162. data: {
  163. wpid
  164. },
  165. success(res) {
  166. that.wtArray = res.data;
  167. that.wtId = res.data[0].id;
  168. }
  169. });
  170. }
  171. },
  172. // 获取停机事件
  173. requestSafeList(wpId,wtid) {
  174. let that = this;
  175. if(wpId && wtid){
  176. that.wpId = wpId;
  177. that.wtid = wtid;
  178. }
  179. if(typeof that.value1[0].valueOf() != 'string'){
  180. that.value1[0] = that.formatDate(that.value1[0].valueOf())
  181. }
  182. if(typeof that.value1[1].valueOf() != 'string'){
  183. that.value1[1] = that.formatDate(that.value1[1].valueOf())
  184. }
  185. let data = {
  186. WindPowerStation: that.wpId,
  187. wtid:that.wtid,
  188. beginDate: that.value1[0].valueOf(),
  189. endDate: that.value1[1].valueOf(),
  190. };
  191. that.API.requestData({
  192. showLoading:true,
  193. subUrl: "/operationrecord/zhlb",
  194. data,
  195. success(res) {
  196. if (res.code == 200) {
  197. that.tableData.data = [];
  198. if (res.data.length) {
  199. let data = res.data;
  200. for (var i = 0; i < data.length; i++) {
  201. let obj = {
  202. index: i+1,
  203. time: data[i].zhsj,
  204. qType: data[i].beforeConversionName,
  205. hType: data[i].AfterConversionName,
  206. glfj: data[i].wtid,
  207. };
  208. that.tableData.data.push(obj);
  209. }
  210. }
  211. }
  212. },
  213. });
  214. },
  215. },
  216. watch:{
  217. wtId(e){
  218. this.requestSafeList(this.wpId,e);
  219. },
  220. value1(){
  221. this.requestSafeList(this.wpId,this.wtId);
  222. }
  223. }
  224. };
  225. </script>
  226. <style lang="less" scope>
  227. @titleGray: #9ca5a8;
  228. @rowGray: #606769;
  229. @darkBack: #536268;
  230. .knowledge-2 {
  231. .el-select {
  232. width: 200px;
  233. }
  234. .el-input {
  235. width: 200px;
  236. }
  237. }
  238. </style>