From f5052fa7d4e73c0df5a02a6ad8987f35df42b8f8 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期四, 07 十一月 2024 17:23:50 +0800
Subject: [PATCH] 1. 完成场景报告模块 2. 日报管理模块添加时间范围选择以及word报告生成

---
 src/views/fysp/data-product/ProdDailyReport.vue |  344 +++++++++++++++++++++++---------------------------------
 1 files changed, 143 insertions(+), 201 deletions(-)

diff --git a/src/views/fysp/data-product/ProdDailyReport.vue b/src/views/fysp/data-product/ProdDailyReport.vue
index ec520f7..510d10a 100644
--- a/src/views/fysp/data-product/ProdDailyReport.vue
+++ b/src/views/fysp/data-product/ProdDailyReport.vue
@@ -1,46 +1,55 @@
 <template>
   <!-- 涓诲唴瀹� -->
+  <FYSearchBar ref="searchRef" @search="search" :loading="loading">
+    <template #options>
+      <!-- 鍖哄幙 -->
+      <FYOptionLocation
+        :allOption="false"
+        :level="3"
+        :checkStrictly="false"
+        v-model:value="formSearch.locations"
+        style="width: 300px"
+      ></FYOptionLocation>
+      <!-- 鍦烘櫙绫诲瀷 -->
+      <!-- <FYOptionScene
+        :allOption="true"
+        :type="2"
+        v-model:value="formSearch.scenetype"
+      ></FYOptionScene> -->
+      <!-- 鏃堕棿 -->
+      <FYOptionTime
+        :initValue="false"
+        type="datetimerange"
+        v-model:value="formSearch.timeArray"
+        style="width: 250px"
+      ></FYOptionTime>
+    </template>
+    <template #buttons>
+      <el-button
+        icon="Download"
+        type="primary"
+        class=""
+        :loading="docLoading"
+        :disabled="!docParam"
+        @click="genWord()"
+      >
+        鐢熸垚鎶ュ憡
+      </el-button>
+      <el-button
+        icon="Download"
+        type="success"
+        class=""
+        :disabled="!docParam"
+        @click="exportToExcel()"
+      >
+        涓嬭浇琛ㄦ牸
+      </el-button>
+    </template>
+  </FYSearchBar>
+
   <div class="m-task container">
     <!--澶撮儴淇℃伅-->
     <div class="h-top col-md-12">
-      <div class="options">
-        <!-- <input type="date" class="c-time c-check" /> -->
-        <!-- 鏃堕棿 -->
-        <el-form-item label="鏃堕棿" :prop="prop" style="margin-left: 10px">
-          <el-date-picker
-            v-model="formSearch.time"
-            type="date"
-            placeholder="閫夋嫨鏃堕棿"
-            start-placeholder="閫夋嫨寮�濮嬫椂闂�"
-            end-placeholder="閫夋嫨缁撴潫鏃堕棿"
-            style="width: 180px"
-          />
-        </el-form-item>
-        <el-form-item label="鍖哄煙" :prop="prop" style="margin-left: 10px">
-          <el-select
-            placeholder="Select"
-            v-model="formSearch.districtCode"
-            class="c-area c-check"
-            style="width: 100px"
-          >
-            <el-option label="閲戝北鍖�" value="310116"></el-option>
-            <el-option label="闈欏畨鍖�" value="310106"></el-option>
-            <el-option label="寰愭眹鍖�" value="310104"></el-option>
-            <el-option label="闀垮畞鍖�" value="310105"></el-option>
-          </el-select>
-        </el-form-item>
-
-        <el-button
-          style="margin-left: 10px"
-          class="check-msg"
-          @click="search"
-          type="primary"
-          >鏌ヨ</el-button
-        >
-        <el-button type="primary" class="" @click="exportToExcel()">
-          鐢熸垚鎶ュ憡
-        </el-button>
-      </div>
       <div class="m-top">
         <span class="title-input"> {{ reportName }} </span>
         <!-- <input
@@ -52,21 +61,10 @@
     </div>
 
     <div class="m-msg col-md-12">
-      <span
-        name="desc"
-        class="desc-textarea"
-        rows="5"
-        value=""
-        cols=""
-        disabled
-      ></span>
+      <span>{{ descMsg }}</span>
       <div class="report-table row">
         <table id="table_subtask" class="" border="1"></table>
       </div>
-    </div>
-
-    <div class="dark-screen">
-      <i class="fa fa-spinner fa-spin fa-3x" style="color: white"></i>
     </div>
   </div>
 </template>
@@ -77,28 +75,13 @@
 import * as XLSX from 'xlsx';
 import FileSaver from 'file-saver';
 import analysisApi from '@/api/fysp/analysisApi.js';
