<template>
	<lay-container fluid="true" class="content-box">
		<lay-table id="dataTable" v-if="dataColumn.length > 0" height="320px" :columns="dataColumn" :data-source="dataList"
			:cellStyle="cellStyle" :cellClassName="cellClassName">
			<template v-slot:toolbar v-if="dataInfoObj.FCanEdit != 2">
				<!-- <lay-button size="sm" @click="saveBatch" type="primary" :disabled="editColumn.length === 0">保存
				</lay-button> -->
				<lay-input :class="this.isShow ? 'isShow' : 'isHidden'" v-model="inputCodeValue" :readonly="true">
					<template #prepend>半成品编号：</template>
				</lay-input>
				<lay-input :class="this.isShow ? 'isShow' : 'isHidden'" v-model="inputDescValue" :readonly="true">
					<template #prepend>描述：</template>
				</lay-input>
				<lay-button size="sm" type="primary" 
					@click="_clickFreezingColumnSetting()">固定项
				</lay-button>
				<lay-button size="sm" style="float:right" type="primary">导出</lay-button>
				<lay-button size="sm" style="float:right">刷新</lay-button>
			</template>
			<template v-for="item in editColumn" v-slot:[item.key]="{ data }">
				<lay-select v-if="item.key == 'FTypeID1'" size="sm" v-model="data['FTypeID1']"
					@change="_changeType(data, 1)" :showEmpty="false">
					<lay-select-option v-for="(tIdv, tIdx) in typeList[0]" :key="tIdx" :value="tIdv.FID"
						:label="tIdv.FName"></lay-select-option>
				</lay-select>
				<lay-select v-else-if="item.key == 'FTypeID2'" size="sm" v-model="data['FTypeID2']"
					@change="_changeType(data, 2)" :showEmpty="false">
					<lay-select-option v-show="data.FTypeID1 == tIdv.FParentID" v-for="(tIdv, tIdx) in typeList[1]"
						:key="tIdx" :value="tIdv.FID" :label="tIdv.FName"></lay-select-option>
				</lay-select>
				<lay-select v-else-if="item.selectType" size="sm" v-model="data[item.key]" :showEmpty="false">
					<lay-select-option v-for="(tIdv, tIdx) in selectDataMap['FType' + item.selectTypeId]" :key="tIdx"
						:value="tIdv.FValue" :label="tIdv.FName"></lay-select-option>
				</lay-select>
				<lay-input v-else-if="!item.dataType" size="sm" v-model="data[item.key]"></lay-input>
			</template>
		</lay-table>
		<OperateLog v-if="dataInfoObj.FTeamID" ref="OperateLog" :dataInfoObj="dataInfoObj"></OperateLog>
	</lay-container>
</template>

<style scoped>
.content-box {
	margin: 30px 10px;
	display: block;
	position: relative;
	clear: both;
	float: none;
	min-height: 740px;
}


.row-select td {
	overflow: inherit;
}

.layui-select {
	width: 100%;
}

.edit {
	color: green;
}

:deep(.edit-item .layui-input) {
	border-color: #5FB878 !important;
}

:deep(.edit-item .layui-input:hover) {
	border-color: #009688 !important;
	color: #009688;
}

.isShow {
	width: 370px;
	height: 30px;
	border: none;
}

.isHidden {
	display: none;
}

.isBomHidden {
	display: none;
}
</style>
<script>
import {
	ref
} from 'vue';
import {
	getListByTeamId,
	updateBatchById2
} from "/src/api/api/view";
import {
	getBasicRoleList
} from "/src/api/api/user";
import {
	getDataCode,
	commonSave
} from "/src/api/api/common";

import {
	getInfoData,
	changeInfoData
} from "/src/api/api/materialType";
import OperateLog from "./OperateLog.vue";
import FormulaView from "./FormulaView.vue";
import FreezingColumnSetting from './FreezingColumnSetting.vue';

