import Clipboard from 'clipboard';
import { ElMessage } from 'element-plus';
import { Decimal } from 'decimal.js';

/**
 * jx 模块共用方法
 */
// jx 6.25 全局订单号 规则 - 限制
const orderRexgu = (val) => {
	if (val) {
		return val.toString().replace(/[^A-Za-z0-9\\-]/g, '');
	} else {
		return '';
	}
};

// jx 6.25 订单号 复制按钮
const orderCopy = () => {
	var clipboard = new Clipboard('.copyBtn');
	clipboard.on('success', () => {
		ElMessage.success({ message: '复制成功', showClose: true });
		clipboard.destroy();
	});
	clipboard.on('error', () => {
		ElMessage.error({ message: '复制失败', showClose: true });
		clipboard.destroy();
	});
};

// jx 7.8 时间 年 - 月 - 日
const getNowTimeGlobal = () => {
	let date = new Date();
	let year = date.getFullYear();
	let month =
		date.getMonth() + 1 < 10
			? '0' + (date.getMonth() + 1)
			: date.getMonth() + 1;
	let day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
	return year + '-' + month + '-' + day;
};

// jx 7.12 含税单价精度 输入限制
const pricePrecisionNumberCom = (
	baseInfoForm,
	salePrecisionNumber,
	isPrecision,
	index,
	key,
	val
) => {
	if (isPrecision[index]) {
		if (val.toString().indexOf('.') !== -1) {
			baseInfoForm.details[index][key] = Decimal(val).toFixed(
				0,
				Decimal.ROUND_DOWN
			);
		}
		return baseInfoForm.details[index][key].toString().replace(/\D/g, '');
	} else {
		let numD = '';
		let count = '\\d';
		for (let ind = 0; ind < salePrecisionNumber[index]; ind++) {
			numD = numD + count;
		}
		let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
		return baseInfoForm.details[index][key]
			.toString()
			.replace(/[^\d^\\.]+/g, '')
			.replace('.', '$#$')
			.replace(/\./g, '')
			.replace('$#$', '.')
			.replace(eval(reg), '$1$2.$3');
	}
};

// jx 7.12 数量精度 输入限制
const numberPrecisionCom = (unitpriceAccuracy, value) => {
	let numD = '';
	let count = '\\d';
	for (let index = 0; index < unitpriceAccuracy; index++) {
		numD = numD + count;
	}
	let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
	if (value) {
		if (unitpriceAccuracy === 0) {
			return Number(value).toFixed(0);
		} else {
			return value
				.toString()
				.replace(/[^\d.]/g, '')
				.replace(/\.{2,}/g, '.')
				.replace(/^\./g, '')
				.replace('.', '$#$')
				.replace(/\./g, '')
				.replace('$#$', '.')
				.replace(eval(reg), '$1$2.$3');
		}
	}
};

// jx 6.25 折扣率 规则 - 限制
const disRateRexgu = (val) => {
	if (val > 100) {
		return 100;
	} else {
		if (val) {
			return val
				.toString()
				.replace(/[^\d^\\.]+/g, '')
				.replace('.', '$#$')
				.replace(/\./g, '')
				.replace('$#$', '.')
				.replace(/^(\\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3');
		} else {
			return '';
		}
	}
};

// jx 8.17 枚举获取name
const getObjectName = (obj, val) => {
	let name = '';
	for (const key in obj) {
		if (key == val) {
			name = obj[key];
		}
	}
	return name;
};

// jx 8.19 array获取name
const getArrayName = (arr, val) => {
	let name = '';
	let tempName = [];
	if (arr) {
		tempName = arr.filter((it) => it.id === val);
	}
	if (tempName.length > 0) {
		name = tempName[0].name;
	}
	return name;
};

// jx 8.25 211 半成品获取name
const getArrayName211 = (arr, val) => {
	let name = '';
	let tempName = [];
	if (arr) {
		tempName = arr.filter((it) => it.name === val);
	}
	if (tempName.length > 0) {
		name = tempName[0].name;
	}
	return name;
};

// jx 10.10 保存\提交 排除物料\SKU为空的数据
const filterMaterialData = (baseInfoForm) => {
	let tempArr = [];
	tempArr = baseInfoForm.details.filter((it) => {
		if (it.materialId) {
			return it;
		}
	});
	baseInfoForm.details = tempArr;
	return;
};

// jx 10.12 处理 其它模块 添加行
const bottomAddRow = (data, addRow) => {
	let lastIndex = data.length;
	data.splice(lastIndex, 0, addRow);
	return data;
};

// jx 11.28 前8后6
// 验证输入百分比是数字，0，或者小数，首位不允许多个0
const numberRexgu = (value) => {
	if (value) {
		if (value.toString().indexOf('.') != -1) {
			let value_after = parseInt(
				value.toString().substring(0, value.indexOf('.'))
			);
			let value_before = value.replace(/\d+\.(\d*)/, '$1');
			if (value_after.toString().length > 8) {
				let newValue =
					value_after.toString().substring(0, 8) + '.' + value_before;
				return (newValue.toString().match(/\d{1,8}(\.\d{0,6})?/) || [
					'',
				])[0];
			} else {
				return (value.toString().match(/\d{1,8}(\.\d{0,6})?/) || [
					'',
				])[0];
			}
		}
		return (value.toString().match(/\d{1,8}(\.\d{0,6})?/) || [''])[0];
	} else {
		return '';
	}
};

/**
 * 销售订单 -- 页面方法
 */
// jx 6.25 销售 添加行 addRow
const addRowCom = (details, name) => {
	let addRow = {};
	let keys = Object.keys(details[0]);
	for (const key in details[0]) {
		if (keys.indexOf(key) > -1) {
			addRow[key] = details[0][key];
			addRow.id = 0;
			addRow.fid = 0;
			addRow.purchaseNumber = 0;
		}
	}
	addRow.isMaterialShow = false;
	addRow.isSkuShow = false;
	addRow.isSaleShow = false;
	addRow.isTaxPrice = false;
	addRow.isTaxRate = false;
	addRow.isWareHouse = false;
	addRow.isCustomerStock = false;
	addRow.isOrderreMarks = false;
	addRow.isDeliveryDate = false;
	addRow.isDiscountRate = false;
	addRow.isSettleOrgName = false;
	addRow.isOnlineOrderNo = false;
	addRow.isBarCode = false;
	return addRow;
};

// jx 6.25 销售 含税单价 规则 - 限制
const taxPriceNumberRexgu = (val, unitpriceAccuracy) => {
	let numD = '';
	let count = '\\d';
	for (let index = 0; index < unitpriceAccuracy; index++) {
		numD = numD + count;
	}
	let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
	if (val) {
		if (unitpriceAccuracy === 0) {
			return Number(val).toFixed(0);
		} else {
			return val
				.toString()
				.replace(/[^\d^\\.]+/g, '')
				.replace('.', '$#$')
				.replace(/\./g, '')
				.replace('$#$', '.')
				.replace(eval(reg), '$1$2.$3');
		}
	} else {
		return '';
	}
};

// jx 6.27  销售 上下查订单类型
const searchOrder = (val) => {
	let pathName = '';
	if (val === 1) {
		// "生产订单"
		return (pathName = 'ProductOrder');
	}
	if (val === 2) {
		// "采购订单"
		return (pathName = 'DemandOrder');
	}
	if (val === 3) {
		// "委外订单"
		return (pathName = 'OutsourcOrder');
	}
	if (val === 5) {
		// "发货通知单"
		return (pathName = 'WarehouseSalesDeliveryNorice');
	}
	if (val === 6) {
		// "销售退货单"
		return (pathName = 'SaleReturnOrder');
	}
	if (val === 10) {
		// "组织间需求单"
		return (pathName = 'OrgNeeds');
	}
};

// jx 6.27 销售 下推确定
const pushDownSure = (val) => {
	let result = {
		pathName: '',
		routerName: '',
	};
	if (val === '1') {
		// "生产订单"
		result.pathName = 'SalOrder/PushDownProduceOrder';
		result.routerName = 'ProductOrderCreate';
	}
	if (val === '2') {
		// "采购订单"
		result.pathName = 'SalOrder/PushDownPurchaseOrder';
		result.routerName = 'CreatePurchase';
	}
	if (val === '3') {
		// "委外订单"
		result.pathName = 'SalOrder/PushDownOutSourc';
		result.routerName = 'AddOutSourcOrder';
	}
	if (val === '5') {
		// "发货通知单"
		result.pathName = 'SalOrder/PushDownDeliveryNoticeOrder';
		result.routerName = 'SaleDeliveryAddnotice';
	}
	if (val === '6') {
		// "销售退货单"
		result.pathName = 'SalOrder/PushDownReturnStockOrder';
		result.routerName = 'CreateRuturnOrder';
	}
	if (val === '10') {
		// "组织间需求单"
		result.pathName = 'SalOrder/PushDownOrganizationOrder';
		result.routerName = 'CreateOrgNeeds';
	}
	return result;
};

// jx 6.27 销售 物料编码、规格型号携带的参数 --> 针对详情输入 + 批量填充 + 单元格点击
const materSpecCarry = (details, element, customerInfo) => {
	details.materialId = element.id;
	details.specificationId = element.id;
	details.matterName = element.name;
	details.unitId = element.baseUnitId;
	details.unitName = element.baseUnitName;
	details.materialNumber = element.number;
	details.specification = element.specifications;
	details.paezOrgName = element.paezOrgName;
	details.defaultSupplierName = element.defaultSupplierName;
	details.defaultSupplierTaxRate = element.defaultSupplierTaxRate;
	details.is211 = element.is211 ? element.is211 : false;
	details.supplyChainName = element.supplyChain;
	details.supplyChain = element.supplyChainKey;
	details.lifeCycle = element.lifeCycleKey;
	details.lifeCycleName = element.lifeCycle;
	details.supplyOriginId = element.paezOrgId;
	details.defaultSupplier = element.defaultSupplierId;
	element.taxRateId
		? (details.taxRate = element.taxRateNmae)
		: customerInfo && customerInfo.length > 0
		? (details.taxRate = customerInfo[0].defaultRate)
		: (details.taxRate = 0);
	return details;
};

// jx 6.27 物料编码、规格型号携带的数据 --> 输入框 模糊匹配
const materSpecSearh = (baseInfoForm, ind, el, details) => {
	baseInfoForm.details[ind].materialId = el.id;
	baseInfoForm.details[ind].specificationId = el.id;
	baseInfoForm.details[ind].matterName = el.name;
	baseInfoForm.details[ind].unitId = el.baseUnitId;
	baseInfoForm.details[ind].paezOrgName = el.paezOrgName;
	if (!details) {
		baseInfoForm.details[ind].defaultSupplierName = el.defaultSupplierName;
		baseInfoForm.details[ind].defaultSupplierTaxRate =
			el.defaultSupplierTaxRate;
	}
	baseInfoForm.details[ind].is211 = el.is211 ? el.is211 : false;
	baseInfoForm.details[ind].supplyChainName = el.supplyChain;
	baseInfoForm.details[ind].supplyChain = el.supplyChainKey;
	baseInfoForm.details[ind].lifeCycle = el.lifeCycleKey;
	baseInfoForm.details[ind].lifeCycleName = el.lifeCycle;
	baseInfoForm.details[ind].supplyOriginId = el.paezOrgId;
	baseInfoForm.details[ind].defaultSupplier = el.defaultSupplierId;
	return baseInfoForm;
};

// jx 10.9 明细信息 添加行
const insertRow = (
	data,
	baseInfoForm,
	customeStockArrylist,
	matterallCodelist,
	specificationalllist,
	addRow
) => {
	const index = baseInfoForm.details.length;
	baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)));
	customeStockArrylist.splice(index, 0, []);
	matterallCodelist.splice(index, 0, []);
	specificationalllist.splice(index, 0, []);
	for (const key in baseInfoForm.details[index]) {
		baseInfoForm.details[index][key] = '';
	}
	baseInfoForm.details[index].id = 0;
	baseInfoForm.details[index].fid = 0;
	baseInfoForm.details[index].isFree = false;
	baseInfoForm.details[index].isDisabled = false;
	baseInfoForm.details[index].isCusHouse = true;
	baseInfoForm.details[index].isHouse = false;
	if (baseInfoForm.saleorgId) {
		baseInfoForm.details[index].settleOrg = baseInfoForm.saleorgId;
		baseInfoForm.details[index].settleOrgName = baseInfoForm.saleorgName;
		baseInfoForm.details[index].purchaseNumber = 0;
	}
	return {
		data,
		baseInfoForm,
		customeStockArrylist,
		matterallCodelist,
		specificationalllist,
	};
};

