index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--机构数据-->
  5. <el-col :span="4" :xs="24">
  6. <org-tree v-model="queryParams.orgId" @defaultKey="getDefaultKey" @defaultOrg="getDefaultOrg" @checkChange="checkChange"
  7. @click="clickTreeNode"></org-tree>
  8. </el-col>
  9. <el-col :span="20" :xs="24">
  10. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
  11. label-width="68px">
  12. <el-form-item label="设备名称" prop="deviceName">
  13. <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" maxlength="50"
  14. @keyup.enter.native="handleQuery" />
  15. </el-form-item>
  16. <el-form-item label="资产类别" prop="assetType">
  17. <el-select style="width: 100%;" v-model="queryParams.assetType" placeholder="请选择"
  18. @change="changeSelectDevice">
  19. <el-option v-for="dict in dict.type.sys_asset_type" :key="dict.value" :label="dict.label"
  20. :value="`${dict.value}`"></el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="设备分类" prop="deviceType">
  24. <el-select style="width: 100%;" v-model="queryParams.deviceType" placeholder="请选择">
  25. <el-option v-for="item in devices" :key="item.dictValue" :label="item.dictLabel"
  26. :value="item.dictValue"></el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item>
  30. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  31. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  32. </el-form-item>
  33. </el-form>
  34. <el-row :gutter="10" class="mb8">
  35. <!-- <el-col :span="1.5">
  36. <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
  37. v-hasPermi="['system:device:import']">导入</el-button>
  38. </el-col> -->
  39. <el-col :span="1.5">
  40. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleImport" v-hasPermi="['system:device:importData']">导入</el-button>
  41. </el-col>
  42. <el-col :span="1.5">
  43. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['system:device:add']">新增</el-button>
  44. </el-col>
  45. <el-col :span="1.5">
  46. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleOut" v-hasPermi="['system:user:export']">导出模版</el-button>
  47. </el-col>
  48. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  49. </el-row>
  50. <el-table border height="600" size="small" v-loading="loading" :data="deviceList"
  51. @selection-change="handleSelectionChange">
  52. <!--<el-table-column type="selection" width="55" align="center" />-->
  53. <el-table-column label="序号" align="center" min-width="50">
  54. <template v-slot:default="scope">
  55. <span v-text="getPageIndex(scope.$index)"> </span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="所属机构" align="left" prop="orgName" />
  59. <el-table-column label="资产类别" align="center" key="assetType" prop="assetType" width="80">
  60. <template slot-scope="scope">
  61. <dict-tag :options="dict.type.sys_asset_type" :value="scope.row.assetType" />
  62. </template>
  63. </el-table-column>
  64. <el-table-column label="设备分类" align="center" key="deviceType" prop="deviceType" width="80">
  65. <template slot-scope="scope">
  66. <dict-tag :options="dict.type.sys_device_type" :value="scope.row.deviceType" />
  67. </template>
  68. </el-table-column>
  69. <el-table-column label="设备名称" align="center" prop="deviceName" />
  70. <el-table-column label="设备品牌" align="center" prop="deviceBrand" />
  71. <el-table-column label="有效期至" align="center" prop="checkTime" width="160">
  72. </el-table-column>
  73. <!-- <el-table-column label="保修期限" align="center" prop="maintenanceTerm" /> -->
  74. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  75. <template slot-scope="scope">
  76. <el-button size="mini" type="text" icon="el-icon-edit-outline" @click="handleUpdate(scope.row)"
  77. v-hasPermi="['system:device:edit']">编辑</el-button>
  78. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  79. v-hasPermi="['system:device:remove']">删除</el-button>
  80. </template>
  81. </el-table-column>
  82. </el-table>
  83. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
  84. :limit.sync="queryParams.pageSize" @pagination="getList" />
  85. </el-col>
  86. </el-row>
  87. <!-- 添加或修改【请填写功能名称】对话框 -->
  88. <DialogCom
  89. :title="title"
  90. :visible.sync="open"
  91. width="700px"
  92. @close="closeHandler"
  93. append-to-body
  94. >
  95. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  96. <el-row>
  97. <el-col :span="20">
  98. <el-form-item label="所属机构" prop="orgId">
  99. <tree-select
  100. v-model="form.orgId"
  101. :options="deptOptions"
  102. :show-count="true"
  103. :normalizer="tenantIdnormalizer"
  104. :props="{ checkStrictly: true, label: 'name' }"
  105. placeholder="请选择归属机构"
  106. @select="changeSelect"
  107. clearValueText="清除"
  108. />
  109. </el-form-item>
  110. </el-col>
  111. </el-row>
  112. <el-row>
  113. <el-col :span="12">
  114. <el-form-item label="资产类别" prop="assetType">
  115. <el-select style="width: 100%;" v-model="form.assetType" placeholder="请选择" @change="changeSelectDevice">
  116. <el-option v-for="dict in dict.type.sys_asset_type" :key="dict.value" :label="dict.label"
  117. :value="`${dict.value}`"></el-option>
  118. </el-select>
  119. </el-form-item>
  120. </el-col>
  121. <el-col :span="12">
  122. <el-form-item label="设备分类" prop="deviceType">
  123. <el-select style="width: 100%" v-model="form.deviceType" placeholder="请选择">
  124. <el-option v-for="item in devices" :key="item.dictValue" :label="item.dictLabel"
  125. :value="item.dictValue"></el-option>
  126. </el-select>
  127. </el-form-item>
  128. </el-col>
  129. </el-row>
  130. <el-row>
  131. <el-col :span="12">
  132. <el-form-item label="设备名称" prop="deviceName">
  133. <el-input v-model="form.deviceName" placeholder="请输入" maxlength="50"/>
  134. </el-form-item>
  135. </el-col>
  136. <el-col :span="12">
  137. <el-form-item label="设备品牌" prop="deviceBrand">
  138. <el-input v-model="form.deviceBrand" placeholder="请输入" maxlength="50" />
  139. </el-form-item>
  140. </el-col>
  141. </el-row>
  142. <el-row>
  143. <el-col :span="12">
  144. <el-form-item v-if="form.deviceType == 2" label="主机" prop="hostId">
  145. <el-select style="width: 100%" v-model="form.hostId" placeholder="请选择">
  146. <el-option v-for="item in hostList" :key="item.id" :label="item.deviceName" :value="item.id"></el-option>
  147. </el-select>
  148. </el-form-item>
  149. </el-col>
  150. <el-col :span="12">
  151. <el-form-item v-if="form.deviceType == 2" label="通道号" prop="channel">
  152. <el-input type="number" max="64" min="0"
  153. oninput="if(value<=0)value=null;if(value>=64)value=64;value=parseInt(value)" v-model="form.channel"
  154. placeholder="请输入" />
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. <el-row>
  159. <el-col :span="12">
  160. <el-form-item v-if="form.assetType == 0" label="有效期至" prop="checkTime">
  161. <el-date-picker style="width: 100%" clearable v-model="form.checkTime" type="date"
  162. value-format="yyyy-MM-dd HH:mm:ss" placeholder="请选择时间">
  163. </el-date-picker>
  164. </el-form-item>
  165. </el-col>
  166. </el-row>
  167. <el-row>
  168. </el-row>
  169. </el-form>
  170. <div slot="footer" class="dialog-footer">
  171. <el-button type="primary" @click="submitForm">确 定</el-button>
  172. <el-button @click="cancel">取 消</el-button>
  173. </div>
  174. </DialogCom>
  175. <!-- 设备导入对话框 -->
  176. <DialogCom :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
  177. <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
  178. :action="upload.url " :disabled="upload.isUploading"
  179. :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" drag>
  180. <i class="el-icon-upload"></i>
  181. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  182. </el-upload>
  183. <div slot="footer" class="dialog-footer">
  184. <el-button type="primary" @click="submitFileForm">确 定</el-button>
  185. <el-button @click="upload.open = false">取 消</el-button>
  186. </div>
  187. </DialogCom>
  188. </div>
  189. </template>
  190. <script>
  191. import { getToken } from "@/utils/auth";
  192. import orgDropDown from "../../../components/orgTree/orgDropDown.vue";
  193. import OrgTree from "@/components/orgTree";
  194. import tableList from '@/mixins/tableList'
  195. import treeselect from '@riophae/vue-treeselect'
  196. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  197. import { deptTreeSelect } from "@/api/system/public";
  198. import { getDeviceType } from "@/api/system/dict/data";
  199. import { listDevice, getDevice, delDevice, addDevice, updateDevice, getHostByOrgId ,downInCharge} from "@/api/system/device";
  200. export default {
  201. /** 引入基础minxins*/
  202. mixins: [tableList],
  203. dicts: ['sys_asset_type', 'sys_device_type'],
  204. name: "Device",
  205. components: { OrgTree, treeselect,orgDropDown },
  206. data() {
  207. return {
  208. checkList: [],
  209. roleOptions: [],
  210. defaultKeys: [],
  211. //是否关联下级
  212. checked: false,
  213. defaultProps: {
  214. children: "children",
  215. label: "name"
  216. },
  217. rules: {
  218. deviceName: [
  219. { required: true, message: '请输入设备名称', trigger: 'change' },
  220. ],
  221. orgId: [
  222. { required: true, message: '请选择所属机构', trigger: 'blur' },
  223. ],
  224. assetType: [
  225. { required: true, message: '请选择资产类别', trigger: 'change' },
  226. ],
  227. hostId: [{ required: true, message: '请选择主机', trigger: 'change' }],
  228. channel: [{ required: true, message: '请输入通道号', trigger: 'change' }],
  229. deviceType: [
  230. { required: true, message: '请选择设备分类', trigger: 'change' },
  231. ],
  232. checkTime: [
  233. { required: true, message: '请选择有效期', trigger: 'blur' },
  234. ]
  235. },
  236. // 遮罩层
  237. loading: true,
  238. // 选中数组
  239. ids: [],
  240. // 非单个禁用
  241. single: true,
  242. //搜索tree
  243. deptName: null,
  244. // 非多个禁用
  245. multiple: true,
  246. // 显示搜索条件
  247. showSearch: true,
  248. // 总条数
  249. total: 0,
  250. inparm: 0,
  251. // 【请填写功能名称】表格数据
  252. deviceList: [],
  253. devices: null,
  254. //主机集合
  255. hostList: [],
  256. deviceType: 0,
  257. // 弹出层标题
  258. title: "",
  259. // 是否显示弹出层
  260. open: false,
  261. // 查询参数
  262. dept:{
  263. id:null
  264. },
  265. queryParams: {
  266. pageNum: 1,
  267. pageSize: 10,
  268. orgId: null,
  269. orgName: null,
  270. deviceName: null,
  271. assetType: null,
  272. deviceType: null,
  273. deviceBrand: null,
  274. checkTime: null,
  275. maintenanceTerm: null,
  276. hostId: null,
  277. channel: null,
  278. checkSub: true
  279. },
  280. // 设备导入参数
  281. upload: {
  282. // 是否显示弹出层(用户导入)
  283. open: false,
  284. // 弹出层标题(用户导入)
  285. title: "",
  286. // 是否禁用上传
  287. isUploading: false,
  288. // 设置上传的请求头部
  289. headers: { Authorization: "Bearer " + getToken() },
  290. // 上传的地址
  291. url: process.env.NODE_ENV === "development"?process.env.VUE_APP_BASE_API + "/system/device/importData":window.origin+"/system/device/importData",
  292. },
  293. // 表单参数
  294. form: {
  295. orgId: null,
  296. deviceName: null,
  297. assetType: null,
  298. deviceType: null,
  299. deviceBrand: null,
  300. checkTime: null,
  301. maintenanceTerm: null,
  302. hostId: null,
  303. channel: null
  304. },
  305. // 表单校验
  306. //修改新增中的机构树
  307. deptOptions: [],
  308. selectOrgId: null,
  309. };
  310. },
  311. created() {
  312. this.getDeptTree();
  313. //this.getList();
  314. },
  315. watch: {
  316. // 根据名称筛选部门树
  317. deptName(val) {
  318. this.$refs.tree.filter(val);
  319. }
  320. },
  321. methods: {
  322. onOrgSelect(node) {
  323. this.form.orgPath = node.path;
  324. debugger
  325. this.form.orgName = node.name;
  326. },
  327. // 文件上传中处理
  328. handleFileUploadProgress(event, file, fileList) {
  329. this.upload.isUploading = true;
  330. },
  331. handleImport() {
  332. this.upload.title = "设备导入";
  333. this.upload.open = true;
  334. },
  335. // 文件上传成功处理
  336. handleFileSuccess(response, file, fileList) {
  337. this.upload.open = false;
  338. this.upload.isUploading = false;
  339. this.$refs.upload.clearFiles();
  340. this.$alert(
  341. "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
  342. response.msg +
  343. "</div>",
  344. "导入结果",
  345. { dangerouslyUseHTMLString: true }
  346. );
  347. this.getList();
  348. },
  349. getDefaultOrg(org){
  350. this.orgName = org.name;
  351. },
  352. getDefaultKey(key) {
  353. this.queryParams.orgId = key;
  354. this.getList();
  355. },
  356. //单选框状态改变
  357. checkChange(state) {
  358. this.queryParams.checkSub = state;
  359. this.handleQuery();
  360. },
  361. getPageIndex($index) {
  362. //表格序号
  363. return (
  364. (this.queryParams.pageNum - 1) * this.queryParams.pageSize + $index + 1
  365. );
  366. },
  367. /** 下穿状态改变*/
  368. changeCheckBox() {
  369. this.getList();
  370. },
  371. // 筛选节点
  372. filterNode(value, data) {
  373. if (!value) return true;
  374. return data.name.indexOf(value) !== -1;
  375. },
  376. /** 查询机构树数据 */
  377. // 节点单击事件
  378. handleNodeClick(data) {
  379. this.queryParams.orgId = data.id;
  380. this.selectOrgId = data.id;
  381. this.changeSelect(data);
  382. this.handleQuery();
  383. },
  384. changeSelect(val) {
  385. getHostByOrgId(val).then(response => {
  386. this.form.hostId = null;
  387. this.hostList = response.data;
  388. })
  389. },
  390. handleOut(){
  391. this.download('system/device/downInChargeOfTemplate', {
  392. ...this.queryParams
  393. }, `${this.orgName+'-设备导入-'+this.formatTime(new Date(),'YYYYMMhh')}.xlsx`)
  394. },
  395. /** 查询【请填写功能名称】列表 */
  396. getList() {
  397. this.loading = true;
  398. listDevice(this.queryParams).then(response => {
  399. this.deviceList = response.rows;
  400. this.total = response.total;
  401. this.loading = false;
  402. });
  403. },
  404. /** 查询部门下拉树结构 */
  405. getDeptTree() {
  406. deptTreeSelect().then(response => {
  407. this.deptOptions = response.data;
  408. this.defaultKeys.push(response.data[0].id);
  409. this.queryParams.orgId = response.data[0].id;
  410. this.selectOrgId = response.data[0].id;
  411. this.handleQuery();
  412. });
  413. },
  414. // 节点单击事件
  415. clickTreeNode(data) {
  416. this.queryParams.orgId = data.id;
  417. this.handleQuery();
  418. },
  419. /** treeSelect组件自定义数据*/
  420. tenantIdnormalizer(node, instanceId) {
  421. if (node.children && !node.children.length) {
  422. delete node.children;
  423. }
  424. return {
  425. id: node.id,
  426. label: node.shortName,
  427. children: node.children,
  428. };
  429. },
  430. // 取消按钮
  431. cancel() {
  432. this.open = false;
  433. this.reset();
  434. },
  435. closeHandler() {
  436. this.reset();
  437. },
  438. // 表单重置
  439. reset() {
  440. this.form = {
  441. id: null,
  442. orgId: null,
  443. orgName: null,
  444. deviceName: null,
  445. assetType: null,
  446. deviceType: null,
  447. deviceBrand: null,
  448. checkTime: null,
  449. maintenanceTerm: null,
  450. createTime: null,
  451. updateTime: null,
  452. createBy: null,
  453. updateBy: null,
  454. delFlag: null,
  455. hostId: null,
  456. channel: null
  457. };
  458. this.resetForm("form");
  459. },
  460. /** 搜索按钮操作 */
  461. handleQuery() {
  462. this.queryParams.pageNum = 1;
  463. this.getList();
  464. },
  465. /** 重置按钮操作 */
  466. resetQuery() {
  467. this.devices=null;
  468. this.resetForm("queryForm");
  469. this.handleQuery();
  470. },
  471. // 多选框选中数据
  472. handleSelectionChange(selection) {
  473. this.ids = selection.map(item => item.id)
  474. this.names = selection.map(item => item.deviceName)
  475. this.single = selection.length !== 1
  476. this.multiple = !selection.length
  477. },
  478. /** 新增按钮操作 */
  479. handleAdd(val) {
  480. this.open = true;
  481. this.title = "新增";
  482. this.form.orgId = this.selectOrgId;
  483. this.dept.id=this.selectOrgId;
  484. this.changeSelect(this.dept);
  485. this.devices=null;
  486. },
  487. changeSelectDevice(val) {
  488. if (val) {
  489. getDeviceType(val).then(response => {
  490. this.devices = response.data;
  491. this.form.deviceType = null;
  492. this.queryParams.deviceType = null;
  493. })
  494. }
  495. },
  496. /** 修改按钮操作 */
  497. handleUpdate(row) {
  498. this.reset();
  499. const id = row.id || this.ids
  500. getDevice(id).then(response => {
  501. this.form = response.data;
  502. this.devices=response.devices;
  503. this.hostList=response.hostList;
  504. this.open = true;
  505. this.title = "编辑";
  506. });
  507. },
  508. /** 提交按钮 */
  509. submitForm() {
  510. this.$refs["form"].validate(valid => {
  511. if (valid) {
  512. if (this.form.id != null) {
  513. updateDevice(this.form).then(response => {
  514. this.$modal.msgSuccess("处理成功");
  515. this.open = false;
  516. this.getList();
  517. });
  518. } else {
  519. addDevice(this.form).then(response => {
  520. this.$modal.msgSuccess("处理成功");
  521. this.open = false;
  522. this.getList();
  523. });
  524. }
  525. }
  526. });
  527. },
  528. /** 删除按钮操作 */
  529. handleDelete(row) {
  530. const ids = row.id || this.ids;
  531. const names = row.deviceName || this.names;
  532. this.$modal.confirm('是否确认删除名称为"' + names + '"的数据项?').then(function () {
  533. return delDevice(ids);
  534. }).then(() => {
  535. this.getList();
  536. this.$modal.msgSuccess("删除成功");
  537. }).catch(() => { });
  538. },
  539. // 提交上传文件
  540. submitFileForm() {
  541. this.$refs.upload.submit();
  542. },
  543. /** 导出按钮操作 */
  544. handleExport() {
  545. this.download('system/device/export', {
  546. ...this.queryParams
  547. }, `device_${new Date().getTime()}.xlsx`)
  548. }
  549. }
  550. };
  551. </script>