internship.js 2.8 KB
const state = () => ({
	schoolForm: {},
	schoolList: [],
	departmentList: [],
	professionalList: [],
	schoolTermList: [],
	classList: [],
	
	

})

// getters
const getters = {
	
}

// actions
const actions = {

	async getSchoolList({
		commit,
		dispatch,
		state
	}, params) {
		const result = await uni.$u.api.getSchoolListApi(params);
		if (result) {
			commit('setSchoolList', result);
		}
	},

	async getDepartmentList({
		commit,
		dispatch,
		state
	}, params) {
		const result = await uni.$u.api.getDepartmentListApi(params);
		if (result) {
			commit('setDepartmentList', result);
		}
	},
	
	async getProfessionalList({
		commit,
		dispatch,
		state
	}, params) {
		const result = await uni.$u.api.getProfessionalListApi(params);
		if (result) {
			commit('setProfessionalList', result);
		}
	},
	
	async getSchoolTermList({
		commit,
		dispatch,
		state
	}, params) {
		const result = await uni.$u.api.getSchoolTermListApi(params);
		if (result) {
			commit('setSchoolTermList', result);
		}
	},
	
	async getClassList({
		commit,
		dispatch,
		state
	}, params) {
		const result = await uni.$u.api.getClassListApi(params);
		if (result) {
			commit('setClassList', result);
		}
	},
	
}

// mutations
const mutations = {
	
	updateSchoolForm(state, params) {
		state.schoolForm = params;
	},

	clearSchoolList(state, result) {
		state.schoolList = [];
	},
	
	clearDepartmentList(state, result) {
		state.departmentList = [];
	},
	
	clearProfessionalList(state, result) {
		state.professionalList = [];
	},
	
	clearClassList(state, result) {
		state.classList = [];
	},

	setSchoolList(state, result) {
		state.schoolList = result.records;
	},

	setDepartmentList(state, result) {
		const {records=[]} = result
		
		let departmentList = [];
		if(records.length > 0) {
			
			records.map((item, index) => {
				departmentList.push({
					value:item.id,
					label:item.name,
				})
			})
		}
		state.departmentList = departmentList;
	},
	
	setProfessionalList(state, result) {
		const {records=[]} = result
		
		let professionalList = [];
		if(records.length > 0) {
			
			records.map((item, index) => {
				professionalList.push({
					value:item.id,
					label:item.name,
				})
			})
		}
		state.professionalList = professionalList;
	},
	
	setSchoolTermList(state, result) {
		const {records=[]} = result
		
		let schoolTermList = [];
		if(records.length > 0) {
			
			records.map((item, index) => {
				schoolTermList.push({
					value:item.id,
					label:item.year,
				})
			})
		}
		state.schoolTermList = schoolTermList;
	},
	
	setClassList(state, result) {
		const {records=[]} = result
		
		let classList = [];
		if(records.length > 0) {
			
			records.map((item, index) => {
				classList.push({
					value:item.id,
					label:item.name,
				})
			})
		}
		state.classList = classList;
	},
	
	
}

export default {
	namespaced: true,
	state,
	getters,
	actions,
	mutations
}