index-copy.vue 15 KB

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