position.js 3.2 KB
const state = () => ({
	positionDetail: {},
	reason: '',
})

const getters = {
	doneReleaseTime: state => {
		let {
			publishTime = 0
		} = state.positionDetail;

		return publishTime > 0 ? uni.$u.timeFormat(publishTime, 'mm/dd') : '';
	},

	doneSalary: state => {
		let {
			wageType = '', wageLower = '', wageUpper = '',
		} = state.positionDetail;

		let wageTypeOption = {
			"monthly": "月",
			"daily": "日",
			"hourly": "时",
			"annual": "年"
		};

		let salary = '';

		switch (wageType) {

			case 'negotiable':
				salary = '薪资面议'
				break;

			default:
				if (wageLower == wageUpper) {
					salary = `${wageLower}/${wageTypeOption[wageType]}`
				} else {
					salary = `${wageLower}~${wageUpper}/${wageTypeOption[wageType]}`
				}
				break;
		}

		return salary;
	},

	doneAddress: state => {
		let {
			province = '', district = '',
		} = state.positionDetail;

		return `${province}/${district}`;
	},

	doneWorkHour: state => {
		let {
			attendanceType = '', attendanceDay = '',
		} = state.positionDetail;

		let attendanceTypeOption = {
			"week": "周",
			"month": "月",
			"year": "年"
		};

		return attendanceType && attendanceDay ? `${attendanceDay}/${attendanceTypeOption[attendanceType]}` :
			"";
	},

	doneProperty: state => {
		let {
			property = '',
		} = state.positionDetail;

		let propertyOptions = {
			"part_time": "兼职",
			"internship": "实习",
			"full_time": "全职",
			"other": "其他"
		}

		return propertyOptions[property];
	},

	doneCategory: state => {
		let {
			category = '',
		} = state.positionDetail;

		let categoryOptions = {
			"0": "不限",
			"manufacture": "智能制造",
			"preschool": "学前教育",
			"healthy": "智慧康养",
			"software": "大数据与软件",
			"other": "其他",
		}

		return categoryOptions[category];
	},

	doneDegree: state => {
		let {
			degreeRequires = '',
		} = state.positionDetail;

		let degreeOptions = {
			"0": "不限",
			"1": "初中",
			"2": "高中",
			"3": "中专/技校",
			"4": "大专",
			"5": "本科",
			"6": "硕士",
			"7": "博士",
			"8": "MBA/EMBA"
		}

		return degreeRequires ? degreeOptions[degreeRequires] : "";
	},

	doneWorkExp: state => {
		let {
			workExp = '',
		} = state.positionDetail;

		let workExpOptions = {
			"0": "不限",
			"1": "在校生",
			"2": "应届生",
			"3": "1年以内",
			"4": "1-3年",
			"5": "3-5年",
			"6": "5-10年",
			"7": "10年以上",
		}

		return workExpOptions[workExp];
	},
	
	doneFlag: state => {
		let {
			flag = '',
		} = state.positionDetail;
		
		
		if(flag) {
			return flag.split(',');
		} else {
			return [];
		}
	},

}

const actions = {

	async getPositionDetail({
		commit,
		dispatch,
		state
	}, params) {
		const result = await uni.$u.api.getJobDetailApi(params);
		if (result) {
			commit('setPositionDetail', result);
			return result;
		}
	},

}

const mutations = {

	setPositionDetail(state, result) {
		state.positionDetail = result;
	},

	setPositionReason(state, result) {
		state.reason = result;
	},

}

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