superviseLog.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <!-- -->
  2. <template>
  3. <div class="superviseLog_box">
  4. <el-row>
  5. <el-col>
  6. <div class="search_box">
  7. <!-- 监测人员 -->
  8. <el-select
  9. filterable
  10. v-model="input"
  11. clearable
  12. @change="searchData"
  13. placeholder="请选择监测人员"
  14. size="mini"
  15. >
  16. <el-option
  17. v-for="item in conductorList"
  18. :key="item.value"
  19. :label="item.label"
  20. :value="item.value"
  21. >
  22. </el-option>
  23. </el-select>
  24. <!-- 时间筛选 -->
  25. <el-date-picker
  26. size="mini"
  27. v-model="value"
  28. @change="searchData"
  29. type="daterange"
  30. range-separator="至"
  31. start-placeholder="开始日期"
  32. end-placeholder="结束日期"
  33. align="right"
  34. :editable="false"
  35. >
  36. </el-date-picker>
  37. <div class="btn_box">
  38. <el-button type="info" size="mini" @click="searchData"
  39. >搜索</el-button
  40. >
  41. <el-button size="mini" @click="reset">重置</el-button>
  42. <el-button
  43. :disabled="btnShow"
  44. type="info"
  45. size="mini"
  46. @click="exportData"
  47. >
  48. <i v-if="loadingShow" class="el-icon-loading"></i>
  49. 导出数据</el-button
  50. >
  51. </div>
  52. </div>
  53. </el-col>
  54. </el-row>
  55. <el-card style="margin-top: 15px">
  56. <!-- 表格 -->
  57. <el-table
  58. :data="tableData"
  59. v-loading="loading"
  60. stripe
  61. :height="48 * 13"
  62. style="width: 100%; overflow-y: auto"
  63. >
  64. <!-- <el-table-column prop="ind" label="序号" width="100"> </el-table-column>
  65. <el-table-column prop="owner_user" label="监测人员" width="200">
  66. </el-table-column>
  67. <el-table-column prop="monitor_time" label="监测时间" width="250">
  68. </el-table-column>
  69. <el-table-column prop="weather" label="天气" width="200">
  70. </el-table-column>
  71. <el-table-column prop="temperature" label="温度" width="200">
  72. </el-table-column>
  73. <el-table-column prop="address" label="地点" width="280">
  74. </el-table-column>
  75. <el-table-column prop="monitor_time" label="提交时间" width="180">
  76. </el-table-column>
  77. <el-table-column label="操作" width="180" fixed="right">
  78. <template slot-scope="scope">
  79. <a
  80. href="javascript:;"
  81. class="reset"
  82. @click="examineDetail(scope.row)"
  83. >查看</a
  84. >
  85. </template>
  86. </el-table-column> -->
  87. <el-table-column prop="ind" label="序号">
  88. <template slot-scope="scope">
  89. <span>{{ ((page-1)*20)+scope.row.ind}}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column prop="owner_user" label="监测人员"> </el-table-column>
  93. <el-table-column prop="monitor_time" label="监测时间">
  94. </el-table-column>
  95. <el-table-column prop="weather" label="天气"> </el-table-column>
  96. <el-table-column prop="temperature" label="温度"> </el-table-column>
  97. <el-table-column prop="address" label="地点"> </el-table-column>
  98. <el-table-column prop="monitor_time" label="提交时间">
  99. </el-table-column>
  100. <el-table-column label="操作" fixed="right">
  101. <template slot-scope="scope">
  102. <a
  103. href="javascript:;"
  104. class="reset"
  105. @click="examineDetail(scope.row)"
  106. >查看</a
  107. >
  108. </template>
  109. </el-table-column>
  110. </el-table>
  111. <!-- 分页 -->
  112. <el-pagination
  113. style="margin: 60px 0 0 0"
  114. :page-size="20"
  115. @current-change="newPage"
  116. :current-page="page"
  117. v-if="tableData.length > 0"
  118. background
  119. layout="prev, pager, next, jumper"
  120. :total="tableSum"
  121. >
  122. </el-pagination>
  123. </el-card>
  124. </div>
  125. </template>
  126. <script>
  127. export default {
  128. //import引入的组件需要注入到对象中才能使用
  129. components: {},
  130. data() {
  131. //这里存放数据
  132. return {
  133. fullHeight: document.documentElement.clientHeight - 116, //
  134. // 筛选
  135. conductorList: [], // 监测人员 - 筛选列表
  136. input: "", // 监测人员
  137. value: "", // 时间筛选
  138. startTime: "", //开始时间
  139. endTime: "", // 结束时间
  140. loadingShow: false, // 导出加载
  141. // 表格
  142. tableData: [],
  143. loading: false, // 加载
  144. // 分页
  145. page: 1, // 当前页码
  146. tableSum: 0, // 总页码
  147. btnShow: false, // 防止导出数据重复下载
  148. };
  149. },
  150. //监听属性 类似于data概念
  151. computed: {},
  152. //监控data中的数据变化
  153. watch: {
  154. fullHeight(val) {
  155. //监控浏览器高度变化
  156. if (!this.timer) {
  157. this.fullHeight = val;
  158. this.timer = true;
  159. let that = this;
  160. setTimeout(function () {
  161. //防止过度调用监测事件,导致卡顿
  162. that.timer = false;
  163. }, 400);
  164. }
  165. },
  166. },
  167. //方法集合
  168. methods: {
  169. //动态获取浏览器高度
  170. get_boderHeight() {
  171. const that = this;
  172. window.onresize = () => {
  173. return (() => {
  174. window.fullHeight = document.documentElement.clientHeight;
  175. that.fullHeight = window.fullHeight;
  176. })();
  177. };
  178. },
  179. // 表格列表
  180. tableList() {
  181. this.$axios({
  182. method: "POST",
  183. url: "/api/api_gateway?method=control_center.task.monitor_log_list",
  184. data: this.qs.stringify({
  185. page: this.page, // 当前页码
  186. page_item: "20", //
  187. monitor_user_id: this.input, // 监测人id
  188. start_time: this.startTime, // 开始时间
  189. end_time: this.endTime, // 结束时间
  190. }),
  191. })
  192. .then((res) => {
  193. if (res.data.data.total_item !== 0) {
  194. var data = res.data.data.page_list;
  195. this.tableSum = res.data.data.total_item;
  196. var list = [];
  197. data.forEach((item, index) => {
  198. item.ind = index + 1;
  199. item.temperature =
  200. item.temperature !== "" || item.temperature !== undefined
  201. ? item.temperature + "°C"
  202. : "暂无";
  203. list.push(item);
  204. });
  205. this.tableData = list;
  206. }
  207. this.loading = false;
  208. })
  209. .catch((err) => {
  210. this.loading = false;
  211. });
  212. },
  213. // 筛选列表 - 监测人员
  214. conductorAxios() {
  215. this.$axios({
  216. method: "POST",
  217. url: "/api/api_gateway?method=control_center.task.task_user_list",
  218. data: this.qs.stringify({
  219. user_type: "supervisor", // 用户类型,operator(任务处理人), supervisor(任务监督人), owner(任务发布人)
  220. operator_id: "", // 已经选择的任务处理人id
  221. supervisor_id: "", // 已经选择的任务监督人id
  222. owner_id: "", // 已经选择的任务发布人id
  223. }),
  224. })
  225. .then((res) => {
  226. if (res.data.data.length !== 0) {
  227. var data = res.data.data;
  228. var list = [];
  229. data.forEach((item) => {
  230. var obj = {};
  231. obj["value"] = item.user_id;
  232. obj["label"] = item.real_name;
  233. list.push(obj);
  234. });
  235. this.conductorList = list;
  236. }
  237. })
  238. .catch((err) => {});
  239. },
  240. // 筛选
  241. searchData() {
  242. if (this.value) {
  243. this.startTime = this.formatTime(this.value[0], "yyyy-MM-dd");
  244. this.endTime = this.formatTime(this.value[1], "yyyy-MM-dd");
  245. } else {
  246. this.startTime = "";
  247. this.endTime = "";
  248. }
  249. this.loading = true;
  250. this.tableData = [];
  251. this.page = 1;
  252. this.tableList();
  253. },
  254. // 重置
  255. reset() {
  256. this.input = ""; // 监测人员
  257. this.value = ""; // 时间筛选
  258. this.startTime = ""; // 开始时间
  259. this.endTime = ""; // 结束时间
  260. this.tableData = [];
  261. this.loading = true;
  262. this.page = 1
  263. this.tableList();
  264. },
  265. // 下页
  266. newPage(page) {
  267. this.page = page;
  268. this.loading = true;
  269. this.tableData = [];
  270. this.tableList();
  271. },
  272. // 查看
  273. examineDetail(data) {
  274. this.$router.push({
  275. path: "/index/superviseLogDetails",
  276. query: {
  277. id: data.id,
  278. },
  279. });
  280. },
  281. // 导出数据
  282. exportData() {
  283. this.loadingShow = true;
  284. this.btnShow = true;
  285. this.$axios({
  286. method: "POST",
  287. url: "/api/api_gateway?method=control_center.task.monitor_log_export",
  288. data: this.qs.stringify({
  289. monitor_user_id: this.input, // 非必填 监测人id
  290. start_time: this.startTime, // 非必填 开始时间
  291. end_time: this.endTime, // 非必填 结束时间
  292. }),
  293. responseType: "blob",
  294. })
  295. .then((res) => {
  296. this.downloadFile(res, "监测日志.xls");
  297. this.loadingShow = false;
  298. setTimeout(() => {
  299. this.btnShow = false;
  300. }, 1500);
  301. })
  302. .catch((err) => {
  303. this.loadingShow = false;
  304. setTimeout(() => {
  305. this.btnShow = false;
  306. }, 1500);
  307. });
  308. },
  309. // 流文件下载
  310. downloadFile(res, name) {
  311. let link = document.createElement("a");
  312. link.href = window.URL.createObjectURL(new Blob([res.data]));
  313. link.target = "_blank";
  314. // 文件名和格式
  315. link.download = name;
  316. document.body.appendChild(link);
  317. link.click();
  318. document.body.removeChild(link);
  319. },
  320. },
  321. //生命周期 - 创建完成(可以访问当前this实例)
  322. created() {},
  323. //生命周期 - 挂载完成(可以访问DOM元素)
  324. mounted() {
  325. this.loading = true;
  326. this.get_boderHeight(); // 动态获取浏览器高度
  327. this.tableList(); // 表格列表数据
  328. this.conductorAxios(); // 筛选 - 监测人员列表
  329. },
  330. beforeCreate() {}, //生命周期 - 创建之前
  331. beforeMount() {}, //生命周期 - 挂载之前
  332. beforeUpdate() {}, //生命周期 - 更新之前
  333. updated() {}, //生命周期 - 更新之后
  334. beforeDestroy() {}, //生命周期 - 销毁之前
  335. destroyed() {}, //生命周期 - 销毁完成
  336. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  337. };
  338. </script>
  339. <style lang="less" scoped>
  340. .superviseLog_box {
  341. // 搜索
  342. .search_box {
  343. display: flex;
  344. /deep/.el-select {
  345. margin: 0 15px 0 0;
  346. }
  347. /deep/.el-input {
  348. margin: 0 15px 0 0;
  349. }
  350. .btn_box {
  351. margin: 0 0 0 15px;
  352. // width: 50%;
  353. display: flex;
  354. justify-content: start;
  355. }
  356. /deep/.el-range-editor--mini.el-input__inner {
  357. width: 20%;
  358. }
  359. }
  360. a {
  361. text-decoration: none;
  362. }
  363. .reset {
  364. color: #1890ff;
  365. }
  366. /deep/.el-card {
  367. overflow: hidden;
  368. overflow-y: auto;
  369. }
  370. }
  371. /deep/.el-date-editor {
  372. cursor: pointer;
  373. .el-range-input {
  374. cursor: pointer;
  375. }
  376. }
  377. /deep/.el-table .cell {
  378. text-align: center;
  379. }
  380. /deep/.el-button--info {
  381. background-color: #409eff;
  382. border-color: #409eff;
  383. }
  384. </style>