DepartWindow.vue 6.1 KB

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