chooseSomeone.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. <template>
  2. <div class="chooseSomeone">
  3. <div class="chooseSomeone_selsect">
  4. <van-search v-model.trim="selectValue" shape="round" background="#F4F4F4" placeholder="请输入姓名" @search="onSearch"
  5. @input="onSearch"></van-search>
  6. </div>
  7. <div class="chooseSomeone_Con contentRoll">
  8. <!-- 单选 -->
  9. <van-radio-group v-model="radioVal" class="chooseSomeone_radio_group" v-if="newGroupView == 1">
  10. <van-radio :name="item.id" v-for="item, index in personnelList" :key="index">
  11. <div class="chooseSomeone_radio_group_item">
  12. <div>{{ item.name }}</div>
  13. <div class="textBeyondHiding">{{ item.workStation }}</div>
  14. </div>
  15. </van-radio>
  16. </van-radio-group>
  17. <!-- 复选 -->
  18. <van-checkbox-group v-model="groupVal" class="chooseSomeoneo_group" v-if="newGroupView == 2">
  19. <van-checkbox :name="item.id" v-for="item, index in personnelList" :key="index">
  20. <div class="chooseSomeone_group_item">
  21. <div>{{ item.name }}</div>
  22. <div class="textBeyondHiding">{{ item.jobNumber }}</div>
  23. </div>
  24. </van-checkbox>
  25. </van-checkbox-group>
  26. <!-- tree -->
  27. <div class="treeBox" v-show="newGroupView == 3">
  28. <div class="treeBox_tree_text" v-if="!newGroupViewBack && groupView"
  29. @click="newGroupViewBackCli(true, groupView)"><van-icon name="arrow-left" />返回</div>
  30. <div class="treeBox_tree">
  31. <el-tree ref="tree" v-model="treeVal" show-checkbox node-key="id" :data="personnelTree" :props="defaultProps"
  32. :filter-node-method="filterNode">
  33. <span class="custom-tree-node" slot-scope="{ node, data }">
  34. <span>
  35. {{ node.label }}
  36. </span>
  37. </span>
  38. </el-tree>
  39. </div>
  40. </div>
  41. </div>
  42. <div class="chooseSomeone_btn" v-if="newGroupViewBack">
  43. <van-button round size="small" v-if="newGroupViewBack" @click="newGroupViewBackCli(false, 3)">从其他工位选择员工</van-button>
  44. <van-button round type="info" size="small" :loading="loadingBtn" @click="handClick()">确定</van-button>
  45. </div>
  46. <div class="chooseSomeone_btn" v-if="!newGroupViewBack">
  47. <van-button round type="info" size="small" style="width: 100%;" @click="treeHandClick()">确定</van-button>
  48. </div>
  49. </div>
  50. </template>
  51. <script>
  52. /**
  53. * peopleList 数据格式要求
  54. * 传过来的数据必须包含 以下四个字段
  55. * id: 人员id
  56. * name: 人员姓名
  57. * phone: 人员电话
  58. * jobNumber: 人员工号
  59. */
  60. export default {
  61. props: {
  62. groupView: {
  63. type: Number,
  64. default: () => 1 // 1单选 2复选 3tree
  65. },
  66. groupViewBack: {
  67. type: Boolean,
  68. default: () => false // 是否显示从其他工位选择员工
  69. },
  70. peopleList: {
  71. type: Array,
  72. default: () => []
  73. },
  74. peopleListId: { // 选中的Id
  75. type: Array,
  76. default: () => []
  77. },
  78. },
  79. components: {},
  80. data() {
  81. return {
  82. selectValue: '',
  83. radioVal: '',
  84. groupVal: [],
  85. treeVal: [],
  86. // 人员数组
  87. personnelList: [],
  88. personnelTree: [],
  89. newPersonnelTree: [],
  90. defaultProps: {
  91. children: 'children',
  92. label: 'label'
  93. },
  94. newGroupView: '', // 组件传过来的值
  95. newGroupViewBack: '', // 组件传过来的值
  96. loadingBtn: false // 确定按钮loading
  97. };
  98. },
  99. computed: {},
  100. watch: {
  101. selectValue(val) {
  102. this.$refs.tree.filter(val);
  103. }
  104. },
  105. created() { },
  106. mounted() {
  107. this.newGroupView = JSON.parse(JSON.stringify(this.groupView))
  108. this.newGroupViewBack = JSON.parse(JSON.stringify(this.groupViewBack))
  109. this.personnelList = JSON.parse(JSON.stringify(this.peopleList))
  110. let newPpeopleListId = JSON.parse(JSON.stringify(this.peopleListId))
  111. if (newPpeopleListId.length > 0) {
  112. if (this.groupView == 1) {
  113. this.radioVal = newPpeopleListId[0]
  114. } else if (this.groupView == 2) {
  115. this.groupVal = newPpeopleListId
  116. } else if (this.groupView == 3) {
  117. // tree 额外处理
  118. console.log('tree 额外处理')
  119. }
  120. }
  121. console.log(this.groupVal)
  122. if (this.peopleList.length <= 0) {
  123. this.getPeople()
  124. }
  125. this.getDepartmentPersonnel()
  126. },
  127. methods: {
  128. onSearch() {
  129. if (!this.selectValue) {
  130. this.personnelList = JSON.parse(JSON.stringify(this.peopleList))
  131. return
  132. }
  133. if (this.groupView != 3) {
  134. this.personnelList = this.personnelList.filter(item => {
  135. return item.name.indexOf(this.selectValue) != -1 || item.jobNumber.indexOf(this.selectValue) != -1
  136. })
  137. }
  138. console.log(this.personnelList)
  139. },
  140. filterNode(value, data) {
  141. if (!value) return true;
  142. return data.label.indexOf(value) !== -1;
  143. },
  144. newGroupViewBackCli(flg, i) {
  145. this.newGroupViewBack = flg
  146. this.newGroupView = i
  147. this.$refs.tree.setCheckedKeys(this.groupVal)
  148. },
  149. // 获取所有人员
  150. getPeople() {
  151. this.$axios.post('/user/getSimpleActiveUserList', {})
  152. .then(res => {
  153. if (res.code == "ok") {
  154. if (!this.peopleList) {
  155. this.peopleList = res.data.map(item => {
  156. return {
  157. name: item.name,
  158. id: item.id,
  159. phone: item.phone,
  160. jobNumber: item.jobNumber
  161. }
  162. })
  163. }
  164. } else {
  165. this.$toast.clear();
  166. this.$toast.fail(res.msg);
  167. }
  168. }).catch(err => { this.$toast.clear(); });
  169. },
  170. // 获取部门人员
  171. getDepartmentPersonnel() {
  172. this.$axios.post('/department/listAllMemb', {})
  173. .then(res => {
  174. if (res.code == "ok") {
  175. let list = res.data;
  176. this.setUserToDept(res.data)
  177. this.personnelTree = list
  178. this.newPersonnelTree = JSON.parse(JSON.stringify(list))
  179. console.log(this.personnelTree)
  180. } else {
  181. this.$toast.clear();
  182. this.$toast.fail(res.msg);
  183. }
  184. }).catch(err => { this.$toast.clear(); });
  185. },
  186. // 递归设置人员到部门
  187. setUserToDept(list) {
  188. for (var i in list) {
  189. if (list[i].children != null) {
  190. this.setUserToDept(list[i].children);
  191. }
  192. if (list[i].userList != null) {
  193. if (list[i].children == null) {
  194. list[i].children = [];
  195. }
  196. list[i].userList.forEach(element => {
  197. var obj = { id: element.id, label: element.name, parentId: element.departmentId, isUser: 1 };
  198. list[i].children.push(obj);
  199. });
  200. }
  201. }
  202. },
  203. // 单选和复选点击确定触发的事件
  204. handClick() {
  205. let arr = this.groupView == 1 ? [this.radioVal] : this.groupVal
  206. let newArr = this.personnelList.filter(item => {
  207. return arr.includes(item.id)
  208. })
  209. this.loadingBtn = true
  210. this.$emit('ChooseSomeoneChanhe', newArr)
  211. },
  212. treeHandClick() {
  213. console.log(this.treeVal)
  214. console.log(this.$refs.tree.getCheckedNodes())
  215. let arr = this.$refs.tree.getCheckedNodes()
  216. let newArr = arr.map(item => {
  217. return {
  218. id: item.id,
  219. name: item.label || '',
  220. phone: item.phone || '',
  221. jobNumber: item.jobNumber || ''
  222. }
  223. })
  224. this.loadingBtn = true
  225. this.$emit('ChooseSomeoneChanhe', newArr)
  226. }
  227. },
  228. };
  229. </script>
  230. <style scoped lang="less">
  231. * {
  232. box-sizing: border-box;
  233. }
  234. .chooseSomeone {
  235. display: flex;
  236. flex-wrap: wrap;
  237. flex-direction: column;
  238. width: 100%;
  239. height: 100%;
  240. padding: 10px 15px 0px 15px;
  241. .chooseSomeone_selsect {
  242. .van-search__content {
  243. background-color: #fff;
  244. }
  245. }
  246. .treeBox {
  247. width: 100%;
  248. height: 100%;
  249. display: flex;
  250. flex-direction: column;
  251. .treeBox_tree {
  252. flex: 1;
  253. overflow-y: auto;
  254. padding: 10px;
  255. }
  256. .treeBox_tree_text {
  257. font-size: 14px;
  258. color: #999;
  259. display: flex;
  260. align-items: center;
  261. padding: 8px;
  262. .van-icon {
  263. margin-right: 6px;
  264. }
  265. }
  266. // 调整组件的默认样式
  267. .el-tree-node__content {
  268. height: 30px;
  269. }
  270. }
  271. .chooseSomeone_Con {
  272. flex: 1;
  273. background-color: #fff;
  274. border-radius: 10px;
  275. overflow-y: auto;
  276. padding: 10px;
  277. .chooseSomeoneo_group {
  278. .van-radio,
  279. .van-checkbox {
  280. width: 100%;
  281. padding: 10px;
  282. font-size: 16px;
  283. color: #333;
  284. border-bottom: 1px solid #F4F4F4;
  285. .van-radio__label {
  286. flex: 1 !important;
  287. }
  288. .van-checkbox__label {
  289. flex: 1 !important;
  290. }
  291. }
  292. .chooseSomeone_group_item {
  293. display: flex;
  294. justify-content: space-between;
  295. div:last-child {
  296. font-size: 12px;
  297. color: #999;
  298. width: 50%;
  299. text-align: right;
  300. }
  301. }
  302. }
  303. }
  304. .chooseSomeone_btn {
  305. display: flex;
  306. justify-content: space-between;
  307. align-items: center;
  308. height: 50px;
  309. .van-button {
  310. width: 48%;
  311. }
  312. }
  313. }</style>