<template>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="sale-details-container order-mc-bg main-container"
	>
		<div class="sale-details-btn-group">
			<!-- 顶部按钮 -->
			<toolBtn
				:btnType="btnType"
				:isDisable="isDisable"
				@actionhandel="actionhandel"
			></toolBtn>
		</div>
		<div class="sale-details-base-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				v-if="fromData.documentStatus === 'c'"
			/>
			<el-tabs
				style="margin-bottom: 8px"
				type="border-card"
				v-loading="isLoading"
			>
				<!-- 主产品信息 -->
				<el-tab-pane label="主产品信息">
					<div class="base-info-form-box">
						<el-form
							:model="fromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="20">
								<el-col :span="4">
									<el-form-item
										class="item-bt-s Iisshow"
										label="BOM版本"
									>
										<el-input
											:maxlength="255"
											:disabled="
												fromData.documentStatus ===
													'b' ||
												fromData.documentStatus === 'c'
											"
											placeholder="(保存时自动生成)"
											v-model.trim="fromData.version"
										></el-input>
										<div
											:data-clipboard-text="
												fromData.version
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="4">
									<el-form-item
										:required="true"
										class="item-bt-s Iisshow"
										label="父项物料编码"
									>
										<el-select
											:disabled="isEditBom"
											:remote-method="matterCodeChange"
											@change="metterFxChange"
											filterable
											placeholder="请输入关键词"
											remote
											reserve-keyword
											v-model="fromData.materialNumber"
										>
											<el-option
												:style="{
													height: item.disable
														? '0px'
														: 'auto',
												}"
												:key="item.id + item.number"
												:label="item.number"
												:value="item.id"
												v-for="item in materialList"
											></el-option>
										</el-select>
										<div
											:data-clipboard-text="
												fromData.materialNumber
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="4">
									<el-form-item
										class="item-bt-s"
										label="父项物料单位"
									>
										<el-select
											class="arrow_none"
											disabled
											placeholder="由物料编码获取"
											v-model="fromData.unitId"
										>
											<el-option
												:key="index"
												:label="item.name"
												:value="item.id"
												class="f-12"
												v-for="(
													item, index
												) in unitList"
												:style="{
													height: item.disable
														? '0px'
														: 'auto',
												}"
											></el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row :gutter="20">
								<el-col :span="4">
									<el-form-item
										class="item-bt-s Iisshow"
										label="物料名称"
									>
										<el-input
											:maxlength="255"
											disabled
											placeholder="由物料编码获取"
											v-model.trim="fromData.materialName"
										></el-input>
										<div
											:data-clipboard-text="
												fromData.materialName
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="4">
									<el-form-item
										:required="true"
										class="item-bt-s Iisshow"
										label="规格型号"
									>
										<el-select
											:disabled="isEditBom"
											:remote-method="skuCodeChange"
											@change="metterFxChange"
											filterable
											placeholder="请输入关键词"
											remote
											reserve-keyword
											v-model="fromData.specification"
										>
											<el-option
												:key="item.id + item.number"
												:label="item.specifications"
												:value="item.id"
												v-for="item in materialList"
												:style="{
													height: item.disable
														? '0px'
														: 'auto',
												}"
											></el-option>
										</el-select>
										<div
											:data-clipboard-text="
												fromData.specification
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
								</el-col>
								<el-col :span="4">
									<el-form-item
										class="item-bt-s"
										label="数据状态"
									>
										<el-select
											disabled
											placeholder="请选择"
											v-model="fromData.documentStatus"
										>
											<el-option
												:key="key + index"
												:label="value"
												:value="key"
												class="f-12"
												v-for="(
													value, key, index
												) in noticeType"
											></el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
							<el-row :gutter="20">
								<el-col :span="4">
									<el-form-item
										class="item-bt-s Iisshow"
										label="是否禁用"
									>
										<el-select
											v-model="fromData.isDisable"
											placeholder="请选择"
											:clearable="true"
											:disabled="
												fromData.documentStatus ==
													'b' ||
												fromData.documentStatus == 'c'
											"
											@change="
												clearCom(
													fromData.isDisable,
													'isDisable'
												)
											"
										>
											<el-option
												class="f_12"
												v-for="item in isDisablelist"
												@click="
													searchComC(
														fromData.isDisable,
														'isDisable'
													)
												"
												:key="item.id"
												:label="item.name"
												:value="item.id"
											></el-option>
										</el-select>
									</el-form-item>
								</el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<!-- 操作记录 -->
				<el-tab-pane :disabled="!fromData.version" label="操作记录">
					<div
						:style="{ height: '185px!important' }"
						class="base-info-form-box"
					>
						<el-form
							:model="fromData"
							label-width="80px"
							ref="fromData"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="创建人"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													fromData.createName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="创建时间"
										>
											<el-input
												disabled
												placeholder
												v-model="fromData.createDate"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											class="item-bt-s"
											label="最后修改人"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													fromData.modifyName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												disabled
												placeholder
												v-model="fromData.modifyDate"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="提交时间"
										>
											<el-input
												disabled
												placeholder
												v-model="fromData.commitDate"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													:maxlength="50"
													class="item-bt-s"
													label="审核人"
												>
													<el-input
														disabled
														placeholder
														v-model.trim="
															fromData.checkName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														disabled
														placeholder
														v-model="
															fromData.checkDate
														"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													:maxlength="50"
													class="item-bt-s"
													label="禁用人"
												>
													<el-input
														disabled
														placeholder
														v-model.trim="
															fromData.disableName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="禁用时间"
												>
													<el-input
														disabled
														placeholder
														v-model="
															fromData.disableDate
														"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<div class="sale-details-base-info">
			<el-tabs
				@tab-click="handleClick(activeName)"
				style="margin-bottom: 8px"
				type="border-card"
				v-model="activeName"
			>
				<!-- 明细信息 -->
				<el-tab-pane label="明细信息" name="details">
					<div class="org-info-form-box">
						<!-- 明细工具栏 -->
						<div class="tell-info-button-group">
							<DetailsOperation
								:deviationSelectArr="selectRowIndexArr"
								:isEdit="isEdit"
								@copyCellcolumn="copyCellcolumn"
								@copyRow="bottomCopyRow"
								@deleteRow="selectDeleteRow"
								@insertObj="getInsertInfo"
							></DetailsOperation>
						</div>
					</div>
					<!-- 表格信息-->
					<div class="tell-info-table">
						<el-table
							:cell-class-name="tableCellClassName"
							:data="fromData.details"
							:header-cell-class-name="mustAfter"
							@cell-click="getRowCol"
							@select="selectRow"
							@select-all="selectAll"
							border
							max-height="430"
							ref="multipleTable"
							style="font-size: 12px"
							v-loading="isLoading"
						>
							<el-table-column
								align="center"
								fixed
								type="selection"
								width="40"
							/>
							<!-- @paste="pasteExcel($event,scope.$index,scope,'taxPrice')" -->
							<!-- @paste="pasteExcel($event,scope.$index,scope,'materialNumber')" -->
							<el-table-column
								align="left"
								label="子项物料编码"
								prop="materialNumber"
								width="190"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>子项物料编码
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isMaterialNumber">{{
										scope.row.materialNumber
									}}</span>
									<el-select
										v-if="scope.row.isMaterialNumber"
										:id="'materialNumber' + scope.$index"
										:disabled="isEdit"
										:remote-method="
											(query) => {
												matterCodeChange1(
													query,
													scope.$index
												);
											}
										"
										@change="
											metterCxChange($event, scope.$index)
										"
										filterable
										placeholder="请输入关键词"
										remote
										reserve-keyword
										v-model="scope.row.materialNumber"
									>
										<el-option
											:key="item.id + item.number"
											:label="item.number"
											:value="item.id"
											@click="
												batchClick(
													item.id,
													'materialId',
													scope.row,
													scope.column
												)
											"
											v-for="item in materialList1[
												scope.$index
											]"
											:style="{
												height: item.disable
													? '0px'
													: 'auto',
											}"
										></el-option>
									</el-select>
								</template>
							</el-table-column>
							<!-- @paste="pasteExcel($event,scope.$index,scope,'specification')" -->
							<el-table-column
								align="left"
								label="规格型号(SKU)"
								prop="specification"
								width="200"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>规格型号(SKU)
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isSpecification">{{
										scope.row.specification
									}}</span>
									<el-select
										v-if="scope.row.isSpecification"
										:id="'specification' + scope.$index"
										:disabled="isEdit"
										:remote-method="
											(query) => {
												skuCodeChange1(
													query,
													scope.$index
												);
											}
										"
										@change="
											metterCxChange($event, scope.$index)
										"
										filterable
										placeholder="请输入关键词"
										remote
										reserve-keyword
										v-model="scope.row.specification"
									>
										<el-option
											:key="item.id + item.number"
											:label="item.specifications"
											:value="item.id"
											:style="{
												height: item.disable
													? '0px'
													: 'auto',
											}"
											@click="
												batchClick(
													item.id,
													'materialId',
													scope.row,
													scope.column
												)
											"
											v-for="item in materialList1[
												scope.$index
											]"
										></el-option>
									</el-select>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="物料名称"
								prop="materialName"
								width="190"
							>
								<template #default="scope">
									<span>{{ scope.row.materialName }}</span>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="子项子单位"
								prop="subUnitIdName"
								width="190"
							>
								<template #default="scope">
									<span>{{
										getName(unitList, scope.row.subUnitId)
									}}</span>
									<!-- <el-select
                    class="arrow_none"
                    disabled
                    placeholder="由物料编码获取"
                    v-model="scope.row.subUnitId"
                  >
                    <el-option
                      :key="index"
                      :label="item.name"
                      :value="item.id"
                      class="f-12"
                      v-for="(item,index) in unitList"
                    ></el-option>
                  </el-select>-->
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="用量：分子"
								prop="numerator"
								width="120"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>用量：分子
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isNmerator">{{
										scope.row.numerator
									}}</span>
									<div
										class="el-input click-cell-ipt"
										:class="{ 'is-disabled': isEdit }"
										v-if="scope.row.isNmerator"
									>
										<input
											:disabled="isEdit"
											:id="'numerator' + scope.$index"
											:maxlength="255"
											autocomplete="off"
											@blur="
												batchClick(
													scope.row.numerator,
													'numerator',
													scope.row,
													scope.column
												)
											"
											@paste="
												pasteExcel(
													$event,
													scope.$index,
													scope,
													'numerator'
												)
											"
											placeholder
											v-model.lazy="scope.row.numerator"
											class="el-input__inner"
										/>
									</div>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="用量：分母"
								prop="denominator"
								width="120"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>用量：分母
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isDnominator">{{
										scope.row.denominator
									}}</span>
									<div
										class="el-input click-cell-ipt"
										:class="{ 'is-disabled': isEdit }"
										v-if="scope.row.isDnominator"
									>
										<input
											:disabled="isEdit"
											:id="'denominator' + scope.$index"
											:maxlength="255"
											autocomplete="off"
											@blur="
												batchClick(
													scope.row.denominator,
													'denominator',
													scope.row,
													scope.column
												)
											"
											@paste="
												pasteExcel(
													$event,
													scope.$index,
													scope,
													'denominator'
												)
											"
											placeholder
											v-model.lazy="scope.row.denominator"
											class="el-input__inner"
										/>
									</div>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="损耗率%"
								prop="ffixscrapqty"
								width="120"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>损耗率%
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isFixscrapqty">{{
										scope.row.ffixscrapqty
									}}</span>
									<div
										class="el-input click-cell-ipt"
										:class="{ 'is-disabled': isEdit }"
										v-if="scope.row.isFixscrapqty"
									>
										<input
											:disabled="isEdit"
											:id="'ffixscrapqty' + scope.$index"
											:maxlength="255"
											autocomplete="off"
											@blur="
												batchClick(
													scope.row.ffixscrapqty,
													'ffixscrapqty',
													scope.row,
													scope.column
												)
											"
											@paste="
												pasteExcel(
													$event,
													scope.$index,
													scope,
													'ffixscrapqty'
												)
											"
											placeholder
											v-model.lazy="
												scope.row.ffixscrapqty
											"
											class="el-input__inner"
										/>
									</div>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="发料方式"
								prop="fissueType"
								width="190"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>发料方式
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isFissueType">{{
										getNameObj(flType, scope.row.fissueType)
									}}</span>
									<el-select
										v-if="scope.row.isFissueType"
										:id="'fissueType' + scope.$index"
										:disabled="isEdit"
										@change="changeFissuetype(scope.row)"
										placeholder="请选择"
										v-model="scope.row.fissueType"
									>
										<el-option
											:key="value + key"
											:label="value"
											:value="key"
											@click="
												batchClick(
													scope.row.fissueType,
													'fissueType',
													scope.row,
													scope.column
												)
											"
											class="f-12"
											v-for="(value, key) in flType"
										></el-option>
									</el-select>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="默认发料仓库"
								prop="stockId"
								width="190"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>默认发料仓库
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isStockId">{{
										getName(
											warehouseList,
											scope.row.stockId
										)
									}}</span>
									<el-select
										v-if="scope.row.isStockId"
										:id="'stockId' + scope.$index"
										:disabled="isEdit"
										placeholder="请选择"
										v-model="scope.row.stockId"
									>
										<el-option
											:key="index"
											:label="value.name"
											:value="value.id"
											@click="
												batchClick(
													scope.row.stockId,
													'stockId',
													scope.row,
													scope.column
												)
											"
											class="f-12"
											v-for="(
												value, index
											) in warehouseList"
										></el-option>
									</el-select>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="超发比例%"
								prop="overRatio"
								width="120"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>超发比例%
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isOverRatio">{{
										scope.row.overRatio
									}}</span>
									<div
										class="el-input click-cell-ipt"
										:class="{ 'is-disabled': isEdit }"
										v-if="scope.row.isOverRatio"
									>
										<input
											:id="'overRatio' + scope.$index"
											:disabled="isEdit"
											:maxlength="255"
											autocomplete="off"
											@blur="
												batchClick(
													scope.row.overRatio,
													'overRatio',
													scope.row,
													scope.column
												)
											"
											@paste="
												pasteExcel(
													$event,
													scope.$index,
													scope,
													'overRatio'
												)
											"
											placeholder
											v-model.lazy="scope.row.overRatio"
											class="el-input__inner"
										/>
									</div>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="物料承担方"
								prop="materialBear"
								width="120"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>物料承担方
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isMaterialBear">{{
										getNameObj(
											materialBear,
											scope.row.materialBear
										)
									}}</span>
									<el-select
										v-if="scope.row.isMaterialBear"
										:id="'materialBear' + scope.$index"
										:disabled="isEdit"
										clearable
										placeholder="请选择"
										v-model="scope.row.materialBear"
									>
										<el-option
											:key="value + key"
											:label="value"
											:value="key"
											@click="
												batchClick(
													scope.row.materialBear,
													'materialBear',
													scope.row,
													scope.column
												)
											"
											class="f-12"
											v-for="(value, key) in materialBear"
										></el-option>
										<!-- :style="{ 'height': item.disable ? '0px' : 'auto' }" -->
									</el-select>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="子项单位"
								prop="unitIdName"
								width="190"
							>
								<template #default="scope">
									<span>{{
										getName(unitList, scope.row.unitId)
									}}</span>
									<!-- <el-select
                    class="arrow_none"
                    disabled
                    placeholder="由物料编码获取"
                    v-model="scope.row.unitId"
                  >
                    <el-option
                      :key="index"
                      :label="item.name"
                      :value="item.id"
                      class="f-12"
                      v-for="(item,index) in unitList"
                    ></el-option>
                  </el-select>-->
								</template>
							</el-table-column>
							<el-table-column
								align="center"
								label="是否关健件"
								prop="isKeyComponent"
								width="90"
							>
								<template #default="scope">
									<el-checkbox
										:disabled="isEdit"
										v-model="scope.row.isKeyComponent"
									></el-checkbox>
								</template>
							</el-table-column>
							<el-table-column
								align="left"
								label="位置号/模号/备注"
								prop="remark"
								width="190"
							>
								<!-- isRemark -->
								<!-- @paste="pasteExcel($event,scope.$index,scope,'remark')" -->
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>位置号/模号/备注
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isRemark">{{
										scope.row.remark
									}}</span>
									<div
										class="el-input click-cell-ipt"
										:class="{ 'is-disabled': isEdit }"
										v-if="scope.row.isRemark"
									>
										<input
											:id="'remark' + scope.$index"
											:disabled="isEdit"
											:maxlength="255"
											autocomplete="off"
											@blur="
												batchClick(
													scope.row.remark,
													'remark',
													scope.row,
													scope.column
												)
											"
											placeholder="请输入"
											v-model.lazy="scope.row.remark"
											class="el-input__inner"
										/>
									</div>
								</template>
							</el-table-column>
							<el-table-column
								align="center"
								label="是否失效"
								prop="isEffect"
								width="80"
							>
								<template #default="scope">
									<el-checkbox
										v-model="scope.row.isEffect"
									></el-checkbox>
								</template>
							</el-table-column>
						</el-table>
					</div>
				</el-tab-pane>
				<!-- 组织使用明细 -->
				<el-tab-pane label="组织使用明细" name="orgDetals">
					<div class="org-info-form-box">
						<div class="tell-info-button-group">
							<DetailsOperation
								:deviationSelectArr="selectRowIndexArr"
								:isEdit="isEdit"
								@copyCellcolumn="copyCellcolumn"
								@copyRow="bottomCopyRow"
								@deleteRow="selectDeleteRow"
								@insertObj="getInsertInfo"
							></DetailsOperation>
						</div>
					</div>
					<!-- 表格信息-->
					<div class="tell-info-table">
						<el-table
							:cell-class-name="tableCellClassName"
							:data="fromData.blacks"
							@cell-click="getRowCol1"
							@select="selectRow"
							@select-all="selectAll"
							ref="multipleTable1"
							border
							max-height="430"
							style="font-size: 12px"
						>
							<el-table-column
								align="center"
								fixed
								type="selection"
								width="40"
							/>
							<el-table-column
								align="left"
								label="不使用该BOM组织"
								prop="orgId"
								width="190"
							>
								<template #header>
									<span
										class="iconfont icon-bianji1 iconfont-mg"
									></span
									>不使用该BOM组织
								</template>
								<template #default="scope">
									<span v-if="!scope.row.isOrgId">{{
										getName(orgList, scope.row.orgId)
									}}</span>
									<el-select
										v-if="scope.row.isOrgId"
										:id="'orgId' + scope.$index"
										:disabled="isEdit"
										clearable
										filterable
										placeholder="请输入关键词"
										remote
										reserve-keyword
										v-model="scope.row.orgId"
									>
										<el-option
											:key="item.id"
											:label="item.name"
											:value="item.id"
											@click="
												batchClick(
													scope.row.orgId,
													'orgId',
													scope.row,
													scope.column
												)
											"
											v-for="item in orgList"
										></el-option>
									</el-select>
								</template>
							</el-table-column>
						</el-table>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
	</div>
