index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  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="装置名称" prop="devName">
  5. <el-input
  6. v-model="queryParams.devName"
  7. placeholder="请输入装置名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="工作区域" prop="workArea">
  14. <el-input
  15. v-model="queryParams.workArea"
  16. placeholder="请输入工作区域"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item label="区域负责人" prop="regionalHead">
  23. <el-input
  24. v-model="queryParams.regionalHead"
  25. placeholder="请输入区域负责人"
  26. clearable
  27. size="small"
  28. @keyup.enter.native="handleQuery"
  29. />
  30. </el-form-item>
  31. <el-form-item>
  32. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  33. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. <el-row :gutter="10" class="mb8">
  37. <el-col :span="1.5">
  38. <el-button
  39. type="primary"
  40. icon="el-icon-plus"
  41. size="mini"
  42. @click="handleAdd"
  43. v-hasPermi="['invoice:device:add']"
  44. >新增</el-button>
  45. </el-col>
  46. <el-col :span="1.5">
  47. <el-button
  48. type="success"
  49. icon="el-icon-edit"
  50. size="mini"
  51. :disabled="single"
  52. @click="handleUpdate"
  53. v-hasPermi="['invoice:device:edit']"
  54. >修改</el-button>
  55. </el-col>
  56. <el-col :span="1.5">
  57. <el-button
  58. type="danger"
  59. icon="el-icon-delete"
  60. size="mini"
  61. :disabled="multiple"
  62. @click="handleDelete"
  63. v-hasPermi="['invoice:device:remove']"
  64. >删除</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="['invoice:device:export']"
  73. >导出</el-button>
  74. </el-col>
  75. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  76. </el-row>
  77. <el-table v-loading="loading" ref="deviceTable" :data="deviceList" @selection-change="handleSelectionChange" :height="clientHeight" border>
  78. <el-table-column type="selection" width="55" align="center" />
  79. <el-table-column label="装置名称" align="center" prop="devName" :show-overflow-tooltip="true"/>
  80. <el-table-column label="工作区域" align="center" prop="workArea" :show-overflow-tooltip="true"/>
  81. <el-table-column label="区域负责人" align="center" prop="regionalHeadName" :show-overflow-tooltip="true"/>
  82. <el-table-column label="备注" align="center" prop="remarks" :show-overflow-tooltip="true"/>
  83. <el-table-column label="操作" 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="['invoice:device:edit']"
  91. >修改</el-button>
  92. <el-button
  93. size="mini"
  94. type="text"
  95. icon="el-icon-delete"
  96. @click="handleDelete(scope.row)"
  97. v-hasPermi="['invoice:device:remove']"
  98. >删除</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 :title="title" :visible.sync="open" width="500px" append-to-body>
  111. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  112. <el-form-item label="装置名称" prop="devName">
  113. <el-input v-model="form.devName" placeholder="请输入装置名称" />
  114. </el-form-item>
  115. <el-form-item label="工作区域" prop="workArea">
  116. <el-input v-model="form.workArea" placeholder="请输入工作区域" />
  117. </el-form-item>
  118. <el-form-item label="区域负责人" prop="regionalHead">
  119. <el-select
  120. v-model="form.regionalHead"
  121. placeholder="请选择区域负责人"
  122. style="width: 100%"
  123. filterable
  124. multiple
  125. >
  126. <el-option
  127. v-for="dict in principalList"
  128. :key="dict.userId"
  129. :label="dict.nickName"
  130. :value="dict.userId">
  131. </el-option>
  132. </el-select>
  133. </el-form-item>
  134. <el-form-item label="归属部门" prop="deptId">
  135. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
  136. </el-form-item>
  137. <el-form-item label="备注" prop="remarks">
  138. <el-input v-model="form.remarks" placeholder="请输入备注" />
  139. </el-form-item>
  140. </el-form>
  141. <div slot="footer" class="dialog-footer">
  142. <el-button type="primary" @click="submitForm">确 定</el-button>
  143. <el-button @click="cancel">取 消</el-button>
  144. </div>
  145. </el-dialog>
  146. <!-- 用户导入对话框 -->
  147. <el-dialog :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 + '?updateSupport=' + upload.updateSupport"
  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. 将文件拖到此处,或
  163. <em>点击上传</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">下载模板</el-link>
  168. </div>
  169. <div class="el-upload__tip" style="color:red" slot="tip">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
  170. </el-upload>
  171. <div slot="footer" class="dialog-footer">
  172. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  173. <el-button @click="upload.open = false">取 消</el-button>
  174. </div>
  175. </el-dialog>
  176. </div>
  177. </template>
  178. <script>
  179. import { listDevice, getDevice, delDevice, addDevice, updateDevice, exportDevice, importTemplate} from "@/api/invoice/device";
  180. import { treeselect } from "@/api/system/dept";
  181. import { getToken } from "@/utils/auth";
  182. import Treeselect from "@riophae/vue-treeselect";
  183. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  184. import {listPostUser} from "@/api/system/user";
  185. export default {
  186. name: "Device",
  187. components: { Treeselect },
  188. data() {
  189. return {
  190. // 遮罩层
  191. loading: true,
  192. // 选中数组
  193. ids: [],
  194. // 非单个禁用
  195. single: true,
  196. // 非多个禁用
  197. multiple: true,
  198. // 显示搜索条件
  199. showSearch: false,
  200. // 总条数
  201. total: 0,
  202. // 装置区域管理表格数据
  203. deviceList: [],
  204. principalList: [],
  205. // 弹出层标题
  206. title: "",
  207. // 部门树选项
  208. deptOptions: undefined,
  209. clientHeight:300,
  210. // 是否显示弹出层
  211. open: false,
  212. // 用户导入参数
  213. upload: {
  214. // 是否显示弹出层(用户导入)
  215. open: false,
  216. // 弹出层标题(用户导入)
  217. title: "",
  218. // 是否禁用上传
  219. isUploading: false,
  220. // 是否更新已经存在的用户数据
  221. updateSupport: 0,
  222. // 设置上传的请求头部
  223. headers: { Authorization: "Bearer " + getToken() },
  224. // 上传的地址
  225. url: process.env.VUE_APP_BASE_API + "/invoice/device/importData"
  226. },
  227. // 查询参数
  228. queryParams: {
  229. pageNum: 1,
  230. pageSize: 20,
  231. devName: null,
  232. workArea: null,
  233. regionalHead: null,
  234. createrCode: null,
  235. createdate: null,
  236. updaterCode: null,
  237. updatedate: null,
  238. deptId: null,
  239. remarks: null
  240. },
  241. // 表单参数
  242. form: {},
  243. // 表单校验
  244. rules: {
  245. devName: [
  246. { required: true, message: "装置名称不能为空", trigger: "blur" }
  247. ],
  248. workArea: [
  249. { required: true, message: "工作区域不能为空", trigger: "blur" }
  250. ],
  251. regionalHead: [
  252. { required: true, message: "负责人不能为空", trigger: "blur" }
  253. ],
  254. deptId: [
  255. { required: true, message: "所属部门不能为空", trigger: "blur" }
  256. ],
  257. }
  258. };
  259. },
  260. watch: {
  261. // 根据名称筛选部门树
  262. deptName(val) {
  263. this.$refs.tree.filter(val);
  264. }
  265. },
  266. created() {
  267. //设置表格高度对应屏幕高度
  268. this.$nextTick(() => {
  269. this.clientHeight = document.body.clientHeight -250
  270. })
  271. this.getList();
  272. this.getTreeselect();
  273. },
  274. methods: {
  275. /** 查询装置区域管理列表 */
  276. getList() {
  277. listPostUser({}).then(response => {
  278. this.principalList = response;
  279. let _this = this
  280. this.loading = true;
  281. listDevice(this.queryParams).then(response => {
  282. this.deviceList = response.rows;
  283. this.$nextTick(() => {
  284. this.$refs.deviceTable.doLayout(); // 解决表格错位
  285. });
  286. this.total = response.total;
  287. this.loading = false;
  288. this.deviceList.forEach(function (value, key, arr) {
  289. var principalName = null;
  290. let principal = null;
  291. if (value.regionalHead != null) {
  292. principal = value.regionalHead.split(",");
  293. principal.forEach(function (value, key, arr) {
  294. _this.principalList.forEach(function (v, k, arr) {
  295. if (value == v.userId) {
  296. if (key != 0) {
  297. principalName = principalName + "," + v.nickName;
  298. } else if (key == 0) {
  299. principalName = v.nickName;
  300. }
  301. }
  302. })
  303. });
  304. }
  305. _this.deviceList[key].regionalHead = principal;
  306. _this.deviceList[key].regionalHeadName = principalName;
  307. })
  308. });
  309. });
  310. },
  311. /** 查询部门下拉树结构 */
  312. getTreeselect() {
  313. treeselect().then(response => {
  314. this.deptOptions = response.data;
  315. });
  316. },
  317. // 取消按钮
  318. cancel() {
  319. this.open = false;
  320. this.reset();
  321. },
  322. // 表单重置
  323. reset() {
  324. this.form = {
  325. id: null,
  326. devName: null,
  327. workArea: null,
  328. regionalHead: null,
  329. delFlag: null,
  330. createrCode: null,
  331. createdate: null,
  332. updaterCode: null,
  333. updatedate: null,
  334. deptId: null,
  335. remarks: null
  336. };
  337. this.resetForm("form");
  338. },
  339. /** 搜索按钮操作 */
  340. handleQuery() {
  341. this.queryParams.pageNum = 1;
  342. this.getList();
  343. },
  344. /** 重置按钮操作 */
  345. resetQuery() {
  346. this.resetForm("queryForm");
  347. this.handleQuery();
  348. },
  349. // 多选框选中数据
  350. handleSelectionChange(selection) {
  351. this.ids = selection.map(item => item.id)
  352. this.single = selection.length!==1
  353. this.multiple = !selection.length
  354. },
  355. /** 新增按钮操作 */
  356. handleAdd() {
  357. this.reset();
  358. this.open = true;
  359. this.title = "添加 装置区域管理信息";
  360. },
  361. /** 修改按钮操作 */
  362. handleUpdate(row) {
  363. this.reset();
  364. const id = row.id || this.ids
  365. getDevice(id).then(response => {
  366. this.form = response.data;
  367. let regionalHead=this.form.regionalHead.split(",");
  368. regionalHead.forEach(function (value,key,arr){
  369. value=value-0;
  370. regionalHead[key]=value
  371. })
  372. this.form.regionalHead=regionalHead;
  373. this.open = true;
  374. this.title = "修改装置区域管理";
  375. });
  376. },
  377. /** 提交按钮 */
  378. submitForm() {
  379. let regionalHead = "";
  380. this.form.regionalHead.forEach(item =>{
  381. regionalHead+=item+",";
  382. })
  383. this.form.regionalHead=regionalHead.substring(0,regionalHead.length-1);
  384. this.$refs["form"].validate(valid => {
  385. if (valid) {
  386. if (this.form.id != null) {
  387. updateDevice(this.form).then(response => {
  388. this.msgSuccess("修改成功");
  389. this.open = false;
  390. this.getList();
  391. });
  392. } else {
  393. addDevice(this.form).then(response => {
  394. this.msgSuccess("新增成功");
  395. this.open = false;
  396. this.getList();
  397. });
  398. }
  399. }
  400. });
  401. },
  402. /** 删除按钮操作 */
  403. handleDelete(row) {
  404. const ids = row.id || this.ids;
  405. this.$confirm('是否确认删除?', "警告", {
  406. confirmButtonText: "确定",
  407. cancelButtonText: "取消",
  408. type: "warning"
  409. }).then(function() {
  410. return delDevice(ids);
  411. }).then(() => {
  412. this.getList();
  413. this.msgSuccess("删除成功");
  414. })
  415. },
  416. /** 导出按钮操作 */
  417. handleExport() {
  418. const queryParams = this.queryParams;
  419. this.$confirm('是否确认导出所有装置区域管理数据项?', "警告", {
  420. confirmButtonText: "确定",
  421. cancelButtonText: "取消",
  422. type: "warning"
  423. }).then(function() {
  424. return exportDevice(queryParams);
  425. }).then(response => {
  426. this.download(response.msg);
  427. })
  428. },
  429. /** 导入按钮操作 */
  430. handleImport() {
  431. this.upload.title = "用户导入";
  432. this.upload.open = true;
  433. },
  434. /** 下载模板操作 */
  435. importTemplate() {
  436. importTemplate().then(response => {
  437. this.download(response.msg);
  438. });
  439. },
  440. // 文件上传中处理
  441. handleFileUploadProgress(event, file, fileList) {
  442. this.upload.isUploading = true;
  443. },
  444. // 文件上传成功处理
  445. handleFileSuccess(response, file, fileList) {
  446. this.upload.open = false;
  447. this.upload.isUploading = false;
  448. this.$refs.upload.clearFiles();
  449. this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
  450. this.getList();
  451. },
  452. // 提交上传文件
  453. submitFileForm() {
  454. this.$refs.upload.submit();
  455. }
  456. }
  457. };
  458. </script>