Blame view

components/ncc/ncc-org-select/index.vue 1.72 KB
290144e9   易尊强   第一次
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
  <template>
  	<view class="ncc-org-select">
  		<ncc-tree-select v-model="innerValue" :placeholder="placeholder" :options="options" :multiple="multiple"
  			:lastLevel="type!=='organize'" lastLevelKey="type" :lastLevelValue="type" :disabled="disabled"
  			@change="onChange">
  		</ncc-tree-select>
  	</view>
  </template>
  
  <script>
  	import nccTreeSelect from '../ncc-tree-select/index.vue';
  	export default {
  		name: 'ncc-org-select',
  		model: {
  			prop: 'value',
  			event: 'input'
  		},
  		components: {
  			nccTreeSelect
  		},
  		props: {
  			value: {
  				default: ''
  			},
  			// organize/department/position/user
  			type: {
  				type: String,
  				default: 'user'
  			},
  			placeholder: {
  				type: String,
  				default: '请选择'
  			},
  			disabled: {
  				type: Boolean,
  				default: false
  			},
  			multiple: {
  				type: Boolean,
  				default: false
  			}
  		},
  		data() {
  			return {
  				options: [],
  				innerValue: '',
  				defaultValue: []
  			}
  		},
  		watch: {
  			innerValue(val) {
  				this.$emit('input', val)
  			},
  			value(val) {
  				this.innerValue = val
  			}
  		},
  		created() {
  			this.getOptions()
  		},
  		methods: {
  			getMethod() {
  				let method = ''
  				switch (this.type) {
  					case 'organize':
  						method = 'getOrganizeTree'
  						break;
  					case 'department':
  						method = 'getDepartmentTree'
  						break;
  					case 'position':
  						method = 'getPositionTree'
  						break;
  					default:
  						method = 'getUserTree'
  						break;
  				}
  				return method
  			},
  			onChange(e) {
  				this.$emit('change', e)
  			},
  			async getOptions() {
  				const method = this.getMethod()
  				this.options = await this.$store.dispatch(`base/${method}`)
  				this.innerValue = this.value
  			}
  		}
  	}
  </script>
  <style lang="scss" scoped>
  	.ncc-org-select {
  		width: 100%;
  	}
  </style>