</template>
<script>
import examineTop from '@/components/examineTop/index.vue';
import { mapState, mapActions } from 'vuex';
import { reactive } from 'vue';
import { Decimal } from 'decimal.js';
import { copyValueMethods } from '@/utils/pubulic.js';
import {
	getArrayName,
	getObjectName,
	orderCopy,
	bottomAddRow,
	filterMaterialData,
} from '@/utils/takeMethods.js';
export default {
	name: 'mateBomSet',
	components: {
		examineTop,
	},
	data() {
		return {
			isDisablelist: [
				{
					name: '是',
					id: 'true',
				},
				{
					name: '否',
					id: 'false',
				},
			],
			isEditBom: false,
			isLoading: false,
			isDisable: false,
			isDisableTop: false,
			heightNum: 0,
			fromData: {
				version: '', //
				isEffect: '',
				name: '',
				materialId: 0,
				materialNumber: '',
				materialName: '',
				specification: '',
				unitId: null,
				unitIdName: '',
				documentStatus: '',
				isDisable: 'false',
				details: [
					{
						id: 0,
						seq: 1,
						materialId: '',
						materialNumber: '',
						materialName: '',
						specification: '',
						materialProperty: '',
						unitId: null,
						unitIdName: '',
						subUnitId: null,
						subUnitIdName: '',
						numerator: 1,
						denominator: 1,
						ffixscrapqty: 0,
						cost: 0,
						materialBear: '',
						childBomId: 0,
						overRatio: 10000,
						stockId: '',
						fissueType: '1',
						isEffect: false,
						remark: '',
						isKeyComponent: false,
						isSelWarehouse: false,
					},
				],
				blacks: [
					{
						id: 0,
						seq: 1,
						orgId: '',
						paezOrgName: '',
					},
				],
			},
			saveParams: {
				id: 0,
				materialId: '',
				version: '',
				details: [
					{
						id: 0,
						seq: 1,
						materialId: '',
						numerator: 1,
						denominator: 1,
						ffixscrapqty: 0,
						materialBear: '',
						overRatio: 10000,
						stockId: 0,
						fissueType: '1',
						isEffect: false,
						isKeyComponent: false,
						remark: '',
					},
				],
				blacks: [],
			}, //保存/提交参数
			InventoryType: {}, //存货类别
			supplyChainType: {}, //供应链
			productLocationType: {}, //产品定位
			brandType: {}, //品牌类型
			safetyType: {}, //安规
			fileList: [],
			is211List: [
				{
					id: false,
					name: '否',
				},
				{
					id: true,
					name: '是',
				},
			], //是否211列表
			activeName: 'details',
			selectRowIndexArr: [],
			selectRowIndex: '', // 当前 选择行
			currRow: 0,
			addRow: {},
			rowArr: [],
			storeObj: {
				// 存储的行
				storeRow: '',
				storeCol: '',
				storeVal: '',
				storekey: '',
			},
			orgList: [], //供应组织
			materialPropData: {}, //物料属性下拉
			btnType: [
				'copy',
				'revoke',
				's-p-t-g3',
				's-p-t-g4',
				'query',
				's-p-t-g5',
			], // 不需要显示的顶部按钮类型
			id: '',
			unitData: [], //单位
			customlist: [], //客户列表
			specificationlist: [], //供应商
			supplyOrglist: [], //供应组织
			materialPropList: [], //物料属性
			isDisabled: false,
			reqToken: '',
			dialogVisible: false,
			dialogImageUrl: '',
			materialList: [], //物料查询结果
			materialList1: [],
			materialList2: [],
			bomList: [], //BOM组织
			warehouseList: [], //发料仓库
			noticeType: [], //单据类型
			materialBear: [], //物料承担方
			flType: [], // 发料方式
			materialFx: [],
			materialCx: [],
			checkStatus: '',
			unitList: [],
			fxMaterialId: 0,
			cxMaterialId: 0,
			fxMaterialIds: [],
			cxMaterialIds: [],
			mateOrgId: 0,
			isSelWarehouse: false, //发料仓库是否可选择
			isEdit: false,
			operateType: '',
			recordIndex: '',
		};
	},
	methods: {
		Init() {
			// 获取单位、仓库、各种状态
			let vuexKey = ['unitAll', 'warehouseAll'];
			let setVuexData = ['setAllUnit', 'setWarehouseAll'];
			let requestQueryUrl = [
				'SysConfig/GetUnitAllProperty',
				'SysConfig/GetWarehouse',
			];
			let resDataQuery = ['unitList', 'warehouseList'];
			vuexKey.forEach((ele, ind) => {
				if (this[vuexKey[ind]] && this[vuexKey[ind]].length > 0) {
					if (typeof resDataQuery[ind] == 'string') {
						this[resDataQuery[ind]] = JSON.parse(
							JSON.stringify(this[vuexKey[ind]])
						);
					}
				} else {
					this.$http.get(requestQueryUrl[ind]).then((r) => {
						if (r.status === 200) {
							if (typeof resDataQuery[ind] == 'string') {
								this[resDataQuery[ind]] = r.data;
							}
							this[setVuexData[ind]](this[resDataQuery[ind]]);
						}
					});
				}
			});
			// 各种状态
			if (
				this.bomMaterilasObj &&
				JSON.stringify(this.bomMaterilasObj) !== '{}'
			) {
				this.InventoryType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.materialType)
				);
				this.supplyChainType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.supplyChainType)
				);
				this.productLocationType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.productLocationType)
				);
				this.brandType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.brandType)
				);
				this.safetyType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.safetyType)
				);
				this.materialPropData = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.materialPropertyType)
				);
				this.noticeType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.documentStatus)
				);
				this.flType = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.sendMaterialType)
				);
				this.materialBear = JSON.parse(
					JSON.stringify(this.bomMaterilasObj.materialBearType)
				);
			} else {
				this.$http.get('Materials/GetStatus').then((res) => {
					if (res.status == 200) {
						this.setBomMaterilasObj(res.data);
						this.InventoryType = res.data.materialType;
						this.supplyChainType = res.data.supplyChainType;
						this.productLocationType = res.data.productLocationType;
						this.brandType = res.data.brandType;
						this.safetyType = res.data.safetyType;
						this.materialPropData = res.data.materialPropertyType;
						this.noticeType = res.data.documentStatus;
						this.flType = res.data.sendMaterialType;
						this.materialBear = res.data.materialBearType;
					}
				});
			}
			// details = 明细信息  blacks = 组织使用明细
			let data = [];
			if (this.$route.query.type === 'add') {
				this.fromData.version = '';
				this.fromData.documentStatus = 'a';
				if (this.fromData.version) {
					this.isEditBom = true;
				}
			}
			if (this.$route.query.type === 'copy') {
				console.log('克隆');
				this.getDeatails();
			}
			if (this.$route.query.type === 'edit') {
				this.id = this.$route.query.id;
				this.getDeatails();
			}
			if (this.activeName == 'details') {
				data = JSON.parse(JSON.stringify(this.fromData.details));
			} else {
				data = JSON.parse(JSON.stringify(this.fromData.blacks));
			}
			// 获取添加对象
			let keys = Object.keys(data[0]);
			for (const key in data[0]) {
				if (keys.indexOf(key) > -1) {
					this.addRow[key] = data[0][key];
					this.addRow.id = 0;
				}
			}
		},
		// 是否禁用
		searchComC(value, key) {
			// console.log(value)
			this.fromData[key] = value;
		},
		getNameObj(arr, val) {
			return getObjectName(arr, val);
		},
		getName(arr, val) {
			return getArrayName(arr, val);
		},
		// 是否失效 清空
		clearCom(value, key) {
			if (value == '' || !value) {
				this.fromData[key] = '';
			}
		},
		// 验证输入百分比是数字，0，或者小数，首位不允许多个0
		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,4})?/) || [''])[0];
					} else {
						return (value
							.toString()
							.match(/\d{1,8}(\.\d{0,4})?/) || [''])[0];
					}
				}
				return (value.toString().match(/\d{1,8}(\.\d{0,4})?/) || [
					'',
				])[0];
			} else {
				return '';
			}
		},
		// 新增 + 复制 + 详情 进入
		getDeatails() {
			this.isLoading = true;
			this.$http
				.showLoading(false)
				.get('MaterialBom/Get/' + this.id)
				.then((res) => {
					if (res.status == 200) {
						this.fromData = res.data;
						this.fromData.version ? (this.isEditBom = true) : false;
						this.fromData.isDisable = this.fromData.isDisable + '';
						this.fromData.version = this.fromData.version
							? this.fromData.version
							: '';
						this.fromData.documentStatus = this.fromData
							.documentStatus
							? this.fromData.documentStatus
							: 'a';
						if (this.$route.query.type == 'copy') {
							this.fromData.version = '';
							this.isEditBom = false;
							this.fromData.documentStatus = 'a';
							this.fromData.id = 0;
							this.checkStatus = 'a';
							this.fromData.isUseCheck = false;
							this.matterCodeChange(this.fromData.materialNumber);
							this.fromData.details.forEach((el, ind) => {
								el.id = 0;
								el.materialBear =
									el.materialBear || el.materialBear == 0
										? el.materialBear
										: '';
							});
							if (
								Array.isArray(this.fromData.blacks) &&
								this.fromData.blacks.length
							) {
								this.fromData.blacks.forEach((item) => {
									item.id = 0;
								});
							}
							console.log(
								this.fromData,
								'============克隆数据================'
							);
						}
						//父单位
						let arr = [];
						arr = this.unitList.filter((item) => {
							if (this.fromData.unitId == item.id) {
								return item;
							} else {
								return null;
							}
						});
						if (arr.length > 0) {
							this.fromData.unitId = arr[0].id;
						} else {
							this.fromData.unitId = null;
						}
						this.fromData.details.forEach((item, index) => {
							item.overRatio = Decimal(item.overRatio); // .mul(100).toNumber();

							item.ffixscrapqty = Decimal(
								item.ffixscrapqty == '' ||
									item.ffixscrapqty == null ||
									item.ffixscrapqty == undefined
									? 0
									: item.ffixscrapqty
							)
								.mul(100)
								.toNumber();
							item.fissueType = item.fissueType + '';
							item.materialBear =
								item.materialBear || item.materialBear == 0
									? item.materialBear + ''
									: '';
							// 子单位
							let arr1 = [];
							arr1 = this.unitList.filter((item1) => {
								if (
									this.fromData.details[index].unitId ==
									item1.id
								) {
									return item1;
								} else {
									return null;
								}
							});
							if (arr1.length > 0) {
								this.fromData.details[index].unitId =
									arr1[0].id;
							} else {
								this.fromData.details[index].unitId = null;
							}
							//子项子单位
							let arr2 = [];
							arr2 = this.unitList.filter((item2) => {
								if (
									this.fromData.details[index].subUnitId ==
									item2.id
								) {
									return item2;
								} else {
									return null;
								}
							});
							if (arr2.length > 0) {
								this.fromData.details[index].subUnitId =
									arr2[0].id;
							} else {
								this.fromData.details[index].subUnitId = null;
							}
							item.isMaterialNumber = false;
							item.isSpecification = false;
							item.isNmerator = false;
							item.isDnominator = false;
							item.isFixscrapqty = false;
							item.isFissueType = false;
							item.isStockId = false;
							item.isOverRatio = false;
							item.isMaterialBear = false;
							item.isRemark = false;
						});
						this.fromData.blacks.forEach((item, index) => {
							this.supplyOrglist.forEach((item1, index1) => {
								if (item.orgId == item1.id) {
									item.paezOrgName = item1.name;
								}
							});
							item.isOrgId = false;
						});
						this.fromData = reactive(this.fromData);
						// 单据状态
						this.checkStatus = this.fromData.documentStatus;
						if (
							this.checkStatus == 'b' ||
							this.checkStatus == 'c'
						) {
							this.isEdit = true;
							// this.isSelWarehouse = true
						} else {
							this.isEdit = false;
							// this.isSelWarehouse = false
						}
						//根据发料方式来判断仓库是否可选
						this.fromData.details.forEach((item, index) => {
							this.fromData.details[index].isSelWarehouse =
								item.fissueType == '1' ? false : true;
							if (
								this.checkStatus == 'b' ||
								this.checkStatus == 'c'
							) {
								//审核中，或者已审核仓库不可编辑
								this.fromData.details[
									index
								].isSelWarehouse = true;
							}
						});
						this.fromData.details = reactive(this.fromData.details);
						// 获取详情页的初始值
						this.saveParams = {
							id: this.fromData.id,
							materialId: this.fromData.materialId,
							unitId: this.fromData.unitId,
							subUnitId: this.fromData.subUnitId,
							details: [],
							blacks: [],
						};
						let details = [];
						let blacks = [];
						this.getMaterialCustomerDataAll();
						this.fromData.details.forEach((item, index) => {
							details[index] = {
								id: item.id,
								seq: item.seq,
								materialId: item.materialId,
								unitId: item.unitId,
								subUnitId: item.subUnitId,
								numerator: Number(item.numerator),
								denominator: Number(item.denominator),
								ffixscrapqty: Decimal(
									item.ffixscrapqty == '' ||
										item.ffixscrapqty == null ||
										item.ffixscrapqty == undefined
										? 0
										: item.ffixscrapqty
								)
									.div(100)
									.toNumber(),

								materialBear:
									item.materialBear || item.materialBear == 0
										? item.materialBear + ''
										: '',
								overRatio: Decimal(item.overRatio), // .div(100).toNumber(),

								stockId: item.stockId,
								fissueType: item.fissueType + '',
								isEffect: item.isEffect,
								remark: item.remark,
								isKeyComponent: item.isKeyComponent,
							};
						});
						if (this.fromData.blacks.length == 0) {
							this.fromData.blacks[0] = {
								id: 0,
								seq: 1,
								orgId: '',
							};
						}
					}
					this.isLoading = false;
				});
		},
		async getMaterialCustomerDataAll() {
			let materQuery = this.fromData.details.map((it) => {
				return it.materialNumber;
			});
			let houseQuery = [];
			this.fromData.details.forEach((el) => {
				houseQuery.push(this.fromData.custId);
			});
			let _result = await this.matterCodeChangeAll(materQuery, 'Number');
			this.fromData.details.forEach((el, index) => {
				this.materialList1[index] = _result.filter((item) => {
					return item.number === el.materialNumber;
				});
			});
		},
		// 获取所有物料携带信息
		async matterCodeChangeAll(query, type) {
			if (query.length > 0) {
				return this.$http
					.post('SysConfig/GetMaterialLikeList', {
						names: query,
						file: type,
						orgId: this.mateOrgId,
					})
					.then((res) => {
						if (res.status === 200) {
							return res.data.reverse();
						} else {
							return [];
						}
					});
			} else {
				return [];
			}
		},
		// 选择发料方式
		changeFissuetype(item) {
			if (item.fissueType == '1') {
				item.isSelWarehouse = false;
				item.stockId = null;
			} else {
				item.isSelWarehouse = true;
				item.stockId = null;
			}
		},
		getMaterial(val, type) {
			this.materialList = [];
			if (val !== '') {
				setTimeout(() => {
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', {
							name: val,
							file: type,
							orgId: this.mateOrgId,
						})
						.then((res) => {
							if (res.status === 200) {
								this.materialList = res.data;
							}
						});
				}, 200);
			} else {
				this.materialList = [];
			}
		},
		// 根据物料编码 查询父物料
		matterCodeChange(val) {
			this.getMaterial(val, 'Number');
		},
		// 根据sku 查询父物料
		skuCodeChange(val) {
			this.getMaterial(val, 'Specifications');
		},
		// 获取父项物料 清空数据 循环物料编码
		metterFxChange(val) {
			this.fromData.materialNumber = '';
			this.fromData.materialId = '';
			this.fromData.materialName = '';
			this.fromData.unitId = '';
			this.fromData.unitIdName = '';
			this.fromData.name = '';
			this.fromData.specification = '';
			let metterInfo = {};
			this.materialList.forEach((item) => {
				if (item.id == val) {
					metterInfo = item;
				}
			});
			this.fxMaterialId = metterInfo.id;
			this.fxMaterialIds = [];
			if (this.cxMaterialId == this.fxMaterialId) {
				this.$message({
					type: 'error',
					message: '父项物料与子项物料不能相同！',
					showClose: true,
				});
				this.fromData.materialId = '';
				this.fromData.materialNumber = '';
				this.fromData.materialName = '';
				this.fromData.unitId = '';
				this.fromData.name = '';
				this.fromData.specification = '';
			} else {
				//找不到对应单位id,置空
				let arr = [];
				arr = this.unitList.filter((item1) => {
					if (metterInfo.baseUnitId == item1.id) {
						return item1;
					} else {
						return null;
					}
				});
				if (arr.length > 0) {
					this.fromData.unitId = arr[0].id;
				} else {
					this.fromData.unitId = null;
				}
				this.fromData.materialNumber = metterInfo.number;
				this.fromData.materialId = metterInfo.id;
				this.fromData.materialName = metterInfo.name;
				this.fromData.name = metterInfo.name;
				this.fromData.specification = metterInfo.specifications;
				// 获取该物料的所有父级
				this.$http
					.get(
						'MaterialBom/GetParentIdList/' +
							this.fromData.materialId
					)
					.then((res) => {
						if (res.status === 200) {
							this.fxMaterialIds = res.data;
						}
					});
			}
		},
		getMaterial1(val, type, copy, index) {
			this.materialList1[index] = [];
			if (val !== '') {
				setTimeout(() => {
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', {
							name: val,
							file: type,
							orgId: this.mateOrgId,
						})
						.then((res) => {
							if (res.status === 200) {
								this.materialList1[index] = res.data;
								if (copy) {
									this.metterCxChange(
										this.materialList1[index][0].id,
										index
									);
								}
							}
						});
				}, 200);
			} else {
				this.materialList1[index] = [];
			}
		},
		// 根据物料编码 查询子物料
		matterCodeChange1(val, index) {
			this.getMaterial1(val, 'Number', '', index);
		},
		// 根据sku 查询子物料
		skuCodeChange1(val, index) {
			this.getMaterial1(val, 'Specifications', '', index);
		},
		// 获取子物料  清空数据
		metterCxChange(val, index) {
			this.fromData.details[index].materialNumber = '';
			this.fromData.details[index].materialId = '';
			this.fromData.details[index].specification = '';
			this.fromData.details[index].materialName = '';
			this.fromData.details[index].subUnitId = '';
			this.fromData.details[index].subUnitIdName = '';
			this.fromData.details[index].unitId = '';
			this.fromData.details[index].unitIdName = '';
			this.fromData.details[index].cost = 0;
			let metterInfo = {};
			this.rowArr = [];
			//物料编码
			this.materialList1[index].forEach((item, i) => {
				if (item.id == val) {
					metterInfo = item;
					this.rowArr.push(item); // 批量操作带出来的字段
				}
			});
			this.cxMaterialId = metterInfo.id;
			this.cxMaterialIds = [];
			if (this.cxMaterialId == this.fxMaterialId) {
				this.$message({
					type: 'error',
					message: '父项物料与子项物料不能相同！',
					showClose: true,
				});
				this.fromData.details[index].materialNumber = '';
				this.fromData.details[index].materialId = '';
				this.fromData.details[index].specification = '';
				this.fromData.details[index].materialName = '';
				this.fromData.details[index].subUnitId = '';
				this.fromData.details[index].unitId = '';
				this.fromData.details[index].cost = 0;
			} else {
				//找不到对应单位id,置空
				let arr = [];
				arr = this.unitList.filter((item1) => {
					if (metterInfo.baseUnitId == item1.id) {
						//子项单位
						return item1;
					} else {
						return null;
					}
				});
				if (arr.length > 0) {
					this.fromData.details[index].unitId = arr[0].id;
				} else {
					this.fromData.details[index].unitId = null;
				}
				let arr1 = [];
				arr1 = this.unitList.filter((item1) => {
					if (metterInfo.subUnitId == item1.id) {
						//子单位
						return item1;
					} else {
						return null;
					}
				});
				if (arr1.length > 0) {
					this.fromData.details[index].subUnitId = arr[0].id;
				} else {
					this.fromData.details[index].subUnitId = null;
				}
				this.fromData.details[index].materialNumber = metterInfo.number;
				this.fromData.details[index].specification =
					metterInfo.specifications;
				this.fromData.details[index].materialName = metterInfo.name;
				this.fromData.details[index].materialId = metterInfo.id;
				this.fromData.details[index].cost = metterInfo.cost;
				// 获取该物料的所有子级
				// this.$http.get('MaterialBom/GetChildIdList/' + this.fromData.details[index].materialId).then(res => {
				//   if (res.status === 200) {
				//     this.cxMaterialIds = res.data
				//   }
				// })
			}
			this.fromData.details[index].isMaterialNumber = false;
			this.fromData.details[index].isSpecification = false;
			// document.getElementById(key + inde).blur()
		},
		// 选择物料分类
		changeMaterial(val) {
			let levelId = val[val.length - 1];
			this.fromData.groupId = levelId;
		},
		//tab切换
		handleClick(name) {
			this.activeName = name;
			let data = [];
			if (this.activeName == 'details') {
				data = JSON.parse(JSON.stringify(this.fromData.details));
			} else {
				data = JSON.parse(JSON.stringify(this.fromData.blacks));
			}
			let keys = Object.keys(data[0]); // 获取添加对象
			for (const key in data[0]) {
				if (keys.indexOf(key) > -1) {
					if (this.activeName == 'details') {
						this.addRow[key] = data[0][key];
						this.addRow.childBomId = 0;
						this.addRow.cost = 0;
						this.addRow.denominator = 1;
						this.addRow.ffixscrapqty = 0;
						this.addRow.fissueType = '1';
						this.addRow.id = 0;
						this.addRow.isEffect = false;
						this.addRow.isKeyComponent = false;
						this.addRow.isSelWarehouse = false;
						this.addRow.materialBear = '';
						this.addRow.materialId = '';
						this.addRow.materialName = '';
						this.addRow.materialNumber = '';
						this.addRow.materialProperty = '';
						this.addRow.numerator = 1;
						this.addRow.overRatio = 10000;
						this.addRow.remark = '';
						this.addRow.seq = null;
						this.addRow.specification = '';
						this.addRow.stockId = '';
						this.addRow.subUnitId = null;
						this.addRow.subUnitIdName = '';
						this.addRow.unitId = null;
						this.addRow.unitIdName = '';
					} else {
						this.addRow[key] = data[0][key];
						this.addRow.id = 0;
						this.addRow.orgId = '';
					}
				}
			}
		},
		// 失焦处理
		selectBlur() {
			let _this = this;
			let type = _this.activeName == 'details' ? 'details' : 'blacks';
			_this.fromData[type].forEach((el) => {
				if (type == 'details') {
					el.isMaterialNumber = false;
					el.isSpecification = false;
					el.isNmerator = false;
					el.isDnominator = false;
					el.isFixscrapqty = false;
					el.isFissueType = false;
					el.isStockId = false;
					el.isOverRatio = false;
					el.isMaterialBear = false;
					el.isRemark = false;
				} else {
					el.isOrgId = false;
				}
			});
		},
		// 批量操作的单元格
		batchClick(value, key, row, column) {
			if (
				key === 'ffixscrapqty' ||
				key === 'overRatio' ||
				key === 'numerator' ||
				key === 'denominator'
			) {
				row[key] = this.numberRexgu(value);
				this.storeObj.storeVal = row[key];
			} else {
				this.storeObj.storeVal = value;
			}
			if (key === 'orgId') {
				this.fromData.blacks[row.index].isOrgId = false;
			}
			this.currRow = row.index;
			this.storeObj.storekey = key;
			this.storeObj.storeRow = row.index;
			this.storeObj.storeCol = column.index;
		},
		// 插入的行
		getInsertInfo() {
			let _this = this;
			let type = _this.activeName == 'details' ? 'details' : 'blacks';
			_this.fromData[type] = bottomAddRow(
				_this.fromData[type],
				JSON.parse(JSON.stringify(_this.addRow))
			);
			_this.activeName == 'details'
				? _this.materialList1.splice(_this.fromData[type].length, 0, [])
				: false;
			if (_this.activeName == 'details') {
				this.$nextTick(() => {
					this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
						this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
				});
			} else {
				this.$nextTick(() => {
					this.$refs.multipleTable1.$refs.bodyWrapper.scrollTop =
						this.$refs.multipleTable1.$refs.bodyWrapper.scrollHeight;
				});
			}
			_this.selectBlur();
			_this.$refs.multipleTable.clearSelection();
			_this.$refs.multipleTable1.clearSelection();
			// if (data.insertTopVal != 0 && data.insertTopVal != '') {
			//   for (let i = 0; i < data.insertTopVal; i++) {
			//     if (this.activeName == 'details') {
			//       this.fromData.details.splice(this.selectRowIndex, 0, JSON.parse(JSON.stringify(this.addRow)))
			//       this.materialList1.splice(this.selectRowIndex, 0, [])
			//     } else {
			//       this.fromData.blacks.splice(this.selectRowIndex, 0, JSON.parse(JSON.stringify(this.addRow)))
			//     }
			//     this.selectRowIndex = parseInt(this.selectRowIndex) + 1
			//   }
			// }
			// if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
			//   for (let i = 0; i < data.insertBottomVal; i++) {
			//     this.selectRowIndex = parseInt(this.selectRowIndex) + 1
			//     if (this.activeName == 'details') {
			//       this.fromData.details.splice(this.selectRowIndex, 0, JSON.parse(JSON.stringify(this.addRow)))
			//       this.materialList1.splice(this.selectRowIndex, 0, [])
			//     } else {
			//       this.fromData.blacks.splice(this.selectRowIndex, 0, JSON.parse(JSON.stringify(this.addRow)))
			//     }
			//   }
			//   this.selectRowIndex = this.selectRowIndex - data.insertBottomVal // 回朔
			// }
		},
		// 向下复制行
		bottomCopyRow() {
			// 向下复制行
			let listKey = this.activeName == 'details' ? 'details' : 'blacks';
			if (this.selectRowIndexArr.length > 0) {
				if (this.selectRowIndexArr.length == 1) {
					let tableArr = JSON.parse(
						JSON.stringify(
							this.fromData[listKey][this.selectRowIndex]
						)
					);
					let insertNum = this.selectRowIndex + 1;
					this.materialList1.splice(
						insertNum,
						0,
						this.materialList1[this.selectRowIndex]
					);
					this.fromData[listKey].splice(insertNum, 0, tableArr);
					this.fromData[listKey][insertNum].id = 0;
				} else {
					// 获取最后选择的行
					let lastIndex = -1;
					this.selectRowIndexArr.forEach((el) => {
						el > lastIndex ? (lastIndex = el) : false;
					});
					// 添加行
					this.selectRowIndexArr.forEach((el) => {
						lastIndex = lastIndex + 1;
						let tableArr = JSON.parse(
							JSON.stringify(this.fromData[listKey][el])
						);
						this.materialList1.splice(
							lastIndex,
							0,
							this.materialList1[el]
						);
						this.fromData[listKey].splice(lastIndex, 0, tableArr);
						this.fromData[listKey][lastIndex].id = 0;
					});
				}
				this.selectBlur();
				this.$refs.multipleTable.clearSelection();
				this.$refs.multipleTable1.clearSelection();
				this.selectRowIndexArr = [];
			} else {
				this.$message.error({
					message: '请选择一行或多行复制!',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow() {
			let datas = [];
			if (this.activeName == 'details') {
				datas = this.fromData.details;
			} else {
				datas = this.fromData.blacks;
			}
			if (
				datas.length > 1 &&
				datas.length != this.selectRowIndexArr.length
			) {
				// 不能为空
				if (this.selectRowIndexArr.length != 0) {
					this.selectRowIndexArr.sort(function (a, b) {
						return a - b;
					});
					for (let i = 0; i < this.selectRowIndexArr.length; i++) {
						// 删除一次索引就变一次
						datas.splice(this.selectRowIndexArr[i] - i, 1);
						this.materialList1.splice(
							this.selectRowIndexArr[i] - i,
							1
						);
					}
					let numberList = [
						'isMaterialNumber',
						'isSpecification',
						'isNmerator',
						'isDnominator',
						'isFixscrapqty',
						'isFissueType',
						'isStockId',
						'isOverRatio',
						'isMaterialBear',
						'isRemark',
					];
					this.fromData.details.forEach((ele, inde) => {
						numberList.forEach((el) => {
							ele[el] = false;
						});
					});
					this.selectBlur();
					this.$refs.multipleTable.clearSelection();
					this.$refs.multipleTable1.clearSelection();
					this.selectRowIndexArr = [];
					this.recordIndex = '';
				} else {
					this.$message.error({
						message: '请先选择要删除的行',
						showClose: true,
					});
				}
			} else {
				this.$message.error({
					message: '表格不能为空!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn() {
			let datas = [];
			if (this.activeName == 'details') {
				datas = this.fromData.details;
			} else {
				datas = this.fromData.blacks;
			}
			let nextRow = this.storeObj.storeRow + 1;
			let storeKey = this.storeObj.storekey;
			for (let i = nextRow; i < datas.length; i++) {
				for (const key in datas[i]) {
					if (key === storeKey) {
						if (key === 'materialId') {
							datas[i][key] = this.storeObj.storeVal;
							this.rowArr.forEach((el) => {
								if (el.id === datas[i - 1].materialId) {
									datas[i].materialId = el.id;
									datas[i].materialNumber = el.number;
									datas[i].specification = el.specifications;
									datas[i].materialName = el.name;
									datas[i].subUnitId = el.subUnitId;
									datas[i].unitId = el.baseUnitId;
									datas[i].cost = el.cost;
									//根据id获取单位名称
									let arr = [];
									arr = this.unitList.filter((item1) => {
										if (datas[i].unitId == item1.id) {
											//子项单位
											return item1;
										} else {
											return null;
										}
									});
									if (arr.length > 0) {
										datas[i].unitId = arr[0].id;
									} else {
										datas[i].unitId = null;
									}
									let arr1 = [];
									arr1 = this.unitList.filter((item1) => {
										if (datas[i].subUnitId == item1.id) {
											//子单位
											return item1;
										} else {
											return null;
										}
									});
									if (arr1.length > 0) {
										datas[i].subUnitId = arr[0].id;
									} else {
										datas[i].subUnitId = null;
									}
								}
							});
						} else if (key == 'fissueType') {
							datas[i][key] = this.storeObj.storeVal;
							if (datas[i].fissueType == '1') {
								//1--直接领料 2--直接倒冲
								datas[i].isSelWarehouse = false;
								datas[i].stockId = null;
							} else {
								datas[i].isSelWarehouse = true;
								datas[i].stockId = null;
							}
						} else if (key == 'stockId') {
							//仓库
							datas[i][key] = this.storeObj.storeVal;
							// if (datas[i].fissueType == '1') {
							//   datas[i][key] = this.storeObj.storeVal
							// } else {
							//   continue
							// }
						} else {
							datas[i][key] = this.storeObj.storeVal;
						}
					}
				}
			}
		},
		getRowCol1(row, column) {
			let _that = this;
			_that.currRow = row.index;
			_that.storeObj.storeRow = row.index;
			_that.storeObj.storeCol = column.index;

			if (_that.recordIndex != '' || _that.recordIndex == '0') {
				_that.fromData.details[_that.recordIndex].isOrgId = false;
			}

			switch (column.label) {
				case '不使用该BOM组织':
					row.isOrgId = true;
					_that.recordIndex = row.index;
					break;
			}
		},
		// 单元格被点击
		getRowCol(row, column) {
			let _that = this;
			_that.currRow = row.index;
			_that.storeObj.storeRow = row.index;
			_that.storeObj.storeCol = column.index;

			if (_that.recordIndex != '' || _that.recordIndex == '0') {
				_that.fromData.details[
					_that.recordIndex
				].isMaterialNumber = false;
				_that.fromData.details[
					_that.recordIndex
				].isSpecification = false;
				_that.fromData.details[_that.recordIndex].isNmerator = false;
				_that.fromData.details[_that.recordIndex].isDnominator = false;
				_that.fromData.details[_that.recordIndex].isFixscrapqty = false;
				_that.fromData.details[_that.recordIndex].isFissueType = false;
				_that.fromData.details[_that.recordIndex].isStockId = false;
				_that.fromData.details[_that.recordIndex].isOverRatio = false;
				_that.fromData.details[
					_that.recordIndex
				].isMaterialBear = false;
				_that.fromData.details[_that.recordIndex].isRemark = false;
			}

			switch (column.label) {
				case '子项物料编码':
					row.isMaterialNumber = true;
					_that.recordIndex = row.index;
					break;
				case '规格型号(SKU)':
					row.isSpecification = true;
					_that.recordIndex = row.index;
					break;
				case '用量：分子':
					row.isNmerator = true;
					_that.recordIndex = row.index;
					break;
				case '用量：分母':
					row.isDnominator = true;
					_that.recordIndex = row.index;
					break;
				case '损耗率%':
					row.isFixscrapqty = true;
					_that.recordIndex = row.index;
					break;
				case '发料方式':
					row.isFissueType = true;
					_that.recordIndex = row.index;
					break;
				case '默认发料仓库':
					row.isStockId = true;
					_that.recordIndex = row.index;
					break;
				case '超发比例%':
					row.isOverRatio = true;
					_that.recordIndex = row.index;
					break;
				case '物料承担方':
					row.isMaterialBear = true;
					_that.recordIndex = row.index;
					break;
				case '位置号/模号/备注':
					row.isRemark = true;
					_that.recordIndex = row.index;
					break;
			}

			this.$nextTick(() => {
				let strArr = [
					'子项物料编码',
					'规格型号(SKU)',
					'用量：分子',
					'用量：分母',
					'损耗率%',
					'发料方式',
					'默认发料仓库',
					'超发比例%',
					'物料承担方',
					'位置号/模号/备注',
				];
				if (strArr.indexOf(column.label) !== -1) {
					document
						.getElementById(column.property + row.index)
						.focus();
				}
			});
		},
		// 明细选择行的数据处理
		selectdataSet(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (row) {
				this.selectRowIndex = row.index;
			}
			if (selection && selection.length > 0) {
				this.selectRowIndex = selection[0].index;
			}
			if (selection.length != 0) {
				this.selectRowIndexArr = selection.map((it) => {
					return it.index;
				});
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 选择全部明细(全选)
		selectAll(selection) {
			this.selectdataSet(selection);
		},
		// 选择的行（单选）
		selectRow(selection, row) {
			this.selectdataSet(selection);
		},
		// 星星--头部必填ico显示
		mustAfter(obj) {
			let arry = [1, 2];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},

		// 表格cell类名--解构
		tableCellClassName({ row, column, rowIndex, columnIndex }) {
			//利用单元格的 className 的回调方法，给行列索引赋值
			row.index = rowIndex;
			column.index = columnIndex;
		},
		// 顶部公共按钮操作
		actionhandel(type) {
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			if (type == 'add') {
				this.$router.push({
					path: '/material/mateBom/mateBomSet',
					query: { type: 'add', id: '', tags: Math.random() * 36 },
				});
			}
			let ids = [];
			ids.push(this.id);
			// 点击撤销 - 审核 - 反审 - 删除
			if (type === 'revoke') {
				if (this.checkStatus === 'b') {
					this.toolarFn('MaterialBom/Revoke', ids, 'revoke');
					return false;
				} else {
					this.$message({
						type: 'error',
						message: '该状态不可进行撤销操作！',
						showClose: true,
					});
				}
			}
			// 点击审核
			if (type === 'audit') {
				if (this.checkStatus === 'b') {
					this.toolarFn('MaterialBom/Check', ids, 'audit');
					return false;
				} else {
					this.$message({
						type: 'error',
						message: '该状态不可进行审核操作！',
						showClose: true,
					});
				}
			}
			// 点击反审核
			if (type === 'de-approval') {
				if (this.checkStatus === 'c') {
					this.toolarFn('MaterialBom/NoCheck', ids, 'de-approval');
					return false;
				} else {
					this.$message({
						type: 'error',
						message: '该状态不可进行反审核操作！',
						showClose: true,
					});
				}
			}
			this.saveParams = {
				id: this.fromData.id ? this.fromData.id : 0,
				materialId: this.fromData.materialId,
				parentIds: this.fxMaterialIds,
				isDisable: this.fromData.isDisable
					? this.fromData.isDisable == 'true'
						? true
						: false
					: false,
				details: [],
				blacks: [],
			};
			// 没有数据不提交给后端
			this.fromData.blacks.forEach((item, index) => {
				if (item.orgId) {
					this.saveParams.blacks[index] = {
						id: item.id ? item.id : 0,
						seq: index + 1,
						orgId: item.orgId,
					};
				}
			});
			this.fromData.details.forEach((item, index) => {
				// 分子 分母
				if (item.numerator == '' || item.numerator == null) {
					item.numerator = 1;
				}
				if (item.denominator == '' || item.denominator == null) {
					item.denominator = 1;
				}
				if (item.overRatio == '' || item.overRatio == null) {
					//超发比例
					item.overRatio = 10000;
				}
				if (item.materialId != '') {
					this.saveParams.details[index] = {
						id: item.id ? item.id : 0,
						seq: index + 1,
						materialId: item.materialId,
						childIds: this.cxMaterialIds,
						numerator: Number(item.numerator),
						denominator: Number(item.denominator),
						ffixscrapqty: Decimal(
							item.ffixscrapqty == '' ||
								item.ffixscrapqty == null ||
								item.ffixscrapqty == undefined
								? 0
								: item.ffixscrapqty
						)
							.div(100)
							.toNumber(),
						materialBear:
							item.materialBear || item.materialBear == 0
								? item.materialBear + ''
								: '',
						overRatio: Decimal(item.overRatio), // .div(100).toNumber()
						stockId: item.stockId,
						fissueType: item.fissueType + '',
						isEffect: item.isEffect,
						remark: item.remark,
						isKeyComponent: item.isKeyComponent,
					};
				}
			});
			// 保存 - 提交
			if (type === 'save' || type === 'submit') {
				let pathName =
					type === 'save' ? 'MaterialBom/Save' : 'MaterialBom/Commit';
				let msg = '存在相同的子物料,请修改后再提交!';
				let resMsg = type === 'save' ? '保存成功!' : '提交成功!';
				const ids = this.saveParams.details.map(
					(value) => value.materialId
				);
				const idsSet = new Set(ids);
				if (idsSet.size != ids.length) {
					this.$message({
						type: 'error',
						message: msg,
						showClose: true,
					});
					return false;
				}
				filterMaterialData(this.saveParams);
				this.saveParams.version = this.fromData.version;
				this.$http
					.showLoading(true)
					.post(pathName, this.saveParams)
					.then((res) => {
						if (res.status == 200) {
							this.$message({
								type: 'success',
								message: resMsg,
								showClose: true,
							});
							this.saveSubmitGetData(res, type);
						}
					});
			}
		},
		formatNumber(num) {
			const formattedNumber = num.toFixed(4);

			// 使用正则表达式去除非零后面的零
			const regex = /\.?0+$/;
			return formattedNumber.replace(regex, '');
		},

		// 处理保存提交返回来的数据
		saveSubmitGetData(res, type) {
			res.data.details.forEach((el, ind) => {
				el.overRatio = Decimal(el.overRatio); //.mul(100).toNumber();
				el.ffixscrapqty = this.formatNumber(
					Decimal(el.ffixscrapqty).mul(100).toNumber()
				);
				el.fissueType = el.fissueType + '';
				el.materialBear =
					el.materialBear || el.materialBear == 0
						? el.materialBear + ''
						: '';
			});
			this.id = res.data.id;
			this.fromData = res.data;
			this.fromData.isDisable = this.fromData.isDisable + '';
			this.fromData.version ? (this.isEditBom = true) : false;
			this.saveParams = res.data;
			if (this.fromData.blacks.length == 0) {
				this.fromData.blacks = [
					{
						id: null,
						seq: 1,
						orgId: null,
					},
				];
			}
			type === 'submit' ? (this.checkStatus = 'b') : false;
		},
		// 顶部操作方法-公共部分封装
		toolarFn(path, newArry, type) {
			let formdata = { ids: newArry };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					if (res.data) {
						res.data[0].isSuccess
							? this.$message.success({
									message: res.data[0].msg
										? res.data[0].msg
										: '成功',
									showClose: true,
							  })
							: this.$message.error({
									message: res.data[0].msg,
									showClose: true,
							  });
						type === 'revoke'
							? res.data[0].isSuccess
								? (this.isEdit = false)
								: false
							: false;
						type === 'revoke'
							? res.data[0].isSuccess
								? (this.fromData.documentStatus = 'a')
								: false
							: false;
						type === 'de-approval'
							? res.data[0].isSuccess
								? (this.isEdit = false)
								: false
							: false;
						type === 'de-approval'
							? res.data[0].isSuccess
								? (this.fromData.documentStatus = 'd')
								: false
							: false;
						type === 'de-approval'
							? res.data[0].isSuccess
								? (this.checkStatus = 'd')
								: false
							: false;
						type === 'audit'
							? res.data[0].isSuccess
								? (this.isEdit = true)
								: false
							: false;
						type === 'audit'
							? res.data[0].isSuccess
								? (this.fromData.documentStatus = 'c')
								: false
							: false;
						type === 'audit'
							? res.data[0].isSuccess
								? (this.checkStatus = 'c')
								: false
							: false;
					}
					if (type == 'audit' || type === 'de-approval') {
						this.$http
							.showLoading(false)
							.get('MaterialBom/Get/' + this.id)
							.then((res) => {
								if (res.status == 200) {
									this.fromData = res.data;
									this.fromData.isDisable =
										this.fromData.isDisable + '';
									this.fromData.details[0].fissueType =
										this.fromData.details[0].fissueType +
										'';
									this.fromData.details.forEach((item) => {
										item.ffixscrapqty = (
											Number(item.ffixscrapqty) * 100
										).toFixed(4);
									});
								}
							});
					}
				} else {
					if (
						this.operateType == 'save' ||
						this.operateType == 'submit' ||
						this.operateType == 'revoke' ||
						this.operateType == 'audit' ||
						this.operateType == 'de-approval'
					) {
						this.$message({
							type: 'error',
							message: res.message,
							showClose: true,
						});
					}
				}
			});
		},
		// 复制粘贴
		pasteExcel(event, index, scope, key) {
			let result = copyValueMethods(event, this.storeObj.storeVal);
			setTimeout(async () => {
				if (result.isPasteOneCol) {
					this.fromData.details[index][key] = result.oldVal;
					this.$message.error({
						message: '请选择一列复制粘贴!',
						showClose: true,
					});
					return;
				}
				let recordAddIndex = index;
				for (let i = 0; i < result.rows.length; i++) {
					if (result.rows[i] !== '') {
						if (key === 'remark') {
							if (
								this.fromData.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								let num = result.rows[i] * 1;
								if (!isNaN(num)) {
									this.fromData.details[recordAddIndex][key] =
										num + '';
								} else {
									this.$message.error({
										message:
											'粘贴内容有误,请重新选择复制内容!',
										showClose: true,
									});
									return;
								}
							}
							recordAddIndex++;
						} else if (
							key === 'ffixscrapqty' ||
							key === 'overRatio' ||
							key === 'numerator' ||
							key === 'denominator'
						) {
							let key = scope.column.property;
							let num = result.rows[i] * 1;
							if (!isNaN(num)) {
								this.fromData.details[recordAddIndex][key] =
									this.numberRexgu(num);
							} else {
								this.$message.error({
									message: '粘贴内容有误,请重新选择复制内容!',
									showClose: true,
								});
								return;
							}
							recordAddIndex++;
						} else if (
							key === 'materialNumber' ||
							key === 'specification'
						) {
							if (key === 'materialNumber') {
								this.fromData.details[recordAddIndex][key] =
									result.rows[i];
								this.getMaterial1(
									result.rows[i],
									'Number',
									'copy',
									recordAddIndex
								);
							}
							if (key === 'specification') {
								this.fromData.details[recordAddIndex][key] =
									result.rows[i];
								this.getMaterial1(
									result.rows[i],
									'Specifications',
									'copy',
									recordAddIndex
								);
							}
							recordAddIndex++;
						}
					}
				}
			}, 0);
		},
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setWarehouseAll: 'storeData/setWarehouseAll',
			setBomMaterilasObj: 'storeData/setBomMaterilasObj',
		}),
	},
	computed: {
		...mapState({
			// 获取当前组织 - 标签
			orgId: (state) => (state && state.user ? state.user.orgId : null),
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			tags: (state) => state.topNavTag.tags,
			unitAll: (state) => state.storeData.allUnit,
			warehouseAll: (state) => state.storeData.warehouseAll,
			bomMaterilasObj: (state) => state.storeData.bomMaterilasObj,
		}),
		// // 监听组织ID
		// orgIdChange() {
		//   return this.$store.state && this.$store.state.org ? this.$store.state.org.orgId : null
		// }
	},
	watch: {
		orgId(value) {
			this.orgId = value;
		},
		// 数据状态发生改变时
		'fromData.documentStatus'() {
			// 标签名字修改
			if (
				this.fromData.documentStatus === 'a' ||
				this.fromData.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增物料清单');
			} else {
				this.$topNavTagRename('编辑物料清单');
			}
			// 不需要显示的顶部按钮类型
			if (
				this.fromData.documentStatus === 'a' ||
				this.fromData.documentStatus === 'd'
			) {
				this.btnType = [
					'add',
					'copy',
					'revoke',
					'audit',
					'de-approval',
					'delete',
					'push-down',
					'query',
					'refresh',
					's-p-t-g3',
					'operation',
					's-p-t-g4',
				];
				this.isEdit = false;
			} else {
				this.btnType = [
					'copy',
					's-p-t-g4',
					'query',
					's-p-t-g5',
					'delete',
				];
				this.isEdit = true;
			}
		},
		// 组织改变清空物料数据
		orgIdChange: function () {},
	},
	created() {
		this.id = this.$route.query.id;
		this.heightNum =
			document.documentElement.clientHeight - (40 + 30 + 16 + 16);
		this.Init();
		this.reqToken = localStorage.getItem('userToken');
		this.orgList = this.orgIdArr;
		this.supplyOrglist = this.orgIdArr;
		this.mateOrgId = this.$store.state.org
			? this.$store.state.org.orgId
			: null;
	},
	activated() {
		this.mateOrgId = this.$store.state.org
			? this.$store.state.org.orgId
			: null;
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderDetails.scss';
@import '@/assets/style/materialBom/bom.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
