<template>
	<div class="contain_bom">
		<div class="title" style="margin-bottom: 10px">
			<span>
				<el-button size="small" icon="ele-Plus" :disabled="material.isLock" @click="addClickPar"> 新增工序 </el-button>
				<el-button size="small" icon="ele-Mouse" :disabled="material.isLock" @click="changeSort"> 调整工序排序 </el-button>
				<!--        <el-button size="small" icon="ele-GobletFull" :disabled="material.isLock || material.processApproveStatus == 1" @click="submitAbove"> 提交审核-->
				<!--        </el-button>-->
				<!-- <el-button size="small" icon="ele-Mouse" :disabled="material.isLock" @click="tongbuClick"> 同步其他产品工艺路线
       </el-button> -->
				<!--        <el-button size="small" icon="ele-Connection" :disabled="material.isLock" @click="versionClick"> 版本更新-->
				<!--        </el-button>-->
				<!--        <span style="margin-left: 10px;">当前版本：<el-input v-model="material.processVerNo" disabled style="width: 200px;" placeholder="请输入版本号"></el-input> </span>-->
			</span>
			<!--      <span>-->
			<!--        <el-button size="small" icon="ele-Search" @click="histroyClick"> 历史版本查询-->
			<!--        </el-button>-->
			<!--      </span>-->
			<!-- <el-button size="small" icon="ele-Plus"> 提交审批
            </el-button> -->
		</div>
		<!-- <div class="approve">
      <img src="/@/assets/submitok.png" v-if="material.processApproveStatus == 2" style="width:100px;" />
      <img src="/@/assets/pedding.png" v-else style="width:100px;" />
    </div> -->
		<div class="table">
			<el-table
				:data="bomData"
				id="bomtable"
				style="width: 100%; margin-bottom: 10px"
				height="180px"
				size="small"
				row-key="id"
				border
				default-expand-all
				:row-style="tableRowClassName"
				@row-click="cellClick"
				:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
			>
				<el-table-column prop="materialCode" label="物料编码" width="260" show-overflow-tooltip="" />
				<el-table-column prop="materialName" label="物料名称" width="140" show-overflow-tooltip="" />
				<el-table-column prop="specs" label="规格型号" show-overflow-tooltip="" />
				<!-- <el-table-column prop="unitGroupName" label="计量单位组名称" show-overflow-tooltip="" /> -->
				<el-table-column prop="unitName" label="计量单位名称" show-overflow-tooltip="" />
				<!-- <el-table-column prop="purchaseUnitUse" label="采购用量" width="120" show-overflow-tooltip="" /> -->
				<el-table-column prop="unitUse" label="单位用量" width="120" show-overflow-tooltip="" />
				<el-table-column prop="supplyType" label="供应方式" show-overflow-tooltip="">
					<template #default="scope">
						<span v-if="scope.row.supplyType == 1">外协</span>
						<span v-else>自制</span>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<div v-if="selectBom.productCode">
			<div class="process_list">
				<el-table :data="processData" style="width: 100%" height="280px" tooltip-effect="light" row-key="id" border>
					<el-table-column type="index" label="步骤" width="50" align="center" />
					<!-- <el-table-column prop="stepNo" label="" width="140" show-overflow-tooltip="" /> -->
					<el-table-column prop="processCode" label="工序编码" show-overflow-tooltip="" width="100" />
					<el-table-column prop="processName" label="工序名称" :show-overflow-tooltip="true" width="120" />
					<el-table-column prop="asCode" label="自定工序编码" width="90" show-overflow-tooltip="">
						<template #default="scope">
							<el-input style="width: 100%" v-model="scope.row.asCode" placeholder="请输入自定工序编码" clearable />
						</template>
					</el-table-column>
					<!--          <el-table-column prop="workHour" label="工时(小时)" width="100" show-overflow-tooltip="">-->
					<!--            <template #default="scope">-->
					<!--              <el-input-number style="width:100%" v-model="scope.row.workHour" placeholder="请输入工时(小时)" clearable />-->
					<!--            </template>-->
					<!--          </el-table-column>-->
					<el-table-column prop="workHourQuota" label="工时定额(h)" width="100" show-overflow-tooltip="" />
					<el-table-column prop="workPrice" label="工价(元)" width="100" show-overflow-tooltip="" />
					<el-table-column prop="cutQuota" label="下料定额(kg)" width="100" show-overflow-tooltip="" />
					<el-table-column prop="isBG" label="是否报工工序" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isBG" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="bgType" label="报工方式" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-select clearable v-model="scope.row.bgType">
								<el-option label="批量" :value="0"></el-option>
								<el-option label="单件" :value="1"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column prop="bgUnitCode" label="报工单位" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-select clearable v-model="scope.row.bgUnitCode">
								<el-option v-for="item in UnitCodeList" :label="item.value" :value="item.code"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column prop="isQI" label="是否检验工序" width="90" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isQI" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isZJ" label="是否自检" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isZJ" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isFQI" label="是否首检" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isFQI" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isLQI" label="是否末检" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isLQI" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isWW" label="是否委外" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isWW" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isAssemble" label="是否装配" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isAssemble" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isGenProcessJob" label="生成工序任务" width="100" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isGenProcessJob" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<!-- <el-table-column prop="isGenEquipJob" label="生成机台任务" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isGenEquipJob" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column> -->
					<el-table-column prop="isCharge" label="开工上料" width="80" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isCharge" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="chargeType" label="上料类型" width="80" show-overflow-tooltip="">
						<template #default="scope">
							<span v-if="scope.row.chargeType == 0">原材料</span>
							<span v-if="scope.row.chargeType == 1">载具</span>
						</template>
					</el-table-column>
					<!-- <el-table-column prop="chargeMaterialTypeCodes" label="上料MES编码" width="120" show-overflow-tooltip="">
						<template #default="scope"> -->
							<!--              <el-input v-model="scope.row.chargeMaterialTypeCodes"></el-input>-->
							<!-- <el-cascader :options="linehistroy"
                           :props="{ checkStrictly: true, emitPath: false, value: 'materialTypeCode', label: 'materialTypeName' }"
                           placeholder="请选择存货分类" clearable="" class="w100" v-model="scope.row.chargeMaterialTypeCodes">
                <template #default="{ node, data }">
                  <span>{{ data.materialTypeName }}</span>
                  <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
                </template>
              </el-cascader> -->
							<!-- <el-select clearable multiple filterable v-model="scope.row.chargeMaterialTypeCodes">
								<el-option v-for="item in bomList" :label="`[${item.materialCode}]${item.materialName}`" :value="item.materialCode"></el-option>
							</el-select>
						</template>
					</el-table-column> -->
					<!--          <el-table-column prop="chargeMaterialTypeNames" label="上料MES名称" width="65" show-overflow-tooltip="">-->
					<!--            <template #default="scope">-->
					<!--              <el-input v-model="scope.row.chargeMaterialTypeNames"></el-input>-->
					<!--            </template>-->
					<!--          </el-table-column>-->
					<el-table-column prop="isDeduct" label="是否扣料" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isDeduct" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isScanBoard" label="开工扫看板" width="100" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isScanBoard" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="isRelMold" label="开工关联模具" width="100" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isRelMold" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<!-- <el-table-column prop="relMolds" label="关联模具" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-select clearable multiple v-model="scope.row.relMolds">
								<el-option v-for="item in moldList" :label="item.device_name" :value="item.device_code"></el-option>
							</el-select>
						</template>
					</el-table-column> -->
					<!-- <el-table-column prop="isTransfer" label="是否转运" width="65" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isTransfer" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column>
					<el-table-column prop="transferType" label="转运方式" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-select clearable v-model="scope.row.transferType">
								<el-option label="批量" :value="0"></el-option>
								<el-option label="单件" :value="1"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column prop="transferNum" label="转运数量" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-input-number style="width: 100%" v-model="scope.row.transferNum" placeholder="请输入转运数量" clearable />
						</template>
					</el-table-column>
					<el-table-column prop="isGenTransferJob" label="是否生成转运任务" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-switch v-model="scope.row.isGenTransferJob" :active-value="1" :inactive-value="0" />
						</template>
					</el-table-column> -->
					<el-table-column prop="craftFiles" label="工艺文件" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<div v-if="scope.row.craftFiles">
								<a :href="scope.row.craftFiles?.url" :download="scope.row.craftFiles?.name" target="_block" style="cursor: pointer; color: blue">下载</a> {{ scope.row.craftFiles?.name }}
							</div>
						</template>
					</el-table-column>
					<!-- <el-table-column prop="defaultEquipCode" label="默认设备编码" width="120" show-overflow-tooltip="">
            <template #default="scope">
              <el-input :value="(scope.row.resourceList || []).find(item=>item.isDefault)?.resourceName" disabled></el-input>
            </template>
          </el-table-column> -->
					<el-table-column prop="rangEquipCodes" label="设备群组" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-select clearable v-model="scope.row.rangEquipCodes">
								<el-option v-for="item in mesEquipmentGroupList" :label="item.equipmentGroupName" :value="item.equipmentGroupCode"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<!-- <el-table-column prop="technicalCodes" label="技术要求" width="120" show-overflow-tooltip="">
            <template #default="scope">
            	<el-select clearable multiple v-model="scope.row.technicalCodes">
								<el-option v-for="item in mesTechnicalList.filter((u:any)=>u.processCode==scope.row.processCode)" :label="item.technicalName" :value="item.technicalCode"></el-option>
							</el-select>
            </template>
          </el-table-column> -->
					<!--          <el-table-column prop="rangEquipNames" label="可加工设备群组名称" width="100" show-overflow-tooltip="">-->
					<!--            <template #default="scope">-->
					<!--              <el-input v-model="scope.row.rangEquipNames"></el-input>-->
					<!--            </template>-->
					<!--          </el-table-column>-->
					<!--          <el-table-column prop="isPart" label="半成品工艺路线" width="120" show-overflow-tooltip="">-->
					<!--            <template #default="scope">-->
					<!--              <el-switch v-model="scope.row.isPart" :active-value="1" :inactive-value="0" />-->
					<!--            </template>-->
					<!--          </el-table-column>-->
					<el-table-column label="操作" width="160" align="center" fixed="right" show-overflow-tooltip="">
						<template #default="scope">
							<!--    自检          -->
							<!--              <el-button icon="ele-ChatLineSquare" size="small" text="" type="primary" @click="zijianClick(scope.row, material.isLock)"></el-button>-->
							<!--  刀具 -->
							<!--              <el-button icon="ele-CoffeeCup" size="small" text="" type="primary" @click="daojuClick(scope.row, material.isLock)"></el-button>-->
							<!--       设备配置       -->
							<!-- <el-button icon="ele-Calendar" size="small" text="" type="primary" @click="lineSetClick(scope.row, material.isLock)">设备配置</el-button> -->
							<el-button icon="ele-Edit" :disabled="material.isLock" size="small" text="" type="primary" @click="openEditProductBomProcess(scope.row)">编辑</el-button>
							<el-button icon="ele-Delete" :disabled="material.isLock" size="small" text="" type="primary" @click="delMesProductBomProcess(scope.row, scope.$index)">删除 </el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>

		<!--   新增工序   -->
		<el-dialog v-model="isShowDialog" v-if="isShowDialog" :width="800" draggable="" destroy-on-close>
			<template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>{{ title }}</span>
				</div>
			</template>
			<el-form :model="ruleForm" ref="ruleFormRef" label-width="120" :rules="rules">
				<el-row :gutter="20">
					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="工序步骤" prop="stepNo">
                            <el-input-number v-model="ruleForm.stepNo" placeholder="请输入工序步骤" clearable />
                        </el-form-item>
                    </el-col> -->
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<!-- <el-form-item label="工序编码" prop="processCode">
                            <el-input v-model="ruleForm.processCode" placeholder="请输入工序编码" maxlength="100" show-word-limit
                                clearable />
                        </el-form-item> -->
						<el-form-item label="工序" prop="processCode">
							<el-select clearable filterable v-model="ruleForm.processCode" placeholder="请选择工序编码" @change="processSelect">
								<el-option v-for="(item, index) in mesProcessProcessCodeDropdownList" :key="index" :value="item.value" :label="`[${item.code}] ${item.label}`" />
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="自定工序编码" prop="asCode">
							<el-input v-model="ruleForm.asCode" placeholder="请输入自定工序编码" clearable />
						</el-form-item>
					</el-col>

					<!--          <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">-->
					<!--            <el-form-item label="工时(小时)" prop="workHour">-->
					<!--              <el-input-number v-model="ruleForm.workHour" placeholder="请输入工时(小时)" clearable />-->
					<!--            </el-form-item>-->
					<!--          </el-col>-->
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="工时定额(h)" prop="workHourQuota">
							<el-input-number v-model="ruleForm.workHourQuota" placeholder="请输入工时定额" :precision="2" clearable style="width: 100%" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="工价(元)" prop="workPrice">
							<el-input-number v-model="ruleForm.workPrice" placeholder="请输入工价" :precision="6" clearable style="width: 100%" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="下料定额(kg)" prop="cutQuota">
							<el-input-number v-model="ruleForm.cutQuota" placeholder="请输入下料定额" :precision="2" clearable style="width: 100%" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="出数" prop="outputNum">
							<el-input-number v-model="ruleForm.outputNum" placeholder="请输入出数" :precision="0" :min="1" clearable style="width: 100%" />
						</el-form-item>
					</el-col>
					<!-- <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20"></el-col> -->

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="ruleForm.isBG == 1">
						<el-form-item label="报工类别" prop="bgType">
							<el-select clearable v-model="ruleForm.bgType">
								<el-option label="批量" :value="0"></el-option>
								<el-option label="单件" :value="1"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="报工单位" prop="bgUnitCode">
							<el-select clearable v-model="ruleForm.bgUnitCode">
								<el-option v-for="item in UnitCodeList" :label="item.value" :value="item.code"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="报工工序" prop="isBG">
							<el-switch v-model="ruleForm.isBG" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="检验工序" prop="isQI">
							<el-switch v-model="ruleForm.isQI" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="ruleForm.isQI == 1">
						<el-form-item label="是否自检" prop="isZJ">
							<el-switch v-model="ruleForm.isZJ" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="ruleForm.isQI == 1">
						<el-form-item label="是否首检" prop="isFQI">
							<el-switch v-model="ruleForm.isFQI" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="ruleForm.isQI == 1">
						<el-form-item label="是否末检" prop="isLQI">
							<el-switch v-model="ruleForm.isLQI" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>

					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="是否委外" prop="isWW">
							<el-switch v-model="ruleForm.isWW" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="生成工序任务" prop="isGenProcessJob">
							<el-switch v-model="ruleForm.isGenProcessJob" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="是否装配" prop="isAssemble">
							<el-switch v-model="ruleForm.isAssemble" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="false">
						<el-form-item label="生成机台任务" prop="isGenEquipJob">
							<el-switch v-model="ruleForm.isGenEquipJob" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :span="24"> </el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="开工上料" prop="isCharge">
							<el-switch v-model="ruleForm.isCharge" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="上料类型" prop="chargeType">
							<el-select clearable v-model="ruleForm.chargeType">
								<el-option :label="'原材料'" :value="0"></el-option>
								<el-option :label="'载具'" :value="1"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :span="24" class="mb20">
						<el-form-item label="上料存货" prop="chargeMaterialTypeCodes">
							<!--              <el-input v-model="ruleForm.chargeMaterialTypeCodes"></el-input>-->
							<!-- <el-cascader :options="mesMaterialTypeTreeData"
                           :props="{ checkStrictly: true, emitPath: false, value: 'materialTypeCode', label: 'materialTypeName' }"
                           placeholder="请选择存货分类" clearable="" class="w100" v-model="ruleForm.chargeMaterialTypeCodes">
                <template #default="{ node, data }">
                  <span>{{ data.materialTypeName }}</span>
                  <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
                </template>
              </el-cascader> -->
							<!-- <el-select clearable multiple v-model="ruleForm.chargeMaterialTypeCodes">
								<el-option v-for="item in bomList" :label="item.materialName" :value="item.materialCode"></el-option>
							</el-select> -->
							<el-button type="primary" @click="subAdd2">选择</el-button>
							<div style="margin-top: 6px;display: block;">
								<el-tag v-for="(tag,tagIdx) in ruleForm.chargeMaterialTypeCodes" :key="tag" style="margin-right: 5px;" closable type="primary" @close="onRemoveMold2(tag,tagIdx)"> [{{ tag }}]{{ ruleForm.chargeMaterialTypeNames[tagIdx] }} </el-tag>
							</div>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="false">
						<el-form-item label="是否扣料" prop="isDeduct">
							<el-switch v-model="ruleForm.isDeduct" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20" v-if="false">
						<el-form-item label="开工是否扫看板" prop="isScanBoard">
							<el-switch v-model="ruleForm.isScanBoard" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :span="24"> </el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="开工是否关联模具" prop="isRelMold">
							<el-switch v-model="ruleForm.isRelMold" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
						</el-form-item>
					</el-col>
					<el-col :span="24" class="mb20">
						<el-form-item label="模具" prop="relMolds"
							><el-button type="primary" @click="subAdd">选择</el-button>
							<!-- <el-select clearable multiple v-model="ruleForm.relMolds">
								<el-option v-for="item in moldList" :label="item.device_name" :value="item.device_code"></el-option>
							</el-select> -->
							<div style="margin-top: 6px;display: block;">
								<el-tag v-for="(tag,tagIdx) in ruleForm.relMolds" :key="tag.device_code" style="margin-right: 5px;" closable type="primary" @close="onRemoveMold(tag,tagIdx)"> [{{ tag }}]{{ ruleForm.relMoldNames[tagIdx] }} </el-tag>
							</div>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="设备组" prop="rangEquipCodes">
							<el-select clearable v-model="ruleForm.rangEquipCodes" filterable>
								<el-option v-for="item in mesEquipmentGroupList" :label="`[${item.equipmentGroupCode}]${item.equipmentGroupName}`" :value="item.equipmentGroupCode"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
						<el-form-item label="技术要求" prop="technicalCodes">
							<el-select clearable multiple v-model="ruleForm.technicalCodes">
								<el-option v-for="item in mesTechnicalList.filter((u: any) => u.processCode == ruleForm.processCode)" :label="item.technicalName" :value="item.technicalCode"></el-option>
							</el-select>
						</el-form-item>
					</el-col>

					<template v-if="false">
						<el-divider content-position="center">转运</el-divider>

						<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
							<el-form-item label="是否转运" prop="isTransfer">
								<el-switch v-model="ruleForm.isTransfer" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
							<el-form-item label="转运方式" prop="transferType">
								<el-select clearable v-model="ruleForm.transferType">
									<el-option label="批量" :value="0"></el-option>
									<el-option label="单件" :value="1"></el-option>
								</el-select>
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
							<el-form-item label="转运数量" prop="transferNum">
								<el-input-number style="width: 100%" v-model="ruleForm.transferNum" placeholder="请输入转运数量" clearable />
							</el-form-item>
						</el-col>
						<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
							<el-form-item label="是否生成转运任务" prop="isGenTransferJob">
								<el-switch v-model="ruleForm.isGenTransferJob" :active-value="1" :inactive-value="0" active-text="是" inactive-text="否" />
							</el-form-item>
						</el-col>
					</template>

					<el-col :xs="24" :sm="12" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="作业指导书" prop="filePath">
							<el-upload :show-file-list="false" :http-request="uploadFilePathHandle" v-if="!ruleForm.craftFiles?.url">
								<el-button type="primary">点击上传</el-button>
							</el-upload>
							<div v-else>
								<el-icon size="14" style="margin-right: 5px; display: inline; vertical-align: middle; color: red; cursor: pointer" @click="ruleForm.craftFiles = null">
									<ele-Delete />
								</el-icon>
								{{ ruleForm.craftFiles?.name }}
							</div>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="isShowDialog = false">取 消</el-button>
					<el-button type="primary" @click="submitClick">确 定</el-button>
				</span>
			</template>
		</el-dialog>
		<!-- 工序顺序排序 -->
		<el-dialog v-model="sortShow" :width="600" destroy-on-close>
			<template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>调整工序排序</span>
				</div>
			</template>
			<div>
				<el-tree :data="TreeList" node-key="id" default-expand-all draggable :allow-drop="allowDrop">
					<template #default="{ node, data }">
						<span class="custom-tree-node">
							<span>{{ data.processCode }}-{{ data.processName }} </span>
						</span>
					</template>
				</el-tree>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="sortShow = false">取 消</el-button>
					<el-button type="primary" @click="sortOk">确 定</el-button>
				</span>
			</template>
		</el-dialog>

		<el-dialog v-model="processtip" width="800" destroy-on-close>
			<template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>保存失败！已下设备已被删除，请前去确认</span>
				</div>
			</template>
			<el-table :data="processtipData">
				<el-table-column property="resourceCode" label="设备编码" show-overflow-tooltip="" />
				<el-table-column property="resourceName" label="设备名称" show-overflow-tooltip="" />
			</el-table>
		</el-dialog>
		<!--  同步工艺路线  -->
		<el-dialog v-model="tongbuline" :width="1200" destroy-on-close>
			<template #header>
				<div style="color: #fff">
					<!--<el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle"> <ele-Edit /> </el-icon>-->
					<span>同步工艺路线</span>
				</div>
			</template>
			<div style="width: 100%">
				<el-form style="width: 100%" labelWidth="90">
					<el-row>
						<el-col :span="8" class="mb10">
							<el-form-item label="存货档案">
								<el-input v-model="tongbu.materialCode" @click="chooseProduct()" clearable="" placeholder="请存货档案" />
							</el-form-item>
						</el-col>
						<el-col :span="8" class="mb10">
							<el-form-item label="存货档案">
								<el-input v-model="tongbu.materialName" :disabled="true" @click="chooseProduct()" clearable="" placeholder="请存货档案" />
							</el-form-item>
						</el-col>
						<el-col :span="8" class="mb10">
							<el-form-item label="选择Bom">
								<el-cascader
									:options="BomDataForTongbu"
									:props="{ checkStrictly: true, emitPath: false, value: 'productBomId', label: 'materialName', expandTrigger: 'hover' }"
									placeholder="选择Bom"
									clearable
									class="w100"
									v-model="tongbu.bomId"
									@change="bomTongbuChange"
								>
									<template #default="{ node, data }">
										<span>{{ data.materialName }}</span>
										<span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
									</template>
								</el-cascader>
							</el-form-item>
						</el-col>
					</el-row>
				</el-form>

				<el-table :data="lineListForTongbu" ref="lineList" style="width: 100%; margin: 10px 0px" size="small" row-key="id" border default-expand-all>
					<el-table-column type="index" label="工序步骤" width="100" align="center" />
					<!-- <el-table-column prop="stepNo" label="" width="140" show-overflow-tooltip="" /> -->
					<el-table-column prop="processCode" label="工序编码" show-overflow-tooltip="" />
					<el-table-column prop="processName" label="工序名称" show-overflow-tooltip="" />
					<el-table-column prop="asCode" label="自定工序编码" width="120" show-overflow-tooltip="" />
					<el-table-column prop="workHour" label="工时(S)" width="140" show-overflow-tooltip="" />
					<el-table-column prop="workHourQuota" label="工时定额" width="140" show-overflow-tooltip="" />
					<el-table-column prop="isQI" label="检验工序" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-tag v-if="scope.row.isQI"> 是 </el-tag>
							<el-tag type="danger" v-else> 否 </el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="isWW" label="委外工序" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-tag v-if="scope.row.isWW"> 是 </el-tag>
							<el-tag type="danger" v-else> 否 </el-tag>
						</template>
					</el-table-column>
					<el-table-column prop="isFQI" label="首件检验" width="120" show-overflow-tooltip="">
						<template #default="scope">
							<el-tag v-if="scope.row.isFQI"> 是 </el-tag>
							<el-tag type="danger" v-else> 否 </el-tag>
						</template>
					</el-table-column>
					<!--          <el-table-column prop="isPart" label="半成品工艺路线" width="145" show-overflow-tooltip="">-->
					<!--            <template #default="scope">-->
					<!--              <el-tag v-if="scope.row.isPart"> 是 </el-tag>-->
					<!--              <el-tag type="danger" v-else> 否 </el-tag>-->
					<!--            </template>-->
					<!--          </el-table-column>-->
				</el-table>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="tongbuline = false">取 消</el-button>
					<el-button type="primary" @click="tonbuLineOk">确 定</el-button>
				</span>
			</template>
		</el-dialog>
		<lineset ref="line" :process="clickProcessObj" :onlyView="onlyViewTT" @submit="submitRes" :productCode="material.materialCode" @versionClick="onLinesetUpdateVer" />
	</div>
	<materialDialog title="选择产品" ref="materialDialogRef" type="2" :isMore="false" @finish="onChooseFinish"></materialDialog>
	<materialDialog title="选择产品" ref="materialDialogRef2"  :isAny="true" @finish="onChooseFinish2"></materialDialog>
	<!--  设备选择组件  -->
	<choose-equipment-mj title="选择模具" ref="chooseEquipmentRef" :is-any="true" @finish="onChooseFinish1"></choose-equipment-mj>
