index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. <template>
  2. <div class="app-container">
  3. <el-row :gutter="20">
  4. <!--部门数据-->
  5. <el-col :span="4" :xs="24">
  6. <div class="head-container">
  7. <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search"
  8. style="margin-bottom: 20px" />
  9. </div>
  10. <div class="tree-container">
  11. <div style="margin-bottom: 10px;">
  12. <el-checkbox v-model="queryParams.checkSub" @change="changeCheckBox">是否关联下级机构</el-checkbox>
  13. </div>
  14. <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
  15. :filter-node-method="filterNode" ref="tree" node-key="id" :default-expanded-keys="defaultKeys"
  16. :default-checked-keys="defaultKeys" @node-click="handleNodeClick" />
  17. </div>
  18. </el-col>
  19. <el-col :span="20" :xs="24">
  20. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  21. <el-form-item label="设备名称" prop="deviceName">
  22. <el-input v-model="queryParams.deviceName" placeholder="请输入设备名称" clearable
  23. @keyup.enter.native="handleQuery" />
  24. </el-form-item>
  25. <el-form-item label="资产类别" prop="assetType">
  26. <el-select style="width: 100%;" v-model="queryParams.assetType" placeholder="请选择">
  27. <el-option v-for="dict in dict.type.sys_asset_type" :key="dict.value" :label="dict.label"
  28. :value="`${dict.value}`"></el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="设备分类" prop="deviceType">
  32. <el-select style="width: 100%;" v-model="queryParams.deviceType" placeholder="请选择">
  33. <el-option v-for="dict in dict.type.sys_device_type" :key="dict.value" :label="dict.label"
  34. :value="`${dict.value}`"></el-option>
  35. </el-select>
  36. </el-form-item>
  37. <el-form-item>
  38. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  39. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  40. </el-form-item>
  41. </el-form>
  42. <el-row :gutter="10" class="mb8">
  43. <el-col :span="1.5">
  44. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  45. v-hasPermi="['system:device:add']">新增</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
  49. v-hasPermi="['system:device:edit']">修改</el-button>
  50. </el-col>
  51. <el-col :span="1.5">
  52. <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
  53. v-hasPermi="['system:device:remove']">删除</el-button>
  54. </el-col>
  55. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  56. </el-row>
  57. <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
  58. <el-table-column type="selection" width="55" align="center" />
  59. <el-table-column label="所属机构" align="center" prop="orgName" />
  60. <el-table-column label="设备名称" align="center" prop="deviceName" />
  61. <el-table-column label="资产类别" align="center" key="assetType" prop="assetType" width="80">
  62. <template slot-scope="scope">
  63. <dict-tag :options="dict.type.sys_asset_type" :value="scope.row.assetType" />
  64. </template>
  65. </el-table-column>
  66. <el-table-column label="设备分类" align="center" key="deviceType" prop="deviceType" width="80">
  67. <template slot-scope="scope">
  68. <dict-tag :options="dict.type.sys_device_type" :value="scope.row.deviceType" />
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="设备品牌" align="center" prop="deviceBrand" />
  72. <el-table-column label="验收日期" align="center" prop="checkTime" width="160">
  73. </el-table-column>
  74. <el-table-column label="保修期限" align="center" prop="maintenanceTerm" />
  75. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  76. <template slot-scope="scope">
  77. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  78. v-hasPermi="['system:device:edit']">修改</el-button>
  79. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  80. v-hasPermi="['system:device:remove']">删除</el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
  85. @pagination="getList" />
  86. </el-col>
  87. </el-row>
  88. <!-- 添加或修改【请填写功能名称】对话框 -->
  89. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  90. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  91. <el-row>
  92. <el-col :span="10">
  93. <el-form-item label="设备名称" prop="deviceName">
  94. <el-input v-model="form.deviceName" placeholder="请输入" />
  95. </el-form-item>
  96. </el-col>
  97. <el-col :span="10">
  98. <el-form-item label="所属机构" prop="orgId">
  99. <tree-select v-model="form.orgId" :options="deptOptions" :show-count="true" :normalizer="tenantIdnormalizer"
  100. :props="{ checkStrictly: true, label: 'name' }" placeholder="请选择归属机构" @select="changeSelect">
  101. </tree-select>
  102. </el-form-item>
  103. </el-col>
  104. </el-row>
  105. <el-row>
  106. <el-col :span="10">
  107. <el-form-item label="资产类别" prop="assetType">
  108. <el-select style="width: 100%;" v-model="form.assetType" placeholder="请选择">
  109. <el-option v-for="dict in dict.type.sys_asset_type" :key="dict.value" :label="dict.label"
  110. :value="`${dict.value}`"></el-option>
  111. </el-select>
  112. </el-form-item>
  113. </el-col>
  114. <el-col :span="10">
  115. <el-form-item label="设备分类" prop="deviceType">
  116. <el-select style="width: 100%;" v-model="form.deviceType" placeholder="请选择">
  117. <el-option v-for="dict in dict.type.sys_device_type" :key="dict.value" :label="dict.label"
  118. :value="`${dict.value}`"></el-option>
  119. </el-select>
  120. </el-form-item>
  121. </el-col>
  122. </el-row>
  123. <el-row>
  124. <el-col :span="10">
  125. <el-form-item v-if="form.deviceType == 2" label="主机" prop="hostId">
  126. <el-select v-model="form.hostId" placeholder="请选择">
  127. <el-option v-for="item in hostList" :key="item.id" :label="item.deviceName" :value="item.id"></el-option>
  128. </el-select>
  129. </el-form-item>
  130. </el-col>
  131. <el-col :span="10">
  132. <el-form-item v-if="form.deviceType == 2" label="通道号" prop="channel">
  133. <el-input v-model="form.channel" placeholder="请输入" />
  134. </el-form-item>
  135. </el-col>
  136. </el-row>
  137. <el-row>
  138. <el-col :span="10">
  139. <el-form-item label="设备品牌" prop="deviceBrand">
  140. <el-input v-model="form.deviceBrand" placeholder="请输入" maxlength="30" />
  141. </el-form-item>
  142. </el-col>
  143. <el-col :span="10">
  144. <el-form-item style="width: 517px;" label="验收日期" prop="checkTime">
  145. <el-date-picker clearable v-model="form.checkTime" type="date" value-format="yyyy-MM-dd HH:mm:ss"
  146. placeholder="请选择时间">
  147. </el-date-picker>
  148. </el-form-item>
  149. </el-col>
  150. </el-row>
  151. <el-row>
  152. <el-col :span="10">
  153. <el-form-item label="保修期限" prop="maintenanceTerm">
  154. <el-input v-model="form.maintenanceTerm" placeholder="请输入" maxlength="11" />
  155. </el-form-item>
  156. </el-col>
  157. </el-row>
  158. </el-form>
  159. <div slot="footer" class="dialog-footer">
  160. <el-button type="primary" @click="submitForm">确 定</el-button>
  161. <el-button @click="cancel">取 消</el-button>
  162. </div>
  163. </el-dialog>
  164. </div>
  165. </template>
  166. <script>
  167. import tableList from '@/mixins/tableList'
  168. import treeselect from '@riophae/vue-treeselect'
  169. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  170. import { deptTreeSelect } from "@/api/system/public";
  171. import { listDevice, getDevice, delDevice, addDevice, updateDevice, getHostByOrgId } from "@/api/system/device";
  172. export default {
  173. /** 引入基础minxins*/
  174. mixins: [tableList],
  175. dicts: ['sys_asset_type', 'sys_device_type'],
  176. name: "Device",
  177. components: { treeselect },
  178. data() {
  179. return {
  180. checkList: [],
  181. roleOptions: [],
  182. defaultKeys: [],
  183. //是否关联下级
  184. checked: false,
  185. defaultProps: {
  186. children: "children",
  187. label: "name"
  188. },
  189. rules: {
  190. deviceName: [
  191. { required: true, message: '请输入设备名称', trigger: 'change' },
  192. ],
  193. orgId: [
  194. { required: true, message: '请选择所属机构', trigger: 'blur' },
  195. ],
  196. assetType: [
  197. { required: true, message: '请选择资产类别', trigger: 'blur' },
  198. ],
  199. hostId: [{ required: true, message: '请选择主机', trigger: 'blur' }],
  200. channel: [{ required: true, message: '请输入通道号', trigger: 'change' }],
  201. deviceType: [
  202. { required: true, message: '请选择设备分类', trigger: 'blur' },
  203. ],
  204. },
  205. // 遮罩层
  206. loading: true,
  207. // 选中数组
  208. ids: [],
  209. // 非单个禁用
  210. single: true,
  211. //搜索tree
  212. deptName: null,
  213. // 非多个禁用
  214. multiple: true,
  215. // 显示搜索条件
  216. showSearch: true,
  217. // 总条数
  218. total: 0,
  219. // 【请填写功能名称】表格数据
  220. deviceList: [],
  221. //主机集合
  222. hostList: [],
  223. deviceType: 0,
  224. // 弹出层标题
  225. title: "",
  226. // 是否显示弹出层
  227. open: false,
  228. // 查询参数
  229. queryParams: {
  230. pageNum: 1,
  231. pageSize: 10,
  232. orgId: null,
  233. orgName: null,
  234. deviceName: null,
  235. assetType: null,
  236. deviceType: null,
  237. deviceBrand: null,
  238. checkTime: null,
  239. maintenanceTerm: null,
  240. hostId: null,
  241. channel: null
  242. },
  243. // 表单参数
  244. form: {
  245. orgId: null,
  246. deviceName: null,
  247. assetType: null,
  248. deviceType: null,
  249. deviceBrand: null,
  250. checkTime: null,
  251. maintenanceTerm: null,
  252. hostId: null,
  253. channel: null
  254. },
  255. // 表单校验
  256. //修改新增中的机构树
  257. deptOptions: [],
  258. };
  259. },
  260. created() {
  261. this.getDeptTree();
  262. this.getList();
  263. },
  264. watch: {
  265. // 根据名称筛选部门树
  266. deptName(val) {
  267. this.$refs.tree.filter(val);
  268. }
  269. },
  270. methods: {
  271. /** 下穿状态改变*/
  272. changeCheckBox() {
  273. this.getList();
  274. },
  275. // 筛选节点
  276. filterNode(value, data) {
  277. if (!value) return true;
  278. return data.name.indexOf(value) !== -1;
  279. },
  280. /** 查询机构树数据 */
  281. /** 查询部门下拉树结构 */
  282. getDeptTree() {
  283. deptTreeSelect().then(response => {
  284. this.deptOptions = response.data;
  285. console.log(this.deptOptions, ' this.deptOptions')
  286. this.defaultKeys.push(response.data[0].id);
  287. this.queryParams.orgId = response.data[0].id;
  288. this.handleQuery();
  289. });
  290. },
  291. /** treeSelect组件自定义数据*/
  292. tenantIdnormalizer(node, instanceId) {
  293. if (node.children && !node.children.length) {
  294. delete node.children
  295. }
  296. return {
  297. id: node.id,
  298. label: node.name,
  299. children: node.children
  300. }
  301. },
  302. // 节点单击事件
  303. handleNodeClick(data) {
  304. this.queryParams.orgId = data.id;
  305. this.handleQuery();
  306. },
  307. changeSelect(val) {
  308. getHostByOrgId(val).then(response => {
  309. this.form.hostId = null;
  310. this.hostList = response.data;
  311. })
  312. },
  313. /** 查询【请填写功能名称】列表 */
  314. getList() {
  315. this.loading = true;
  316. listDevice(this.queryParams).then(response => {
  317. this.deviceList = response.rows;
  318. this.total = response.total;
  319. this.loading = false;
  320. });
  321. },
  322. /** 查询部门下拉树结构 */
  323. getDeptTree() {
  324. deptTreeSelect().then(response => {
  325. this.deptOptions = response.data;
  326. console.log(this.deptOptions, ' this.deptOptions')
  327. this.defaultKeys.push(response.data[0].id);
  328. this.queryParams.orgId = response.data[0].id;
  329. this.handleQuery();
  330. });
  331. },
  332. tenantIdnormalizer(node, instanceId) {
  333. if (node.children && !node.children.length) {
  334. delete node.children
  335. }
  336. return {
  337. id: node.id,
  338. label: node.name,
  339. children: node.children
  340. }
  341. },
  342. // 取消按钮
  343. cancel() {
  344. this.open = false;
  345. this.reset();
  346. },
  347. // 表单重置
  348. reset() {
  349. this.form = {
  350. id: null,
  351. orgId: null,
  352. orgName: null,
  353. deviceName: null,
  354. assetType: null,
  355. deviceType: null,
  356. deviceBrand: null,
  357. checkTime: null,
  358. maintenanceTerm: null,
  359. createTime: null,
  360. updateTime: null,
  361. createBy: null,
  362. updateBy: null,
  363. delFlag: null,
  364. hostId: null,
  365. channel: null
  366. };
  367. this.resetForm("form");
  368. },
  369. /** 搜索按钮操作 */
  370. handleQuery() {
  371. this.queryParams.pageNum = 1;
  372. this.getList();
  373. },
  374. /** 重置按钮操作 */
  375. resetQuery() {
  376. this.resetForm("queryForm");
  377. this.handleQuery();
  378. },
  379. // 多选框选中数据
  380. handleSelectionChange(selection) {
  381. this.ids = selection.map(item => item.id)
  382. this.names = selection.map(item => item.deviceName)
  383. this.single = selection.length !== 1
  384. this.multiple = !selection.length
  385. },
  386. /** 新增按钮操作 */
  387. handleAdd() {
  388. this.reset();
  389. this.open = true;
  390. this.title = "新增";
  391. },
  392. /** 修改按钮操作 */
  393. handleUpdate(row) {
  394. this.reset();
  395. const id = row.id || this.ids
  396. getDevice(id).then(response => {
  397. this.form = response.data;
  398. this.open = true;
  399. this.title = "修改";
  400. });
  401. listDevice().then(response => {
  402. this.hostList = response.rows;
  403. })
  404. },
  405. /** 提交按钮 */
  406. submitForm() {
  407. this.$refs["form"].validate(valid => {
  408. if (valid) {
  409. if (this.form.id != null) {
  410. updateDevice(this.form).then(response => {
  411. this.$modal.msgSuccess("修改成功");
  412. this.open = false;
  413. this.getList();
  414. });
  415. } else {
  416. addDevice(this.form).then(response => {
  417. this.$modal.msgSuccess("新增成功");
  418. this.open = false;
  419. this.getList();
  420. });
  421. }
  422. }
  423. });
  424. },
  425. /** 删除按钮操作 */
  426. handleDelete(row) {
  427. const ids = row.id || this.ids;
  428. const names = row.deviceName || this.names;
  429. this.$modal.confirm('是否确认删除名称为"' + names + '"的数据项?').then(function () {
  430. return delDevice(ids);
  431. }).then(() => {
  432. this.getList();
  433. this.$modal.msgSuccess("删除成功");
  434. }).catch(() => { });
  435. },
  436. /** 导出按钮操作 */
  437. handleExport() {
  438. this.download('system/device/export', {
  439. ...this.queryParams
  440. }, `device_${new Date().getTime()}.xlsx`)
  441. }
  442. }
  443. };
  444. </script>