// // jx 6.27 销售 向上、向下插入行
// const insertRow = (data,baseInfoForm,index,customeStockArrylist,matterallCodelist,specificationalllist,addRow) => {
//   if (data.insertTopVal != 0 && data.insertTopVal != '') {
//     for (let i = 0; i < data.insertTopVal; i++) {
//       baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(index, 0, [])
//       matterallCodelist.splice(index, 0, [])
//       specificationalllist.splice(index, 0, [])
//       for (const key in baseInfoForm.details[index]) {
//         baseInfoForm.details[index][key] = ''
//       }
//       baseInfoForm.details[index].id = 0
//       baseInfoForm.details[index].fid = 0
//       baseInfoForm.details[index].isFree = false
//       baseInfoForm.details[index].isDisabled = false
//       baseInfoForm.details[index].isCusHouse = true
//       baseInfoForm.details[index].isHouse = false
//       if (baseInfoForm.saleorgId) {
//         baseInfoForm.details[index].settleOrg = baseInfoForm.saleorgId
//         baseInfoForm.details[index].settleOrgName = baseInfoForm.saleorgName
//         baseInfoForm.details[index].purchaseNumber = 0
//       }
//       index = parseInt(index) + 1
//     }
//   }
//   if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
//     for (let i = 0; i < data.insertBottomVal; i++) {
//       index = parseInt(index) + 1
//       baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(index, 0, [])
//       matterallCodelist.splice(index, 0, [])
//       specificationalllist.splice(index, 0, [])
//       for (const key in baseInfoForm.details[index]) {
//         baseInfoForm.details[index][key] = ''
//       }
//       baseInfoForm.details[index].id = 0
//       baseInfoForm.details[index].fid = 0
//       baseInfoForm.details[index].isFree = false
//       baseInfoForm.details[index].isDisabled = false
//       baseInfoForm.details[index].isCusHouse = true
//       baseInfoForm.details[index].isHouse = false
//       if (baseInfoForm.saleorgId) {
//         baseInfoForm.details[index].settleOrg = baseInfoForm.saleorgId
//         baseInfoForm.details[index].settleOrgName = baseInfoForm.saleorgName
//         baseInfoForm.details[index].purchaseNumber = 0
//       }
//     }
//     index = index - data.insertBottomVal // 回朔
//   }
//   return {data,baseInfoForm,index,customeStockArrylist,matterallCodelist,specificationalllist}
// }

// jx 6.27 销售订单 处理 保存、提交、审核 操作记录里面的日期
const saveSubmitBackData = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.approveDate = req.data.approveDate;
	baseInfoForm.approverName = req.data.approverName;
	baseInfoForm.commitDate = req.data.commitDate;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifierName = req.data.modifierName;
	return baseInfoForm;
};

// jx 6.27 销售订单 切换组织 清空相应数据
const changeCustomerClearData = (baseInfoForm, statusForm, addRow) => {
	baseInfoForm.custId = ''; //  清空客户
	baseInfoForm.saleDeptId = ''; //  清空部门
	//   statusForm.followPersons = []
	//   statusForm.salePerson = []
	baseInfoForm.salerId = ''; // 清空销售员
	baseInfoForm.salesManId = ''; // 清空跟单员
	baseInfoForm.recconditionId = ''; // 收款条件
	baseInfoForm.settlemodeId = ''; // 结算方式
	baseInfoForm.settlecurrId = ''; // 结算币别
	baseInfoForm.exchangeRate = ''; // 汇率
	baseInfoForm.logistics = ''; // 物流
	baseInfoForm.logisticsNo = ''; // 物流单号
	baseInfoForm.linkMan = ''; // 联系人
	baseInfoForm.linkPhone = ''; // 联系电话
	baseInfoForm.linkAdress = ''; // 客户地址
	baseInfoForm.taxaMount = '';
	baseInfoForm.billtypeId = ''; // 单据类型
	baseInfoForm.amount = '';
	baseInfoForm.allAmount = '';
	baseInfoForm.exchangeTypeId = '';
	baseInfoForm.details = [addRow]; // 清空物料
	for (const key in baseInfoForm.details[0]) {
		baseInfoForm.details[0][key] = '';
		baseInfoForm.details[0].id = 0;
		baseInfoForm.details[0].fid = 0;
		baseInfoForm.details[0].isFree = false;
		baseInfoForm.details[0].isDisabled = false;
		baseInfoForm.details[0].isHouse = false;
		baseInfoForm.details[0].isCusHouse = true;
	}
	baseInfoForm.details.forEach((element) => {
		element.settleOrg = baseInfoForm.saleorgId;
		element.settleOrgName = baseInfoForm.saleorgName;
		element.customerStock = '';
	});
	return { baseInfoForm, statusForm };
};

//jx 6.27 销售订单克隆 - 单据头需要清空的数据
const orderCopyClearHeaderData = (baseInfoForm) => {
	baseInfoForm.billNo = '';
	baseInfoForm.documentStatus = 'a';
	baseInfoForm.createDate = '';
	baseInfoForm.creatorName = '';
	baseInfoForm.approveDate = '';
	baseInfoForm.approverName = '';
	baseInfoForm.commitDate = '';
	baseInfoForm.modifyDate = '';
	baseInfoForm.modifierName = '';
	baseInfoForm.id = 0;
	baseInfoForm.detailsIds = [];
	baseInfoForm.isPushDown = false;
	return baseInfoForm;
};

// jx 6.27 销售订单克隆 - 表格明细需要清空的数据
const orderCopyClearInfoData = (element) => {
	element.id = 0;
	element.pid = 0;
	element.parentOrderId = '';
	element.parentOrderType = '';
	element.parentOrderBillNo = '';
	element.parentOrderNumber = '';
	element.purchaseNumber = '';
	// element.unitName = ''
	element.pushDownSaleorgId = '';
	element.salesNumber =
		element.salesNumber == null ? '' : element.salesNumber;
	element.taxPrice = element.taxPrice == null ? '' : element.taxPrice;
	return element;
};

// jx 6.27 销售订单 - 客户改变时携带出来的数据
const customerChangeCarryData = (baseInfoForm, customerInfo) => {
	baseInfoForm.linkMan =
		customerInfo[0].linkMan == null ? '' : customerInfo[0].linkMan; // 联系人
	baseInfoForm.linkPhone =
		customerInfo[0].linkphone == null ? '' : customerInfo[0].linkphone; // 联系电话
	baseInfoForm.linkAdress =
		customerInfo[0].address == null ? '' : customerInfo[0].address; // 客户地址
	baseInfoForm.recconditionId =
		customerInfo[0].reccondition == null ||
		customerInfo[0].reccondition == 0
			? ''
			: customerInfo[0].reccondition; // 收款条件
	baseInfoForm.settlemodeId =
		customerInfo[0].settlemode == null || customerInfo[0].settlemode == 0
			? ''
			: customerInfo[0].settlemode; // 结算方式
	baseInfoForm.settlecurrId =
		customerInfo[0].settlecurr == null || customerInfo[0].settlecurr == 0
			? ''
			: customerInfo[0].settlecurr; // 结算币别
	baseInfoForm.saleDeptId =
		customerInfo[0].sellDept == null ? '' : customerInfo[0].sellDept; // 销售部门
	baseInfoForm.salerId =
		customerInfo[0].sellPerson == null ? '' : customerInfo[0].sellPerson; // 销售员
	baseInfoForm.salesManId =
		customerInfo[0].salesMan == null ? '' : customerInfo[0].salesMan; // 跟单员
	return baseInfoForm;
};

