2dff5355753f37723c664578b20e70a6e35d5c87.svn-base 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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-tree
  17. multiple
  18. treeCheckable="tree"
  19. checkable
  20. @expand="onExpand"
  21. :expandedKeys="expandedKeysss"
  22. :checkedKeys="checkedKeys"
  23. allowClear="true"
  24. :checkStrictly="true"
  25. @check="onCheck"
  26. :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
  27. :treeData="departTree"
  28. placeholder="请选择上级部门"
  29. >
  30. </a-tree>
  31. </a-form-item>
  32. </a-form>
  33. </template>
  34. </a-modal>
  35. </template>
  36. <script>
  37. import pick from 'lodash.pick'
  38. import { getAction } from '@/api/manage'
  39. import { queryIdTree } from '@/api/api'
  40. export default {
  41. name: "DepartWindow",
  42. components: {
  43. },
  44. data () {
  45. return {
  46. checkedKeys:[], // 存储选中的部门id
  47. expandedKeysss:[],//展开的节点
  48. userId:"", // 存储用户id
  49. model:{}, // 存储SysUserDepartsVO表
  50. userDepartModel:{userId:'',departIdList:[]}, // 存储用户id一对多部门信息的对象
  51. departList:[], // 存储部门信息
  52. modalWidth:400,
  53. departTree:[],
  54. title:"操作",
  55. visible: false,
  56. labelCol: {
  57. xs: { span: 24 },
  58. sm: { span: 5 },
  59. },
  60. wrapperCol: {
  61. xs: { span: 24 },
  62. sm: { span: 16 },
  63. },
  64. confirmLoading: false,
  65. headers:{},
  66. form:this.$form.createForm(this),
  67. url: {
  68. userId:"/sys/user/generateUserId", // 引入生成添加用户情况下的url
  69. },
  70. }
  71. },
  72. methods: {
  73. add (checkedDepartKeys,userId) {
  74. this.checkedKeys = checkedDepartKeys;
  75. this.userId = userId;
  76. this.edit({});
  77. },
  78. edit (record) {
  79. this.departList = [];
  80. this.queryDepartTree();
  81. this.form.resetFields();
  82. this.visible = true;
  83. this.model = Object.assign({}, record);
  84. let filedsVal = pick(this.model,'id','userId','departIdList');
  85. this.$nextTick(() => {
  86. this.form.setFieldsValue(filedsVal);
  87. });
  88. },
  89. close () {
  90. this.$emit('close');
  91. this.visible = false;
  92. this.departList = [];
  93. this.checkedKeys = [];
  94. },
  95. handleSubmit () {
  96. const that = this;
  97. // 触发表单验证
  98. this.form.validateFields((err) => {
  99. if (!err) {
  100. that.confirmLoading = true;
  101. if(this.userId == null){
  102. getAction(this.url.userId).then((res)=>{
  103. if(res.success){
  104. let formData = {userId:res.result,
  105. departIdList:this.departList}
  106. console.log(formData)
  107. that.$emit('ok', formData);
  108. }
  109. }).finally(() => {
  110. that.departList = [];
  111. that.confirmLoading = false;
  112. that.close();
  113. })
  114. }else {
  115. let formData = {userId:this.userId,
  116. departIdList:this.departList}
  117. console.log(formData)
  118. that.departList = [];
  119. that.$emit('ok', formData);
  120. that.confirmLoading = false;
  121. that.close();
  122. }
  123. }
  124. })
  125. },
  126. handleCancel () {
  127. this.close()
  128. },
  129. // 选择部门时作用的API
  130. onCheck(checkedKeys, info){
  131. this.departList = [];
  132. this.checkedKeys = checkedKeys.checked;
  133. let checkedNodes = info.checkedNodes;
  134. for (let i = 0; i < checkedNodes.length; i++) {
  135. let de = checkedNodes[i].data.props;
  136. let depart = {key:"",value:"",title:""};
  137. depart.key = de.value;
  138. depart.value = de.value;
  139. depart.title = de.title;
  140. this.departList.push(depart);
  141. }
  142. console.log('onCheck', checkedKeys, info);
  143. },
  144. queryDepartTree(){
  145. queryIdTree().then((res)=>{
  146. if(res.success){
  147. this.departTree = res.result;
  148. if(this.checkedKeys&&this.checkedKeys.length >0){
  149. let treekey=[];
  150. let arr=res.result;
  151. if(arr&&arr.length>0){
  152. arr.forEach(item => {
  153. treekey.push(item.key);
  154. /* if(item.children&&item.children.length>0){
  155. item.children.forEach(item1 => {
  156. treekey.push(item1.key);
  157. })
  158. }*/
  159. })
  160. this.expandedKeysss = treekey
  161. }
  162. }
  163. }
  164. })
  165. },
  166. onExpand(expandedKeys){
  167. this.expandedKeysss = expandedKeys;
  168. },
  169. modalFormOk(){
  170. }
  171. },
  172. }
  173. </script>
  174. <style lang="less" scoped>
  175. .ant-table-tbody .ant-table-row td{
  176. padding-top:10px;
  177. padding-bottom:10px;
  178. }
  179. /deep/ .ant-modal{
  180. height: 700px;
  181. }
  182. </style>