</template>
<script lang="ts" setup>
import { ref, defineProps, computed, defineExpose, watch, toRefs, reactive, onMounted, nextTick } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import type { FormRules } from 'element-plus';
import { saveBom, getBomList, saveBomProcess, getBomProcessList, getVerNos, getVerInfo, approve, uploadFilePath, queryMoldList } from '/@/api/mes/mesProduct.ts';
import { deepClone, listToTree } from '/@/utils/other.ts';

// import Zijian from './line/Zijian.vue';
// import Daoju from './line/Daoju.vue';
import materialDialog from '/@/businessComponents/chooseMaterial.vue';
import lineset from './equipmentConfig.vue';
import { ElLoading } from 'element-plus';
import { getMesProcessProcessCodeDropdown } from '/@/api/mes/mesProduct';
import { pageMesUnit } from '/@/api/mes/mesUnit';
import { getMesMaterialTypeTree } from '/@/api/mes/mesMaterial';
import { listMesEquipmentGroup } from '/@/api/mes/mesEquipmentGroup';
import { listMesTechnical } from '/@/api/mes/mesTechnical';
import chooseEquipmentMj from '/@/businessComponents/chooseEquipmentMj.vue';

const props = defineProps({
	material: {
		type: Object,
		default: () => {},
	},
});
const clickProcessObj = ref({});
const histroyValue = ref('');
const tongbuline = ref(false);
const lineList = ref();
const histroyList = ref<any[]>([]);
const linehistroy = ref<any[]>([]);
const historySecoundData = ref<any[]>([]);
const BomDataForTongbu = ref<any[]>([]);
const lineListForTongbu = ref<any[]>([]);

