<template>
	<el-switch
		v-hasPermi="['base:group-team:edit-worker']"
		v-model="state"
		type="text"
		size="small"
		:disabled="readonly"
		@change="changeHandler" />
</template>

<script>
export default {
	props: {
		injectData: {
			type: Object,
			default: () => ({}),
		},
	},
	data() {
		return {
			state: false,
		};
	},
	computed: {
		readonly() {
			return !!this.injectData.readonly;
		},
	},
	mounted() {
		this.mapToState();
	},
	methods: {
		mapToState() {
			if (this.injectData.prop === 'enabled') {
				this.state = this.injectData.enabled === 1 ? true : false;
			}
		},
		changeHandler() {
			let params = {};
			let payload = {};
			params.name = 'state';
			payload.id = this.injectData.id;
			payload.enabled = this.state ? '1' : '0';
			payload.code = this.injectData.code;
			payload.name = this.injectData.name;
			payload.leaderId = this.injectData.leaderId;
			params.payload = payload;
			this.$emit('emitData', params);
		},
	},
};
</script>
