123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <template>
- <uni-data-picker v-model="select" :placeholder="placeholder" popup-title="请选择"
- :localdata="options"
- @change="onchange" @nodeclick="onnodeclick">
- </uni-data-picker>
- </template>
- <script>
- import {
- getAllChildren
- } from '@/api/system'
- export default {
- name: "simpleCascader",
- props: {
- value: {
- type: [String, Number],
- required: false,
- default: null,
- },
- data: {
- type: [String, Array],
- required: true
- },
- loadType: {
- type: String,
- required: false,
- default: "local"
- },
- field: {
- type: String,
- required: false,
- default: "default"
- },
- ext: {
- type: Object,
- required: false,
- default: () => ({}),
- },
- readonly: {
- type: Boolean,
- required: false,
- default: false,
- },
- placeholder: {
- type: String,
- required: false,
- default: '请选择',
- }
- },
- computed: {
- isLocal() {
- return this.loadType === 'local'
- },
- isDict() {
- return this.loadType === 'dict'
- },
- isStatic() {
- return this.loadType === 'static'
- }
- },
- data() {
- return {
- select: this.value,
- options: []
- };
- },
- watch: {
- value(n, o) {
- this.select = n
- }
- },
- mounted() {
- this.init()
- },
- methods: {
- init() {
- this.options = []
- if(this.isDict) {
- this.loadDict()
- }else if(this.isLocal) {
- this.options = this.data
- }else if(this.isStatic) {
-
- }
- },
- parseList(list) {
- return list.map(d => {
- let children = null
- if(d.children && d.children.length > 0) {
- children = this.parseList(d.children)
- }
- const ret = {
- text: d.enumname,
- raw: d,
- }
-
- if (this.field === 'default') {
- ret.value = d.enumid
- } else if (this.field.startsWith('raw.')) {
- const [
- _,
- f
- ] = this.field.split('\.')
- ret.value = d[f]
- }
-
- if(children) {
- ret.children = children
- }
- return ret
- })
- },
- loadDict() {
- getAllChildren({
- enumid: this.data,
- isQueryFristNode: false,
- ... this.ext
- }).then(resp => {
- const list = resp.data || []
- this.options = this.parseList(list)
- })
- },
- onchange() {
- this.$emit('input', this.select)
- },
- onnodeclick() {
- }
- }
- }
- </script>
- <style>
- </style>
|