// jx 6.28 销售订单 - 新增清空字段
const clearData = (baseInfoForm) => {
	for (const key in baseInfoForm) {
		if (key !== 'details') {
			key == 'id' ? (baseInfoForm[key] = 0) : (baseInfoForm[key] = '');
		}
		if (key === 'details') {
			for (const keyB in baseInfoForm[key][0]) {
				keyB == 'id'
					? (baseInfoForm[key][0][keyB] = 0)
					: keyB == 'detailId'
					? (baseInfoForm[key][0][keyB] = 0)
					: keyB == 'deliveryDate'
					? (baseInfoForm[key][0][keyB] = null)
					: keyB == 'isFree'
					? (baseInfoForm[key][0][keyB] = false)
					: keyB == 'isDisabled'
					? (baseInfoForm[key][0][keyB] = false)
					: keyB == 'isCusHouse'
					? (baseInfoForm[key][0][keyB] = true)
					: keyB == 'isHouse'
					? (baseInfoForm[key][0][keyB] = false)
					: (baseInfoForm[key][0][keyB] = '');
			}
		}
	}
	return baseInfoForm;
};
/**
 * 销售退货单 -- 页面方法
 */

// jx 6.29 销售退货单 - 上下查
const srSearchOrder = (CXcheckVal, upOrDownList) => {
	let pathName = '';
	let ary = [];
	if (CXcheckVal === 7) {
		pathName = 'SaleOrder';
	}
	ary = upOrDownList.filter((it) => {
		return it.orderType === CXcheckVal;
	});
	return { pathName, ary };
};

// jx 6.29 销售退货单 -- 确定下推
const srSurePushDown = (pushdownVal) => {
	let pathName = '';
	let routerName = '';
	if (pushdownVal === '7') {
		pathName = 'ReturnStockOrder/PushDownSalOrder';
		routerName = 'SaleOrderCreate';
	}
	return { pathName, routerName };
};

// jx 7.1 销售退货单 -- 批量填充
const srMaterialCarry = (details, el) => {
	details.materialId = el.id;
	details.materialNumber = el.number;
	details.specificationId = el.id;
	details.specification = el.specifications;
	details.matterName = el.name;
	details.unitId = el.baseUnitId;
	details.unitName = el.baseUnitName;
	details.paezOrgName = el.paezOrgName;
	details.defaultSupplierName = el.defaultSupplierName;
	details.taxRate = el.taxRateNmae;
	details.is211 = el.is211 ? el.is211 : false;
	details.supplyChain = el.supplyChain;
	details.lifeCycle = el.lifeCycle;
	details.supplyOriginId = el.paezOrgId;
	details.defaultSupplier = el.defaultSupplierId;
	details.taxPrice = '0';
	return details;
};

// jx 10.10 销售退货单 -添加行 - row 314 - 554
const srInsertRow = (
	data,
	baseInfoForm,
	customeStockArrylist,
	matterallCodelist,
	specificationalllist,
	addRow
) => {
	const index = baseInfoForm.details.length;
	baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)));
	customeStockArrylist.splice(index, 0, []);
	matterallCodelist.splice(index, 0, []);
	specificationalllist.splice(index, 0, []);
	for (const key in baseInfoForm.details[index]) {
		baseInfoForm.details[index][key] = '';
	}
	baseInfoForm.details[index].id = 0;
	baseInfoForm.details[index].fid = 0;
	baseInfoForm.details[index].isFree = false;
	baseInfoForm.details[index].isDisabled = false;
	baseInfoForm.details[index].isCusHouse = true;
	baseInfoForm.details[index].isHouse = false;
	return {
		data,
		baseInfoForm,
		customeStockArrylist,
		matterallCodelist,
		specificationalllist,
	};
};

// jx 7.1 销售退货单 -- 插入行
// const srInsertRow = (data,baseInfoForm,selectRowIndex,customeStockArrylist,matterallCodelist,specificationalllist,addRow) => {
//   if (data.insertTopVal != 0 && data.insertTopVal != '') {
//     for (let i = 0; i < data.insertTopVal; i++) {
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       for (const key in baseInfoForm.details[selectRowIndex]) {
//         baseInfoForm.details[selectRowIndex][key] = ''
//       }
//       baseInfoForm.details[selectRowIndex].id = 0
//       baseInfoForm.details[selectRowIndex].fid = 0
//       baseInfoForm.details[selectRowIndex].isFree = false
//       baseInfoForm.details[selectRowIndex].isDisabled = false
//       baseInfoForm.details[selectRowIndex].isCusHouse = true
//       baseInfoForm.details[selectRowIndex].isHouse = false
//       selectRowIndex = parseInt(selectRowIndex) + 1
//     }
//   }
//   if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
//     for (let i = 0; i < data.insertBottomVal; i++) {
//       selectRowIndex = parseInt(selectRowIndex) + 1
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       for (const key in baseInfoForm.details[selectRowIndex]) {
//         baseInfoForm.details[selectRowIndex][key] = ''
//       }
//       baseInfoForm.details[selectRowIndex].id = 0
//       baseInfoForm.details[selectRowIndex].fid = 0
//       baseInfoForm.details[selectRowIndex].isFree = false
//       baseInfoForm.details[selectRowIndex].isDisabled = false
//       baseInfoForm.details[selectRowIndex].isCusHouse = true
//       baseInfoForm.details[selectRowIndex].isHouse = false
//     }
//     selectRowIndex = selectRowIndex - data.insertBottomVal // 回朔
//   }
//   return {data,baseInfoForm,selectRowIndex,customeStockArrylist,matterallCodelist,specificationalllist}
// }

// jx 7.1 销售退货单 -- 操作记录 返回日期
const srSaveSubmitBackData = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.checkDate = req.data.checkDate;
	baseInfoForm.checkName = req.data.checkName;
	baseInfoForm.commitDate = req.data.commitDate;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifyName = req.data.modifyName;
	return baseInfoForm;
};

// jx 7.1 销售退货单 -- 线上订单号 限制规则
const onLineOrderRexgu = (value) => {
	if (value) {
		return value.toString().replace(/[^0-9A-Za-z]/g, '');
	} else {
		return '';
	}
};

// jx 7.1 销售退货单 -- 详情进入 物料编码 规格型号 携带出来
const srDetailsMaterSpecSearh = (
	details,
	el,
	unitData,
	isPrecision,
	salePrecisionNumber
) => {
	details.materialId = el.id;
	details.specificationId = el.id;
	details.matterName = el.name;
	details.materialNumber = el.number;
	details.specification = el.specifications;
	details.unitId = el.baseUnitId;
	details.unitName = el.baseUnitName;
	let tempList = unitData.filter((it) => it.id === details.unitId);
	tempList[0].precision == 0 ? (isPrecision = true) : (isPrecision = false);
	tempList[0].precision == 0
		? (salePrecisionNumber = 0)
		: (salePrecisionNumber = tempList[0].precision);
	details.paezOrgName = el.paezOrgName;
	details.defaultSupplierName = el.defaultSupplierName;
	details.supplyOriginId = el.paezOrgId;
	details.defaultSupplier = el.defaultSupplierId;
	details.taxRate = el.taxRateNmae;
	details.is211 = el.is211 ? el.is211 : false;
	details.supplyOriginId = el.paezOrgId;
	details.defaultSupplier = el.defaultSupplierId;
	return { details, isPrecision, salePrecisionNumber };
};

// 7.1 jx 销售退货单 -- 组织改变清空 客户、部门、销售员、仓管员
const srOrgChangeClearData = (baseInfoForm, addRow) => {
	baseInfoForm.retcustId = '';
	baseInfoForm.settlemodeId = '';
	baseInfoForm.recconditionId = '';
	baseInfoForm.saleParts = [];
	baseInfoForm.saleDeptId = '';
	baseInfoForm.salesmanId = '';
	baseInfoForm.stockStaff = '';
	baseInfoForm.returnReason = '';
	baseInfoForm.receiveAddress = '';
	baseInfoForm.details = [addRow]; // 清空物料
	for (const key in baseInfoForm.details[0]) {
		baseInfoForm.details[0][key] = '';
		baseInfoForm.details[0].id = 0;
		baseInfoForm.details[0].isFree = false;
		baseInfoForm.details[0].isDisabled = false;
		baseInfoForm.details[0].isCusHouse = true;
	}
	return baseInfoForm;
};

// 7.1 jx 销售退货单 -- 编码 规格 模糊匹配
const srMaterSpecSearch = (details, el, inner) => {
	details.materialId = el.id;
	details.specificationId = el.id;
	details.matterName = el.name;
	details.materialNumber = el.number;
	details.specification = el.specifications;
	details.unitId = el.baseUnitId;
	details.unitName = el.baseUnitName;
	details.paezOrgName = el.paezOrgName;
	if (inner) {
		details.defaultSupplierName = el.defaultSupplierName;
		details.defaultSupplierTaxRate = el.defaultSupplierTaxRate;
	}
	details.supplyOriginId = el.paezOrgId;
	details.defaultSupplier = el.defaultSupplierId;
	details.taxRateNmae = el.taxRateNmae;
	details.is211 = el.is211 ? el.is211 : false;
	details.supplyOriginId = el.paezOrgId;
	details.defaultSupplier = el.defaultSupplierId;
	return details;
};

// 7.1 jx 销售退货单 -- 克隆 进入需要清空的数据
const srCopyInnerClearData = (baseInfoForm, unitpriceAccuracy) => {
	baseInfoForm.billNo = '';
	baseInfoForm.documentStatus = 'a';
	baseInfoForm.createDate = '';
	baseInfoForm.creatorName = '';
	baseInfoForm.checkDate = '';
	baseInfoForm.checkName = '';
	baseInfoForm.commitDate = '';
	baseInfoForm.modifyDate = '';
	baseInfoForm.modifyName = '';
	baseInfoForm.id = 0;
	baseInfoForm.detailsIds = [];
	baseInfoForm.isPushDown = false;
	baseInfoForm.details.forEach((element, ind) => {
		element.id = 0;
		element.fid = 0;
		element.parentOrderId = '';
		element.parentOrderType = '';
		element.parentOrderBillNo = '';
		element.parentOrderNumber = '';
		element.pushDownSaleorgId = '';
		element.realQty = element.realQty == null ? '' : element.realQty;
		element.taxPrice = element.taxPrice == null ? '' : element.taxPrice;
		element.taxPrice = Decimal(element.taxPrice).toFixed(unitpriceAccuracy);
	});
	return baseInfoForm;
};

/**
 * 组织间 -- 页面方法
 */
// 7.8 jx 新增清空的
const orgNeedsClearData = (baseInfoForm) => {
	for (const key in baseInfoForm) {
		key === 'createType'
			? (baseInfoForm[key] = '1')
			: key == 'isPushDown'
			? (baseInfoForm[key] = false)
			: key == 'id'
			? (baseInfoForm[key] = 0)
			: key == 'is211'
			? (baseInfoForm[key] = null)
			: (baseInfoForm[key] = '');
	}
	return baseInfoForm;
};
// 7.8 jx 组织间 -- 克隆需要清空的值
const ndCopyClearData = (baseInfoForm) => {
	baseInfoForm.documentStatus = 'a';
	baseInfoForm.createType = '1';
	baseInfoForm.billNo = '';
	baseInfoForm.createDate = '';
	baseInfoForm.creatorName = '';
	baseInfoForm.approveDate = '';
	baseInfoForm.approverName = '';
	baseInfoForm.submitDate = '';
	baseInfoForm.modifyDate = '';
	baseInfoForm.modifierName = '';
	baseInfoForm.closerName = '';
	baseInfoForm.closeDate = '';
	baseInfoForm.id = 0;
	baseInfoForm.maxNumber = 0;
	baseInfoForm.isPushDown = false;
	baseInfoForm.deliveredQty = '';
	baseInfoForm.undeliveredQty = '';
	baseInfoForm.transferQty = '';
	baseInfoForm.untransferQty = '';
	baseInfoForm.parentOrderId = '';
	baseInfoForm.parentOrderType = '';
	baseInfoForm.parentOrderBillNo = '';
	return baseInfoForm;
};

// 7.8 jx 组织间 -- 监听客户改变获取请求客户仓库值
const watchCustomerChange = (baseInfoForm) => {
	let isInner = false;
	let query = {};
	if (
		baseInfoForm.customerId &&
		baseInfoForm.customerId != '' &&
		baseInfoForm.stockId &&
		baseInfoForm.stockId != ''
	) {
		isInner = true;
		query.customerId =
			baseInfoForm.customerId === null
				? ''
				: parseInt(baseInfoForm.customerId);
		query.orgId =
			baseInfoForm.demandOrgId === null
				? ''
				: parseInt(baseInfoForm.demandOrgId);
		query.stockId =
			baseInfoForm.stockId === null || baseInfoForm.stockId === 0
				? ''
				: parseInt(baseInfoForm.stockId);
	}
	return { isInner, query };
};

// 7.8 jx 组织间 -- 处理保存提交的返回数据
const ndSaveSubBackData = (baseInfoForm, req, type) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.approveDate = req.data.approveDate;
	baseInfoForm.approverName = req.data.approverName;
	baseInfoForm.submitDate = req.data.submitDate;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifierName = req.data.modifierName;
	baseInfoForm.closerName = req.data.closerName;
	baseInfoForm.closeDate = req.data.closeDate;
	if (type) {
		baseInfoForm.undeliveredQty = req.data.undeliveredQty;
		baseInfoForm.untransferQty = req.data.untransferQty;
	}
	return baseInfoForm;
};

