IssueTypeSelect.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <el-cascader
  3. :value="vModel"
  4. :options="options"
  5. :clearable="true"
  6. :show-all-levels="false"
  7. @change="onChange"
  8. ></el-cascader>
  9. </template>
  10. <script>
  11. import { getList } from '@/api/help/type';
  12. const resetList = (arr = []) => {
  13. const reuslt = arr.map(x => ({
  14. value: x.id,
  15. label: x.name,
  16. children: x.children && x.children.length > 0 ? resetList(x.children) : null
  17. }));
  18. return reuslt;
  19. };
  20. const checkList = (list = []) => {
  21. list = list.reduce((init, item) => {
  22. if (item.children) {
  23. init.push(item);
  24. }
  25. return init;
  26. }, []);
  27. return list;
  28. };
  29. export default {
  30. name: 'IssueTypeSelect',
  31. props: {
  32. value: {
  33. type: String,
  34. default: ''
  35. }
  36. },
  37. data() {
  38. return {
  39. vModel: this.value,
  40. options: []
  41. };
  42. },
  43. watch: {
  44. value: {
  45. handler(val) {
  46. this.vModel = val;
  47. },
  48. immediate: true
  49. }
  50. },
  51. mounted() {
  52. this.loadData();
  53. },
  54. methods: {
  55. onChange(value) {
  56. console.log(value);
  57. this.$emit('input', value[1] || null);
  58. },
  59. async loadData() {
  60. const { success, data, msg } = await getList({
  61. data: {
  62. isShow: null
  63. },
  64. limit: 999999,
  65. start: 1
  66. });
  67. if (success) {
  68. let result = resetList(data.data);
  69. this.options = checkList(result);
  70. }
  71. }
  72. }
  73. };
  74. </script>
  75. <style lang="scss" scoped></style>