departmentSelectionPersonnel.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <el-dialog :title="$t('selectingParticipants')" :visible.sync="participantsVisible" :close-on-click-modal="false"
  3. customClass="customWidth" width="500px" :before-close="changeVisable">
  4. <div class="tree" style="height:400px">
  5. <el-scrollbar style="height:100%">
  6. <el-input v-if="user.userNameNeedTranslate != 1" :placeholder="$t('keywordfiltering')"
  7. v-model="participantsFilterText">
  8. </el-input>
  9. <div v-if="user.userNameNeedTranslate == '1'">
  10. <el-input :placeholder="$t('qingShuShuRuGuanJianZiGuoLv')" v-model.trim="participantsFilterText"
  11. class="input-with-select" @keyup.enter.native="echartDepartment()">
  12. <el-button slot="append" icon="el-icon-search" @click="echartDepartment()"></el-button>
  13. </el-input>
  14. </div>
  15. <el-tree :data="deptMembData" show-checkbox :props="defaultProps" node-key="id" ref="chooseMembTree2"
  16. @check-change="onTreeItemChange" :default-checked-keys="alreadyPartArray" highlight-current
  17. :filter-node-method="filterNode" v-loading="filterNodeFlag">
  18. <span class="custom-tree-node" slot-scope="{ node, data }">
  19. <span v-if="user.userNameNeedTranslate == '1'">
  20. <span v-if="node.data.children">
  21. <TranslationOpenDataText type='departmentName' :openid='node.label'>
  22. </TranslationOpenDataText>
  23. </span>
  24. <span v-else>
  25. <TranslationOpenDataText type='userName' :openid='node.label'></TranslationOpenDataText>
  26. </span>
  27. </span>
  28. <span v-if="user.userNameNeedTranslate != '1'">
  29. {{ node.label }}
  30. </span>
  31. </span>
  32. </el-tree>
  33. </el-scrollbar>
  34. </div>
  35. <div>{{ $t('btn.choose') }}&nbsp;{{ chosenMembCount }}&nbsp;{{ $t('other.people') }}</div>
  36. <div slot="footer" class="dialog-footer">
  37. <el-button @click="changeVisable()">{{ $t('btn.cancel') }}</el-button>
  38. <el-button type="primary" @click="submitData()">{{ $t('btn.determine') }}</el-button>
  39. </div>
  40. </el-dialog>
  41. </template>
  42. <script>
  43. export default {
  44. name: '',
  45. components: {},
  46. props: {
  47. visible: {
  48. type: Boolean,
  49. default: false
  50. }
  51. },
  52. data() {
  53. return {
  54. participantsFilterText: '',
  55. participantsVisible: false,
  56. filterNodePersonnel: [],
  57. chosenMembCount: 0,
  58. alreadyPartArray: [], // 已参与的人员
  59. filterNodeFlag: false,
  60. user: JSON.parse(sessionStorage.getItem("user")),
  61. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  62. deptMembData: [
  63. {
  64. id: 0,
  65. label: this.$t('lable.unassigned'),
  66. }
  67. ],
  68. defaultProps: {
  69. children: 'children',
  70. label: 'label'
  71. },
  72. }
  73. },
  74. computed: {},
  75. watch: {
  76. visible(val) {
  77. console.log('执行')
  78. this.participantsVisible = val
  79. },
  80. participantsFilterText(val) {
  81. let { userNameNeedTranslate } = JSON.parse(sessionStorage.getItem("user"))
  82. if (userNameNeedTranslate != 1) {
  83. this.$refs.chooseMembTree2.filter(val);
  84. }
  85. if (!val) {
  86. this.$refs.chooseMembTree2.filter(val);
  87. }
  88. }
  89. },
  90. created() { },
  91. mounted() {
  92. this.getDepartmentList()
  93. },
  94. methods: {
  95. submitData() {
  96. let chosenList = this.$refs.chooseMembTree2.getCheckedNodes();
  97. let chose2 = chosenList.filter(item => item.isUser == 1)
  98. if((chose2 || []).length == 0) {
  99. this.$message({
  100. message: this.$t('pleaseselectpersonnel'),
  101. type: "error"
  102. });
  103. return
  104. }
  105. this.$refs.chooseMembTree2.setCheckedKeys([]);
  106. this.$emit("submitParticipant", chose2)
  107. },
  108. changeVisable(done) {
  109. this.$refs.chooseMembTree2.setCheckedKeys([]);
  110. this.$emit("changeParticipant", false)
  111. if (done) {
  112. done()
  113. }
  114. },
  115. // 筛选逻辑
  116. filterNode(value, data) {
  117. let { userNameNeedTranslate } = this.user
  118. if (!value) return true;
  119. if (userNameNeedTranslate != '1') {
  120. return data.label.indexOf(value) !== -1;
  121. } else {
  122. return this.filterNodePersonnel.some(item => item.includes(data.label))
  123. }
  124. },
  125. // 选中改变
  126. onTreeItemChange() {
  127. var chosenList = this.$refs.chooseMembTree2.getCheckedNodes();
  128. var list = chosenList.filter(item => item.isUser == 1);
  129. this.chosenMembCount = list.length;
  130. },
  131. echartDepartment() {
  132. if (this.participantsFilterText != '') {
  133. this.filterNodeFlag = true
  134. this.http.post("/user/getEmployeeList", {
  135. keyword: this.participantsFilterText,
  136. cursor: '',
  137. departmentId: -1,
  138. pageIndex: 1,
  139. pageSize: 1000
  140. },
  141. res => {
  142. if (res.code == "ok") {
  143. this.filterNodePersonnel = res.data.records.map(item => item.name)
  144. this.$refs.chooseMembTree2.filter(this.participantsFilterText);
  145. } else {
  146. this.$message({
  147. message: res.msg,
  148. type: "error"
  149. });
  150. }
  151. this.filterNodeFlag = false
  152. },
  153. error => {
  154. this.filterNodeFlag = false
  155. this.$message({
  156. message: error,
  157. type: "error"
  158. });
  159. });
  160. }
  161. },
  162. getDepartmentList() {
  163. this.http.post('/department/listAllMemb', {
  164. }, res => {
  165. if (res.code == 'ok') {
  166. let list = res.data
  167. this.haveUsersList(list)
  168. this.deptMembData = JSON.parse(JSON.stringify(list))
  169. } else {
  170. this.$message({
  171. message: res.msg,
  172. type: 'error'
  173. })
  174. }
  175. }, error => {
  176. this.$message({
  177. message: error,
  178. type: 'error'
  179. })
  180. })
  181. },
  182. haveUsersList(list) {
  183. for (var i in list) {
  184. if (list[i].children != null) {
  185. this.haveUsersList(list[i].children);
  186. }
  187. if (list[i].userList != null) {
  188. if (list[i].children == null) {
  189. list[i].children = [];
  190. }
  191. list[i].userList.forEach(element => {
  192. var obj = { id: element.id, label: element.name, parentId: element.departmentId, isUser: 1 };
  193. list[i].children.push(obj);
  194. });
  195. }
  196. }
  197. },
  198. },
  199. }
  200. </script>
  201. <style scoped lang='scss'></style>