export default {
	components: {
		OperateLog,
		FormulaView,
		FreezingColumnSetting
	},
	setup() {
		const dataColumn = ref([]);
		const dataList = ref([]);
		const editColumn = ref([]);
		const selectDataMap = ref(null);
		const typeList = ref([
			[],
			[]
		]);
		const userPower = ref([
			[],
			[]
		]);
		const cellStyle = function (row, column, rowIndex, columnIndex) {
			let back = column.table == "TFS_ViewMaterial" ? "background:rgb(246, 246, 246)" : ""
			return back;
		}
		const cellClassName = function (row, column, rowIndex, columnIndex) {
			return column.cellClass || "";
		}
		const inputCodeValue = ref("");
		const inputDescValue = ref("");
		const visible2 = ref(false)
		const changeVisible2 = function () {
			visible2.value = !visible2.value
		};
		const showFreezingColumnSettingBox = ref(false);
		const freezingColumnSetting = ref([]);
		const originalColumns = ref([]);
		const tmpDataColumn = ref([]);
		return {
			dataColumn,
			dataList,
			editColumn,
			selectDataMap,
			typeList,
			userPower,
			cellStyle,
			cellClassName,
			inputCodeValue,
			inputDescValue,
			isShow: false,
			isBomShow: false,
			visible2,
			changeVisible2,
			showFreezingColumnSettingBox,
			freezingColumnSetting,
			originalColumns,
			tmpDataColumn
		};
	},
	props: {
		dataInfoObj: {
			type: Object,
			default: () => { },
		},
		viewDataList: {
			type: Object,
			default: () => [],
		}
	},
	mounted() {
		this.getUserPower();
	},
	methods: {
		async getUserPower() {
			if (this.dataInfoObj.FCanEdit != 2) {
				this.userPower[0] = (await getBasicRoleList({
					FRoleType: 40,
					FViewType: this.dataInfoObj.FViewType
				}) || []).map(it => parseInt(it.F2))
				this.userPower[1] = (await getBasicRoleList({
					FRoleType: 44,
					FViewType: this.dataInfoObj.FViewType
				}) || []).map(it => parseInt(it.F2))
			}
			this.initPage(layer.load(2));
		},
		async initPage(idx) {

			debugger
			this.dataInfoObj["FTeamID"]=224;
			
			this.dataColumn = [{"width":"160px","align":"center","title":"试验号","style":"color:#1E9FFF;background:#ccc !important","key":"F1","rowspan":1},{"width":"160px","align":"center","title":"一级分类","style":"color:#1E9FFF;background:#ccc !important","key":"FTypeName1","rowspan":1},{"width":"160px","align":"center","title":"二级分类","style":"color:#1E9FFF;background:#ccc !important","key":"FTypeName2","rowspan":1},{"width":"160px","align":"center","title":"K3系统代码","style":"color:#1E9FFF;background:#ccc !important","key":"FK3Code","rowspan":1},{"width":"160px","align":"center","title":"K3系统名称","style":"color:#1E9FFF;background:#ccc !important","key":"FK3Name","rowspan":1},{"width":"160px","align":"center","title":"K3系统短代码","style":"color:#1E9FFF;background:#ccc !important","key":"FK3ShortCode","rowspan":1},{"width":"160px","align":"center","title":"产品试验号","style":"color:#1E9FFF;background:#ccc !important","key":"FTestCode","rowspan":1},{"width":"160px","align":"center","title":"SAP系统代码","style":"color:#1E9FFF;background:#ccc !important","key":"FCode","rowspan":1},{"width":"160px","align":"center","title":"SAP系统描述","style":"color:#1E9FFF;background:#ccc !important","key":"FName","rowspan":1},{"width":"160px","align":"center","title":"物料组","style":"color:#1E9FFF;background:#ccc !important","key":"FMaterialGroup","rowspan":1},{"width":"160px","align":"center","title":"物料主分类","style":"color:#1E9FFF;background:#ccc !important","key":"FMaterialType","rowspan":1},{"width":"160px","align":"center","title":"客供料标识","style":"color:#1E9FFF;background:#ccc !important","key":"FCustomerCode","rowspan":1},{"width":"160px","align":"center","title":"总仓地址","style":"color:#1E9FFF;background:#ccc !important","key":"FStoreHouse","rowspan":1},{"width":"160px","align":"center","title":"BOM录入情况","style":"color:#1E9FFF;background:#ccc !important","key":"FBomEntry","rowspan":1},{"width":"160px","align":"center","title":"线边仓地址","style":"color:#1E9FFF;background:#ccc !important","key":"FLineHouse","rowspan":1},{"width":"160px","align":"center","title":"产品说明","style":"color:#1E9FFF;background:#ccc !important","key":"FProductDesc","rowspan":1},{"width":"160px","align":"center","title":"工作中心","style":"color:#1E9FFF;background:#ccc !important","key":"FWorkCenter","rowspan":1},{"width":"160px","align":"center","title":"工艺说明","style":"color:#1E9FFF;background:#ccc !important","key":"FCraftExplain","rowspan":1},{"width":"160px","align":"center","title":"标识符","style":"color:#1E9FFF;background:#ccc !important","key":"FIidentifier","rowspan":1},{"width":"160px","align":"center","title":"保质期","style":"color:#1E9FFF;background:#ccc !important","key":"FGuaranteePeriod","rowspan":1},{"width":"160px","align":"center","title":"存储条件","style":"color:#1E9FFF;background:#ccc !important","key":"FStorageConditions","rowspan":1},{"width":"160px","align":"center","title":"安全库存","style":"color:#1E9FFF;background:#ccc !important","key":"FSafetyStock","rowspan":1},{"width":"160px","align":"center","title":"触发比例","style":"color:#1E9FFF;background:#ccc !important","key":"FTriggerRatio","rowspan":1},{"width":"160px","align":"center","title":"最小量","style":"color:#1E9FFF;background:#ccc !important","key":"FMinAmount","rowspan":1},{"width":"160px","align":"center","title":"最大量","style":"color:#1E9FFF;background:#ccc !important","key":"FMaxAmount","rowspan":1},{"width":"160px","align":"center","title":"得率","style":"color:#1E9FFF;background:#ccc !important","key":"FYield","rowspan":1},{"width":"160px","align":"center","title":"固损","style":"color:#1E9FFF;background:#ccc !important","key":"FFixedLoss","rowspan":1},{"width":"160px","align":"center","title":"理论得率","style":"color:#1E9FFF;background:#ccc !important","key":"FTheoryYield","rowspan":1},{"width":"160px","align":"center","title":"品质检验1","style":"color:#1E9FFF;background:#ccc !important","key":"FQualityTest1","rowspan":1},{"width":"160px","align":"center","title":"品质检验2","style":"color:#1E9FFF;background:#ccc !important","key":"FQualityTest2","rowspan":1},{"width":"160px","align":"center","title":"行业领域","style":"color:#1E9FFF;","key":"FOrganizeIndustryField","rowspan":1},{"width":"160px","align":"center","title":"物料类型","style":"color:#1E9FFF;","key":"FOrganizeMaterialType","rowspan":1},{"width":"160px","align":"center","title":"工厂","style":"color:#1E9FFF;","key":"FOrganizeFactory","rowspan":1},{"width":"160px","align":"center","title":"库存地点","style":"color:#1E9FFF;","key":"FOrganizeInventoryLocation","rowspan":1},{"width":"160px","align":"center","title":"销售组织","style":"color:#1E9FFF;","key":"FOrganizeSalesOrganize","rowspan":1},{"width":"160px","align":"center","title":"分销渠道","style":"color:#1E9FFF;","key":"FOrganizeDistributionChannel","rowspan":1},{"width":"160px","align":"center","title":"物料编号","style":"color:#009688","key":"FBaseMaterialCode","rowspan":1},{"width":"160px","align":"center","title":"试验号","style":"color:#009688","key":"FBaseTestCode","rowspan":1},{"width":"160px","align":"center","title":"基本计量","style":"color:#009688","key":"FBaseBasicMeter","rowspan":1},{"width":"320px","align":"center","title":"物料描述","style":"color:#009688","key":"FBaseMaterialDesc","rowspan":1},{"width":"160px","align":"center","title":"物料组","style":"color:#009688","key":"FBaseMaterialGroup","rowspan":1},{"width":"160px","align":"center","title":"大小/量纲(规格)","style":"color:#009688","key":"FBaseSpecification","rowspan":1},{"width":"160px","align":"center","title":"物料长文本","style":"color:#009688","key":"FBaseMaterialText","rowspan":1},{"width":"160px","align":"center","title":"标识符:固体/液体","style":"color:#009688","key":"FBaseIdentifier","rowspan":1},{"width":"160px","align":"center","title":"体积单位","style":"color:#009688","key":"FBaseVolumeUnit","rowspan":1},{"width":"160px","align":"center","title":"毛重","style":"color:#009688","key":"FBaseGrossWeight","rowspan":1},{"width":"160px","align":"center","title":"净重","style":"color:#009688","key":"FBaseNetWeight","rowspan":1},{"width":"160px","align":"center","title":"重量单位","style":"color:#009688","key":"FBaseWeightUnit","rowspan":1},{"width":"160px","align":"center","title":"业务量","style":"color:#009688","key":"FBaseBusinessVolume","rowspan":1},{"width":"160px","align":"center","title":"fame号","style":"color:#009688","key":"FBaseFameCode","rowspan":1},{"width":"160px","align":"center","title":"采购组","style":"color:#1E9FFF;","key":"FPurchaseGroup","rowspan":1},{"width":"160px","align":"center","title":"采购单位","style":"color:#1E9FFF;","key":"FPurchaseCompany","rowspan":1},{"width":"160px","align":"center","title":"采购单位数量","style":"color:#1E9FFF;","key":"FPurchaseCompanyCount","rowspan":1},{"width":"160px","align":"center","title":"采购基本单位数量","style":"color:#1E9FFF;","key":"FPurchaseBaseCompanyCount","rowspan":1},{"width":"160px","align":"center","title":"采购价值码","style":"color:#1E9FFF;","key":"FPurchaseValueCode","rowspan":1},{"width":"160px","align":"center","title":"工厂特定状态","style":"color:#1E9FFF;","key":"FPurchaseFactorySpecificStatus","rowspan":1},{"width":"160px","align":"center","title":"自动采购单标识","style":"color:#1E9FFF;","key":"FPurchaseAutoOrder","rowspan":1},{"width":"160px","align":"center","title":"货源清单","style":"color:#1E9FFF;","key":"FPurchaseGoodsSource","rowspan":1},{"width":"160px","align":"center","title":"类别种类","style":"color:#009688","key":"FTypeCategoryType","rowspan":1},{"width":"160px","align":"center","title":"类别","style":"color:#009688","key":"FTypeType","rowspan":1},{"width":"160px","align":"center","title":"交货工厂","style":"color:#1E9FFF;","key":"FSaleDeliveryFactory","rowspan":1},{"width":"160px","align":"center","title":"税金分类","style":"color:#1E9FFF;","key":"FSaleTaxType","rowspan":1},{"width":"160px","align":"center","title":"物料统计组","style":"color:#1E9FFF;","key":"FSaleMaterialStatisticsGroup","rowspan":1},{"width":"160px","align":"center","title":"销售单位","style":"color:#1E9FFF;","key":"FSaleSalesCompany","rowspan":1},{"width":"160px","align":"center","title":"基本单位数量","style":"color:#1E9FFF;","key":"FSaleBaseCompanyCount","rowspan":1},{"width":"160px","align":"center","title":"销售单位数量","style":"color:#1E9FFF;","key":"FSaleSalesCompanyCount","rowspan":1},{"width":"160px","align":"center","title":"科目设置组","style":"color:#1E9FFF;","key":"FSaleAccountSettingGroup","rowspan":1},{"width":"160px","align":"center","title":"普通项目类别组","style":"color:#1E9FFF;","key":"FSaleGeneralProjectCategoryGroup","rowspan":1},{"width":"160px","align":"center","title":"项目类别组","style":"color:#1E9FFF;","key":"FSaleProjectCategoryGroup","rowspan":1},{"width":"160px","align":"center","title":"可用性检查","style":"color:#1E9FFF;","key":"FSaleAvailabilityCheck","rowspan":1},{"width":"160px","align":"center","title":"装载组","style":"color:#1E9FFF;","key":"FSaleOutfitGroup","rowspan":1},{"width":"160px","align":"center","title":"旧物料号","style":"color:#1E9FFF;","key":"FSaleOldMaterialCode","rowspan":1},{"width":"160px","align":"center","title":"存储条件","style":"color:#009688","key":"FStorageConditions","rowspan":1},{"width":"160px","align":"center","title":"批次管理","style":"color:#009688","key":"FStorageBatchManage","rowspan":1},{"width":"160px","align":"center","title":"最大存储期间","style":"color:#009688","key":"FStorageMaxStoragePeriod","rowspan":1},{"width":"160px","align":"center","title":"时间单位","style":"color:#009688","key":"FStorageTimeUnit","rowspan":1},{"width":"160px","align":"center","title":"最小剩余货架寿命","style":"color:#009688","key":"FStorageMinSurplusShelfLife","rowspan":1},{"width":"160px","align":"center","title":"总货架寿命","style":"color:#009688","key":"FStorageTotalShelfLife","rowspan":1},{"width":"160px","align":"center","title":"SLED期间标识","style":"color:#009688","key":"FStorageSLEDCode","rowspan":1},{"width":"160px","align":"center","title":"MRP类型","style":"color:#1E9FFF;","key":"FMRP1Type","rowspan":1},{"width":"160px","align":"center","title":"MRP控制者","style":"color:#1E9FFF;","key":"FMRP1Controller","rowspan":1},{"width":"160px","align":"center","title":"批量大小","style":"color:#1E9FFF;","key":"FMRP1BatchSize","rowspan":1},{"width":"160px","align":"center","title":"最小批量大小","style":"color:#1E9FFF;","key":"FMRP1MinBatchSize","rowspan":1},{"width":"160px","align":"center","title":"最大批量大小","style":"color:#1E9FFF;","key":"FMRP1MaxBatchSize","rowspan":1},{"width":"160px","align":"center","title":"MRP组","style":"color:#1E9FFF;","key":"FMRP1Group","rowspan":1},{"width":"160px","align":"center","title":"舍入值","style":"color:#1E9FFF;","key":"FMRP1RoundValue","rowspan":1},{"width":"160px","align":"center","title":"产品分类","style":"color:#1E9FFF;","key":"FMRP1ProductType","rowspan":1},{"width":"160px","align":"center","title":"客户代码","style":"color:#1E9FFF;","key":"FMRP1CustomerCode","rowspan":1},{"width":"160px","align":"center","title":"大小料","style":"color:#1E9FFF;","key":"FMRP1SizeMaterial","rowspan":1},{"width":"160px","align":"center","title":"小料标准（小于）","style":"color:#1E9FFF;","key":"FMRP1SmallMaterialStandard","rowspan":1},{"width":"160px","align":"center","title":"采购类型","style":"color:#009688","key":"FMRP2PurchaseType","rowspan":1},{"width":"160px","align":"center","title":"计划边际码","style":"color:#009688","key":"FMRP2PlanMarginalCode","rowspan":1},{"width":"160px","align":"center","title":"特殊采购类","style":"color:#009688","key":"FMRP2SpecialProcurement","rowspan":1},{"width":"160px","align":"center","title":"反冲","style":"color:#009688","key":"FMRP2Recoil","rowspan":1},{"width":"160px","align":"center","title":"自制生产时间","style":"color:#009688","key":"FMRP2SelfProductTime","rowspan":1},{"width":"160px","align":"center","title":"计划交货时间","style":"color:#009688","key":"FMRP2PlannDeliveryTime","rowspan":1},{"width":"160px","align":"center","title":"收货处理时间","style":"color:#009688","key":"FMRP2ReceiveProcessTime","rowspan":1},{"width":"160px","align":"center","title":"安全库存","style":"color:#009688","key":"FMRP2SafeStock","rowspan":1},{"width":"160px","align":"center","title":"发货库存地点","style":"color:#009688","key":"FMRP2DeliveryInventoryPlace","rowspan":1},{"width":"160px","align":"center","title":"外部采购仓储地点","style":"color:#009688","key":"FMRP2ExternalStoragePlace","rowspan":1},{"width":"160px","align":"center","title":"策略组","style":"color:#1E9FFF;","key":"FMRP3PolicyGroup","rowspan":1},{"width":"160px","align":"center","title":"消耗模式","style":"color:#1E9FFF;","key":"FMRP3ConsumePattern","rowspan":1},{"width":"160px","align":"center","title":"向前消耗期间","style":"color:#1E9FFF;","key":"FMRP3ForwardConsumePeriod","rowspan":1},{"width":"160px","align":"center","title":"逆向消耗期","style":"color:#1E9FFF;","key":"FMRP3ReverseConsumePeriod","rowspan":1},{"width":"160px","align":"center","title":"混合MRP","style":"color:#1E9FFF;","key":"FMRP3BlendMRP","rowspan":1},{"width":"160px","align":"center","title":"可用性检查","style":"color:#1E9FFF;","key":"FMRP3AvailabilityCheck","rowspan":1},{"width":"160px","align":"center","title":"单独或集中","style":"color:#1E9FFF;","key":"FMRP4AloneOrFocus","rowspan":1},{"width":"160px","align":"center","title":"生产计划参数文件","style":"color:#009688","key":"FPlanProductPlanParam","rowspan":1},{"width":"160px","align":"center","title":"无限制过量交货","style":"color:#009688","key":"FPlanUnlimitedOverDelivery","rowspan":1},{"width":"160px","align":"center","title":"不足交货允差","style":"color:#009688","key":"FPlanUnderDeliveryTolerance","rowspan":1},{"width":"160px","align":"center","title":"过度交货允差","style":"color:#009688","key":"FPlanOverDeliveryTolerance","rowspan":1},{"width":"160px","align":"center","title":"发货单位","style":"color:#009688","key":"FPlanDeliverCompany","rowspan":1},{"width":"160px","align":"center","title":"发货单位数量","style":"color:#009688","key":"FPlanDeliverCompanyCount","rowspan":1},{"width":"160px","align":"center","title":"发货基本单位数量","style":"color:#009688","key":"FPlanBaseCompanyCount","rowspan":1},{"width":"160px","align":"center","title":"检验类型1","style":"color:#1E9FFF;","key":"FQualityType1","rowspan":1},{"width":"160px","align":"center","title":"检验类型2","style":"color:#1E9FFF;","key":"FQualityType2","rowspan":1},{"width":"160px","align":"center","title":"检验类型3","style":"color:#1E9FFF;","key":"FQualityType3","rowspan":1},{"width":"160px","align":"center","title":"检验类型4","style":"color:#1E9FFF;","key":"FQualityType4","rowspan":1},{"width":"160px","align":"center","title":"检验类型5","style":"color:#1E9FFF;","key":"FQualityType5","rowspan":1},{"width":"160px","align":"center","title":"检验类型6","style":"color:#1E9FFF;","key":"FQualityType6","rowspan":1},{"width":"160px","align":"center","title":"价格控制","style":"color:#009688","key":"FAccountPriceControl","rowspan":1},{"width":"160px","align":"center","title":"价格确定","style":"color:#009688","key":"FAccountPriceDetermine","rowspan":1},{"width":"160px","align":"center","title":"价格单位","style":"color:#009688","key":"FAccountPriceUnit","rowspan":1},{"width":"160px","align":"center","title":"评估分类","style":"color:#009688","key":"FAccountAccessType","rowspan":1},{"width":"160px","align":"center","title":"VC: 销售订单库存","style":"color:#009688","key":"FAccountSaleOrderInventory","rowspan":1},{"width":"160px","align":"center","title":"标准价格","style":"color:#009688","key":"FAccountStandardPrice","rowspan":1},{"width":"160px","align":"center","title":"利润中心","style":"color:#009688","key":"FAccountProfitCenter","rowspan":1},{"width":"160px","align":"center","title":"成本核算批量","style":"color:#009688","key":"FAccountCostAccountBatch","rowspan":1}];
				this.dataList=[{"F1":"试验号1","FID":490,"FType":"K1.24.(受托C310)其他自制物料","FDataID":67965,"FMaterialGroup":"","FMaterialType":"","FCustomerCode":"","FStoreHouse":"","FBomEntry":"","FLineHouse":"","FProductDesc":"","FWorkCenter":"","FIidentifier":"","FGuaranteePeriod":"","FStorageConditions":"","FSafetyStock":"","FTriggerRatio":"","FMinAmount":"","FMaxAmount":"","FYield":"","FFixedLoss":"","FTheoryYield":"","FQualityTest1":"","FQualityTest2":"","FAddUser":2,"FAddDate":"2023-04-14T03:11:06.827","FEditUser":0,"FEditDate":"2023-04-14T03:11:06.827","FTypeID1":"","FTypeID2":"","FK3Code":"","FK3Name":"","FK3ShortCode":"","FTestCode":"","FRelationCode":"","FRelationName":"","FOrganizeIndustryField":"M","FOrganizeMaterialType":"ZMAT","FOrganizeFactory":"","FOrganizeInventoryLocation":"","FOrganizeSalesOrganize":"","FOrganizeDistributionChannel":"90","FBaseMaterialCode":"","FBaseTestCode":"","FBaseBasicMeter":"g","FBaseSpecification":"","FBaseMaterialText":"","FBaseIdentifier":"","FBaseVolumeUnit":"M3","FBaseGrossWeight":"","FBaseNetWeight":"","FBaseFameCode":"","FBaseBusinessVolume":"","FPurchaseGroup":"G12","FPurchaseCompany":"","FPurchaseCompanyCount":"","FPurchaseBaseCompanyCount":"","FPurchaseValueCode":"4","FPurchaseFactorySpecificStatus":"","FPurchaseAutoOrder":"X","FPurchaseGoodsSource":"","FTypeCategoryType":"023","FTypeType":"ZBATCLS","FSaleDeliveryFactory":"","FSaleTaxType":"1","FSaleMaterialStatisticsGroup":"1","FSaleSalesCompany":"","FSaleBaseCompanyCount":"","FSaleSalesCompanyCount":"","FSaleAccountSettingGroup":"10","FSaleGeneralProjectCategoryGroup":"","FSaleProjectCategoryGroup":"NORM","FSaleAvailabilityCheck":"02","FSaleOutfitGroup":"0001","FSaleOldMaterialCode":"","FStorageBatchManage":"X","FStorageMaxStoragePeriod":"","FStorageTimeUnit":"","FStorageMinSurplusShelfLife":"1","FStorageTotalShelfLife":"","FStorageSLEDCode":"D","FMRP1Type":"PD","FMRP1ReorderLocation":"","FMRP1RegularBatchSize":"","FMRP1MaxInventorySize":"","FMRP1Controller":"","FMRP1BatchSize":"MB","FMRP1MinBatchSize":"","FMRP1MaxBatchSize":"","FMRP1Group":"0099","FMRP1RoundValue":"","FMRP1ProductType":"","FMRP1CustomerCode":"","FMRP1SizeMaterial":"","FMRP1IgnoreLack":"","FMRP1laminated":"","FMRP1SafeStock":"","FMRP1RequireCount":"","FMRP1SmallMaterialStandard":"","FMRP2PurchaseType":"F","FMRP2PlanMarginalCode":"000","FMRP2SpecialProcurement":"","FMRP2Recoil":"","FMRP2SelfProductTime":"","FMRP2PlannDeliveryTime":"","FMRP2ReceiveProcessTime":"","FMRP2SafeStock":"","FMRP2DeliveryInventoryPlace":"","FMRP2ExternalStoragePlace":"3000","FMRP3PolicyGroup":"40","FMRP3ConsumePattern":"2","FMRP3ForwardConsumePeriod":"365","FMRP3ReverseConsumePeriod":"90","FMRP3BlendMRP":"3","FMRP3AvailabilityCheck":"02","FMRP4AloneOrFocus":"2","FMRP4DiscontinuousIidentifier":"","FMRP4EffectivePeriod":"","FMRP4FollowMaterial":"","FPlanProductPlanParam":"","FPlanUnlimitedOverDelivery":"","FPlanUnderDeliveryTolerance":"","FPlanOverDeliveryTolerance":"","FPlanDeliverCompany":"","FPlanDeliverCompanyCount":"","FPlanBaseCompanyCount":"","FQualityType1":"","FQualityType2":"","FQualityType3":"","FQualityType4":"","FQualityType5":"","FQualityType6":"","FAccountPriceControl":"S","FAccountPriceDetermine":"3","FAccountPriceUnit":"1000","FAccountAccessType":"2000","FAccountSaleOrderInventory":"2010","FAccountStandardPrice":"","FAccountProfitCenter":"PC30","FAccountCostAccountBatch":"1000","FMStorageConditions":"","FTypeID1Type":"0","FTypeID2Type":"0","FK3CodeType":"0","FK3NameType":"0","FK3ShortCodeType":"0","FTestCodeType":"0","FRelationCodeType":"0","FRelationNameType":"0","FSAPCodeType":"0","FSAPDescriptionType":"0","FMaterialGroupType":"0","FMaterialTypeType":"0","FCustomerCodeType":"0","FStoreHouseType":"0","FBomEntryType":"0","FLineHouseType":"0","FProductDescType":"0","FWorkCenterType":"0","FCraftExplainType":"0","FIidentifierType":"0","FGuaranteePeriodType":"0","FStorageConditionsType":"0","FSafetyStockType":"0","FTriggerRatioType":"0","FMinAmountType":"0","FMaxAmountType":"0","FYieldType":"0","FFixedLossType":"0","FTheoryYieldType":"0","FQualityTest1Type":"0","FQualityTest2Type":"0","FOrganizeIndustryFieldType":"0","FOrganizeMaterialTypeType":"0","FOrganizeFactoryType":"0","FOrganizeInventoryLocationType":"0","FOrganizeSalesOrganizeType":"0","FOrganizeDistributionChannelType":"0","FBaseMaterialCodeType":"0","FBaseTestCodeType":"0","FBaseBasicMeterType":"0","FBaseMaterialDescType":"0","FBaseMaterialGroupType":"0","FBaseSpecificationType":"0","FBaseMaterialTextType":"0","FBaseIdentifierType":"0","FBaseVolumeUnitType":"0","FBaseGrossWeightType":"0","FBaseNetWeightType":"0","FBaseWeightUnitType":"0","FBaseFameCodeType":"0","FBaseBusinessVolumeType":"0","FPurchaseGroupType":"0","FPurchaseCompanyType":"0","FPurchaseCompanyCountType":"0","FPurchaseBaseCompanyCountType":"0","FPurchaseValueCodeType":"0","FPurchaseFactorySpecificStatusType":"0","FPurchaseAutoOrderType":"0","FPurchaseGoodsSourceType":"0","FTypeCategoryTypeType":"0","FTypeTypeType":"0","FSaleDeliveryFactoryType":"0","FSaleTaxTypeType":"0","FSaleMaterialStatisticsGroupType":"0","FSaleSalesCompanyType":"0","FSaleBaseCompanyCountType":"0","FSaleSalesCompanyCountType":"0","FSaleAccountSettingGroupType":"0","FSaleGeneralProjectCategoryGroupType":"0","FSaleProjectCategoryGroupType":"0","FSaleAvailabilityCheckType":"0","FSaleOutfitGroupType":"0","FSaleOldMaterialCodeType":"0","FMStorageConditionsType":"0","FStorageBatchManageType":"0","FStorageMaxStoragePeriodType":"0","FStorageTimeUnitType":"0","FStorageMinSurplusShelfLifeType":"0","FStorageTotalShelfLifeType":"0","FStorageSLEDCodeType":"0","FMRP1TypeType":"0","FMRP1ReorderLocationType":"0","FMRP1RegularBatchSizeType":"0","FMRP1MaxInventorySizeType":"0","FMRP1ControllerType":"0","FMRP1BatchSizeType":"0","FMRP1MinBatchSizeType":"0","FMRP1MaxBatchSizeType":"0","FMRP1GroupType":"0","FMRP1RoundValueType":"0","FMRP1ProductTypeType":"0","FMRP1CustomerCodeType":"0","FMRP1SizeMaterialType":"0","FMRP1IgnoreLackType":"0","FMRP1laminatedType":"0","FMRP1SafeStockType":"0","FMRP1RequireCountType":"0","FMRP1SmallMaterialStandardType":"0","FMRP2PurchaseTypeType":"0","FMRP2PlanMarginalCodeType":"0","FMRP2SpecialProcurementType":"0","FMRP2RecoilType":"0","FMRP2SelfProductTimeType":"0","FMRP2PlannDeliveryTimeType":"0","FMRP2ReceiveProcessTimeType":"0","FMRP2SafeStockType":"0","FMRP2DeliveryInventoryPlaceType":"0","FMRP2ExternalStoragePlaceType":"0","FMRP3PolicyGroupType":"0","FMRP3ConsumePatternType":"0","FMRP3ForwardConsumePeriodType":"0","FMRP3ReverseConsumePeriodType":"0","FMRP3BlendMRPType":"0","FMRP3AvailabilityCheckType":"0","FMRP4AloneOrFocusType":"0","FMRP4DiscontinuousIidentifierType":"0","FMRP4EffectivePeriodType":"0","FMRP4FollowMaterialType":"0","FPlanProductPlanParamType":"0","FPlanUnlimitedOverDeliveryType":"0","FPlanUnderDeliveryToleranceType":"0","FPlanOverDeliveryToleranceType":"0","FPlanDeliverCompanyType":"0","FPlanDeliverCompanyCountType":"0","FPlanBaseCompanyCountType":"0","FQualityType1Type":"0","FQualityType2Type":"0","FQualityType3Type":"0","FQualityType4Type":"0","FQualityType5Type":"0","FQualityType6Type":"0","FAccountPriceControlType":"0","FAccountPriceDetermineType":"0","FAccountPriceUnitType":"0","FAccountAccessTypeType":"0","FAccountSaleOrderInventoryType":"0","FAccountStandardPriceType":"0","FAccountProfitCenterType":"0","FAccountCostAccountBatchType":"0","FTypeName1":"","FTypeName2":""}];
			
			setTimeout(function () {
				layer.close(idx);
			}, 500);
		},
		cancelClick(isRefresh) {
			isRefresh = isRefresh == undefined ? false : isRefresh;
			this.$emit('cancelClick', isRefresh);
		},
		async _changeType(data, type) {
			if (type == 1) {
				data.FTypeID2 = -1;
			} else {
				if (data.FTypeID2) {
					let result = await getInfoData({
						"FDataID": data.FTypeID2,
						"FType": 1
					}) || null;

					if (result != null && result.FID) {
						let col7 = this.dataColumn.filter(s => s.fieldType == 7) || [];
						col7.forEach((item) => {
							if (item.table == "TFS_MaterialInfo") {
								data[item.key] = result[item.key] || data[item.key] || "";
							}
						});

						this.dataColumn.map(function (item) {
							let str = result[item.key + "Type"];

							if (typeof (str) != "undefined") {
								switch (str) {
									case "1":
										if (typeof (item.cellClass) == "undefined") {
											return item["cellClass"] = "one";
										}
										return item.cellClass = item.cellClass.split(" ")[0] + " one";
									case "2":
										if (typeof (item.cellClass) == "undefined") {
											return item["cellClass"] = "twe";
										}
										return item.cellClass = item.cellClass.split(" ")[0] + " twe";
									case "3":
										if (typeof (item.cellClass) == "undefined") {
											return item["cellClass"] = "three";
										}
										return item.cellClass = item.cellClass.split(" ")[0] + " three";
									case "4":
										if (typeof (item.cellClass) == "undefined") {
											return item["cellClass"] = "four";
										}
										return item.cellClass = item.cellClass.split(" ")[0] + " four";
								}
							}

							return item["cellClass"]="";
						})
					}
				}
			}
		},
		async saveBatch() {
			let idx = layer.load(2);
			let updateObj = {
				LogList: [],
				FTeamID: this.dataInfoObj['FTeamID'],
				FViewType: this.dataInfoObj.FViewType
			};
			let saveId = this.dataInfoObj.FViewType + "_" + this.dataInfoObj.FID;
			let cacheDataList = JSON.parse(localStorage.getItem('EditView' + saveId));
			this.dataList.forEach((row, index) => {
				let cache = cacheDataList[index];
				let dataObj = {};
				for (let col of this.editColumn) {
					let valTemp = row[col.key];
					if (valTemp != cache[col.key]) {
						if (!dataObj[col.table]) {
							dataObj[col.table] = {};
							dataObj[col.table].FMaterialID = row["FMaterialID"];
						}
						dataObj[col.table][col.key] = valTemp;
						if (col.key == "FTypeID1" || col.key == "FTypeID2") {
							let temps = this.typeList[col.key == "FTypeID1" ? 0 : 1] || [];
							let temp = temps.find(s => s.FID == valTemp) || null;
							valTemp = temp == null ? "" : temp.FName;
						}
						updateObj.LogList.push(col.title + "：" + (valTemp == "" ? "删除" : valTemp));
					}
				}
				for (let key in dataObj) {
					if (!updateObj[key]) updateObj[key] = [];
					updateObj[key].push(dataObj[key]);
				}
			});
			let updateLog = updateObj.LogList.join("、");
			if (updateLog != "") {
				delete updateObj.LogList
				// 发送保存请求
				let _result = await updateBatchById2(updateObj);
				if (_result.Code === 200) {
					await commonSave({
						teamId: updateObj.FTeamID,
						type: this.dataInfoObj['FType'],
						desc: updateLog
					}, "OperateLog");
					let $this = this;
					//$this.initPage();
					localStorage.setItem('EditView' + saveId, JSON.stringify(this.dataList));
					setTimeout(function () {
						layer.close(idx);
						layer.msg('保存成功');
						$this.$emit('cancelClick', true, true);
						$this.$refs.OperateLog._getPageList();
					}, 500);
				}
			} else {
				layer.close(idx);
				layer.msg('您没有做任何更改')
			}
		},
		_clickFreezingColumnSetting() {
			this.dataColumn = ref([]);
			this.showFreezingColumnSettingBox = true;
		},
		setFreezingColumns() {
			this.tmpDataColumn = this.deepCopy(this.originalColumns);
			let freezingColumns = [];
			if (this.freezingColumnSetting && this.freezingColumnSetting.length > 0) {
				this.freezingColumnSetting.forEach(column => {
					let colIndex = this.tmpDataColumn.findIndex(d => d.key === column);
					if (colIndex >= 0) {
						let fc = this.tmpDataColumn.splice(colIndex, 1)[0];
						if (fc) {
							fc.fixed = "left";
							freezingColumns.push(fc);
						}
					}
				})

				this.dataColumn = freezingColumns.concat(this.tmpDataColumn);
			} else {
				this.dataColumn = this.tmpDataColumn;
			}
		},
		setFreezingColumnsSetting(fcs) {
			this.freezingColumnSetting = fcs;
			if (fcs && fcs.length > 0) {
			} else {
				this.dataColumn = this.originalColumns;
			}
			this.showFreezingColumnSettingBox = false;
		},
		closeFreezingSetting() {
			this.setFreezingColumns();
		},
		deepCopy(arr) {
			return JSON.parse(JSON.stringify(arr))
		}
	}
}
</script>
