selectPositions.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <el-cascader ref="cascader"
  3. v-model="selectDatas"
  4. :options="options"
  5. :props="props"
  6. :collapse-tags="true"
  7. class="cascader">
  8. </el-cascader>
  9. </template>
  10. <script>
  11. import curdPost from "@/business/platform/form/utils/custom/joinCURD.js";
  12. import TreeUtils from "@/utils/tree";
  13. export default {
  14. data() {
  15. const { level, userId, userInfo } = this.$store.getters;
  16. return {
  17. level,
  18. userId,
  19. userInfo,
  20. props: {
  21. children: "children",
  22. label: "NAME_",
  23. value: "ID_",
  24. multiple: true,
  25. expandTrigger: "hover",
  26. checkStrictly: true
  27. },
  28. options: [],
  29. selectDatas: [],
  30. iniselectDatas: [],
  31. };
  32. },
  33. mounted() {
  34. this.getPositionList();
  35. },
  36. methods: {
  37. // 获取本账户所在的部门
  38. getPositionList() {
  39. let positonsSql = "";
  40. // 金通账号id
  41. if (this.userId == "702117247933480960") {
  42. positonsSql = `select * FROM ibps_party_entity WHERE party_type_ = 'position'
  43. AND (
  44. DEPTH_ IN (1,2) OR (
  45. (DEPTH_=3 AND NAME_ = '检验科') OR parent_id_ IN (SELECT id_ FROM ibps_party_entity WHERE DEPTH_=3 AND NAME_ = '检验科' ) )
  46. )`;
  47. } else {
  48. // 所属医院的系统管理员
  49. let isAdmin = this.userInfo.role.some((so) => {
  50. return so.name == "系统管理角色";
  51. });
  52. if (isAdmin) {
  53. positonsSql = `select * from ibps_party_entity where party_type_ = 'position' and PATH_ like '%${this.level.first}%'
  54. AND (
  55. DEPTH_ IN (1,2) OR (
  56. (DEPTH_=3 AND NAME_ = '检验科') OR parent_id_ IN (SELECT id_ FROM ibps_party_entity WHERE DEPTH_=3 AND NAME_ = '检验科' ) )
  57. )`;
  58. } else {
  59. let allPositions = [];
  60. for (var i of this.userInfo.positions) {
  61. for (var item of i.path.split(".")) {
  62. if (item !== "") {
  63. allPositions.push(`id_ like '%${item}%'`);
  64. }
  65. }
  66. }
  67. allPositions = [...new Set(allPositions)];
  68. // 如果是单纯的是普通账户登录,就只显示所属部门的信息
  69. positonsSql = `select * from ibps_party_entity where ${allPositions.join(
  70. " or "
  71. )}`;
  72. }
  73. }
  74. curdPost("sql", positonsSql).then((res) => {
  75. if (res.state === 200) {
  76. const datas = res.variables.data;
  77. let positionsValue = [];
  78. if (datas.length > 0) {
  79. // datas = datas.filter(fil => {
  80. // return fil.DEPTH_ == 3 && fil.NAME_ !== '检验科'
  81. // })
  82. this.options = this.toTree(datas);
  83. // for (var i of this.options) {
  84. // // if (i.children !== undefined) {
  85. // // }
  86. // const getTail = (item) =>
  87. // item.children && item.children.length > 0
  88. // ? item.children.map((m) => getTail(m))
  89. // : [item];
  90. // let result = _.flattenDeep(i.children.map((m) => getTail(m)));
  91. // console.log('result', result)
  92. // for (var item of result) {
  93. // let itemArr = item.PATH_.split(".");
  94. // // console.log('itemArr', itemArr)
  95. // itemArr.splice(itemArr.length - 1, 1);
  96. // positionsValue.push(itemArr);
  97. // }
  98. // }
  99. for (var i of datas) {
  100. let itemArr = i.PATH_.split(".");
  101. itemArr.splice(itemArr.length - 1, 1);
  102. positionsValue.push(itemArr);
  103. }
  104. this.selectDatas = positionsValue;
  105. if (this.iniselectDatas.length == 0) {
  106. this.iniselectDatas = positionsValue;
  107. }
  108. }
  109. }
  110. });
  111. },
  112. toTree(data) {
  113. return TreeUtils.transformToTreeFormat(data, {
  114. idKey: "ID_",
  115. pIdKey: "PARENT_ID_",
  116. childrenKey: "children",
  117. });
  118. },
  119. },
  120. watch: {
  121. selectDatas(v) {
  122. if (v.length == 0) {
  123. this.selectDatas = this.iniselectDatas;
  124. this.$emit("handleFunc", this.iniselectDatas);
  125. } else {
  126. this.$emit("handleFunc", v);
  127. }
  128. },
  129. },
  130. };
  131. </script>
  132. <style lang="less" scoped>
  133. /deep/ .el-tag--info {
  134. color: #fcfcfc;
  135. background-color: #00083e;
  136. }
  137. /deep/.el-input__inner {
  138. background-color: #00083e;
  139. border: 1px solid #4ea5d6;
  140. }
  141. </style>