+import { exportDocx } from '@/utils/doc';
+
 export default {
   name: 'DailyReport',
   computed: {
     reportName() {
-      var city = '';
-      switch (this.formSearch.districtCode) {
-        case '310116':
-          city = '閲戝北鍖�';
-          break;
-        case '310106':
-          city = '闈欏畨鍖�';
-          break;
-        case '310104':
-          city = '寰愭眹鍖�';
-          break;
-        case '310105':
-          city = '闀垮畞鍖�';
-          break;
-      }
-
-      let title = `${city}鎵皹姹℃煋杈呭姪鐩戠宸ヤ綔鏃ユ姤`;
-      return title;
+      return `${this.formSearch.locations.dName}鎵皹姹℃煋杈呭姪鐩戠宸ヤ綔鏃ユ姤`;
     }
   },
   data() {
@@ -235,10 +218,18 @@
         headers: [],
         data: []
       },
+      loading: false,
       formSearch: {
+        locations: {},
+        scenetype: {},
         time: [],
+        timeArray: [new Date(), new Date()],
         districtCode: '310116'
-      }
+      },
+      descMsg: '',
+      // 瀵煎嚭鎶ュ憡鍙傛暟
+      docParam: undefined,
+      docLoading: false
     };
   },
   watch: {
@@ -365,147 +356,98 @@
         `${this.reportName}.xlsx`
       );
     },
