import { TITLES, WIDTHS } from '../constant/index.js';
export const rigthBtnDataInit = (datas, item) => {
	if (
		datas.ruleForm.documentStatus !== 'a' &&
		datas.ruleForm.documentStatus !== 'd'
	) {
		return;
	}
	datas.timelineItemIndex = item.id;
	datas.title = TITLES[item.tag];
	datas.width = WIDTHS[item.tag];
	for (let key in datas.showDialogContent) {
		datas[key] = false;
		datas[item.tag] = true;
	}
	//禁止
	if (item.id > 1) {
		let wayItem =
			datas.ruleForm.details[datas.detailsIndex].ways[item.id - 2];
		let type = wayItem ? wayItem.type : 0;
		//审批方式
		let methodValue = wayItem ? wayItem.method : '1';
		let wayItemLength = wayItem ? wayItem.wayApprovers.length : 0;
		if (wayItemLength) {
			datas.setConditionsData.deptValue = wayItem.wayApprovers[0].deptId;
			datas.setConditionsData.checkIds = wayItem.wayApprovers;
		}

		if (type) {
			datas.setConditionsData.methodValue = methodValue + '';
			datas.setConditionsData.radioValue = type + '';
			datas.radios.forEach((item) => {
				item.disabled = true;
				if (item.value == type) {
					item.disabled = false;
				}
			});
		} else {
			let types = [];
			datas.setConditionsData.methodValue = '1';
			datas.ruleForm.details[datas.detailsIndex].ways.forEach((item) => {
				if (item.type) {
					types.push(item.type + '');
				}
			});
			datas.radios.forEach((item) => {
				item.disabled = false;
				if (types.includes(item.value)) {
					item.disabled = types.includes(item.value);
				}
			});
			const radioValueArr = ['1', '2', '3'];
			for (let i = 0; i < radioValueArr.length; i++) {
				if (!types.includes(radioValueArr[i])) {
					datas.setConditionsData.radioValue = radioValueArr[i];
					return;
				}
			}
		}
	}

	if (item.title === '审批适用范围') {
		//回填
		datas.applicableScopeData.remark =
			datas.ruleForm.details[datas.detailsIndex].remark;
		datas.ruleForm.details[datas.detailsIndex].ranges.forEach((item) => {
			datas.applicableScopeData.checkIds.push(item.deptId);
		});
	}
};