// 7.8 jx 组织间 -- 切换下单组织清空相关数据
const changeDownOrgClearData = (baseInfoForm, statusForm) => {
	baseInfoForm.stockId = '';
	baseInfoForm.customerId = '';
	baseInfoForm.saleDeptId = '';
	baseInfoForm.salespersonId = '';
	baseInfoForm.merchandiserId = '';
	statusForm.stocks = [];
	statusForm.saleDept = [];
	//   statusForm.salePerson = []
	//   statusForm.qcPerson = []
	return { baseInfoForm, statusForm };
};

// 7.8 jx 组织间 -- 下单组织切换时需要清空的数据
const ndIptDownOrgChangeClearData = (baseInfoForm, statusForm) => {
	statusForm.custList = [];
	baseInfoForm.customerId = '';
	baseInfoForm.materialId = '';
	baseInfoForm.skuId = '';
	baseInfoForm.materialName = '';
	baseInfoForm.unitId = '';
	baseInfoForm.is211 = '';
	baseInfoForm.supplyChain = '';
	return { baseInfoForm, statusForm };
};

// jx 7.8 组织间 上下查订单类型
const ndSearchOrder = (val) => {
	let pathName = '';
	if (val === 1) {
		// "生产"
		return (pathName = 'ProductOrder');
	}
	if (val === 3) {
		// "委外"
		return (pathName = 'OutsourcOrder');
	}
	if (val === 2) {
		// "采购"
		return (pathName = 'DemandOrder');
	}
	if (val === 20) {
		// "分步式"
		return (pathName = 'WarehouseAllocationkissue');
	}
	if (val === 10) {
		// "组织间需求"
		return (pathName = 'OrgNeeds');
	}
	if (val === 7) {
		// "销售订单"
		return (pathName = 'SaleOrder');
	}
};

// jx 7.8 组织间 上下查订单类型
const ndSurePushDown = (CXcheckVal) => {
	let pathName = '';
	let routerName = '';
	if (CXcheckVal === 1) {
		// "生产订单"
		pathName = 'Organization/push/produce';
		routerName = 'ProductOrderCreate';
	}
	if (CXcheckVal === 3) {
		// "采购订单"
		pathName = 'Organization/push/purchase';
		routerName = 'CreatePurchase';
	}
	if (CXcheckVal === 2) {
		// "委外订单"
		pathName = 'Organization/push/outsource';
		routerName = 'AddOutSourcOrder';
	}
	if (CXcheckVal === 4) {
		// "组织间需求单"
		pathName = 'Organization/push/self/';
		routerName = 'CreateOrgNeeds';
	}
	if (CXcheckVal === 5) {
		// "分步式调出单"
		pathName = 'Organization/push/transferout';
		routerName = 'ActiveIssue';
	}
	return { pathName, routerName };
};

// jx 7.8 组织间 物料编码携带出来的值
const ndSearchMaterSku = (baseInfoForm, el) => {
	baseInfoForm.materialId = el.id; // 物料编码 id
	baseInfoForm.skuId = el.id; // sku id
	baseInfoForm.specification = el.specifications; // sku 名称
	baseInfoForm.materId = el.id; // 编码 id
	baseInfoForm.materialNumber = el.number; // 编码 名称
	baseInfoForm.materialName = el.name; // 物料名称
	baseInfoForm.unitId = el.baseUnitId; // 销售单位
	baseInfoForm.is211 = el.is211 ? el.is211 : false; // 是否211
	baseInfoForm.supplyChain =
		el.supplyChainKey == null ? '' : el.supplyChainKey + ''; // 供应链
	return baseInfoForm;
};

/**
 * 采购订单
 */
// jx 7.9 采购订单 -- 确定上下查
const purSureUpDownSearch = (CXcheckVal) => {
	let pathName = '';
	if (CXcheckVal === 8) {
		// "采购入库单"
		return (pathName = 'WarehousePurchaseWarehouse');
	}
	if (CXcheckVal === 9) {
		// "采购退料单"
		return (pathName = 'WarehousePurchaseReturnOrder');
	}
	if (CXcheckVal === 7) {
		// "销售订单"
		return (pathName = 'SaleOrder');
	}
	if (CXcheckVal === 10) {
		// "组织间需求单"
		return (pathName = 'OrgNeeds');
	}
	if (CXcheckVal === 3) {
		// "委外"
		return (pathName = 'OutsourcOrder');
	}
};

// jx 7.9 采购订单 -- 下推确定
const purPushDownSure = (CXcheckVal) => {
	let pathName = '';
	let routerName = '';
	if (CXcheckVal === 1) {
		// "采购入库单"
		pathName = 'Purchase/push/instock';
		routerName = 'ActiveWareHouse';
	}
	if (CXcheckVal === 2) {
		// "采购退料单"
		pathName = 'Purchase/push/return';
		routerName = 'ActiveReturnOrder';
	}
	return { pathName, routerName };
};

// jx 7.9 采购订单 -- 下推请求
const purPushDownRequest = (details, req, element) => {
	let tempRow = req.data.details.filter((it) => it.id === element.id);
	details.mrpCloseStatus = tempRow[0].mrpCloseStatus;
	return details;
};

// jx 7.9 采购订单 -- 物料编码 模糊匹配 携带参数
const purMaterialSkuSearch = (baseInfoForm, element, ind) => {
	baseInfoForm.details[ind].materialId = element.id; // 物料编码
	baseInfoForm.details[ind].specificationId = element.id;
	baseInfoForm.details[ind].materialName = element.name; // 名称
	baseInfoForm.details[ind].materialNumber = element.number; // 名称
	baseInfoForm.details[ind].specification = element.specifications; // 名称
	baseInfoForm.details[ind].unitId = element.baseUnitId; // 采购单位
	baseInfoForm.details[ind].unitName = element.baseUnitName; // 采购单位
	baseInfoForm.details[ind].supplyChainName = element.supplyChain;
	baseInfoForm.details[ind].supplyChain = element.supplyChainKey;
	baseInfoForm.details[ind].lifeCycle = element.lifeCycleKey;
	baseInfoForm.details[ind].lifeCycleName = element.lifeCycle;
	baseInfoForm.details[ind].supplyOriginId = element.paezOrgId;
	baseInfoForm.details[ind].defaultSupplier = element.defaultSupplierId;
	baseInfoForm.details[ind].is211 = element.is211 ? element.is211 : false; // 是否211
	return baseInfoForm;
};

