index.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="bf-organization">
  3. <!-- 上级组织 -->
  4. <div class="left">
  5. <div class="paren_header">
  6. <p>{{ title }}</p>
  7. <template v-if="doesJobShow">
  8. <div class="column" v-show="vice">
  9. <div :class="active == index ? 'column_childs' : 'column_child'" v-for="(item, index) in colType" :key="index" @click="upStart(index)">
  10. {{ item.name }}
  11. </div>
  12. </div>
  13. </template>
  14. </div>
  15. <div class="paren_content">
  16. <div class="dptBox" v-show="active == 0">
  17. <el-scrollbar style="height: 100%">
  18. <el-tree :data="data" :check-strictly="true" :default-expanded-keys="defaultExpandedKeys" show-checkbox @node-click="nodeClick" @check-change="currentChange" :props="defaultProps" :default-checked-keys="checkedKeys" :node-key="nodekey" ref="tree" highlight-current>
  19. <span v-if="orgType == 'org'" slot-scope="{ data }" :title="data.OrganName" class="org-data-tree-node">
  20. {{ data.OrganName }}
  21. </span>
  22. <span v-else slot-scope="{ data }" :title="data.AuthName" class="org-data-tree-node">
  23. {{ data.AuthName }}
  24. </span>
  25. </el-tree>
  26. </el-scrollbar>
  27. </div>
  28. <div class="dptBox" v-if="doesJobShow" v-show="active == 1">
  29. <Rolelist :type="true" @radioChange="radioChange" :radioCheck="radioCheck" :number="8" :active="true" class="lessData" :mainData="mainData" />
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. <script>
  36. import Rolelist from '@/components/rolelist'
  37. export default {
  38. props: {
  39. title: {
  40. type: String,
  41. default: "",
  42. },
  43. vice: {
  44. type: Boolean,
  45. default: false,
  46. },
  47. data: {
  48. type: Array,
  49. default: () => [],
  50. },
  51. nodekey: {
  52. type: String,
  53. default: "",
  54. },
  55. defaultProps: {
  56. type: Object,
  57. default: () => { },
  58. },
  59. checkedKeys: {
  60. //已选中
  61. type: Array,
  62. default: () => [],
  63. },
  64. lessData: {
  65. //副岗
  66. type: Array,
  67. default: () => [],
  68. },
  69. mainData: {
  70. //主岗
  71. type: Array,
  72. default: () => [],
  73. },
  74. radioCheck: {
  75. type: Number,
  76. default: 0,
  77. },
  78. checkBoxList: {
  79. type: Array,
  80. default: () => [],
  81. },
  82. orgType: {
  83. type: String,
  84. default: "org",
  85. },
  86. orgList: {
  87. type: Array,
  88. default: () => []
  89. }
  90. },
  91. components: { Rolelist },
  92. data () {
  93. return {
  94. active: 0,
  95. colType: [
  96. {
  97. name: "组织",
  98. },
  99. {
  100. name: "职务",
  101. }
  102. ],
  103. checkedDatas: [],
  104. checkedId: null,
  105. checkedList: [], //选中的列表,
  106. nodekeys: "nodekey",
  107. defaultExpandedKeys: [-1],
  108. getExpandedKeysStep: [false, false]
  109. };
  110. },
  111. watch: {
  112. checkedKeys: {
  113. handler (val) {
  114. console.log(val)
  115. this.checkedList = val;
  116. this.$refs.tree.setCheckedKeys(val)
  117. this.getExpandedKeysStep.splice(0, 1, true)
  118. },
  119. deep: true,
  120. },
  121. orgList: {
  122. handler(val) {
  123. this.getExpandedKeysStep.splice(1, 1, true)
  124. },
  125. deep: true
  126. },
  127. getExpandedKeysStep: {
  128. handler(val) {
  129. if (val.every(v => v)) {
  130. this.defaultExpandedKeys = [-1]
  131. this.checkedKeys.forEach(key => {
  132. if (key !== -1) {
  133. const org = this.orgList.find(item => item.OrganId == key)
  134. const OrganUpid = org.OrganUpid
  135. if (!this.defaultExpandedKeys.includes(OrganUpid)) {
  136. this.defaultExpandedKeys.push(OrganUpid)
  137. }
  138. }
  139. })
  140. }
  141. },
  142. deep: true
  143. }
  144. },
  145. mounted () {
  146. if (this.data != null) {
  147. this.data = this.formatData(this.data)
  148. }
  149. },
  150. methods: {
  151. //点击选择
  152. upStart (index) {
  153. this.active = index;
  154. this.$emit("getTreeindex", index)
  155. },
  156. formatData (params) {
  157. let data = params;
  158. data.map((item) => {
  159. if (item.hasOwnProperty('children')) {
  160. item.disabled = true;
  161. this.formatData(item.children)
  162. }
  163. });
  164. return data;
  165. },
  166. currentChange (data, isChecked) {
  167. if (this.orgType == 'org') {
  168. const { OrganId } = data
  169. this.$emit("getTreeData", this.$refs.tree.getCheckedNodes())
  170. if (isChecked) {
  171. const checked = [OrganId]
  172. this.$refs.tree.setCheckedKeys(checked)
  173. }
  174. } else if (this.orgType == 'auth') {
  175. const { AuthId } = data
  176. this.$emit("getTreeData", this.$refs.tree.getCheckedNodes())
  177. if (isChecked) {
  178. const checked = [AuthId]
  179. this.$refs.tree.setCheckedKeys(checked)
  180. }
  181. }
  182. },
  183. // 选中后设置初始数据
  184. setDataObj (arr) {
  185. arr.forEach((item) => {
  186. if (!item.children) {
  187. item.children = {
  188. OrganId: item.OrganId,
  189. ValidBegin: "",
  190. ValidEnd: "",
  191. Action: "",
  192. QueryRow: "",
  193. QueryCol: "",
  194. NewCol: "",
  195. EditRow: "",
  196. EditCol: "",
  197. DeleteRow: "",
  198. };
  199. }
  200. });
  201. this.$emit("getTreeData", arr)
  202. },
  203. nodeClick (data) {
  204. this.$emit("getTreeDatas", data)
  205. this.checkedId = data.nodekey
  206. },
  207. radioChange (val) {
  208. this.$emit('radioChange', val)
  209. },
  210. //多选框
  211. checkChange (arr) {
  212. this.$emit("checkChange", arr)
  213. },
  214. checkClick (item) {
  215. this.$emit("checkClick", item)
  216. }
  217. },
  218. };
  219. </script>
  220. <style lang="scss">
  221. @import "./organization.scss";
  222. .DBox {
  223. cursor: not-allowed;
  224. }
  225. .dptBox {
  226. height: 100%;
  227. .org-data-tree-node {
  228. font-size: 14px;
  229. max-width: 10vw;
  230. white-space: nowrap;
  231. text-overflow: ellipsis;
  232. overflow: hidden;
  233. margin-left: 10px;
  234. }
  235. }
  236. </style>