const tongbu = reactive({
	materialCode: '',
	bomMaterialCode: '',
	materialName: '',
	bomId: '',
});
const materialDialogRef = ref();

const UnitCodeList = ref([]);
const GetUnitCodeList = async () => {
	const list = await pageMesUnit({
		page: 1,
		pageSize: 9999,
	});
	UnitCodeList.value = (list.data.result?.items ?? []).map((item: any) => ({
		...item,
		code: item.unitCode,
		value: item.unitName,
	}));
};
GetUnitCodeList();

const mesMaterialTypeTreeData = ref<any>([]);
const getMesMaterialTypeTreeData = async () => {
	let list = await getMesMaterialTypeTree();
	mesMaterialTypeTreeData.value = list.data.result ?? [];
	getBomList().then((res) => {
		const data = res.data.result ?? [];
		mesMaterialTypeTreeData.value = listToTree(data, 'productBomId', 'pid');
		// initStr = JSON.stringify(bomData.value);
	});
};
getMesMaterialTypeTreeData();

const mesEquipmentGroupList = ref([]);
const getMesEquipmentGroupList = () => {
	mesEquipmentGroupList.value = [];
	listMesEquipmentGroup().then((res) => {
		mesEquipmentGroupList.value = res.data.result;
	});
};
getMesEquipmentGroupList();