// jx 7.9 采购订单 -- 克隆清空的单据头数据
const purCopyOrderClearData = (baseInfoForm) => {
	baseInfoForm.documentStatus = 'a';
	baseInfoForm.dataSources = '1';
	baseInfoForm.billNo = '';
	baseInfoForm.createDate = '';
	baseInfoForm.creatorName = '';
	baseInfoForm.approveDate = '';
	baseInfoForm.approverName = '';
	baseInfoForm.commitDate = '';
	baseInfoForm.modifyDate = '';
	baseInfoForm.modifierName = '';
	baseInfoForm.submitDate = '';
	baseInfoForm.confirmerName = '';
	baseInfoForm.confirmeDate = '';
	baseInfoForm.id = 0;
	baseInfoForm.detailsIds = [];
	baseInfoForm.isPushDown = false;
	return baseInfoForm;
};

// jx 7.9 采购订单 -- 克隆清空的明细数据
const purCopyOrderInfoClearData = (element) => {
	element.id = 0;
	element.pid = 0;
	element.parentOrderId = '';
	element.parentOrderType = '';
	element.parentOrderBillNo = '';
	element.parentOrderNumber = '';
	element.pushDownSaleorgId = '';
	element.maxNumber = null;
	element.stockinQty = 0;
	element.remainstockinQty = 0;
	element.qty = element.qty == null ? '' : element.qty;
	element.taxPrice = element.taxPrice == null ? '' : element.taxPrice;
	return element;
};

// jx 7.9 采购订单 -- 克隆获取精度值 和是否第一次进入
const purGetPrecisionNumberFrist = (
	salePrecisionNumber,
	isPrecision,
	unitData,
	ind,
	unitId
) => {
	let tempList = unitData.filter((it) => it.id === unitId);
	if (Array.isArray(tempList) && tempList.length) {
		tempList[0].precision == 0
			? (isPrecision[ind] = true)
			: (isPrecision[ind] = false);
		tempList[0].precision == 0
			? (salePrecisionNumber[ind] = 0)
			: (salePrecisionNumber[ind] = tempList[0].precision);
	}
	return { salePrecisionNumber, isPrecision };
};

// jx 7.9 采购订单 -- 保存提交获取返回处理日期数据
const purGetBackDate = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.approveDate = req.data.approveDate;
	baseInfoForm.approverName = req.data.approverName;
	baseInfoForm.commitDate = req.data.commitDate;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifierName = req.data.modifierName;
	baseInfoForm.confirmerName = req.data.confirmerName;
	baseInfoForm.confirmeDate = req.data.confirmeDate;
	baseInfoForm.submitDate = req.data.submitDate;
	return baseInfoForm;
};

// jx 7.9 采购订单 -- 保存提交后获取返回来的订单号和id
const purGetOrderId = (baseInfoForm, r) => {
	baseInfoForm.billNo = r.data.billNo;
	baseInfoForm.id = r.data.id;
	r.data.details.forEach((el, ind) => {
		baseInfoForm.details[ind].id = el.id;
		baseInfoForm.details[ind].mrpCloseStatus = el.mrpCloseStatus;
	});
	return baseInfoForm;
};

// jx 7.11 采购订单 -- 批量填充 物料SKU携带的数据
const purCopyCellGetData = (baseInfoForm, el, i) => {
	baseInfoForm.details[i].materialId = el.id;
	baseInfoForm.details[i].specificationId = el.id;
	baseInfoForm.details[i].materName = el.number;
	baseInfoForm.details[i].materialNumber = el.number;
	baseInfoForm.details[i].specification = el.specifications;
	baseInfoForm.details[i].skuName = el.specifications;
	baseInfoForm.details[i].matterName = el.name;
	baseInfoForm.details[i].materialName = el.name;
	baseInfoForm.details[i].unitId = el.baseUnitId;
	baseInfoForm.details[i].unitName = el.baseUnitName;
	baseInfoForm.details[i].paezOrgName = el.paezOrgName;
	baseInfoForm.details[i].defaultSupplierName = el.defaultSupplierName;
	baseInfoForm.details[i].taxRate = el.taxRateNmae;
	baseInfoForm.details[i].is211 = el.is211 ? el.is211 : false;
	baseInfoForm.details[i].supplyChainName = el.supplyChain;
	baseInfoForm.details[i].supplyChain = el.supplyChainKey;
	baseInfoForm.details[i].lifeCycle = el.lifeCycleKey;
	baseInfoForm.details[i].lifeCycleName = el.lifeCycle;
	baseInfoForm.details[i].supplyOriginId = el.paezOrgId;
	baseInfoForm.details[i].defaultSupplier = el.defaultSupplierId;
	baseInfoForm.details[i].taxPrice = el.purchasePrice;
	return baseInfoForm;
};

// jx 7.11 采购订单 -- 插入行
// const purInsertRow = (data,baseInfoForm,selectRowIndex,customeStockArrylist,matterallCodelist,specificationalllist,addRow) => {
//   if (data.insertTopVal != 0 && data.insertTopVal != '') {
//     for (let i = 0; i < data.insertTopVal; i++) {
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       selectRowIndex = parseInt(selectRowIndex) + 1
//     }
//   }
//   if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
//     for (let i = 0; i < data.insertBottomVal; i++) {
//       selectRowIndex = parseInt(selectRowIndex) + 1
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])

//     }
//     selectRowIndex = selectRowIndex - data.insertBottomVal // 回朔
//   }
//   return {data,baseInfoForm,selectRowIndex,customeStockArrylist,matterallCodelist,specificationalllist}
// }

// jx 7.11 采购订单 -- 添加行 - row 314 - 554 - 1112
const purInsertRow = (
	data,
	baseInfoForm,
	customeStockArrylist,
	matterallCodelist,
	specificationalllist,
	addRow
) => {
	const index = baseInfoForm.details.length;
	baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)));
	customeStockArrylist.splice(index, 0, []);
	matterallCodelist.splice(index, 0, []);
	specificationalllist.splice(index, 0, []);
	return {
		data,
		baseInfoForm,
		customeStockArrylist,
		matterallCodelist,
		specificationalllist,
	};
};

// 7.11 jx 采购订单 -- 物料编码sku模糊匹配
const purMaterSkuSearchGetData = (
	baseInfoForm,
	element,
	currRow,
	unitData,
	isPrecision,
	salePrecisionNumber
) => {
	baseInfoForm.details[currRow].materialId = element.id; // 物料编码
	baseInfoForm.details[currRow].specificationId = element.id;
	baseInfoForm.details[currRow].materialName = element.name; // 名称
	baseInfoForm.details[currRow].materialNumber = element.number; // 名称
	baseInfoForm.details[currRow].specification = element.specifications; // 名称
	baseInfoForm.details[currRow].unitId = element.baseUnitId; // 采购单位
	baseInfoForm.details[currRow].unitName = element.baseUnitName; // 采购单位
	let tempList = unitData.filter(
		(it) => it.id === baseInfoForm.details[currRow].unitId
	);
	tempList[0].precision == 0
		? (isPrecision[currRow] = true)
		: (isPrecision[currRow] = false);
	tempList[0].precision == 0
		? (salePrecisionNumber[currRow] = 0)
		: (salePrecisionNumber[currRow] = tempList[0].precision);
	baseInfoForm.details[currRow].supplyChainName = element.supplyChain;
	baseInfoForm.details[currRow].supplyChain = element.supplyChainKey;
	baseInfoForm.details[currRow].lifeCycle = element.lifeCycleKey;
	baseInfoForm.details[currRow].lifeCycleName = element.lifeCycle;
	baseInfoForm.details[currRow].supplyOriginId = element.paezOrgId;
	baseInfoForm.details[currRow].defaultSupplier = element.defaultSupplierId;
	baseInfoForm.details[currRow].is211 = element.is211 ? element.is211 : false; // 是否211
	if (!baseInfoForm.details[currRow].giveAway) {
		baseInfoForm.details[currRow].taxPrice = element.purchasePrice;
	}
	baseInfoForm.details[currRow].taxRate = element.taxRateNmae; // 税率
	return { baseInfoForm, isPrecision, salePrecisionNumber };
};

// 7.11 jx 采购订单 -- 折扣率 规则
const purDisCountRateReg = (val) => {
	if (val > 100) {
		return 100;
	} else {
		if (val) {
			return val
				.toString()
				.replace(/[^\d^\\.]+/g, '')
				.replace('.', '$#$')
				.replace(/\./g, '')
				.replace('$#$', '.')
				.replace(/^(\\-)*(\d+)\.(\d\d\d\d).*$/, '$1$2.$3');
		} else {
			return '';
		}
	}
};

// 7.11 jx 采购订单 -- 切换组织 清空的数据
const purChangeOrgClearData = (baseInfoForm, statusForm, addRow) => {
	let tempSettleOrgName = statusForm.settlementOrgList.filter(
		(it) => it.id === baseInfoForm.purchaseorgId
	);
	addRow.isDemandBillNo = false;
	addRow.isMaterialId = false;
	addRow.isSpecificationId = false;
	addRow.isQty = false;
	addRow.isTaxPrice = false;
	addRow.isTaxRate = false;
	addRow.isSoStock = false;
	addRow.isDeliveryDate = false;
	addRow.isCustomerId = false;
	addRow.isCustomerStockId = false;
	addRow.isNote = false;
	addRow.isDiscountRate = false;
	addRow.isSettleOrgId = false;
	addRow.settleOrgName = tempSettleOrgName[0].name;

	statusForm.saleParts = [];
	statusForm.customers = [];
	baseInfoForm.deptId = '';
	baseInfoForm.purchaserId = '';
	baseInfoForm.payConditionId = '';
	baseInfoForm.settleCurrId = '';
	baseInfoForm.billTaxAmount = '';
	baseInfoForm.billAmount = '';
	baseInfoForm.billAllAmount = '';
	baseInfoForm.details = [addRow]; // 清空物料
	for (const key in baseInfoForm.details[0]) {
		baseInfoForm.details[0][key] = '';
		baseInfoForm.details[0].id = 0;
		baseInfoForm.details[0].isFree = false;
		baseInfoForm.details[0].giveAway = false;
		baseInfoForm.details[0].isDisabled = false;
		baseInfoForm.details[0].isCusHouse = false;
		baseInfoForm.details[0].isDemandBillNo = false;
		baseInfoForm.details[0].isMaterialId = false;
		baseInfoForm.details[0].isSpecificationId = false;
		baseInfoForm.details[0].isQty = false;
		baseInfoForm.details[0].isTaxPrice = false;
		baseInfoForm.details[0].isTaxRate = false;
		baseInfoForm.details[0].isSoStock = false;
		baseInfoForm.details[0].isDeliveryDate = false;
		baseInfoForm.details[0].isCustomerId = false;
		baseInfoForm.details[0].isCustomerStockId = false;
		baseInfoForm.details[0].isNote = false;
		baseInfoForm.details[0].isDiscountRate = false;
		baseInfoForm.details[0].isSettleOrgId = false;
		baseInfoForm.details[0].settleOrgName = tempSettleOrgName[0].name;
	}
	return { baseInfoForm, statusForm, addRow };
};

