SelDepartment.vue 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <block v-if="!!list">
  3. <u-select
  4. :value="value"
  5. value-name="id"
  6. label-name="departmentName"
  7. child-name="children"
  8. mode="mutil-column-auto"
  9. :list="list"
  10. @confirm="confirm"
  11. @cancel="cancel"
  12. ></u-select>
  13. </block>
  14. </template>
  15. <script>
  16. export default {
  17. model: {
  18. prop: 'value',
  19. event: 'change'
  20. },
  21. props: {
  22. value: {
  23. type: Boolean,
  24. default: false
  25. }
  26. },
  27. data() {
  28. return {
  29. list: ''
  30. };
  31. },
  32. created() {
  33. this.getAllDepartment();
  34. },
  35. methods: {
  36. confirm(val) {
  37. this.cancel()
  38. this.$emit('confirm', val);
  39. },
  40. cancel(val) {
  41. this.$emit('cancel', val);
  42. },
  43. getAllDepartment() {
  44. this.$u.api.getAllDepartment().then(res => {
  45. // this.list = this.reduceList(res.data);
  46. this.list = res.data;
  47. });
  48. },
  49. reduceList(list) {
  50. list.unshift({
  51. id: 0,
  52. departmentName: '全部'
  53. });
  54. list.forEach(item => {
  55. if (item.children) {
  56. item.children = this.reduceList(item.children);
  57. }
  58. });
  59. return list;
  60. }
  61. }
  62. };
  63. </script>
  64. <style></style>