const mesTechnicalList = ref([]);
const getListMesTechnical = () => {
	mesTechnicalList.value = [];
	listMesTechnical().then((res) => {
		mesTechnicalList.value = res.data.result;
	});
};
getListMesTechnical();

//打开产品选择页面
const chooseProduct = (row: any) => {
	materialDialogRef.value.openDialog({ productType: 2 });
};
const processClassName = ({ row, rowIndex }) => {
	console.log(row);
	if (row.iffind) {
		return 'background-color:#e2ef9c;';
	}
	return '';
};

// 产品选择完成
const onChooseFinish = (e: any) => {
	if (e) {
		const data = e;
		tongbu.materialCode = data.materialCode;
		tongbu.materialName = data.materialName;
		getBomList({ productCode: tongbu.materialCode }).then((res) => {
			const data = res.data.result;
			BomDataForTongbu.value = listToTree(data, 'productBomId', 'pid');
		});
	}
};
const tonbuLineOk = () => {
	if (lineListForTongbu.value.length > 0) {
		processData.value = lineListForTongbu.value.map((item) => {
			return {
				...item,
				id: 0,
				resourceList: item.resourceList.map((item: any) => {
					return {
						...item,
						id: 0,
					};
				}),
				inspectList: item.inspectList.map((item: any) => {
					return {
						...item,
						maxValue: null,
						minValue: null,
						standard: null,
						id: 0,
					};
				}),
				toolList: item.toolList.map((item: any) => {
					return {
						...item,
						id: 0,
					};
				}),
				productBomId: 0,
			};
		});
		tongbuline.value = false;
	} else {
		ElMessage({
			type: 'warning',
			message: '工艺路线为空，请切换',
		});
	}
};
const bomTongbuChange = (e: any) => {
	getBomProcessList({ productBomId: tongbu.bomId }).then((res) => {
		lineListForTongbu.value = res.data.result;
	});
};