/**
 * 采购退料单
 */

// jx 7.12 采购退料单 - 获取物料编码 SKU 模糊匹配信息
const purReMaterialSkuSearch = (baseInfoForm, el, ind) => {
	baseInfoForm.details[ind].materialId = el.id;
	baseInfoForm.details[ind].specificationId = el.id;
	baseInfoForm.details[ind].materName = el.number;
	baseInfoForm.details[ind].specifications = el.specifications;
	baseInfoForm.details[ind].materialNumber = el.number;
	baseInfoForm.details[ind].specification = el.specifications;
	baseInfoForm.details[ind].materialName = el.name;
	baseInfoForm.details[ind].unitId = el.baseUnitId;
	return baseInfoForm;
};

// jx 7.12 采购退料单 - 批量填充 物料携带出来的值
const purReCopyMaterialGetValue = (baseInfoForm, el, i) => {
	baseInfoForm.details[i].materialId = el.id;
	baseInfoForm.details[i].specificationId = el.id;
	baseInfoForm.details[i].materName = el.number;
	baseInfoForm.details[i].specifications = el.specifications;
	baseInfoForm.details[i].materialNumber = el.number;
	baseInfoForm.details[i].specification = el.specifications;
	baseInfoForm.details[i].materialName = el.name;
	baseInfoForm.details[i].unitId = el.baseUnitId;
	baseInfoForm.details[i].taxPrice = '0';
	return baseInfoForm;
};

// jx 7.12 采购退料单 - 向上、下插入行
// const purReInsertRowCom = (data,baseInfoForm,selectRowIndex,customeStockArrylist,matterallCodelist,specificationalllist,addRow) => {
//   if (data.insertTopVal != 0 && data.insertTopVal != '') {
//     for (let i = 0; i < data.insertTopVal; i++) {
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       for (const key in baseInfoForm.details[selectRowIndex]) {
//         baseInfoForm.details[selectRowIndex][key] = ''
//       }
//       baseInfoForm.details[selectRowIndex].id = 0
//       baseInfoForm.details[selectRowIndex].giveAway = 0
//       baseInfoForm.details[selectRowIndex].isCustomer = true
//       selectRowIndex = parseInt(selectRowIndex) + 1
//     }
//   }
//   if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
//     for (let i = 0; i < data.insertBottomVal; i++) {
//       selectRowIndex = parseInt(selectRowIndex) + 1
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       for (const key in baseInfoForm.details[selectRowIndex]) {
//         baseInfoForm.details[selectRowIndex][key] = ''
//       }
//       baseInfoForm.details[selectRowIndex].id = 0
//       baseInfoForm.details[selectRowIndex].giveAway = 0
//       baseInfoForm.details[selectRowIndex].isCustomer = true
//     }
//     selectRowIndex = selectRowIndex - data.insertBottomVal // 回朔
//   }
//   return {data,baseInfoForm,selectRowIndex,customeStockArrylist,matterallCodelist,specificationalllist}
// }

// jx 7.12 采购退料单 - 添加行
const purReInsertRowCom = (
	data,
	baseInfoForm,
	customeStockArrylist,
	matterallCodelist,
	specificationalllist,
	addRow
) => {
	const index = baseInfoForm.details.length;
	baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)));
	customeStockArrylist.splice(index, 0, []);
	matterallCodelist.splice(index, 0, []);
	specificationalllist.splice(index, 0, []);
	for (const key in baseInfoForm.details[index]) {
		baseInfoForm.details[index][key] = '';
	}
	baseInfoForm.details[index].id = 0;
	baseInfoForm.details[index].giveAway = 0;
	baseInfoForm.details[index].isCustomer = true;
	return {
		data,
		baseInfoForm,
		customeStockArrylist,
		matterallCodelist,
		specificationalllist,
	};
};

// jx 7.12 采购退料单 - 保存提交审核获取返回日期
const purReSaveSubmitRequestGetData = (baseInfoForm, req, isInner) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.createName = req.data.createName;
	baseInfoForm.approveDate = req.data.approveDate;
	baseInfoForm.approverName = req.data.approverName;
	baseInfoForm.submitDate = req.data.submitDate;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifiyName = req.data.modifiyName;
	if (isInner) {
		req.data.details.forEach((el, ind) => {
			baseInfoForm.details[ind].id = el.id;
			baseInfoForm.details[ind].fid = el.fid;
		});
	}
	return baseInfoForm;
};

// jx 7.12 采购退料单 - 表格明细操作获取物料或sku
const purReTableInfoMaterialSkuGetData = (
	baseInfoForm,
	el,
	currRow,
	unitData,
	isPrecision,
	salePrecisionNumber,
	supplierList,
	getTaxRateList
) => {
	baseInfoForm.details[currRow].materialId = el.id;
	baseInfoForm.details[currRow].specificationId = el.id;
	baseInfoForm.details[currRow].materName = el.number;
	baseInfoForm.details[currRow].specifications = el.specifications;
	baseInfoForm.details[currRow].materialNumber = el.number;
	baseInfoForm.details[currRow].specification = el.specifications;
	baseInfoForm.details[currRow].materialName = el.name;
	baseInfoForm.details[currRow].unitId = el.baseUnitId;
	if (el.taxRateId || el.taxRateId == 0) {
		baseInfoForm.details[currRow].taxRateId = el.taxRateId;
		baseInfoForm.details[currRow].taxRate = el.taxRateNmae;
	} else {
		if (supplierList) {
			baseInfoForm.details[currRow].taxRateId =
				supplierList.defaultTaxRate;
			let tempList = getTaxRateList.filter(
				(it) => it.id == supplierList.defaultTaxRate
			);
			if (tempList && tempList.length > 0) {
				baseInfoForm.details[currRow].taxRate = tempList[0].name;
			} else {
				baseInfoForm.details[currRow].taxRate = 0;
			}
		}
	}
	let tempList = unitData.filter(
		(it) => it.id === baseInfoForm.details[currRow].unitId
	);
	tempList[0].precision == 0
		? (isPrecision[currRow] = true)
		: (isPrecision[currRow] = false);
	tempList[0].precision == 0
		? (salePrecisionNumber[currRow] = 0)
		: (salePrecisionNumber[currRow] = tempList[0].precision);
	return { baseInfoForm, isPrecision, salePrecisionNumber };
};

// jx 7.12 采购退料单 - 切换组织清空数据
const purReChangeOrgClearData = (baseInfoForm, addRow) => {
	baseInfoForm.returnMaterialDeptId = '';
	baseInfoForm.stockerId = '';
	baseInfoForm.supplierId = '';
	baseInfoForm.settleOrgId = '';
	baseInfoForm.settleCurrId = '';
	baseInfoForm.settleTypeId = '';
	baseInfoForm.payconditionId = '';
	baseInfoForm.details = [addRow]; // 清空物料
	for (const key in baseInfoForm.details[0]) {
		baseInfoForm.details[0][key] = '';
		baseInfoForm.details[0].id = 0;
		baseInfoForm.details[0].giveAway = false;
		baseInfoForm.details[0].note = '';
	}
	return baseInfoForm;
};

// jx 7.12 采购退料单 - 克隆清空的单据头字段
const purReCopyClearData = (baseInfoForm) => {
	baseInfoForm.documentStatus = 'a';
	baseInfoForm.billTypeId = '1';
	baseInfoForm.billNo = '';
	baseInfoForm.createDate = '';
	baseInfoForm.createName = '';
	baseInfoForm.approveDate = '';
	baseInfoForm.approverName = '';
	baseInfoForm.submitDate = '';
	baseInfoForm.modifyDate = '';
	baseInfoForm.modifiyName = '';
	baseInfoForm.isPushDown = false;
	baseInfoForm.id = 0;
	return baseInfoForm;
};

/**
 * jx 7.13 采购入库单
 */
// jx 7.13 采购入库单 - 保存、提交、审核获取日期
const warePurcaseGetResData = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorIdName = req.data.creatorIdName;
	baseInfoForm.approveDate = req.data.approveDate;
	baseInfoForm.approverName = req.data.approverName;
	baseInfoForm.submitDate = req.data.submitDate;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifierName = req.data.modifierName;
	return baseInfoForm;
};

// jx 7.13 采购入库单 - 明细物料SKU携带相关值
const warePurcaseGetMaterialSkuData = (details, el) => {
	details.materialId = el.id;
	details.specificationId = el.id;
	details.materName = el.number;
	details.materialNumber = el.number;
	details.specifications = el.specifications;
	details.specification = el.specifications;
	details.materialName = el.name;
	details.remaininStockUnitId = el.baseUnitId;
	details.remaininStockUnitName = el.baseUnitName;
	details.is211 = el.is211 ? el.is211 : false;
	details.supplyChainName = el.supplyChain;
	details.supplyChain = el.supplyChainKey;
	details.mustQty = 0;
	details.realQty = 0;
	return details;
};