-    downloadFile() {
-      // 鏂囦欢鏍囬
-      let title = this.reportName;
-      // 琛ㄥご鎻忚堪
-      let desc = document.querySelector('.desc-textarea').textContent;
-      // 鏃堕棿
-      let time = document
-        .querySelector('.desc-textarea')
-        .textContent.split('锛�')[0];
-
-      // 鑾峰彇鏁版嵁
-      let thData = Array.from(document.getElementsByTagName('th')).map(
-        (th) => th.innerText
-      );
-      let tdData = Array.from(document.getElementsByTagName('td')).map(
-        (td) => td.innerText
-      );
-      let totalList = [];
-      let subList = [];
-      let index = 2;
-
-      let inputStatus = true;
-      for (let j = 0; j < thData.length; j++) {
-        subList.push(thData[j]);
-      }
-      totalList.push(subList);
-      subList = [];
-
-      for (let i = 0; i < tdData.length; i++) {
-        if (tdData[i] !== String(index)) {
-          if (tdData[i] !== '') {
-            subList.push(tdData[i]);
-          } else {
-            if (inputStatus) {
-              let inputList = document.querySelectorAll(`.input-${subList[0]}`);
-              for (let j = 0; j < inputList.length; j++) {
-                subList.push(inputList[j].value);
-              }
-              inputStatus = false;
-            } else {
-              inputStatus = true;
-            }
-          }
-        } else {
-          totalList.push(subList);
-          subList = [String(index)];
-          index += 1;
-        }
-      }
-      totalList.push(subList);
-
-      // index: 0  head
-      // other: data
-      // title
-
-      let fileData = {
-        title: title,
-        time: time,
-        desc: desc,
-        data: totalList
-      };
-
-      // if (fileData.title && fileData.time && fileData.desc && fileData.data.length) {
-      //     fetch("http://47.100.191.150:9002/dustmonitor/report", {
-      //         method: "POST",
-      //         headers: {
-      //             "Content-Type": "application/json"
-      //         },
-      //         body: JSON.stringify(fileData)
-      //     })
-      //     .then(response => response.json())
-      //     .then(res => {
-      //         if (res.status === 200) {
-      //             let name = res.name.split("./")[1];
-      //             setTimeout(() => {
-      //                 let a = document.createElement("a");
-      //                 a.href = appConfig.downloadUrl + name;
-      //                 a.download = name; // 璁剧疆涓嬭浇鏂囦欢鍚�
-      //                 document.body.appendChild(a);
-      //                 a.click();
-      //                 document.body.removeChild(a);
-      //             }, 1000);
-      //         }
-      //     })
-      //     .catch(error => console.error("Error:", error));
-      // }
-    },
     search() {
-      let sTime = dayjs(this.formSearch.time).hour(0).minute(0).second(0);
-      let eTime = dayjs(this.formSearch.time).hour(23).minute(59).second(59);
-      eTime = eTime.toISOString();
-      sTime = sTime.toISOString();
+      let sTime = dayjs(this.formSearch.timeArray[0])
+        .hour(0)
+        .minute(0)
+        .second(0)
+        .millisecond(0);
+      let eTime = dayjs(this.formSearch.timeArray[1])
+        .hour(23)
+        .minute(59)
+        .second(59)
+        .millisecond(0);
+      // eTime = eTime.toISOString();
+      // sTime = sTime.toISOString();
 
       let config = {
-        startTime: sTime,
-        endTime: eTime,
-        districtCode: this.formSearch.districtCode
+        startTime: sTime.toDate(),
+        endTime: eTime.toDate(),
+        districtCode: this.formSearch.locations.dCode
       };
-      analysisApi.checkProblem(config).then((res) => {
-        this.table.headers = res.tableTitle[0];
-        this.table.data = res.tableContent;
+      this.loading = true;
+      analysisApi
+        .dailyreport(config)
+        .then((res) => {
+          this.table.headers = res.tableTitle[0];
+          this.table.data = res.tableContent;
 
-        this.CompTable.init(res.tableTitle[0], res.tableContent);
-        this.CompTable.show('table_subtask');
+          this.CompTable.init(res.tableTitle[0], res.tableContent);
+          this.CompTable.show('table_subtask');
 
-        const countMap = new Map(); //鍚勫満鏅暟閲�
-        let proCount = 0; //鎬昏闂鏁伴噺
-        let changeCount = 0; //鎬昏鏁存敼鏁伴噺
+          const countMap = new Map(); //鍚勫満鏅暟閲�
+          let proCount = 0; //鎬昏闂鏁伴噺
+          let changeCount = 0; //鎬昏鏁存敼鏁伴噺
+          const tableRows = [];
 
-        res.tableContent.forEach((cList) => {
-          const sceneType = cList[2];
-          if (!(sceneType in countMap)) {
-            countMap[sceneType] = 0;
+          res.tableContent.forEach((cList) => {
+            const sceneType = cList[2];
+            if (!(sceneType in countMap)) {
+              countMap[sceneType] = 0;
+            }
+            countMap[sceneType] += 1;
+            proCount += Number(cList[10]);
+            changeCount += Number(cList[13]);
+
+            tableRows.push({
+              sIndex: cList[0],
+              sType: sceneType,
+              sName: cList[3],
+              sLocation: cList[4],
+              sProblemList: cList[8].split('\n'),
+              time: cList[6],
+              sTown: cList[5],
+              sChangeList: cList[11].split('\n')
+            });
+          });
+
+          let countStr = '';
+          for (const key in countMap) {
+            const e = countMap[key];
+            if (countStr != '') {
+              countStr += '銆�';
+            }
+            countStr += `${key}${e}涓猔;
           }
-          countMap[sceneType] += 1;
-          proCount += Number(cList[10]);
-          changeCount += Number(cList[13]);
-        });
+          this.descMsg = `鍏卞贰鏌�${res.tableContent.length}涓壃灏樺満鏅紙${countStr}锛夛紝鍏卞彂鐜伴棶棰�${proCount}椤癸紝鐫d績鏁存敼浜�${changeCount}椤广�俙;
 
-        let countStr = '';
-        for (const key in countMap) {
-          const e = countMap[key];
-          if (countStr != '') {
-            countStr += '銆�';
-          }
-          countStr += `${key}${e}涓猔;
-        }
-
-        var descMsg = `鍏卞贰鏌�${res.tableContent.length}涓壃灏樺満鏅紙${countStr}锛夛紝鍏卞彂鐜伴棶棰�${proCount}椤癸紝鐫d績鏁存敼浜�${changeCount}椤癸紱鍓嶆湡浣欑暀闂鍧囧凡閿�椤广�俙;
-        console.log('descMsg', descMsg);
-
-        // 鑾峰彇鎵�鏈夌被鍚嶄负 'desc-textarea' 鐨勫厓绱�
-        const textareas = document.querySelectorAll('.desc-textarea');
-
-        // 閬嶅巻杩欎簺鍏冪礌骞惰缃叾 HTML 鍐呭
-        textareas.forEach(function (textarea) {
-          textarea.innerHTML = descMsg;
-        });
-        // $('.desc-textarea').html('');
-        // $('.desc-textarea').html(descMsg);
-      });
+          this.docParam = {
+            month: sTime.month() + 1,
+            day: sTime.date(),
+            index: 1,
+            hasMoreDays: !sTime.isSame(eTime, 'day'),
+            endMonth: eTime.month() + 1,
+            endDay: eTime.date(),
+            totalScene: res.tableContent.length,
+            sceneNumTxt: countStr,
+            proNum: proCount,
+            changeNum: changeCount,
+            unChangeNum: proCount - changeCount,
+            table1: tableRows
+          };
+        })
+        .finally(() => (this.loading = false));
+    },
+    // 鐢熸垚word鎶ュ憡
+    genWord() {
+      if (this.docParam) {
+        const param = this.docParam;
+        exportDocx(
+          '/绉嬪啲瀛g┖姘旇川閲忔敾鍧氬伐浣滄彁绀烘ā鏉�.docx',
+          param,
+          `绉嬪啲瀛g┖姘旇川閲忔敾鍧氬伐浣滄彁绀猴紙${param.month}鏈�${param.day}鏃ワ級.docx`
+        );
+      }
     }
   }
 };

--
Gitblit v1.9.3