const versionChange = (val: any) => {
	historySecoundData.value = [];
	linehistroy.value = [];
	getVerInfo({
		id: val,
	}).then((res) => {
		const data = res.data.result?.dataJson;
		const bomdata = JSON.parse(data);
		linehistroy.value = listToTree(bomdata?.productBom, 'productBomId', 'pid');
	});
};

const title = ref('新增');
const ruleForm = ref({});
const TreeList = ref<any[]>([]);
const isShowDialog = ref(false);
const selectBom = ref({});
const selectBom2 = ref({});
const processData = ref<any[]>([]);
const currentRow = ref<any>(null);
let editRow: any = {};
const zijian = ref();
const daoju = ref();
const line = ref();
const bomList = ref<any[]>([]);
let intnum = 10000;
const sortShow = ref(false);
const { material } = toRefs(props);
const tableRowClassName2 = ({ row, rowIndex }) => {
	if (row.id == selectBom2.value.id) {
		return 'background-color:#e2ef9c;';
	}
	return '';
};

const submitAbove = () => {
	ElMessageBox.confirm(`确定要提交审核吗?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'success',
	})
		.then(async () => {
			const loading = ElLoading.service({
				lock: true,
				text: 'Loading',
				background: 'rgba(255,  255, 255, 0.7)',
			});

			approve({
				productCode: material.value.materialCode,
				type: 1,
			})
				.then((res) => {
					loading.close();
					ElMessage({
						type: 'success',
						message: '提交成功',
					});
					emits('submitAduitAfter');
				})
				.catch(() => {
					loading.close();
				});
		})
		.catch(() => {});
};
const onlyViewTT = ref(false);
const tableRowClassName = ({ row, rowIndex }) => {
	if (row.id == selectBom.value.id) {
		return 'background-color:#e2ef9c;';
	}
	return '';
};
const allowDrop = (draggingNode, dropNode, type) => {
	return type !== 'inner';
};
const cellClick2 = async (row, column, event) => {
	selectBom2.value = row;
	historySecoundData.value = row.processList;
};
const cellClick = async (row, column, event) => {
	if (vaildChange()) {
		const res = await ElMessageBox.confirm(`数据未保存，确定切换?`, '提示', {
			confirmButtonText: '确定',
			cancelButtonText: '取消',
			type: 'warning',
		}).then((res) => {
			selectBom.value = row;
			getProcessList(row.productBomId);
		});
	} else {
		selectBom.value = row;
		getProcessList(row.productBomId);
	}
};
const emits = defineEmits(['versionClick', 'submitAduitAfter']);
const versionClick = () => {
	// if (!selectBom.value.materialCode) {
	//     ElMessage({
	//         type: 'warning',
	//         message: '请选择Bom'
	//     })
	//     return
	// }
	emits('versionClick', {
		productCode: material.value.materialCode,
		verType: 3,
		productBomId: selectBom.value.productBomId,
	});
};

const tongbuClick = () => {
	if (!selectBom.value.materialCode) {
		ElMessage({
			type: 'warning',
			message: '请选择Bom',
		});
		return;
	}
	tongbuline.value = true;
};

const onLinesetUpdateVer = (e: any) => {
	e.productCode = material.value.materialCode;
	e.productBomId = selectBom.value.productBomId;
	emits('versionClick', e);
};

const processSelect = (data) => {
	mesProcessProcessCodeDropdownList.value.map((item) => {
		if (item.code == data) {
			ruleForm.value.processName = item.label;
			ruleForm.value.asCode = item.value;
			// ruleForm.value.isQI = item.isQI;
			// ruleForm.value.isFQI = item.isFQI;
			// ruleForm.value.isBG = item.isBG;
			// ruleForm.value.isWW = item.isWW;
			// ruleForm.value.isZJ = item.isPI;
		}
	});
};

const getProcessList = (id: number) => {
	getBomProcessList({ productBomId: id }).then((res) => {
		res.data.result.forEach((element) => {
			if (element.craftFiles) element.craftFiles = JSON.parse(element.craftFiles);
			else element.craftFiles = [];
			if (element.chargeMaterialTypeCodes){
				element.chargeMaterialTypeCodes = element.chargeMaterialTypeCodes.split(',');
				element.chargeMaterialTypeNames = element.chargeMaterialTypeNames.split(',');
			}
			else{
				element.chargeMaterialTypeCodes = [];
				element.chargeMaterialTypeNames = [];
			}
			if (element.relMolds){
				element.relMolds = element.relMolds.split(',');
			}
			else {
				element.relMolds = [];
			}
			if (element.relMoldNames){
				element.relMoldNames = element.relMoldNames.split(',');
			}
			else {
				element.relMoldNames = [];
			}
		});
		processData.value = res.data.result;
		initStr = JSON.stringify(processData.value);
	});
};
const rules = ref<FormRules>({
	materialCode: [{ required: true, message: '请输入编码！', trigger: 'blur' }],
	unitUse: [{ required: true, message: '请输入用量！', trigger: 'blur' }],
});

watch(material, () => {
	console.log('change', material);
	getBomData();
});

const lineSetClick = (row: any, onlyView: boolean) => {
	onlyViewTT.value = onlyView ? onlyView : false;
	clickProcessObj.value = row;
	setTimeout(() => {
		line.value.opendialog();
	}, 200);
};

const submitTab = (data: any) => {
	clickProcessObj.value.inspectList = deepClone(data);
};
const submitTools = (data: any) => {
	clickProcessObj.value.toolList = deepClone(data);
};
const submitRes = (data: any) => {
	clickProcessObj.value.resourceList = deepClone(data);
};
const changeSort = () => {
	if (!selectBom.value.materialCode) {
		ElMessage({
			type: 'warning',
			message: '请选择Bom',
		});
		return;
	}
	TreeList.value = deepClone(processData.value);
	sortShow.value = true;
};

const saveData = () => {
	try {
		var saveProcessData = JSON.parse(JSON.stringify(processData.value));
		saveProcessData.forEach((item) => {
			// if (item.isBG && (!item.resourceList || item.resourceList.length < 1)) {
			// 	throw new Error(`工序[${item.processCode}]${item.processName}未配置设备`);
			// }
			if (item.craftFiles) item.craftFiles = JSON.stringify(item.craftFiles);
			if (item.chargeMaterialTypeCodes){
				item.chargeMaterialTypeCodes = item.chargeMaterialTypeCodes.join(',');
				item.chargeMaterialTypeNames = item.chargeMaterialTypeNames.join(',');
			}

			if (item.relMolds){
				item.relMolds = item.relMolds.join(',');
				item.relMoldNames = item.relMoldNames.join(',');
			}
			// if (item.isZJ && (!item.inspectList || item.inspectList.length < 1)) {
			// 	throw new Error(`工序[${item.processCode}]${item.processName}配置自检项，需配置自检项`);
			// }
			// if (item.isZJ && item.inspectList && item.inspectList.length > 0) {
			// 	item.inspectList.forEach((element: any) => {
			// 		if (!element.minValue && element.minValue !== 0) {
			// 			throw new Error(`工序[${item.processCode}]${item.processName}自检项，下限值不能为空`);
			// 		}
			// 		if (!element.standard && element.standard !== 0) {
			// 			throw new Error(`工序[${item.processCode}]${item.processName}自检项，标准值不能为空`);
			// 		}
			// 		if (!element.maxValue && element.maxValue !== 0) {
			// 			throw new Error(`工序[${item.processCode}]${item.processName}自检项，上限值不能为空`);
			// 		}
			// 	});
			// }
			// if(item.isFQI==1 && item.isQI==0)
			// {
			//   throw new Error(`工序[${item.processCode}]${item.processName??''}已开启首件检验，未开启检验工序`);
			// }
		});
		// verifyExistResource({
		// 	productBomId: selectBom.value.productBomId,
		// 	processList: processData.value,
		// }).then((msg) => {
		// 	if (msg.data.result && msg.data.result.length > 0) {
		// 		processtipData.value = [];
		// 		let datas = msg.data.result;
		// 		datas.forEach((item: any) => {
		// 			item.productBomProcessResources.forEach((i: any) => {
		// 				let iffind = processtipData.value.find((d) => {
		// 					return d.resourceCode == i.resourceCode;
		// 				});
		// 				if (!iffind) {
		// 					processtipData.value.push({
		// 						resourceCode: i.resource.resourceCode,
		// 						resourceName: i.resource.resourceName,
		// 					});
		// 				}
		// 			});
		// 		});
		// 		processtip.value = true;
		// 		// console.log(processData.value);
		// 	} else {
		//
		// 	}
		// });
		saveBomProcess({
			productBomId: selectBom.value.productBomId,
			processList: saveProcessData,
			processVerNo: material.value.processVerNo,
			productCode: material.value.materialCode,
		}).then((res) => {
			getProcessList(selectBom.value.productBomId);
			ElMessage({
				type: 'success',
				message: '保存完成',
			});
		});
	} catch (error: any) {
		ElMessage({
			type: 'warning',
			message: error.message,
		});
	}
};
const processtip = ref(false);
const processtipData = ref([]);
const setindexPid = (arr: any[], pid: number) => {
	arr.forEach((row) => {
		intnum = intnum + 1;
		row.id = intnum;
		row.pid = pid;
		if (row.children && row.children.length > 0) {
			setindexPid(row.children, row.id);
		}
	});
};
const sortOk = () => {
	processData.value = deepClone(TreeList.value);
	sortShow.value = false;
};

let initStr = '[]';
onMounted(() => {
	getBomData();
});

const chooseEquipmentRef = ref();
const subAdd = () => {
	chooseEquipmentRef.value.openDialog({});
};

const onChooseFinish1 = (data: any) => {
	let list: any[] = (data?.rows || []).map((item: any) => ({
		...item,
		device_name: item.equipmentName,
		device_code: item.equipmentCode,
	}));
	list.forEach((el)=>{
		if(ruleForm.value.relMolds.findIndex((u:any)=>u.device_code==el.device_code)==-1){
			ruleForm.value.relMolds.push(el.device_code);
			ruleForm.value.relMoldNames.push(el.device_name);
		}
	})
};
const onRemoveMold = (tag,tagIdx)=>{
	ruleForm.value.relMolds.splice(tagIdx,1);
	ruleForm.value.relMoldNames.splice(tagIdx,1);
}



const materialDialogRef2 = ref();
const subAdd2 = () => {
	materialDialogRef2.value.openDialog({});
};

const onChooseFinish2 = (data: any) => {
	let list: any[] = (data?.rows || []).map((item: any) => ({
		materialName: item.materialName,
		materialCode: item.materialCode,
	}));
	list.forEach((el)=>{
		if(ruleForm.value.chargeMaterialTypeCodes.findIndex((u:any)=>u==el.materialCode)==-1){
			ruleForm.value.chargeMaterialTypeCodes.push(el.materialCode);
			ruleForm.value.chargeMaterialTypeNames.push(el.materialName);
		}
	})
};
const onRemoveMold2 = (tag,tagIdx)=>{
	ruleForm.value.chargeMaterialTypeCodes.splice(tagIdx,1);
	ruleForm.value.chargeMaterialTypeNames.splice(tagIdx,1);
}

const vaildChange = () => {
	console.log(initStr);
	console.log(JSON.stringify(processData.value));
	return initStr != JSON.stringify(processData.value);
};
const delMesProductBomProcess = (row: any, index: number) => {
	ElMessageBox.confirm(`确定要删除吗?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			processData.value.splice(index, 1);
		})
		.catch(() => {});
};
const mesProcessProcessCodeDropdownList = ref<any>([]);
const getMesProcessProcessCodeDropdownList = async () => {
	let list = await getMesProcessProcessCodeDropdown();
	mesProcessProcessCodeDropdownList.value = list.data.result ?? [];
};
getMesProcessProcessCodeDropdownList();