// jx 7.13 采购入库单 - 物料编码SKU模糊匹配携带值
const warePurcaseGetMaterialSearch = (baseInfoForm, el, ind) => {
	baseInfoForm.details[ind].materName = el.number;
	baseInfoForm.details[ind].skuName = el.specifications;
	baseInfoForm.details[ind].matterName = el.name;
	baseInfoForm.details[ind].remaininStockUnitId = el.baseUnitId;
	baseInfoForm.details[ind].paezOrgName = el.paezOrgName;
	baseInfoForm.details[ind].defaultSupplierName = el.defaultSupplierName;
	baseInfoForm.details[ind].taxRateNmae = el.taxRateNmae;
	baseInfoForm.details[ind].is211 = el.is211 ? el.is211 : false;
	baseInfoForm.details[ind].supplyChainName = el.supplyChain;
	baseInfoForm.details[ind].supplyChain = el.supplyChainKey;
	baseInfoForm.details[ind].lifeCycle = el.lifeCycleKey;
	baseInfoForm.details[ind].lifeCycleName = el.lifeCycle;
	baseInfoForm.details[ind].supplyOriginId = el.paezOrgId;
	baseInfoForm.details[ind].defaultSupplier = el.defaultSupplierId;
	return baseInfoForm;
};

/**
 * 分步式调出单
 */

// jx 7.14 分步式调出单 - 确定上下查数据
const issSureUpDownSearch = (CXcheckVal) => {
	let pathName = '';
	if (CXcheckVal === 10) {
		// "组织间需求单"
		return (pathName = 'OrgNeeds');
	}
	if (CXcheckVal === 21) {
		// "分步式调入单"
		return (pathName = 'WarehouseAllocationEntryorder');
	}
};

// jx 7.14 分步式调出单 - 批量填充 - 物料编码携带值
const issCopyMaterialSkuGetData = (baseInfoForm, el, i) => {
	baseInfoForm.details[i].materialId = el.id;
	baseInfoForm.details[i].specificationId = el.id;
	baseInfoForm.details[i].matterName = el.name;
	baseInfoForm.details[i].materialNumber = el.number;
	baseInfoForm.details[i].specification = el.specifications;
	baseInfoForm.details[i].materialName = el.name;
	baseInfoForm.details[i].unitId = el.baseUnitId;
	baseInfoForm.details[i].paezOrgName = el.paezOrgName;
	baseInfoForm.details[i].defaultSupplierName = el.defaultSupplierName;
	baseInfoForm.details[i].taxRateNmae = el.taxRateNmae;
	baseInfoForm.details[i].is211 = el.is211 ? el.is211 : false;
	baseInfoForm.details[i].supplyChainName = el.supplyChain;
	baseInfoForm.details[i].supplyChain = el.supplyChainKey;
	baseInfoForm.details[i].lifeCycle = el.lifeCycleKey;
	baseInfoForm.details[i].lifeCycleName = el.lifeCycle;
	baseInfoForm.details[i].supplyOriginId = el.paezOrgId;
	baseInfoForm.details[i].defaultSupplier = el.defaultSupplierId;
	baseInfoForm.details[i].qty = '0';
	baseInfoForm.details[i].remainReceiveQty = '0';
	return baseInfoForm;
};

// jx 7.14 分步式调出单 - 向上、下插入行
// const issUpDownInsertRow = (data,baseInfoForm,selectRowIndex,customeStockArrylistInner,customeStockArrylist,matterallCodelist,specificationalllist,addRow) => {
//   if (data.insertTopVal != 0 && data.insertTopVal != '') {
//     for (let i = 0; i < data.insertTopVal; i++) {
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylistInner.splice(selectRowIndex, 0, [])
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       baseInfoForm.details[selectRowIndex].isOutCustomer = true
//       baseInfoForm.details[selectRowIndex].isInnerCustomer = true
//       selectRowIndex = parseInt(selectRowIndex) + 1
//     }
//   }
//   if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
//     for (let i = 0; i < data.insertBottomVal; i++) {
//       selectRowIndex = parseInt(selectRowIndex) + 1
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylistInner.splice(selectRowIndex, 0, [])
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       baseInfoForm.details[selectRowIndex].isOutCustomer = true
//       baseInfoForm.details[selectRowIndex].isInnerCustomer = true
//     }
//     selectRowIndex = selectRowIndex - data.insertBottomVal // 回朔
//   }
//   return {data,baseInfoForm,selectRowIndex,customeStockArrylistInner,customeStockArrylist,matterallCodelist,specificationalllist}
// }

// jx 7.14 分步式调出单 - 添加行
const issUpDownInsertRow = (
	data,
	baseInfoForm,
	customeStockArrylistInner,
	customeStockArrylist,
	matterallCodelist,
	specificationalllist,
	addRow
) => {
	const index = baseInfoForm.details.length;
	baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)));
	customeStockArrylistInner.splice(index, 0, []);
	customeStockArrylist.splice(index, 0, []);
	matterallCodelist.splice(index, 0, []);
	specificationalllist.splice(index, 0, []);
	baseInfoForm.details[index].isOutCustomer = true;
	baseInfoForm.details[index].isInnerCustomer = true;
	return {
		data,
		baseInfoForm,
		customeStockArrylistInner,
		customeStockArrylist,
		matterallCodelist,
		specificationalllist,
	};
};

// jx 7.15 分步式调出单 - 保存、提交、审核
const issSaveSubmitGetData = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifyName = req.data.modifyName;
	baseInfoForm.checkDate = req.data.checkDate;
	baseInfoForm.checkName = req.data.checkName;
	baseInfoForm.commitDate = req.data.commitDate;
	return baseInfoForm;
};

// jx 7.15 分步式调出单 - 详情进入物料SKU携带的公共方法
const issMaterialSkuGetData = (
	baseInfoForm,
	el,
	currRow,
	unitData,
	isPrecision,
	salePrecisionNumber
) => {
	baseInfoForm.details[currRow].materialId = el.id;
	baseInfoForm.details[currRow].specificationId = el.id;
	baseInfoForm.details[currRow].materName = el.number;
	baseInfoForm.details[currRow].materialNumber = el.number;
	baseInfoForm.details[currRow].specifications = el.specifications;
	baseInfoForm.details[currRow].specification = el.specifications;
	baseInfoForm.details[currRow].materialName = el.name;
	baseInfoForm.details[currRow].unitId = el.baseUnitId;

	let tempList = unitData.filter(
		(it) => it.id === baseInfoForm.details[currRow].unitId
	);
	if (tempList.length > 0) {
		tempList[0].precision == 0
			? (isPrecision[currRow] = true)
			: (isPrecision[currRow] = false);
		tempList[0].precision == 0
			? (salePrecisionNumber[currRow] = 0)
			: (salePrecisionNumber[currRow] = tempList[0].precision);
	}

	return { baseInfoForm, isPrecision, salePrecisionNumber };
};

// jx 7.15 分步式调出单 - 切换调出单清空数据
const issChangeStockOrgClear = (baseInfoForm, addRow) => {
	baseInfoForm.phone = '';
	baseInfoForm.deptId = '';
	baseInfoForm.linkMan = '';
	baseInfoForm.stockerId = '';
	baseInfoForm.address = '';
	baseInfoForm.details = [];
	baseInfoForm.details[0] = addRow;
	for (const key in baseInfoForm.details[0]) {
		baseInfoForm.details[0][key] = '';
		baseInfoForm.details[0].id = 0;
		baseInfoForm.details[0].stockReceiveQty = 0;
		baseInfoForm.details[0].isFree = false;
		baseInfoForm.details[0].isDisabled = false;
		baseInfoForm.details[0].isCusHouse = true;
	}
	return baseInfoForm;
};

// jx 7.15 分步式调出单 - 物料编码、SKU模糊匹配
const issMaterSkuSearchGetData = (baseInfoForm, el, ind) => {
	baseInfoForm.details[ind].materialId = el.id;
	baseInfoForm.details[ind].specificationId = el.id;
	baseInfoForm.details[ind].materName = el.number;
	baseInfoForm.details[ind].materialNumber = el.number;
	baseInfoForm.details[ind].specifications = el.specifications;
	baseInfoForm.details[ind].specification = el.specifications;
	baseInfoForm.details[ind].materialName = el.name;
	baseInfoForm.details[ind].unitId = el.baseUnitId;
	return baseInfoForm;
};

/**
 * 分步式调入
 */
// jx 7.17 保存提交返回日期
const enterSaveSubmitCom = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifyName = req.data.modifyName;
	baseInfoForm.checkDate = req.data.checkDate;
	baseInfoForm.checkName = req.data.checkName;
	baseInfoForm.commitDate = req.data.commitDate;
	return baseInfoForm;
};

// jx 7.17 物料编码模糊匹配
const enterMaterialSearch = (baseInfoForm, el, ind) => {
	baseInfoForm.details[ind].matterName = el.name;
	baseInfoForm.details[ind].unitId = el.baseUnitId;
	baseInfoForm.details[ind].paezOrgName = el.paezOrgName;
	baseInfoForm.details[ind].defaultSupplierName = el.defaultSupplierName;
	baseInfoForm.details[ind].taxRateNmae = el.taxRateNmae;
	baseInfoForm.details[ind].is211 = el.is211 ? el.is211 : false;
	baseInfoForm.details[ind].supplyChainName = el.supplyChain;
	baseInfoForm.details[ind].supplyChain = el.supplyChainKey;
	baseInfoForm.details[ind].lifeCycle = el.lifeCycleKey;
	baseInfoForm.details[ind].lifeCycleName = el.lifeCycle;
	baseInfoForm.details[ind].supplyOriginId = el.paezOrgId;
	baseInfoForm.details[ind].defaultSupplier = el.defaultSupplierId;
	return baseInfoForm;
};

