index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <div style="padding: 10px 15px">
  3. <el-row>
  4. <el-col :span="6" style="padding-right: 10px">
  5. <el-card class="box-card">
  6. <template #header>
  7. <div class="card-header">
  8. <span>设备台账区域</span>
  9. <div>
  10. <el-button type="primary" plain @click="addOrganizational()">
  11. 添加
  12. </el-button>
  13. <!-- <el-button type="primary" plain @click="updateOrganizational()">
  14. 编辑
  15. </el-button> -->
  16. </div>
  17. </div>
  18. </template>
  19. <div class="tree">
  20. <LayTree :data="treeList" :tail-node-icon="false" :onlyIconControl="true" v-model:selectedKey="selectedKey"
  21. @node-click="handleClick">
  22. <template #title="{ data }">
  23. <div style="display: flex;flex-direction: row;justify-content: space-around;">
  24. <div @click="handleClickTitle(data)">{{ data.name }}</div>
  25. <div>
  26. <el-icon @click="updateOrganizational(data)">
  27. <Edit />
  28. </el-icon>
  29. <el-popconfirm title="确定删除该标签?" @confirm="deleteOrganizational(data)">
  30. <template #reference>
  31. <el-button link><el-tooltip effect="dark" content="删除"><el-icon>
  32. <Delete />
  33. </el-icon></el-tooltip></el-button>
  34. </template>
  35. </el-popconfirm>
  36. </div>
  37. </div>
  38. </template>
  39. </LayTree>
  40. </div>
  41. </el-card>
  42. </el-col>
  43. <el-col :span="18">
  44. <el-card class="box-card">
  45. <div style="display: flex; flex-direction: row; justify-content: space-between">
  46. <div style="display: flex; flex-direction: row;">
  47. <div style="
  48. display: flex;
  49. flex-direction: row;
  50. flex-wrap: nowrap;
  51. align-items: center;
  52. ">
  53. <div style="font-size: 12px; width: 80px;">设备名称:</div>
  54. <el-input v-model="searchform.name" placeholder="设备名称"></el-input>
  55. </div>
  56. <div style="
  57. display: flex;
  58. flex-direction: row;
  59. flex-wrap: nowrap;
  60. align-items: center;
  61. ">
  62. <div style="font-size: 12px; width: 80px;margin-left: 10px">设备编码:</div>
  63. <el-input v-model="searchform.sn" placeholder="设备编码"></el-input>
  64. </div>
  65. </div>
  66. <div>
  67. <el-button type="primary" plain @click="requery">重置</el-button>
  68. <el-button type="primary" @click="getlistEquipmentSbook">搜索</el-button>
  69. </div>
  70. </div>
  71. </el-card>
  72. <el-card class="box-card" style="margin-top: 10px;">
  73. <template #header>
  74. <div class="card-header">
  75. <span>设备台账</span>
  76. <div>
  77. <el-button type="primary" @click="goadd">添加</el-button>
  78. <el-button type="danger">批量删除</el-button>
  79. <el-button type="primary" plain @click="ziduanshow = true">显示字段</el-button>
  80. </div>
  81. </div>
  82. </template>
  83. <el-row>
  84. <el-col :span="24" style="padding-left: 10px">
  85. <el-table :data="devicetabledata" :border="true">
  86. <el-table-column type="selection" width="55" />
  87. <el-table-column v-for="item in columns.filter(i => i.visible)" :prop="item.prop" :label="item.label">
  88. <template #default="scope" v-if="item.isTemplate">
  89. <span>
  90. {{ getData(item.func, scope.row, item.prop) }}
  91. <!-- {{ eval(item.prop)}} -->
  92. </span>
  93. </template>
  94. </el-table-column>
  95. <!-- <el-table-column label="设备类型">
  96. <template #default="scope">
  97. {{ getTypeName(scope.row) }}
  98. </template>
  99. </el-table-column> -->
  100. <el-table-column label="操作">
  101. <template #default="scope">
  102. <div>
  103. <el-button link @click="goUpdate(scope.row)">
  104. <el-tooltip effect="dark" content="修改">
  105. <el-icon>
  106. <Edit />
  107. </el-icon>
  108. </el-tooltip>
  109. </el-button>
  110. <el-button link @click="goDetail(scope.row)">
  111. <el-tooltip effect="dark" content="详情">
  112. <el-icon>
  113. <Document />
  114. </el-icon>
  115. </el-tooltip>
  116. </el-button>
  117. <el-popconfirm title="确定删除该标签?" @confirm="deleteDevice(scope.row)">
  118. <template #reference>
  119. <el-button link><el-tooltip effect="dark" content="删除"><el-icon>
  120. <Delete />
  121. </el-icon></el-tooltip></el-button>
  122. </template>
  123. </el-popconfirm>
  124. </div>
  125. </template>
  126. </el-table-column>
  127. </el-table>
  128. </el-col>
  129. <el-col :span="24" style="margin-top: 10px;">
  130. <el-pagination style="float: right;" small background layout="prev, pager, next" :total="pagedata.total"
  131. :page-size="pagedata.size" :current-page="pagedata.current" @current-change="onchangepage"
  132. class="mt-4" />
  133. </el-col>
  134. </el-row>
  135. </el-card>
  136. </el-col>
  137. </el-row>
  138. <el-dialog v-model="dialogFormVisible" :title="dialogTitle">
  139. <el-form :model="organizationalQuery">
  140. <el-form-item label="上层位置" :label-width="formLabelWidth">
  141. <el-tree-select v-model="organizationalQuery.parentId" :data="treeList"
  142. :props="{ value: 'id', label: 'name', children: 'children' }" value-key="id" placeholder="请选上层位置"
  143. check-strictly />
  144. </el-form-item>
  145. <el-form-item label="组织机构编码" :label-width="formLabelWidth">
  146. <el-input v-model="organizationalQuery.sn" placeholder="请输入组织编码" />
  147. </el-form-item>
  148. <el-form-item label="组织机构名称" :label-width="formLabelWidth">
  149. <el-input v-model="organizationalQuery.name" placeholder="请输入组织名称" />
  150. </el-form-item>
  151. <el-form-item label="所属公司" :label-width="formLabelWidth">
  152. <el-input v-model="organizationalQuery.company" placeholder="请输入所属公司" />
  153. </el-form-item>
  154. </el-form>
  155. <template #footer>
  156. <span class="dialog-footer">
  157. <el-button @click="dialogFormVisible = false">取消</el-button>
  158. <el-button type="primary" @click="saveOrgainzational()">
  159. 确认
  160. </el-button>
  161. </span>
  162. </template>
  163. </el-dialog>
  164. <el-dialog title="字段显示" v-model="ziduanshow" width="50%" @close="ziduanshow = false">
  165. <div style="display: flex;flex-wrap: wrap;align-content: center;justify-content: center;align-items: center;">
  166. <el-checkbox v-for="item in columns" v-model="item.visible" :label="item.label" size="large" />
  167. </div>
  168. </el-dialog>
  169. </div>
  170. </template>
  171. <script setup lang="ts" name="Units">
  172. import { ref, toRaw } from "vue";
  173. import { LayTree } from "@layui/layui-vue";
  174. import "@layui/layui-vue/lib/index.css";
  175. import { useRoute, useRouter } from "vue-router";
  176. import { listEquipmentOrganizational, addEquipmentOrganizational, updateEquipmentOrganizational, delEquipmentOrganizational } from "@/api/data/equipmentOrganizational"
  177. import { listEquipmentSbook, updateEquipmentSbook } from "@/api/data/equipmentSbook"
  178. import { getDicts } from '@/api/system/dict/data'
  179. import { cloneDeep } from "lodash";
  180. const route = useRoute();
  181. const router = useRouter();
  182. const { proxy } = getCurrentInstance();
  183. const dialogFormVisible = ref(false)
  184. const ziduanshow = ref(false)
  185. const formLabelWidth = '140px'
  186. const dialogTitle = ref("新增组织架构")
  187. const form = {
  188. name: '',
  189. region: ''
  190. }
  191. const organizationalQuery = ref({
  192. id: null,
  193. parentId: "",
  194. name: "",
  195. sn: "",
  196. company: '',
  197. ancestors: ""
  198. })
  199. const organizationalParams = ref({
  200. id: null,
  201. parentId: "",
  202. name: "",
  203. sn: "",
  204. company: '',
  205. ancestors: ''
  206. })
  207. const goUpdate = (item) => {
  208. // router.push({ name: 'EquipmentDashAdd', params: { userId: '123' }})
  209. router.push({ path: '/device/equipmentdash/add', query: { id: item.id } })
  210. // router.push({ name: "EquipmentDashAdd", params: { item } })
  211. // router.push({path:"/device/equipmentdash/add",params:item})
  212. }
  213. const goadd = () => {
  214. router.push("/device/equipmentdash/add")
  215. }
  216. const goDetail = (item) => {
  217. router.push({ path: '/device/equipmentdash/add', query: { id: item.id, isEdit: false } })
  218. }
  219. const handleClick = (node) => {
  220. console.log(node);
  221. }
  222. const handleClickTitle = (node) => {
  223. //console.log("Click Node:" + JSON.stringify(node));
  224. searchform.value.equipmentTreeId = node.id
  225. organizationalParams.value = node
  226. console.log(organizationalParams.value);
  227. getlistEquipmentSbook();
  228. };
  229. const selectedKey = ref(4);
  230. const treeList = ref([]);
  231. const typeList = ref([]);
  232. const organizationalList = ref([]);
  233. const pagedata = ref({
  234. total: 0,
  235. size: 10,
  236. current: 1
  237. });
  238. const devicetabledata = ref([]);
  239. const searchform = ref({
  240. name: "",
  241. sn: "",
  242. equipmentTreeId: ""
  243. });
  244. const columns = ref([
  245. // {label: '上层位置', prop: 'v', visible: true},
  246. { label: '上层位置', prop: 'deptName', visible: true, isTemplate: false },
  247. { label: '设备编码', prop: 'sn', visible: true, isTemplate: false },
  248. { label: '备用编码', prop: 'spareSn', visible: true, isTemplate: false },
  249. { label: '设备名称', prop: 'name', visible: true, isTemplate: false },
  250. { label: '设备模板', prop: 'equipment.name', visible: true, isTemplate: false },
  251. //{label: '所属公司', prop: 'parity', visible: true},
  252. // { label: '所属组织机构', prop: 'deptName', visible: true },
  253. { label: '所属类型', prop: 'equipment.type', visible: true, },
  254. { label: '负责人', prop: 'uuid', visible: false, isTemplate: false },
  255. { label: '安装日期', prop: 'installationDate', visible: false, isTemplate: false },
  256. { label: '安装地点地址', prop: 'address', visible: false, isTemplate: false },
  257. { label: '关联设备Id', prop: 'protocolDesc', visible: false, isTemplate: false },
  258. { label: '标签', prop: 'tagids', visible: false, isTemplate: false },
  259. { label: '状态', prop: 'status', visible: false, isTemplate: false },
  260. { label: '保修期结束日期', prop: 'endOfWarrantyPeriod', visible: false, isTemplate: false },
  261. { label: '制造日期', prop: 'manufacturingDate', visible: false, isTemplate: false },
  262. { label: '资产编码', prop: 'assetNo', visible: false, isTemplate: false },
  263. { label: '资产编号', prop: 'serialNumber', visible: false, isTemplate: false },
  264. { label: '使用证编号', prop: 'useCertificateNo', visible: false, isTemplate: false },
  265. { label: '安全级别', prop: 'securityLevel', visible: false, isTemplate: false },
  266. { label: '使用年限', prop: 'usefulLife', visible: false, isTemplate: false },
  267. { label: '变动日期', prop: 'changeDate', visible: false, isTemplate: false },
  268. { label: '供货厂家', prop: 'supplier', visible: false, isTemplate: false },
  269. { label: '创建人', prop: 'createBy', visible: false, isTemplate: false },
  270. { label: '创建时间', prop: 'createTime', visible: false, isTemplate: false },
  271. { label: '更新人', prop: 'updateBy', visible: false, isTemplate: false },
  272. { label: '更新时间', prop: 'updateTime', visible: false, isTemplate: false },
  273. { label: '备注', prop: 'remark', visible: false, isTemplate: false },
  274. ])
  275. const onchangepage = (page) => {
  276. pagedata.value.current = page;
  277. getlistEquipmentSbook();
  278. }
  279. const getTreedata = () => {
  280. listEquipmentOrganizational({ pageSize: 10000 }).then(res => {
  281. const { rows, total, page, size } = res;
  282. organizationalList.value = res.rows;
  283. treeList.value = proxy.handleTree(res.rows, "id", "parentId");
  284. })
  285. }
  286. const getData = (str, data, prop) => {
  287. console.log(data);
  288. // let value = eval("data."+prop);
  289. // console.log(value)
  290. let value = eval(str + "(data)")
  291. console.log(value);
  292. return value
  293. }
  294. // function getlistEquipmentSbook(){
  295. // listEquipmentSbook({ ...searchform.value, pageSize: pagedata.value.size, pageNum: pagedata.value.current }).then(res => {
  296. // const { rows, total, page, size } = res;
  297. // devicetabledata.value = res.rows
  298. // })
  299. // }
  300. const requery = () => {
  301. searchform.value = {
  302. name: "",
  303. sn: "",
  304. equipmentTreeId: ''
  305. }
  306. getlistEquipmentSbook();
  307. }
  308. const getlistEquipmentSbook = () => {
  309. listEquipmentSbook({ ...searchform.value, pageSize: pagedata.value.size, pageNum: pagedata.value.current }).then(res => {
  310. const { rows, total, page, size } = res;
  311. devicetabledata.value = res.rows
  312. })
  313. }
  314. const getDictsData = () => {
  315. getDicts("equipment_type").then(res => {
  316. typeList.value = res.data;
  317. })
  318. }
  319. const addOrganizational = () => {
  320. organizationalQuery.value = {
  321. id: null,
  322. parentId: "",
  323. name: "",
  324. sn: "",
  325. company: '',
  326. ancestors: ''
  327. }
  328. dialogTitle.value = "新增组织架构"
  329. dialogFormVisible.value = true
  330. }
  331. const updateOrganizational = (data) => {
  332. organizationalQuery.value = data
  333. dialogTitle.value = "修改组织架构"
  334. dialogFormVisible.value = true
  335. }
  336. const deleteOrganizational = (data) => {
  337. delEquipmentOrganizational(data.id).then(res => {
  338. getTreedata();
  339. })
  340. }
  341. const getTypeName = (scope) => {
  342. console.log(scope)
  343. var equipment = toRaw(scope)
  344. if (equipment != null) {
  345. for (var index in typeList.value) {
  346. var obj = toRaw(typeList.value[index]);
  347. if (obj.dictValue == equipment.equipmentTypeId) {
  348. console.log(obj.dictLabel);
  349. return obj.dictLabel
  350. }
  351. }
  352. }
  353. }
  354. const saveOrgainzational = () => {
  355. for (var index in organizationalList.value) {
  356. if (organizationalQuery.value.parentId == organizationalList.value[index].id) {
  357. console.log(organizationalList.value[index]);
  358. organizationalQuery.value.ancestors = organizationalList.value[index].ancestors + "," + organizationalList.value[index].id
  359. }
  360. }
  361. console.log(organizationalQuery.value.id);
  362. if (organizationalQuery.value.id != null) {
  363. let datac = cloneDeep(organizationalQuery.value);
  364. delete datac.parentNode;
  365. delete datac.children;
  366. updateEquipmentOrganizational(datac).then(res => {
  367. console.log(res);
  368. if (res.code == 200) {
  369. getTreedata();
  370. dialogFormVisible.value = false
  371. }
  372. })
  373. } else {
  374. let datac = cloneDeep(organizationalQuery.value);
  375. delete datac.parentNode;
  376. delete datac.children;
  377. addEquipmentOrganizational(datac).then(res => {
  378. if (res.code == 200) {
  379. getTreedata();
  380. dialogFormVisible.value = false
  381. }
  382. })
  383. }
  384. }
  385. const deleteDevice = (scope) => {
  386. console.log(scope.id)
  387. var obj = {
  388. id: scope.id,
  389. isDelete: 1
  390. }
  391. updateEquipmentSbook(obj).then(res => {
  392. getlistEquipmentSbook();
  393. })
  394. }
  395. getTreedata();
  396. getlistEquipmentSbook();
  397. getDictsData();
  398. </script>
  399. <style lang="scss" scoped>
  400. .card-header {
  401. display: flex;
  402. flex-direction: row;
  403. justify-content: space-between;
  404. }
  405. .tree {
  406. *,
  407. *:before,
  408. *:after {
  409. box-sizing: content-box !important;
  410. }
  411. }
  412. </style>