index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item :label="$t('内容')" prop="modulename">
  5. <el-input
  6. v-model="queryParams.modulename"
  7. :placeholder="$t('请输入') + $t('内容')"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item :label="$t('等级')" prop="levelname">
  14. <el-input
  15. v-model="queryParams.levelname"
  16. :placeholder="$t('请输入') + $t('等级')"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t('搜索') }}</el-button>
  24. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
  25. </el-form-item>
  26. </el-form>
  27. <el-row :gutter="10" class="mb8">
  28. <el-col :span="1.5">
  29. <el-button
  30. type="primary"
  31. icon="el-icon-plus"
  32. size="mini"
  33. @click="handleAdd"
  34. v-hasPermi="['production:month:add']"
  35. >{{ $t('新增') }}</el-button>
  36. </el-col>
  37. <el-col :span="1.5">
  38. <el-button
  39. type="success"
  40. icon="el-icon-edit"
  41. size="mini"
  42. :disabled="single"
  43. @click="handleUpdate"
  44. v-hasPermi="['production:month:edit']"
  45. >{{ $t('修改') }}</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="danger"
  50. icon="el-icon-delete"
  51. size="mini"
  52. :disabled="multiple"
  53. @click="handleDelete"
  54. v-hasPermi="['production:month:remove']"
  55. >{{ $t('删除') }}</el-button>
  56. </el-col>
  57. <el-col :span="1.5">
  58. <el-button
  59. type="info"
  60. icon="el-icon-upload2"
  61. size="mini"
  62. @click="handleImport"
  63. v-hasPermi="['production:month:edit']"
  64. >{{ $t('导入') }}</el-button>
  65. </el-col>
  66. <el-col :span="1.5">
  67. <el-button
  68. type="warning"
  69. icon="el-icon-download"
  70. size="mini"
  71. @click="handleExport"
  72. v-hasPermi="['production:month:export']"
  73. >{{ $t('导出') }}</el-button>
  74. </el-col>
  75. <el-col :span="1.5">
  76. <el-button
  77. type="primary"
  78. icon="el-icon-s-data"
  79. size="mini"
  80. @click="handleData"
  81. >{{ $t('数据分析') }}</el-button>
  82. </el-col>
  83. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  84. </el-row>
  85. <el-table v-loading="loading" :data="monthList" @selection-change="handleSelectionChange" :height="clientHeight" border>
  86. <el-table-column type="selection" width="55" align="center" />
  87. <el-table-column :label="$t('内容')" align="center" prop="modulename" :show-overflow-tooltip="true"/>
  88. <el-table-column :label="$t('等级')" align="center" prop="levelname" :show-overflow-tooltip="true"/>
  89. <el-table-column :label="$t('次数')" align="center" prop="count" :show-overflow-tooltip="true"/>
  90. <el-table-column :label="$t('录入日期')" align="center" prop="inputdate" width="100">
  91. <template slot-scope="scope">
  92. <span>{{ parseTime(scope.row.inputdate, '{y}-{m}-{d}') }}</span>
  93. </template>
  94. </el-table-column>
  95. <el-table-column :label="$t('操作')" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
  96. <template slot-scope="scope">
  97. <el-button
  98. size="mini"
  99. type="text"
  100. icon="el-icon-edit"
  101. @click="handleUpdate(scope.row)"
  102. v-hasPermi="['production:month:edit']"
  103. >{{ $t('修改') }}</el-button>
  104. <el-button
  105. size="mini"
  106. type="text"
  107. icon="el-icon-delete"
  108. @click="handleDelete(scope.row)"
  109. v-hasPermi="['production:month:remove']"
  110. >{{ $t('删除') }}</el-button>
  111. </template>
  112. </el-table-column>
  113. </el-table>
  114. <pagination
  115. v-show="total>0"
  116. :total="total"
  117. :page.sync="queryParams.pageNum"
  118. :limit.sync="queryParams.pageSize"
  119. @pagination="getList"
  120. />
  121. <!-- 添加或修改报警统计(上月)对话框 -->
  122. <el-dialog v-dialogDrag :title="title" :visible.sync="open" width="500px" append-to-body>
  123. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  124. <el-form-item :label="$t('装置名称')" prop="plantCode">
  125. <el-select v-model="form.plantCode" :placeholder="$t('请选择') + $t('装置名称')">
  126. <el-option
  127. v-for="dict in plantCodeOptions"
  128. :key="dict.dictValue"
  129. :label="dict.dictLabel"
  130. :value="dict.dictValue"
  131. ></el-option>
  132. </el-select>
  133. </el-form-item>
  134. <el-form-item :label="$t('内容')" prop="modulename">
  135. <el-input v-model="form.modulename" :placeholder="$t('请输入') + $t('内容')" />
  136. </el-form-item>
  137. <el-form-item :label="$t('等级')" prop="levelname">
  138. <el-input v-model="form.levelname" :placeholder="$t('请输入') + $t('等级')" />
  139. </el-form-item>
  140. <el-form-item :label="$t('次数')" prop="count">
  141. <el-input v-model="form.count" :placeholder="$t('请输入') + $t('次数')" />
  142. </el-form-item>
  143. <el-form-item :label="$t('录入日期')" prop="inputdate">
  144. <el-date-picker clearable size="small" style="width: 200px"
  145. v-model="form.inputdate"
  146. type="date"
  147. value-format="yyyy-MM-dd"
  148. :placeholder="$t('请选择') + $t('录入日期')">
  149. </el-date-picker>
  150. </el-form-item>
  151. <el-form-item :label="$t('归属部门')" prop="deptId">
  152. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" :placeholder="$t('请选择') + $t('归属部门')" />
  153. </el-form-item>
  154. <el-form-item :label="$t('备注')" prop="remarks">
  155. <el-input v-model="form.remarks" :placeholder="$t('请输入') + $t('备注')" />
  156. </el-form-item>
  157. </el-form>
  158. <div slot="footer" class="dialog-footer">
  159. <el-button type="primary" @click="submitForm">{{ $t('确 定') }}</el-button>
  160. <el-button @click="cancel">{{ $t('取 消') }}</el-button>
  161. </div>
  162. </el-dialog>
  163. <!-- 用户导入对话框 -->
  164. <el-dialog v-dialogDrag :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  165. <el-upload
  166. ref="upload"
  167. :limit="1"
  168. accept=".xlsx, .xls"
  169. :headers="upload.headers"
  170. :action="upload.url"
  171. :disabled="upload.isUploading"
  172. :on-progress="handleFileUploadProgress"
  173. :on-success="handleFileSuccess"
  174. :auto-upload="false"
  175. drag
  176. >
  177. <i class="el-icon-upload"></i>
  178. <div class="el-upload__text">
  179. {{ $t('将文件拖到此处,或') }}
  180. <em>{{ $t('点击上传') }}</em>
  181. </div>
  182. <div class="el-upload__tip" slot="tip">
  183. <!--<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的用户数据-->
  184. <el-link type="info" style="font-size:12px" @click="importTemplate">{{ $t('下载模板') }}</el-link>
  185. </div>
  186. <form ref="downloadFileForm" :action="upload.downloadAction" target="FORMSUBMIT">
  187. <input name="type" :value="upload.type" hidden />
  188. </form>
  189. <div class="el-upload__tip" style="color:red" slot="tip">{{ $t('提示:仅允许导入“xls”或“xlsx”格式文件!') }}</div>
  190. </el-upload>
  191. <div slot="footer" class="dialog-footer">
  192. <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>
  193. <el-button @click="upload.open = false">{{ $t('取 消') }}</el-button>
  194. </div>
  195. </el-dialog>
  196. <el-drawer
  197. :title="$t('数据分析')"
  198. size="600px"
  199. :visible.sync="drawer"
  200. :direction="direction">
  201. <el-row>
  202. <el-col>
  203. <el-card class="box-card" shadow="hover">
  204. <div slot="header" class="clearfix">
  205. <span>{{ this.$t('报警数') +this.$t('空格') + this.$t('统计') }}</span>
  206. </div>
  207. <div class="text item">
  208. <month-chart></month-chart>
  209. </div>
  210. </el-card>
  211. </el-col>
  212. </el-row>
  213. </el-drawer>
  214. </div>
  215. </template>
  216. <script>
  217. import { listMonth, getMonth, delMonth, addMonth, updateMonth, exportMonth } from "@/api/production/month";
  218. import { treeselect } from "@/api/system/dept";
  219. import { getToken } from "@/utils/auth";
  220. import Treeselect from "@riophae/vue-treeselect";
  221. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  222. import MonthChart from "./monthChart";
  223. export default {
  224. name: "Month",
  225. components: {MonthChart, Treeselect },
  226. data() {
  227. return {
  228. drawer: false,
  229. direction: 'rtl',
  230. // 遮罩层
  231. loading: true,
  232. // 选中数组
  233. ids: [],
  234. // 非单个禁用
  235. single: true,
  236. // 非多个禁用
  237. multiple: true,
  238. // 显示搜索条件
  239. showSearch: false,
  240. // 总条数
  241. total: 0,
  242. // 报警统计(上月)表格数据
  243. monthList: [],
  244. // 弹出层标题
  245. title: "",
  246. // 部门树选项
  247. deptOptions: undefined,
  248. clientHeight:300,
  249. // 是否显示弹出层
  250. open: false,
  251. // 装置名称字典
  252. plantCodeOptions: [],
  253. // 用户导入参数
  254. upload: {
  255. //下载模板请求地址
  256. downloadAction: process.env.VUE_APP_BASE_API + '/common/template',
  257. //下载模板类型
  258. type: "month",
  259. // 是否显示弹出层(用户导入)
  260. open: false,
  261. // 弹出层标题(用户导入)
  262. title: "",
  263. // 是否禁用上传
  264. isUploading: false,
  265. // 是否更新已经存在的用户数据
  266. updateSupport: 0,
  267. // 设置上传的请求头部
  268. headers: { Authorization: "Bearer " + getToken() },
  269. // 上传的地址
  270. url: process.env.VUE_APP_BASE_API + "/production/month/importData"
  271. },
  272. // 查询参数
  273. queryParams: {
  274. pageNum: 1,
  275. pageSize: 20,
  276. modulename: null,
  277. levelname: null,
  278. },
  279. // 表单参数
  280. form: {},
  281. // 表单校验
  282. rules: {
  283. plantCode: [
  284. { required: true, message: this.$t('装置名称') + this.$t('不能为空'), trigger: "change" }
  285. ],
  286. }
  287. };
  288. },
  289. watch: {
  290. // 根据名称筛选部门树
  291. deptName(val) {
  292. this.$refs.tree.filter(val);
  293. }
  294. },
  295. created() {
  296. //设置表格高度对应屏幕高度
  297. this.$nextTick(() => {
  298. this.clientHeight = (document.body.clientHeight - 80) * 0.8
  299. })
  300. this.getList();
  301. this.getTreeselect();
  302. this.getDicts("PLANT_DIVIDE").then(response => {
  303. this.plantCodeOptions = response.data;
  304. });
  305. },
  306. methods: {
  307. /** 查询报警统计(上月)列表 */
  308. getList() {
  309. this.loading = true;
  310. listMonth(this.queryParams).then(response => {
  311. this.monthList = response.rows;
  312. this.total = response.total;
  313. this.loading = false;
  314. });
  315. },
  316. /** 查询部门下拉树结构 */
  317. getTreeselect() {
  318. treeselect().then(response => {
  319. this.deptOptions = response.data;
  320. });
  321. },
  322. // 装置名称字典翻译
  323. plantCodeFormat(row, column) {
  324. return this.selectDictLabel(this.plantCodeOptions, row.plantCode);
  325. },
  326. // 取消按钮
  327. cancel() {
  328. this.open = false;
  329. this.reset();
  330. },
  331. // 表单重置
  332. reset() {
  333. this.form = {
  334. id: null,
  335. plantCode: null,
  336. modulename: null,
  337. levelname: null,
  338. count: null,
  339. inputdate: null,
  340. analysis: null,
  341. delFlag: null,
  342. createrCode: null,
  343. createdate: null,
  344. updaterCode: null,
  345. updatedate: null,
  346. remarks: null,
  347. deptId: null
  348. };
  349. this.resetForm("form");
  350. },
  351. /** 搜索按钮操作 */
  352. handleQuery() {
  353. this.queryParams.pageNum = 1;
  354. this.getList();
  355. },
  356. /** 重置按钮操作 */
  357. resetQuery() {
  358. this.resetForm("queryForm");
  359. this.handleQuery();
  360. },
  361. // 多选框选中数据
  362. handleSelectionChange(selection) {
  363. this.ids = selection.map(item => item.id)
  364. this.single = selection.length!==1
  365. this.multiple = !selection.length
  366. },
  367. /** 新增按钮操作 */
  368. handleAdd() {
  369. this.reset();
  370. this.open = true;
  371. this.title = this.$t('新增') + " " + this.$t('报警统计(上月)');
  372. },
  373. /** 修改按钮操作 */
  374. handleUpdate(row) {
  375. this.reset();
  376. const id = row.id || this.ids
  377. getMonth(id).then(response => {
  378. this.form = response.data;
  379. this.open = true;
  380. this.title = this.$t('修改')+ this.$t('报警统计(上月)');
  381. });
  382. },
  383. /** 提交按钮 */
  384. submitForm() {
  385. this.$refs["form"].validate(valid => {
  386. if (valid) {
  387. if (this.form.id != null) {
  388. updateMonth(this.form).then(response => {
  389. this.msgSuccess(this.$t('修改成功'));
  390. this.open = false;
  391. this.getList();
  392. });
  393. } else {
  394. addMonth(this.form).then(response => {
  395. this.msgSuccess(this.$t('新增成功'));
  396. this.open = false;
  397. this.getList();
  398. });
  399. }
  400. }
  401. });
  402. },
  403. /** 删除按钮操作 */
  404. handleDelete(row) {
  405. const ids = row.id || this.ids;
  406. this.$confirm(this.$t('是否确认删除报警统计(上月)编号为"') + ids + this.$t('"的数据项?'), this.$t('警告'), {
  407. confirmButtonText: this.$t('确定'),
  408. cancelButtonText: this.$t('取消'),
  409. type: "warning"
  410. }).then(function() {
  411. return delMonth(ids);
  412. }).then(() => {
  413. this.getList();
  414. this.msgSuccess(this.$t('删除成功'));
  415. })
  416. },
  417. /** 导出按钮操作 */
  418. handleExport() {
  419. const queryParams = this.queryParams;
  420. this.$confirm(this.$t('是否确认导出所有报警统计(上月)数据项?'), this.$t('警告'), {
  421. confirmButtonText: this.$t('确定'),
  422. cancelButtonText: this.$t('取消'),
  423. type: "warning"
  424. }).then(function() {
  425. return exportMonth(queryParams);
  426. }).then(response => {
  427. this.download(response.msg);
  428. })
  429. },
  430. /** 导入按钮操作 */
  431. handleImport() {
  432. this.upload.title = this.$t('用户导入');
  433. this.upload.open = true;
  434. },
  435. /** 下载模板操作 */
  436. importTemplate() {
  437. this.$refs['downloadFileForm'].submit()
  438. },
  439. // 文件上传中处理
  440. handleFileUploadProgress(event, file, fileList) {
  441. this.upload.isUploading = true;
  442. },
  443. // 文件上传成功处理
  444. handleFileSuccess(response, file, fileList) {
  445. this.upload.open = false;
  446. this.upload.isUploading = false;
  447. this.$refs.upload.clearFiles();
  448. if (response.data[0] != null) {
  449. this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据') + "," + this.$t('第') + response.data + this.$t('行数据出现错误导入失败')+"。", this.$t('导入结果'), { dangerouslyUseHTMLString: true });
  450. }else {
  451. this.$alert(this.$t('成功导入') + response.msg + this.$t('条数据'), this.$t('导入结果'), { dangerouslyUseHTMLString: true });
  452. }
  453. this.getList();
  454. },
  455. // 提交上传文件
  456. submitFileForm() {
  457. this.$refs.upload.submit();
  458. },
  459. //数据分析
  460. handleData(){
  461. this.drawer = true
  462. }
  463. }
  464. };
  465. </script>