const moldList = ref([]);
const queryMoldListApi = async () => {
	let list = await queryMoldList();
	moldList.value = list.data.result || [];
};
// queryMoldListApi();
const openEditProductBomProcess = (row: any) => {
	var temp = JSON.parse(JSON.stringify(row));
	if (row.craftFiles && typeof row.craftFiles == 'string') row.craftFiles = JSON.parse(row.craftFiles);
	editRow = row;
	ruleForm.value = Object.assign({}, row);
	title.value = '编辑';
	isShowDialog.value = true;
};

const addClickPar = () => {
	if (!selectBom.value.materialCode) {
		ElMessage({
			type: 'warning',
			message: '请选择Bom',
		});
		return;
	}
	title.value = '新增';
	ruleForm.value = {
		isBG: 1,
		bgType: 0,
		outputNum:1,

		isZJ: 1,
		isQI: 1,
		isFQI: 1,
		isLQI: 1,
		isGenProcessJob: 1,
		// isWW: 1,
		// isPart: 0,
		// workHour: 0,
		// workHourQuota: 0,
	};
	isShowDialog.value = true;
};
const submitClick = () => {
	if (ruleForm.value.isFQI == 1 && ruleForm.value.isQI == 0) {
		ElMessage({
			type: 'error',
			message: '开启首件检验时需开启检验工序',
		});
		return;
	}
	if (title.value == '新增') {
		const obj = Object.assign({}, ruleForm.value);
		processData.value.push({
			...obj,
			id: new Date().getTime(),
		});
	} else {
		editRow = Object.assign(editRow, ruleForm.value);
		// for (var i in editRow) {
		// 	editRow[i] = obj[i];
		// }
	}
	isShowDialog.value = false;
};
const bomData = ref<any[]>([]);
const getBomData = () => {
	getBomList({ productCode: material.value.materialCode }).then((res) => {
		const data = res.data.result;
		bomList.value = JSON.parse(JSON.stringify(data));
		console.log('aaaaaaaaaaa', bomList.value);

		bomData.value = listToTree(data, 'productBomId', 'pid');
		selectBom.value = {};
	});
};
const uploadFilePathHandle = async (options: UploadRequestOptions) => {
	const res = await uploadFilePath(options);
	ruleForm.value.craftFiles = { url: res.data.result?.url, name: res.data.result?.fileName };
};
defineExpose({
	saveData,
	vaildChange,
});
</script>
<style lang="scss" scoped>
::v-deep.el-table--enable-row-hover .el-table__body tr:hover > td {
	background-color: rgba(0, 0, 0, 0) !important;
}

.process_list {
	margin-top: 8px;
}

.approve {
	position: absolute;
	z-index: 100;
	top: 0px;
	right: 250px;
}

.contain_bom {
	width: 100%;
	position: relative;

	.title {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
}
</style>