//  jx 7.17 详情物料编码携带
const enterMaterialInfoGetData = (baseInfoForm, el, currRow) => {
	baseInfoForm.details[currRow].materialId = el.id;
	baseInfoForm.details[currRow].specificationId = el.id;
	baseInfoForm.details[currRow].materName = el.number;
	baseInfoForm.details[currRow].materialNumber = el.number;
	baseInfoForm.details[currRow].specifications = el.specifications;
	baseInfoForm.details[currRow].specification = el.specifications;
	baseInfoForm.details[currRow].materialName = el.name;
	baseInfoForm.details[currRow].unitId = el.baseUnitId;
	return baseInfoForm;
};

/**
 * 直接调拨单
 */
// jx 7.19 直接调拨 批量填充 物料携带参数
const activeCopyMaterialGetData = (baseInfoForm, el, i) => {
	baseInfoForm.details[i].materialId = el.id;
	baseInfoForm.details[i].specificationId = el.id;
	baseInfoForm.details[i].matterName = el.name;
	baseInfoForm.details[i].materialName = el.name;
	baseInfoForm.details[i].materName = el.number;
	baseInfoForm.details[i].materialNumber = el.number;
	baseInfoForm.details[i].specification = el.specifications;
	baseInfoForm.details[i].unitId = el.baseUnitId;
	baseInfoForm.details[i].paezOrgName = el.paezOrgName;
	baseInfoForm.details[i].defaultSupplierName = el.defaultSupplierName;
	baseInfoForm.details[i].taxRateNmae = el.taxRateNmae;
	baseInfoForm.details[i].is211 = el.is211 ? el.is211 : false;
	baseInfoForm.details[i].supplyChainName = el.supplyChain;
	baseInfoForm.details[i].supplyChain = el.supplyChainKey;
	baseInfoForm.details[i].lifeCycle = el.lifeCycleKey;
	baseInfoForm.details[i].lifeCycleName = el.lifeCycle;
	baseInfoForm.details[i].supplyOriginId = el.paezOrgId;
	baseInfoForm.details[i].defaultSupplier = el.defaultSupplierId;
	baseInfoForm.details[i].qty = '0';
	return baseInfoForm;
};

// jx 7.19 直接调拨单 插入行
// const activeInsertUpDownData = (data,baseInfoForm,selectRowIndex,customeStockArrylistInner,customeStockArrylist,matterallCodelist,specificationalllist,addRow) => {
//   if (data.insertTopVal != 0 && data.insertTopVal != '') {
//     for (let i = 0; i < data.insertTopVal; i++) {
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylistInner.splice(selectRowIndex, 0, [])
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//       selectRowIndex = parseInt(selectRowIndex) + 1
//     }
//   }
//   if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
//     for (let i = 0; i < data.insertBottomVal; i++) {
//       selectRowIndex = parseInt(selectRowIndex) + 1
//       baseInfoForm.details.splice(selectRowIndex, 0, JSON.parse(JSON.stringify(addRow)))
//       customeStockArrylistInner.splice(selectRowIndex, 0, [])
//       customeStockArrylist.splice(selectRowIndex, 0, [])
//       matterallCodelist.splice(selectRowIndex, 0, [])
//       specificationalllist.splice(selectRowIndex, 0, [])
//     }
//     selectRowIndex = selectRowIndex - data.insertBottomVal // 回朔
//   }
//   return {data,baseInfoForm,selectRowIndex,customeStockArrylistInner,customeStockArrylist,matterallCodelist,specificationalllist}
// }

// jx 7.19 直接调拨单 添加行
const activeInsertUpDownData = (
	data,
	baseInfoForm,
	customeStockArrylistInner,
	customeStockArrylist,
	matterallCodelist,
	specificationalllist,
	addRow
) => {
	const index = baseInfoForm.details.length;
	baseInfoForm.details.splice(index, 0, JSON.parse(JSON.stringify(addRow)));
	customeStockArrylistInner.splice(index, 0, []);
	customeStockArrylist.splice(index, 0, []);
	matterallCodelist.splice(index, 0, []);
	specificationalllist.splice(index, 0, []);
	return {
		data,
		baseInfoForm,
		customeStockArrylistInner,
		customeStockArrylist,
		matterallCodelist,
		specificationalllist,
	};
};

// jx 7.19 直接调拨单 物料SKU模糊匹配
const activeMaterialSkuSearchGetData = (baseInfoForm, el, ind) => {
	baseInfoForm.details[ind].materialId = el.id;
	baseInfoForm.details[ind].specificationId = el.id;
	baseInfoForm.details[ind].materName = el.number;
	baseInfoForm.details[ind].materialNumber = el.number;
	baseInfoForm.details[ind].specifications = el.specifications;
	baseInfoForm.details[ind].specification = el.specifications;
	baseInfoForm.details[ind].materialName = el.name;
	baseInfoForm.details[ind].unitId = el.baseUnitId;
	return baseInfoForm;
};

// jx 7.19 直接调拨单 保存、提交、审核 返回日期赋值
const activeSaveSubmitGetData = (baseInfoForm, req) => {
	baseInfoForm.createDate = req.data.createDate;
	baseInfoForm.creatorName = req.data.creatorName;
	baseInfoForm.modifyDate = req.data.modifyDate;
	baseInfoForm.modifyName = req.data.modifyName;
	baseInfoForm.checkDate = req.data.checkDate;
	baseInfoForm.checkName = req.data.checkName;
	baseInfoForm.commitDate = req.data.commitDate;
	return baseInfoForm;
};

// jx 7.19 直接调拨单 详情物料SKU选择 携带出来的数据
const activeMaterialSkuSelctGetData = (
	baseInfoForm,
	el,
	currRow,
	unitData,
	isPrecision,
	salePrecisionNumber
) => {
	baseInfoForm.details[currRow].materialId = el.id;
	baseInfoForm.details[currRow].specificationId = el.id;
	baseInfoForm.details[currRow].materName = el.number;
	baseInfoForm.details[currRow].materialNumber = el.number;
	baseInfoForm.details[currRow].specifications = el.specifications;
	baseInfoForm.details[currRow].specification = el.specifications;
	baseInfoForm.details[currRow].materialName = el.name;
	baseInfoForm.details[currRow].unitId = el.baseUnitId;
	let tempList = unitData.filter(
		(it) => it.id === baseInfoForm.details[currRow].unitId
	);
	tempList[0].precision == 0
		? (isPrecision[currRow] = true)
		: (isPrecision[currRow] = false);
	tempList[0].precision == 0
		? (salePrecisionNumber[currRow] = 0)
		: (salePrecisionNumber[currRow] = tempList[0].precision);
	return { baseInfoForm, isPrecision, salePrecisionNumber };
};

// jx 7.19 直接调拨单 切换组织清空的数据
const activeChangeOrgClearData = (baseInfoForm, addRow) => {
	baseInfoForm.deptId = '';
	baseInfoForm.consignee = '';
	baseInfoForm.phone = '';
	baseInfoForm.stockerId = '';
	baseInfoForm.address = '';
	baseInfoForm.details = [addRow]; // 清空物料
	for (const key in baseInfoForm.details[0]) {
		baseInfoForm.details[0][key] = '';
		baseInfoForm.details[0].id = 0;
		baseInfoForm.details[0].isDisabled = false;
		baseInfoForm.details[0].isCusHouse = true;
	}
	return baseInfoForm;
};

export {
	// 全局
	orderRexgu,
	orderCopy,
	getNowTimeGlobal,
	pricePrecisionNumberCom,
	numberPrecisionCom,
	disRateRexgu,
	filterMaterialData,
	getObjectName,
	getArrayName,
	getArrayName211,
	bottomAddRow,
	numberRexgu,
	// 销售订单
	addRowCom,
	taxPriceNumberRexgu,
	searchOrder,
	pushDownSure,
	materSpecCarry,
	insertRow,
	saveSubmitBackData,
	changeCustomerClearData,
	materSpecSearh,
	orderCopyClearHeaderData,
	orderCopyClearInfoData,
	customerChangeCarryData,
	clearData,
	// 销售退货单
	srSearchOrder,
	srSurePushDown,
	srMaterialCarry,
	srInsertRow,
	srSaveSubmitBackData,
	onLineOrderRexgu,
	srDetailsMaterSpecSearh,
	srOrgChangeClearData,
	srMaterSpecSearch,
	srCopyInnerClearData,
	// 组织间
	orgNeedsClearData,
	ndCopyClearData,
	watchCustomerChange,
	ndSaveSubBackData,
	changeDownOrgClearData,
	ndIptDownOrgChangeClearData,
	ndSearchOrder,
	ndSurePushDown,
	ndSearchMaterSku,
	// 采购订单
	purSureUpDownSearch,
	purPushDownSure,
	purPushDownRequest,
	purMaterialSkuSearch,
	purCopyOrderClearData,
	purCopyOrderInfoClearData,
	purGetPrecisionNumberFrist,
	purGetBackDate,
	purGetOrderId,
	purCopyCellGetData,
	purInsertRow,
	purMaterSkuSearchGetData,
	purDisCountRateReg,
	purChangeOrgClearData,
	// 采购退料单
	purReMaterialSkuSearch,
	purReCopyMaterialGetValue,
	purReInsertRowCom,
	purReSaveSubmitRequestGetData,
	purReTableInfoMaterialSkuGetData,
	purReChangeOrgClearData,
	purReCopyClearData,
	// 采购入库单
	warePurcaseGetResData,
	warePurcaseGetMaterialSkuData,
	warePurcaseGetMaterialSearch,
	// 分步式调出单
	issSureUpDownSearch,
	issCopyMaterialSkuGetData,
	issUpDownInsertRow,
	issSaveSubmitGetData,
	issMaterialSkuGetData,
	issChangeStockOrgClear,
	issMaterSkuSearchGetData,
	// 分步式调入单
	enterSaveSubmitCom,
	enterMaterialSearch,
	enterMaterialInfoGetData,
	// 直接调拨单
	activeCopyMaterialGetData,
	activeInsertUpDownData,
	activeMaterialSkuSearchGetData,
	activeSaveSubmitGetData,
	activeMaterialSkuSelctGetData,
	activeChangeOrgClearData,
};
