You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

603 lines
18 KiB

1 year ago
  1. <template>
  2. <div class="box">
  3. <div style="position: relative">
  4. <div class="contenttitle">
  5. 基础资料 /
  6. <span class="contenttitleBold">危急值类别</span>
  7. </div>
  8. <div style="display: block; margin-top: 7px; margin-right: 110px">
  9. <div style="background-color: #fff; border-radius: 8px; padding: 15px">
  10. <el-table
  11. :data="tableData"
  12. :height="window.pageHeight < 600 ? 450 : window.pageHeight - 130"
  13. row-key="criticalFollowValueTypeId"
  14. :key="tableKey"
  15. default-expand-all
  16. :tree-props="{
  17. children: 'treeChildren',
  18. hasChildren: 'hasChildren',
  19. }"
  20. highlight-current-row
  21. @row-click="treeclick"
  22. ref="tableData"
  23. class="el-table__body-wrapper tbody"
  24. >
  25. <el-table-column prop="displayName" label="类别">
  26. <template slot-scope="scope">
  27. <span>
  28. <span class="treeicons">
  29. <!-- <i
  30. class="el-icon-document-remove"
  31. v-if="data.parentId == null"
  32. ></i> -->
  33. <img
  34. style="width: 20px; height: 20px; vertical-align: sub"
  35. src="@/assets/images/order.png"
  36. v-if="!scope.row.parentId"
  37. />
  38. </span>
  39. <span
  40. :class="
  41. !scope.row.parentId ? 'maxtitle' : 'mintitle'
  42. "
  43. >{{ scope.row.displayName }}</span
  44. >
  45. </span>
  46. </template>
  47. </el-table-column>
  48. <el-table-column
  49. prop="simpleCode"
  50. label="拼音简码"
  51. ></el-table-column>
  52. <el-table-column label="操作" width="" align="center">
  53. <template>
  54. <el-tag
  55. class="move"
  56. style="
  57. cursor: move;
  58. background-color: rgb(245, 245, 245);
  59. border: none;
  60. "
  61. draggable="true"
  62. >
  63. <i
  64. class="el-icon-d-caret"
  65. style="width: 1rem; height: 1rem; color: rgb(113, 113, 113)"
  66. ></i>
  67. </el-tag>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. </div>
  72. </div>
  73. <!-- 按钮区域 -->
  74. <div
  75. style="
  76. margin-left: 10px;
  77. margin-top: 3%;
  78. position: absolute;
  79. top: 0;
  80. right: 0;
  81. "
  82. >
  83. <!-- <el-button type="" @click="addll" class="commonbutton">新增</el-button> -->
  84. <div
  85. v-if="tableData.length == '0' ? true : false"
  86. style="margin-bottom: 10px"
  87. >
  88. <el-button type="" class="commonbutton" @click="append"
  89. >新增危急值类别</el-button
  90. >
  91. </div>
  92. <div>
  93. <el-button
  94. type=""
  95. @click="addll"
  96. :disabled="isshow"
  97. class="commonbutton"
  98. >新增同级</el-button
  99. >
  100. </div>
  101. <div style="margin-top: 10px">
  102. <el-button
  103. type=""
  104. @click="append"
  105. :disabled="isshow"
  106. class="commonbutton"
  107. >新增子级</el-button
  108. >
  109. </div>
  110. <div style="margin-top: 10px">
  111. <el-button
  112. type=""
  113. @click="rena"
  114. :disabled="isshow"
  115. class="commonbutton"
  116. >编辑</el-button
  117. >
  118. </div>
  119. <div style="margin-top: 10px">
  120. <el-button
  121. type=""
  122. @click="deleates"
  123. :disabled="isshow"
  124. class="deleteButton"
  125. >删除</el-button
  126. >
  127. </div>
  128. <div style="margin-top: 10px">
  129. <el-button
  130. type=""
  131. @click="assertion"
  132. :disabled="isshows"
  133. class="commonbutton"
  134. >排序</el-button
  135. >
  136. </div>
  137. <div style="margin-top: 10px">
  138. <el-button
  139. type=""
  140. :disabled="isshows"
  141. @click="cancellation"
  142. class="commonbutton"
  143. >取消</el-button
  144. >
  145. </div>
  146. </div>
  147. </div>
  148. <el-dialog
  149. :title="title == 1 ? '新增' : '修改'"
  150. :visible.sync="dialogVisible"
  151. width="40%"
  152. :close-on-click-modal="false"
  153. >
  154. <el-form :model="form" label-width="80px" :rules="rules" ref="ruleForm">
  155. <el-row v-if="title == 2 ? true : false">
  156. <el-col :span="12">
  157. <el-form-item label="上级部门">
  158. <el-cascader
  159. v-if="title == 2"
  160. ref="depref"
  161. @change="cascaderchang"
  162. :show-all-levels="false"
  163. v-model="departmentname"
  164. style="margin-left: 10px"
  165. :options="itemtypedata"
  166. :props="{
  167. checkStrictly: true,
  168. children: 'treeChildren',
  169. label: 'displayName',
  170. value: 'criticalFollowValueTypeId',
  171. }"
  172. clearable
  173. size="small"
  174. ></el-cascader>
  175. </el-form-item>
  176. </el-col>
  177. </el-row>
  178. <el-row>
  179. <el-col :span="12">
  180. <el-form-item label="名称" prop="displayName">
  181. <el-input
  182. v-model="form.displayName"
  183. ref="refinput"
  184. size="small"
  185. ></el-input>
  186. </el-form-item>
  187. </el-col>
  188. </el-row>
  189. </el-form>
  190. <span slot="footer" class="dialog-footer">
  191. <el-button @click="dialogVisible = false" class="difference"
  192. > </el-button
  193. >
  194. <el-button type="" @click="addoredit" class="commonbutton"
  195. > </el-button
  196. >
  197. </span>
  198. </el-dialog>
  199. </div>
  200. </template>
  201. <script>
  202. import {
  203. criticalFollowValueType ,
  204. pojectadd,
  205. projecteditid,
  206. projecttype,
  207. projectedid,
  208. } from "@/request/commonapi";
  209. import { basicsetings, physicalexaminationlist } from "@/request/systemapi";
  210. import { getapi, postapi, putapi } from "@/api/api";
  211. import { mapState } from "vuex";
  212. import { objCopy } from "@/utlis/proFunc";
  213. import Sortable from "sortablejs";
  214. export default {
  215. data() {
  216. return {
  217. departmentname: "",
  218. itemtypedata: [],
  219. rules: {
  220. displayName: [
  221. { required: true, message: "请输入名称", trigger: "blur" },
  222. ]
  223. },
  224. defaultProps: {
  225. children: "treeChildren",
  226. label: "displayName",
  227. },
  228. title: 1,
  229. tableData: [],
  230. tableHeight: window.innerHeight - 180, //表格动态高度
  231. screenHeight: window.innerHeight, //内容区域高度
  232. form: {
  233. criticalFollowValueTypeId: "",
  234. displayName: "",
  235. parentId: ""
  236. },
  237. dialogVisible: false,
  238. guideoptions: [],
  239. row: {},
  240. isshow: true,
  241. activeRows: [],
  242. message: true,
  243. tableKey:'',
  244. isshows:true
  245. };
  246. },
  247. created() {
  248. this.getlist();
  249. },
  250. mounted() {
  251. this.rowDrop();
  252. },
  253. computed: {
  254. ...mapState(["window"]),
  255. },
  256. methods: {
  257. cascaderchang(v) {
  258. this.departmentname = v[v.length - 1];
  259. },
  260. treeToTable(tree, level, arr = []) {
  261. tree.map((item, index) => {
  262. this.$set(item, "level", level);
  263. arr.push(item);
  264. if (item.treeChildren && item.treeChildren != []) {
  265. arr.push(...this.treeToTable(item.treeChildren, level + 1));
  266. }
  267. });
  268. // 返回结果
  269. return arr;
  270. },
  271. flatToTree(flatData, idProp, parentIdProp) {
  272. const treeData = [];
  273. const idMap = {};
  274. // 将所有节点存储到 idMap 中,方便快速查找节点
  275. for (const node of flatData) {
  276. idMap[node[idProp]] = node;
  277. node.treeChildren = [];
  278. }
  279. // 遍历所有节点,将它们添加到树形结构中
  280. for (const node of flatData) {
  281. const parent = idMap[node[parentIdProp]];
  282. if (parent) {
  283. parent.treeChildren.push(node);
  284. } else {
  285. treeData.push(node);
  286. }
  287. }
  288. return treeData;
  289. },
  290. screenData(tree,row,increase,arr = []){
  291. if(increase){
  292. arr.push(row)
  293. }
  294. tree.map((item,index)=>{
  295. if(item.parentId===row.criticalFollowValueTypeId){
  296. arr.push(item)
  297. if(item.treeChildren && item.treeChildren != []){
  298. arr.push(...this.screenData(item.treeChildren,item));
  299. }
  300. }
  301. })
  302. return arr;
  303. },
  304. //初始化
  305. rowDrop() {
  306. this.$nextTick(() => {
  307. const tbody = document.querySelector(".el-table__body-wrapper tbody");
  308. const _this = this;
  309. Sortable.create(tbody, {
  310. handle: ".move",
  311. animation: 300,
  312. // onStart: () => { // 开始拖拽前把树形结构数据扁平化
  313. // _this.activeRows = _this.treeToTable(_this.tableData) // 把树形的结构转为列表再进行拖拽
  314. // },
  315. onMove({ dragged, related }) {
  316. // if(dragged.rowIndex<related.rowIndex){
  317. // if (_this.message) {
  318. // _this.$message.warning("不允许向下拖拽");
  319. // _this.message = false;
  320. // }
  321. // return false;
  322. // }
  323. const oldRow = _this.activeRows[dragged.rowIndex];
  324. const newRow = _this.activeRows[related.rowIndex];
  325. if (
  326. oldRow.level !== newRow.level ||
  327. oldRow.parentId !== newRow.parentId
  328. ) {
  329. if (_this.message) {
  330. _this.$message.warning("不允许跨级拖拽");
  331. _this.message = false;
  332. }
  333. return false;
  334. }
  335. },
  336. onChoose({newIndex,oldIndex }) {
  337. _this.$refs['tableData'].setCurrentRow(_this.activeRows[oldIndex]);
  338. _this.treeclick(_this.activeRows[oldIndex]);
  339. // const oldRow = _this.activeRows[oldIndex];
  340. // const newRow = _this.activeRows[newIndex];
  341. // if(oldRow.level === newRow.level ||
  342. // oldRow.parentId === newRow.parentId){
  343. // _this.$refs['tableData'].setCurrentRow(_this.activeRows[newIndex]);
  344. // }
  345. },
  346. onEnd({ newIndex, oldIndex }) {
  347. _this.message = true;
  348. const oldRow = _this.activeRows[oldIndex] // 移动的那个元素
  349. const newRow = _this.activeRows[newIndex] // 新的元素
  350. if (oldIndex === newIndex || oldRow.parentId !== newRow.parentId || oldRow.level != newRow.level) return
  351. if (oldIndex !== newIndex || oldRow.level === newRow.level || oldRow.parentId === newRow.parentId) {
  352. let oldRowSuffixData=_this.screenData(_this.activeRows,oldRow,true)
  353. let newRowSuffixData=_this.screenData(_this.activeRows,newRow,true)
  354. const targetRows = _this.activeRows.splice(oldIndex, oldRowSuffixData.length)
  355. if (oldIndex > newIndex) {
  356. _this.activeRows.splice(newIndex, 0, ...targetRows)
  357. } else if (oldIndex < newIndex) {
  358. _this.activeRows.splice(newIndex + newRowSuffixData.length - oldRowSuffixData.length, 0, ...targetRows)
  359. }
  360. let data = _this.flatToTree(
  361. _this.activeRows,
  362. "criticalFollowValueTypeId",
  363. "parentId"
  364. );
  365. _this.$set(_this,'tableData',data)
  366. _this.isshows = false;
  367. let beforeScrollTop = _this.$refs.tableData.$el.querySelector('div.el-table__body-wrapper').scrollTop
  368. _this.tableKey = new Date().getTime()
  369. _this.$nextTick(() => {
  370. _this.$refs.tableData.doLayout()
  371. _this.$refs["tableData"].setCurrentRow(
  372. oldRow
  373. );
  374. _this.treeclick(oldRow);
  375. setTimeout(() => {
  376. _this.$refs.tableData.$el.querySelector('div.el-table__body-wrapper').scrollTop = beforeScrollTop
  377. }, 0)
  378. _this.rowDrop()
  379. });
  380. }
  381. }
  382. })
  383. });
  384. },
  385. //确定排序
  386. assertion() {
  387. const result = [];
  388. this.activeRows.forEach((item, index) => {
  389. result.push({ id: item.criticalFollowValueTypeId, displayOrder: index+1 });
  390. });
  391. postapi("/api/app/CriticalFollowValueType/UpdateSortMany",{ itemList: result }).then((res) => {
  392. if (res.code != -1) {
  393. this.isshows = true;
  394. }
  395. });
  396. },
  397. //取消按钮
  398. cancellation() {
  399. this.getlist()
  400. this.isshows=true
  401. },
  402. //编辑弹框
  403. rena() {
  404. this.departmentname = this.row.parentId;
  405. this.title = 2;
  406. this.dialogVisible = true;
  407. if (this.$refs.ruleForm !== undefined) {
  408. this.$refs.ruleForm.resetFields();
  409. }
  410. postapi("/api/app/CriticalFollowValueType/Get",{
  411. criticalFollowValueTypeId:this.row.criticalFollowValueTypeId
  412. }).then((res) => {
  413. if (res.code != -1) {
  414. objCopy(res.data, this.form);
  415. this.form.criticalFollowValueTypeId=res.data.id
  416. }
  417. });
  418. // getapi(`/api/app/item/in-item-type/${data.id}`).then((res) => {
  419. // this.itemtypedata = res.data;
  420. // console.log(res, "222222222222222222");
  421. // });
  422. //获取项目类别数据结构数据
  423. criticalFollowValueType().then(
  424. (res) => {
  425. if (res.code != -1) {
  426. this.itemtypedata = res.data;
  427. }
  428. }
  429. );
  430. },
  431. // 删除
  432. deleates() {
  433. this.$confirm("是否删除, 是否继续?", "提示", {
  434. confirmButtonText: "确定",
  435. cancelButtonText: "取消",
  436. type: "warning",
  437. cancelButtonClass: "difference",
  438. confirmButtonClass: "commonbutton",
  439. })
  440. .then(() => {
  441. postapi("/api/app/CriticalFollowValueType/Delete",{
  442. criticalFollowValueTypeId:this.row.criticalFollowValueTypeId
  443. }).then((res) => {
  444. if (res.code != -1) {
  445. //this.$message.success("删除成功");
  446. this.row = this.$options.data().row;
  447. this.getlist();
  448. this.isshow = true;
  449. }
  450. });
  451. })
  452. .catch(() => {
  453. this.$message("取消成功");
  454. });
  455. },
  456. append() {
  457. // this.form = {};
  458. // if(node&& data){
  459. // this.form.parentId = data.id;
  460. // }
  461. // Object.assign(this.$data.form, this.$options.data().form);
  462. this.form = this.$options.data().form;
  463. this.form.parentId = this.row.criticalFollowValueTypeId;
  464. this.dialogVisible = true;
  465. if (this.$refs.ruleForm !== undefined) {
  466. this.$refs.ruleForm.resetFields();
  467. }
  468. this.$nextTick(() => {
  469. this.$refs.refinput.focus();
  470. });
  471. },
  472. //新增弹框
  473. addll() {
  474. // this.form = {};
  475. // this.form.parentId = data.parentId;
  476. // Object.assign(this.$data.form, this.$options.data().form);
  477. this.form = this.$options.data().form;
  478. this.form.parentId = this.row.parentId;
  479. this.dialogVisible = true;
  480. this.title = 1;
  481. if (this.$refs.ruleForm !== undefined) {
  482. this.$refs.ruleForm.resetFields();
  483. }
  484. this.$nextTick(() => {
  485. this.$refs.refinput.focus();
  486. });
  487. },
  488. //确定新增或者编辑
  489. addoredit() {
  490. this.$refs.ruleForm.validate((v) => {
  491. if (v) {
  492. if (this.title == 1) {
  493. if (this.tableData.length == 0) {
  494. postapi("/api/app/CriticalFollowValueType/Create", {
  495. displayName: this.form.displayName,
  496. }).then((res) => {
  497. if (res.code != -1) {
  498. this.getlist();
  499. this.$refs["tableData"].setCurrentRow("");
  500. this.dialogVisible = false;
  501. this.isshow = true;
  502. }
  503. });
  504. } else {
  505. postapi("/api/app/CriticalFollowValueType/Create", {
  506. parentId: this.form.parentId,
  507. displayName: this.form.displayName
  508. }).then((res) => {
  509. if (res.code != -1) {
  510. //this.$message.success("新增成功");
  511. this.getlist();
  512. this.$refs["tableData"].setCurrentRow("");
  513. this.dialogVisible = false;
  514. this.isshow = true;
  515. }
  516. });
  517. }
  518. // console.log(this.form);
  519. } else if (this.title == 2) {
  520. postapi("/api/app/CriticalFollowValueType/Update",{
  521. criticalFollowValueTypeId: this.form.criticalFollowValueTypeId,
  522. displayName: this.form.displayName
  523. }).then((res) => {
  524. if (res.code != -1) {
  525. //this.$message.success("修改成功");
  526. this.getlist();
  527. this.$refs["tableData"].setCurrentRow("");
  528. this.dialogVisible = false;
  529. this.isshow = true;
  530. }
  531. });
  532. }
  533. }
  534. });
  535. },
  536. // 点击获取每一列
  537. treeclick(row) {
  538. this.row = { ...row };
  539. this.isshow = false;
  540. },
  541. getlist() {
  542. criticalFollowValueType().then((res) => {
  543. if (res.code != -1) {
  544. this.tableData = [...res.data];
  545. this.activeRows = this.treeToTable(this.tableData, 1);
  546. }
  547. });
  548. },
  549. },
  550. };
  551. </script>
  552. <style scoped>
  553. @import "../../assets/css/global_button.css";
  554. @import "../../assets/css/global_dialog.css";
  555. @import "../../assets/css/global_table.css";
  556. @import "../../assets/css/global_form.css";
  557. @import "../../assets/css/global_input.css";
  558. @import "../../assets/css/global.css";
  559. .box {
  560. display: flex;
  561. flex-direction: column;
  562. }
  563. .layeredleftright {
  564. width: 100%;
  565. display: flex;
  566. flex-direction: column;
  567. }
  568. :deep .el-form-item {
  569. margin-bottom: 14px;
  570. }
  571. /* el-dialog的头部样式 */
  572. :deep .el-dialog__header {
  573. padding: 11px 20px 11px;
  574. }
  575. /* el-dialog的主体样式 */
  576. :deep .el-dialog__body {
  577. padding: 0px 20px 0px;
  578. }
  579. /* el-divider样式 */
  580. :deep .el-divider--horizontal {
  581. margin: 0px 0 12px;
  582. }
  583. /* el-dialog的底部样式 */
  584. :deep .el-dialog__footer {
  585. padding: 0px 20px 14px;
  586. }
  587. :deep .el-table tr {
  588. height: 35px;
  589. }
  590. </style>