1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <template>
- <el-cascader
- :value="vModel"
- :options="options"
- :clearable="true"
- :show-all-levels="false"
- @change="onChange"
- ></el-cascader>
- </template>
- <script>
- import { getList } from '@/api/help/type';
- const resetList = (arr = []) => {
- const reuslt = arr.map(x => ({
- value: x.id,
- label: x.name,
- children: x.children && x.children.length > 0 ? resetList(x.children) : null
- }));
- return reuslt;
- };
- const checkList = (list = []) => {
- list = list.reduce((init, item) => {
- if (item.children) {
- init.push(item);
- }
- return init;
- }, []);
- return list;
- };
- export default {
- name: 'IssueTypeSelect',
- props: {
- value: {
- type: String,
- default: ''
- }
- },
- data() {
- return {
- vModel: this.value,
- options: []
- };
- },
- watch: {
- value: {
- handler(val) {
- this.vModel = val;
- },
- immediate: true
- }
- },
- mounted() {
- this.loadData();
- },
- methods: {
- onChange(value) {
- console.log(value);
- this.$emit('input', value[1] || null);
- },
- async loadData() {
- const { success, data, msg } = await getList({
- data: {
- isShow: null
- },
- limit: 999999,
- start: 1
- });
- if (success) {
- let result = resetList(data.data);
- this.options = checkList(result);
- }
- }
- }
- };
- </script>
- <style lang="scss" scoped></style>
|