DepartWindow.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <template>
  2. <a-modal
  3. :width="modalWidth"
  4. :visible="visible"
  5. title="部门搜索"
  6. :confirmLoading="confirmLoading"
  7. @ok="handleSubmit"
  8. @cancel="handleCancel"
  9. cancelText="关闭"
  10. wrapClassName="ant-modal-cust-warp"
  11. >
  12. <!--部门树-->
  13. <template>
  14. <a-form :form="form">
  15. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="部门">
  16. <a-directory-tree
  17. :expanded-keys="expandedKeys"
  18. :auto-expand-parent="autoExpandParent"
  19. :selected-keys="selectedKeys"
  20. :tree-data="departTree"
  21. @expand="onExpand"
  22. @select="onSelect"
  23. />
  24. </a-form-item>
  25. </a-form>
  26. </template>
  27. </a-modal>
  28. </template>
  29. <script>
  30. import pick from 'lodash.pick'
  31. import { getAction } from '@/api/manage'
  32. import { queryIdTree } from '@/api/api'
  33. import userModal from './UserModal'
  34. export default {
  35. name: "DepartWindow",
  36. components: {
  37. userModal,
  38. },
  39. data () {
  40. return {
  41. expandedKeys: ['1'],
  42. autoExpandParent: true,
  43. checkedKeys: [],
  44. selectedKeys: [],
  45. userId:"", // 存储用户id
  46. model:{}, // 存储SysUserDepartsVO表
  47. userDepartModel:{userId:'',departIdList:[]}, // 存储用户id一对多部门信息的对象
  48. departList:[], // 存储部门信息
  49. modalWidth:400,
  50. departTree:[],
  51. title:"操作",
  52. visible: false,
  53. labelCol: {
  54. xs: { span: 24 },
  55. sm: { span: 5 },
  56. },
  57. wrapperCol: {
  58. xs: { span: 24 },
  59. sm: { span: 16 },
  60. },
  61. confirmLoading: false,
  62. headers:{},
  63. form:this.$form.createForm(this),
  64. url: {
  65. userId:"/sys/user/generateUserId", // 引入生成添加用户情况下的url
  66. },
  67. }
  68. },
  69. methods: {
  70. onExpand(expandedKeys) {
  71. console.log('onExpand', expandedKeys);
  72. // if not set autoExpandParent to false, if children expanded, parent can not collapse.
  73. // or, you can remove all expanded children keys.
  74. this.expandedKeys = expandedKeys;
  75. //this.autoExpandParent = false;
  76. },
  77. onCheck(checkedKeys) {
  78. console.log('onCheck', checkedKeys);
  79. this.checkedKeys = checkedKeys;
  80. },
  81. onSelect(selectedKeys, info) {
  82. console.log('onSelect', selectedKeys);
  83. this.selectedKeys = selectedKeys;
  84. this.departList = [];
  85. let selectedNodes = info.selectedNodes;
  86. for (let i = 0; i < selectedNodes.length; i++) {
  87. let de = selectedNodes[i]._props;
  88. let depart = {key:"",value:"",title:""};
  89. depart.key = de.value;
  90. depart.value = de.value;
  91. depart.title = de.title;
  92. this.departList.push(depart);
  93. }
  94. },
  95. add (checkedDepartKeys,userId) {
  96. this.selectedKeys = checkedDepartKeys;
  97. console.log(checkedDepartKeys)
  98. //this.expandedKeysss=checkedDepartKeys;
  99. this.userId = userId;
  100. this.edit({});
  101. },
  102. edit (record) {
  103. this.departList = [];
  104. this.queryDepartTree();
  105. this.form.resetFields();
  106. this.visible = true;
  107. this.model = Object.assign({}, record);
  108. let filedsVal = pick(this.model,'id','userId','departIdList');
  109. this.$nextTick(() => {
  110. this.form.setFieldsValue(filedsVal);
  111. });
  112. },
  113. close () {
  114. this.$emit('close');
  115. this.visible = false;
  116. this.departList = [];
  117. this.checkedKeys = [];
  118. },
  119. handleSubmit () {
  120. const that = this;
  121. // 触发表单验证
  122. this.form.validateFields((err) => {
  123. if (!err) {
  124. that.confirmLoading = true;
  125. if(this.userId == null){
  126. getAction(this.url.userId).then((res)=>{
  127. if(res.success){
  128. let formData = {userId:res.result,
  129. departIdList:this.departList}
  130. that.$emit('ok', formData);
  131. }
  132. }).finally(() => {
  133. that.departList = [];
  134. that.confirmLoading = false;
  135. that.close();
  136. })
  137. }else {
  138. let formData = {userId:this.userId,
  139. departIdList:this.departList}
  140. that.departList = [];
  141. that.$emit('ok', formData);
  142. that.confirmLoading = false;
  143. that.close();
  144. }
  145. }
  146. })
  147. },
  148. handleCancel () {
  149. this.close()
  150. },
  151. // 选择部门时作用的API
  152. onCheck(checkedKeys, info){
  153. console.log(checkedKeys)
  154. this.departList = [];
  155. this.checkedKeys = checkedKeys.checked;
  156. let selectedNodes = info.selectedNodes;
  157. for (let i = 0; i < selectedNodes.length; i++) {
  158. let de = selectedNodes[i]._props;
  159. let depart = {key:"",value:"",title:""};
  160. depart.key = de.value;
  161. depart.value = de.value;
  162. depart.title = de.title;
  163. this.departList.push(depart);
  164. }
  165. },
  166. queryDepartTree(){
  167. queryIdTree().then((res)=>{
  168. if(res.success){
  169. this.departTree = res.result;
  170. if(this.selectedKeys&&this.selectedKeys.length >0){
  171. // let treekey=[];
  172. // let arr=res.result;
  173. // if(arr&&arr.length>0){
  174. // arr.forEach(item => {
  175. // treekey.push(item.key);
  176. // /* if(item.children&&item.children.length>0){
  177. // item.children.forEach(item1 => {
  178. // treekey.push(item1.key);
  179. // })
  180. // }*/
  181. // })
  182. // this.expandedKeys = treekey
  183. // }
  184. this.expandedKeys = this.selectedKeys;
  185. }
  186. }
  187. })
  188. },
  189. // onExpand(expandedKeys){
  190. // this.expandedKeysss = expandedKeys;
  191. // },
  192. modalFormOk(){
  193. }
  194. },
  195. }
  196. </script>
  197. <style lang="less" scoped>
  198. .ant-table-tbody .ant-table-row td{
  199. padding-top:10px;
  200. padding-bottom:10px;
  201. }
  202. /deep/ .ant-modal{
  203. height: 700px;
  204. }
  205. </style>