|
|
- <!-- 存储位置选择器 -->
- <template>
- <div>
- <el-select style="width:100%" v-model="selected" :placeholder="$t('form.placeholderSelect')" :disabled="readonly" :multiple="multiple" @change="handleChange" :filterable="filterable">
- <el-option v-for="item in list" :key="item.dictCode" :label="item.dictLabel" :value="item.dictLabel" />
- </el-select>
- </div>
- </template>
-
- <script>
- import { listData } from "@/api/system/dict/data"
-
- export default {
- name: "SelectCcwz",
- components: {},
- props: {
- value: {
- type: [Number, String , Array],
- default: '',
- },
- readonly: {
- type: Boolean,
- default: false
- },
- multiple: {
- type: Boolean,
- default: false
- },
- filterable: {
- type: Boolean,
- default: true
- },
- placeholder: {
- type: String,
- default: ''
- }
- },
- watch: {
- value: {
- immediate: true,
- handler(v) {
- if(!this.multiple){
- this.selected = v ? v : ''
- }else{
- if(v){
- //默认传的,分割的字符串,有传数组再改造
- let arr = v.split(',')
- let s = []
- _.forEach(arr,a=>{
- s.push(a)
- })
- this.selected = s
- }else{
- this.selected = []
- }
- }
- }
- },
- },
- data() {
- return {
- selected: '',
- list: [],
- queryParams: {
- pageNum: 1,
- pageSize: 9999,
- dictType: 'system_business_ccwz',
- status: 0
- },
- };
- },
- mounted() {
- this.getList()
- },
- methods: {
- getList() {
- this.list = []
- listData(this.queryParams).then(response => {
- this.list = response.rows
- })
- },
- handleChange(val) {
- this.$emit('input', this.multiple ? (val && val.length>0 ? val.join(','): ''):(val || ''))
- //默认传的,分割的字符串,有传数组再改造
- let _index = _.findIndex(this.list, function (a) {
- return a.dictLabel == val
- })
- console.log(_index)
- if (_index > -1) {
- this.$emit('change', this.list[_index])
- } else {
- this.$emit('change', null)
- }
-
- },
- }
- };
- </script>
|