<template>
	<div>
		<transition name="bounce">
			<examineTop
				v-if="isExmaineTop === 2"
				:radios="radios"
				@handleBtns="handleBtns"
				@handleOpen="handleOpen"
				:isexamineBtns="isexamineBtns"
			/>
			<!-- 	:isexamineBtns="isexamineBtns" -->
		</transition>
	</div>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="sale-details-container order-mc-bg main-container"
	>
		<div class="sale-details-btn-group">
			<!-- 打印摸版组件-->
			<div v-if="printTablelist.length">
				<prtMoledop
					:printData="{
						tableData: printTablelist,
						orderName: '生产用料清单',
						ids: printIds,
					}"
					:theadDate="theadDate"
					v-show="false"
				>
				</prtMoledop>
			</div>
			<!-- 顶部按钮 -->
			<template v-if="isExmaineTop !== 2">
				<toolBtn
					:btnType="btnType"
					:isDisable="isDisable"
					@actionhandel="actionhandel"
					:isExmaineTop="isShow"
				></toolBtn>
			</template>
		</div>
		<div class="sale-details-base-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				v-if="pagefromData.documentStatus === 'c'"
			/>
			<el-tabs style="margin-bottom: 8px" type="border-card">
				<!-- 基本信息 -->
				<el-tab-pane label="基本信息">
					<div class="base-info-form-box">
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<div class="order-number-bx item-bt-s">
											<el-form-item
												class="Iisshow"
												label="生产订单号"
											>
												<el-input
													:disabled="
														pagefromData.documentStatus !==
															'a' &&
														pagefromData.documentStatus !==
															'd'
													"
													:maxlength="255"
													placeholder="(保存时自动生成)"
													v-model.trim="
														pagefromData.produceNo
													"
												/>
												<div
													:data-clipboard-text="
														pagefromData.produceNo
													"
													@click="saleOrderCopy"
													class="copyBtn"
												>
													<i
														class="el-icon-document-copy"
													/>
												</div>
											</el-form-item>
										</div>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="生产订单类型"
										>
											<el-select
												disabled
												filterable
												v-model="
													pagefromData.documentType
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in documentTypelist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s item-date"
											label="下单日期"
										>
											<el-date-picker
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												format="YYYY-MM-DD"
												type="date"
												v-model="pagefromData.date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												placeholder="请选择单据状态"
												v-model="
													pagefromData.documentStatus
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in documentStatuslist"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="生产组织"
										>
											<el-select
												:disabled="
													pagefromData.documentStatus !==
														'a' ||
													($route.query.type ===
														'pushDown' &&
														!!pagefromData.parentOrderId) ||
													$route.query.type ===
														'pushDown'
												"
												@change="orgChange"
												filterable
												placeholder="请选择组织"
												v-model="pagefromData.prdorgId"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in orgIdArr"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item label="数据来源">
											<el-select
												@change="orgChange"
												disabled
												filterable
												v-model="
													pagefromData.dataSources
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													class="f-12"
													v-for="(
														value, key, index
													) in dataSourcesList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="备注"
											style="margin: 20px 0"
										>
											<el-input
												type="textarea"
												:maxlength="255"
												:rows="5"
												class="bz"
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												autosize
												placeholder="请输入内容"
												v-model="pagefromData.remark"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<!-- 操作记录 -->
				<el-tab-pane :disabled="!pagefromData.id" label="操作记录">
					<div
						:style="{ height: '185px!important' }"
						class="base-info-form-box"
					>
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="创建人"
										>
											<el-input
												disabled
												v-model.trim="
													pagefromData.createName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="创建日期"
										>
											<el-input
												disabled
												v-model.trim="
													pagefromData.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
												v-model.trim="
													pagefromData.modifyName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												disabled
												v-model.trim="
													pagefromData.modifyDate
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="提交时间"
										>
											<el-input
												disabled
												v-model.trim="
													pagefromData.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
														v-model.trim="
															pagefromData.checkName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														disabled
														v-model.trim="
															pagefromData.checkDate
														"
													></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-tell-info">
			<div class="tell-info-row-title">
				<h3>明细信息</h3>
				<div class="long-line-bx">
					<div class="long-line"></div>
				</div>
			</div>
			<!-- 明细工具栏 -->
			<div class="tell-info-button-group">
				<DetailsOperation
					:deviationSelectArr="selectRowIndexArr"
					:isEdit="
						pagefromData.documentStatus !== 'a' &&
						pagefromData.documentStatus !== 'd'
					"
					@copyCellcolumn="copyCellcolumn"
					@copyRow="bottomCopyRow"
					@deleteRow="selectDeleteRow"
					@insertObj="getInsertInfo"
				></DetailsOperation>
			</div>
			<!-- 表格信息-->
			<div class="tell-info-table">
				<el-table
					:cell-class-name="tableCellClassName"
					:data="pagefromData.details"
					:header-cell-class-name="mustAfter"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectRowAll"
					border
					max-height="400"
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
				>
					<el-table-column
						align="center"
						fixed
						type="selection"
						width="40"
					/>
					<el-table-column align="left" prop="salOrderNo" width="280">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>销售订单号
						</template>
						<template #default="scope">
							<div v-if="scope.row.issalOrderNoshow">
								<el-input
									:disabled="
										(pagefromData.documentStatus !== 'a' &&
											pagefromData.documentStatus !==
												'd') ||
										($route.query.type === 'pushDown' &&
											!!scope.row.parentOrderId)
									"
									:id="'salOrderNo' + scope.$index"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'salOrderNo'
										)
									"
									placeholder="请输入关键词"
									v-model.trim="scope.row.salOrderNo"
								></el-input>
							</div>
							<div v-else>
								<span>{{ scope.row.salOrderNo }}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="expectDate" width="150">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>期望交期
						</template>
						<template #default="scope">
							<el-date-picker
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:disabledDate="
									(data) => {
										return (
											data.getTime() <
											Date.now() - 24 * 60 * 60 * 1000
										);
									}
								"
								:id="'expectDate' + scope.$index"
								class="item-date"
								format="YYYY-MM-DD"
								placeholder="选择日期"
								type="date"
								v-if="scope.row.isexpectDateshow"
								v-model="scope.row.expectDate"
								value-format="YYYY-MM-DD"
							></el-date-picker>
							<span v-else>{{ scope.row.expectDate }}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="materialId" width="190">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope">
							<el-select
								:id="'materialId' + scope.$index"
								:disabled="
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									($route.query.type === 'pushDown' &&
										!!scope.row.parentOrderId)
								"
								:loading="loading"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											'materialId',
											scope.$index
										);
									}
								"
								@change="metterChange($event, scope.$index)"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'materialId'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'materialId'
									)
								"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.ismaterialshow"
								v-model="scope.row.materialId"
							>
								<el-option
									:key="item.idr"
									:label="item.number"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in matterallCodelist[
										scope.$index
									]"
								></el-option>
							</el-select>
							<span v-else>{{ scope.row.materialNumber }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						prop="specification"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>规格型号(SKU)
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									($route.query.type === 'pushDown' &&
										!!scope.row.parentOrderId)
								"
								:id="'specification' + scope.$index"
								:loading="loading"
								:remote-method="
									(query) => {
										specificationChange(
											query,
											'specification',
											scope.$index
										);
									}
								"
								@change="
									metterChange(
										$event,
										scope.$index,
										'specification'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'specification'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'specification'
									)
								"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isspecificationshow"
								v-model="scope.row.specification"
							>
								<el-option
									:key="item.id + item.number"
									:label="item.specifications"
									:value="item.specifications"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in specificationalllist[
										scope.$index
									]"
								></el-option>
							</el-select>
							<span v-else>{{ scope.row.specification }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="150"
					></el-table-column>
					<el-table-column
						align="left"
						label="单位"
						prop="unitId"
						width="108"
					>
						<template #default="scope">
							<span>{{
								scope.row.unitId
									? publicidbyname(unitlist, scope.row.unitId)
									: null
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="number" width="120">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>数量
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'number' + scope.$index"
								:maxlength="11"
								@blur="
									numberChage(
										scope.row.number,
										scope.$index,
										scope.row,
										'number'
									)
								"
								@click="
									getRowCol(scope.row, scope.column, 'number')
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'number'
									)
								"
								placeholder="0"
								v-if="scope.row.isnumbershow"
								v-model="scope.row.number"
							></el-input>
							<span v-else>{{ scope.row.number }}</span>
						</template>
					</el-table-column>

					<el-table-column align="left" prop="stockId" width="250">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>仓库
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									scope.row.pushkey
								"
								:id="'stockId' + scope.$index"
								@change="changeWarehouse($event, scope.$index)"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'stockId'
									)
								"
								filterable
								placeholder="请选择"
								v-if="scope.row.isstockIdshow"
								v-model="scope.row.stockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									v-for="item in warehouse"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
								></el-option>
							</el-select>
							<span v-else>{{
								scope.row.stockId
									? publicidbyname(
											warehouse,
											scope.row.stockId
									  )
									: null
							}}</span>
						</template>
					</el-table-column>

					<el-table-column
						align="left"
						label="业务状态"
						prop="status"
						width="130"
					>
						<template #default="scope">
							<span>{{
								scope.row.status
									? publicidbyname(
											produceBusinessStatuslist,
											scope.row.status
									  )
									: null
							}}</span>
						</template>
					</el-table-column>

					<el-table-column
						align="left"
						prop="planDateTime"
						width="200"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>计划日期（开工 ~ 完工）
						</template>
						<template #default="scope">
							<div>
								<el-date-picker
									id="sc"
									:disabled="
										pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd'
									"
									@change="
										planDateTimechange($event, scope.$index)
									"
									class="f-12 sc"
									end-placeholder="结束日期"
									format="YYYY-MM-DD"
									range-separator="至"
									start-placeholder="开始日期"
									type="daterange"
									v-if="scope.row.isplanDateTimeshow"
									v-model="scope.row.planDateTime"
									value-format="YYYY-MM-DD"
								></el-date-picker>
								<span v-else>{{
									scope.row.planDateTime
										? scope.row.planDateTime.join(' / ')
										: null
								}}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column align="left" width="200" prop="bomVersion">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>BOM版本
						</template>
						<template #default="scope">
							<el-select
								v-if="scope.row.isBomVersionShow"
								:disabled="
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									scope.row.pushkey
								"
								:id="'bomVersion' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'bomVersion'
									)
								"
								filterable
								placeholder="请选择BOM版本"
								v-model="scope.row.bomVersion"
								@change="bomChange(scope.row, scope.$index)"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.name"
									v-for="item in bomVersions[scope.$index]"
								></el-option>
							</el-select>
							<span
								v-else
								:style="{
									color: scope.row.bomVersion ? '' : 'red',
								}"
							>
								{{
									scope.row.bomVersion
										? scope.row.bomVersion
										: '无bom，请添加'
								}}
							</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="用料清单"
						prop="bomId"
						width="150"
					>
						<template #default="scope">
							<span
								:class="{
									'text-blue':
										pagefromData.documentStatus === 'c',
								}"
								:disabeld="pagefromData.documentStatus !== 'c'"
								@click="jumpUserMaterialSet(index, scope.row)"
							>
								用料清单({{ scope.row.printCount }})
							</span>
						</template>
					</el-table-column>
					<el-table-column align="left" label="领料状态" width="108">
						<template #default="scope">
							<span>{{
								getPageObjValue(
									pickmtStatuslist,
									scope.row.pickmtStatus + ''
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="领料套数"
						prop="pickmtNumber"
						width="120"
					>
						<template #default="scope">
							<span>{{
								scope.row.pickmtNumber
									? scope.row.pickmtNumber
									: 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="结案日期"
						prop="closeDate"
						width="200"
					/>
					<el-table-column
						align="left"
						label="入库数量"
						prop="stockEligibleNumber"
						width="120"
					>
						<template #default="scope">
							<span>{{
								scope.row.stockEligibleNumber
									? scope.row.stockEligibleNumber
									: 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="未入库数量"
						prop="noStockEligibleNumber"
						width="120"
					>
						<template #default="scope">
							<span>
								{{
									scope.row.noStockEligibleNumber &&
									scope.row.noStockEligibleNumbe > 0
										? scope.row.noStockEligibleNumber
										: 0
								}}
							</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="remark" width="225">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'remark' + scope.$index"
								:maxlength="2000"
								@input="
									getRowCol(scope.row, scope.column, 'remark')
								"
								v-if="scope.row.isremarkshow"
								v-model="scope.row.remark"
							></el-input>
							<span v-else>{{ scope.row.remark }}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="workShopId" width="180">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>生产部门
						</template>
						<template
							@click="
								getRowCol(scope.row, scope.column, 'workShopId')
							"
							#default="scope"
						>
							<el-cascader
								:disabled="
									$route.query.typeId === '1'
										? false
										: (pagefromData.documentStatus !==
												'a' &&
												pagefromData.documentStatus !==
													'd') ||
										  ($route.query.type === 'pushDown' &&
												!!scope.row.parentOrderId) ||
										  pagefromData.prdorgId === 0 ||
										  pagefromData.prdorgId === '' ||
										  pagefromData.prdorgId === null
								"
								:id="'workShopId' + scope.$index"
								:options="productDeptList"
								:props="optionProps"
								:show-all-levels="false"
								class="click-cell-ipt-c"
								clearable
								placeholder="请选择部门"
								style="font-size: 12px"
								v-if="scope.row.isworkShopshow"
								v-model="scope.row.workShopId"
							></el-cascader>
							<span v-else>
								{{
									scope.row.workShopId
										? publicidbyname(
												productDeptList,
												scope.row.workShopId
										  )
										: null
								}}
							</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="customerId" width="220">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									!customerWarehouseTaglist[scope.$index] ||
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									($route.query.type === 'pushDown' &&
										!!scope.row.parentOrderId)
								"
								:id="'customerId' + scope.$index"
								@change="
									changecustomer(
										$event,
										scope.$index,
										'product'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerId'
									)
								"
								clearable
								filterable
								placeholder="请选择"
								v-if="scope.row.iscustomerIdshow"
								v-model="scope.row.customerId"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.id"
									v-for="item in customerlist"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
								></el-option>
							</el-select>
							<span v-else>{{
								scope.row.customerId
									? publicidbyname(
											customerlist,
											scope.row.customerId
									  )
									: null
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						prop="customerStockId"
						width="220"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户仓库
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									!customerWarehouseTaglist[scope.$index] ||
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									($route.query.type === 'pushDown' &&
										!!scope.row.parentOrderId)
								"
								:id="'customerStockId' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerStockId'
									)
								"
								clearable
								filterable
								placeholder="请选择"
								v-if="scope.row.iscustomerStockIdshow"
								v-model="scope.row.customerStockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in customeStockArrylist[
										scope.$index
									]"
								></el-option>
							</el-select>
							<span v-else>
								{{
									scope.row.customerStockId
										? publicidbyname(
												customeStockArrylist[
													scope.$index
												],
												scope.row.customerStockId
										  )
										: null
								}}
							</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="是否211"
						prop="is211"
						width="108"
					>
						<template #default="scope">
							<span>{{ scope.row.is211 ? '是' : '否' }}</span>
						</template>
					</el-table-column>

					<el-table-column
						align="left"
						label="模号/备注/位置号"
						prop="Description"
						width="200"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>模号/备注/位置号
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'Description' + scope.$index"
								:maxlength="2000"
								@input="
									getRowCol(
										scope.row,
										scope.column,
										'Description'
									)
								"
								v-if="scope.row.isDescriptionshow"
								v-model="scope.row.Description"
							></el-input>
							<span v-else>{{ scope.row.Description }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<!-- 操作结果 -->
		<el-dialog title="操作结果" v-model="dialogVisible" width="40%">
			<div class="sale-page-table-body">
				<el-table
					:data="tableInfo"
					:header-cell-class-name="headerRigthMethod"
					border
					class="table-box"
					height="300"
					id="tableInfo-table"
				>
					<el-table-column label="序号" prop="date" width="50">
						<template #default="scope">
							<span>{{ scope.$index + 1 }}</span>
						</template>
					</el-table-column>
					<el-table-column
						label="订单号"
						prop="orderNo"
						width="200"
					></el-table-column>
					<el-table-column label="指令" prop="a" width="110">
						<template #default>
							<span>
								{{
									pageactionType === 'submit'
										? '提交'
										: pageactionType === 'revoke'
										? '撤销'
										: pageactionType === 'audit'
										? '审核'
										: pageactionType === 'de-approval'
										? '反审'
										: pageactionType === 'delet'
										? '删除'
										: pageactionType === 'finish'
										? '完工'
										: pageactionType === 'close-case'
										? '结案'
										: pageactionType === 'de-excute-start'
										? '反执行至开工'
										: pageactionType === 'de-approval'
										? '反审'
										: pageactionType === 'delet'
										? '删除'
										: pageactionType === 'finish'
										? '完工'
										: pageactionType === 'close-case'
										? '结案'
										: pageactionType === 'de-excute-finish'
										? '反执行至完工'
										: ''
								}}
							</span>
						</template>
					</el-table-column>
					<el-table-column label="结果" width="80">
						<template #default="scope">
							<span :style="{ 'txt-Red': scope.row.isSuccess }">{{
								scope.row.isSuccess ? '成功' : '失败'
							}}</span>
						</template>
					</el-table-column>
					<el-table-column label="信息" prop="msg">
						<template #default="scope">
							<span class="txt-Red">{{ scope.row.msg }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<span
						class="f-12 ext-black-light"
						style="margin-right: 25px"
					>
						共{{
							tableInfo && tableInfo.length > 0
								? tableInfo.length
								: 0
						}}条
					</span>
					<el-button
						@click="
							handelhtmlToExcel('tableInfo-table', '操作结果');
							dialogVisible = false;
						"
						size="small"
						>导 出</el-button
					>
					<el-button
						@click="dialogVisible = false"
						size="small"
						type="primary"
						>关 闭</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择下推单据 -->
		<el-dialog
			title="选择下推单据"
			top="15%"
			v-model="dialogxt"
			width="20%"
		>
			<div class="sale-page-table-body">
				<el-radio-group v-model="pushdownVal">
					<el-radio :label="1">生产入库单</el-radio>
					<el-radio :label="2">生产补料单</el-radio>
					<el-radio :label="3">生产领料单</el-radio>
					<el-radio :label="4">生产退料单</el-radio>
				</el-radio-group>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="dialogxt = false" size="small"
						>取 消</el-button
					>
					<el-button
						@click="sumitPushdown"
						size="small"
						type="primary"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择上下查单据 -->
		<el-dialog
			:title="CXttile"
			top="15%"
			v-if="upOrDownList.length > 0"
			v-model="dialogCX"
			width="20%"
		>
			<div class="sale-page-table-body">
				<el-radio-group
					v-if="CXttile === '上查结果'"
					v-model="CXcheckVal"
				>
					<el-radio
						:key="index"
						:label="it.orderType"
						v-for="(it, index) in upOrDownList"
					>
						{{ it.orderName }}({{ it.orderCount }})
					</el-radio>
				</el-radio-group>
				<el-radio-group
					v-if="CXttile === '下查结果'"
					v-model="CXcheckVal"
				>
					<el-radio
						:key="index"
						:label="it.orderType"
						v-for="(it, index) in upOrDownList"
					>
						{{ it.orderName }}({{ it.orderCount }})
					</el-radio>
				</el-radio-group>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="dialogCX = false" size="small"
						>取 消</el-button
					>
					<el-button @click="submitCX" size="small" type="primary"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<script>
import examineTop from '@/components/examineTop/index.vue';
import toolBtn from '@/components/public/toolBtn/toolBtn.vue';
import { Decimal } from 'decimal.js';
import { mapState } from 'vuex';
import { orderCopy, bottomAddRow } from '@/utils/takeMethods';
import { countMethodsUnitNumber } from '@/utils/count.js';
import {
	transformTimestamp,
	getObjValue,
	theUnitSet,
	batchhandle,
	quikecopyValue,
	oldstocklist,
	newprintPreview1,
	htmlToExcel,
} from '@/utils/pubulic.js';

import {
	approvalFlowTrackingCreate,
	approvalFlowTrackingGetby,
	approvalFlowTrackingUpdate,
} from '@/utils/api.js';
import prtMoledop from '@/components/public/printviews/prtMoledop.vue';
import { productOrderPrint, pageoPtionProps } from '@/utils/printPagekey.js';
export default {
	name: 'ProductOrderCreate',
	components: {
		examineTop,
		toolBtn,
		prtMoledop,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			examineObj: {},
			radios: [],
			bomVersions: [], //BOM版本
			salePrecisionNumber: [], // 单位精度相关处理
			isPrecision: [], // 单位精度相关处理
			isCount: [], // 单位精度相关处理
			theadDate: JSON.parse(JSON.stringify(productOrderPrint)), // 打印要的字段表
			printTablelist: [], //用来清单打印的数据
			printIds: [],
			isDisable: false,
			optionProps: JSON.parse(JSON.stringify(pageoPtionProps)),
			CXcheckVal: '', // 上下查选中
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrdedetailIds: [], // 勾选的明细id集合
			OrderNoNames: [], // 选择的单据订单号集合
			multipleSelection: [], // 明细列表选中
			pushdownVal: null, // 下推选择
			tableInfo: [], //操作结果
			dialogVisible: false, // 操作弹框显示
			dialogxt: false, // 选择下推单据弹框显示
			customeStocklist: [], // 客户仓库下拉数据
			pageactionType: '', // 操作动作 新增还是修改还是编辑
			actionType: '', // 操作动作 新增还是修改还是编辑
			documentStatuslist: [], // 单据状态
			pickmtStatuslist: [], // 领料状态
			produceBusinessStatuslist: [], // 业务状态
			documentTypelist: [], // 单据类型
			matterallCodelist: [[]], // 物料下拉数据
			specificationalllist: [], // 规格型号（sku）下拉数据
			unitlist:
				this.$store.state && this.$store.state.storeData.allUnit
					? this.$store.state.storeData.allUnit
					: [], // 获取计量单位数据
			productDeptList: [], // 生产部门
			warehouse: [], //仓库下拉数据
			customeStockArrylist: [[]], // 所有的客户仓库下拉数据
			loading: false,
			produceNo: '', // 生产订单号
			customerlist: [], //客户集合
			customerWarehouseTaglist: [], // 判断客户仓库是否必填 这个值有仓库带出默认是不必填
			btnType: [
				'copy',
				'revoke',
				'audit',
				'de-approval',
				'delete',
				'push-down',
				'operation',
				'up-check',
				'down-check',
				// 'query',
				'refresh',
				's-p-t-g3',
				// 's-p-t-g4',
			],
			dataSourcesList: [], //数据来源
			//页面明细信息初始
			pageDetails: {
				id: 0, // 明细的id
				seq: 0, // 序号
				parentCheckDate: null, //上游的审核时间
				salOrderNo: '', // 销售订单号
				expectDate: '', // 期望交期
				materialId: null, //物料编码
				materialName: '', //物料名称
				specification: '', //规格型号
				unitId: null, // 单位
				number: null, // 数量
				status: '1', // 业务状态 默认4 是开工
				workShopId: null, // 生产部门
				planStartDate: transformTimestamp(new Date()), // 计划开工日期
				planFinishDate: transformTimestamp(new Date()), // 计划完成日期
				planDateTime: [
					transformTimestamp(new Date()),
					transformTimestamp(new Date()),
				], // 明细里面的默认计划时间
				bomId: null, // 物料带出来的 BOM版本id
				bomVersion: '', //物料带出来的 BOM版本名称
				pickmtNumber: 0, // 领料套数
				pickmtStatus: '1', // 领料状态
				stockEligibleNumber: 0, // 入库数量
				noStockEligibleNumber: 0, // 未入库数量
				remark: '', //备注
				stockId: null, // 仓库
				stockLocId: null, // 仓位
				customerId: null, // 客户
				customerStockId: null, // 客户仓位
				customerWarehouseTag: false, // 判断客户仓库是否必填 这个值有仓库带出默认是不必填
				closeDate: '', // 结案日期
				is211: '', // 是否211
				Description: '', //模号/备注/位置号
			},
			pagefromData: {
				id: 0, // 单据的id
				date: transformTimestamp(new Date()), //下单日期
				prdorgId: null, //生产组织
				produceNo: '', // 生产订单号
				dataSources: '', //数据来源
				documentType: '', // 单据类型
				documentStatus: 'a', // 单据状态
				createName: '', // 创建人
				createDate: '', // 创建时间
				modifyName: '', // 最后修改人
				modifyDate: '', // 最后修改日期
				checkName: '', // 审核人
				checkDate: '', // 审核日期
				commitDate: '', // 提交时间
				commitStaffName: '', // 提交人
				remark: '', // 备注
				details: [],
			},
			//明细数据
			addRow: {},
			selectRowIndexArr: [],
			selectRowIndex: '', // 当前 选择行
			// 批量填充
			batchfill: {
				romIndex: null,
				columnIndex: null,
				columnkey: null,
			},
			heightNum: 0,
		};
	},
	watch: {
		orgId(value) {
			if (value) {
				if (
					this.pagefromData.id === 0 ||
					this.pagefromData.id === null ||
					this.pagefromData.id === ''
				) {
					this.pagefromData.prdorgId = value;
					if (
						this.pagefromData.documentStatus === 'a' ||
						this.pagefromData.documentStatus === 'd'
					) {
						this.orgChange(value);
					}
				}
				this.orgId = value;
			}
		},
		'pagefromData.documentStatus'(newvalue, oldvalue) {
			if (
				this.pagefromData.documentStatus === 'a' ||
				!this.pagefromData.documentStatus
			) {
				this.$topNavTagRename('新增生产订单');
			} else {
				this.$topNavTagRename('编辑生产订单');
			}
			if (
				this.pagefromData.documentStatus === 'a' ||
				this.pagefromData.documentStatus === 'd'
			) {
				this.btnType = [
					'copy',
					'revoke',
					'audit',
					'de-approval',
					'delete',
					'push-down',
					'operation',
					'up-check',
					'down-check',
					// 'query',
					'refresh',
					's-p-t-g3',
					// 's-p-t-g4',
					'print-brower',
				]; // 不需要显示的顶部按钮类型
			} else {
				this.btnType = [
					'copy',
					'de-close',
					'close',
					'delete',
					'export',
					'refresh',
					'print-brower',
				];
			}
		},
	},
	computed: {
		...mapState({
			orgId: (state) => (state && state.user ? state.user.orgId : null),
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			userId: (state) => state.user.userInfo.staffId || null,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
			getPageObjValue: function () {
				// 根据key值显示对应的键名
				return function (arr, key) {
					return getObjValue(arr, key);
				};
			},
		}),
		isShow: function () {
			return this.isExmaineTop;
		},
		publicidbyname: function () {
			// 根据key值显示对应的键名
			return function (arr, key) {
				return theUnitSet(arr, key);
			};
		},
	},
	created() {
		// 明细信息-初始
		this.heightNum =
			document.documentElement.clientHeight - (40 + 30 + 16 + 16);
		this.actionType = this.$route.query.type;
		this.pagefromData.details = [
			JSON.parse(JSON.stringify(this.pageDetails)),
		];
		this.addRow = JSON.parse(JSON.stringify(this.pageDetails));
		this.Init();
		this.pagefromData.dataSources =
			this.$route.query.type == 'pushDown' ||
			this.$route.query.type == 'add' ||
			this.$route.query.type == 'copy'
				? '1'
				: '2';
		this.setApprovalFlowStatus();
	},
	methods: {
		setExamine(res) {
			if (
				res.status === 200 &&
				res.data &&
				JSON.stringify(res.data) !== '{}'
			) {
				this.examineObj = res.data;
				//有审批流,但是自己不能审批则返回1,否则返回2,如果没有审批流或者报错为了不阻断流程返回3
				let isApprover = res.data.isApprover;
				this.isExmaineTop = isApprover ? 2 : 1;
				if (
					!res.data ||
					JSON.stringify(res.data) === '{}' ||
					this.pagefromData.documentStatus !== 'b'
				) {
					this.isExmaineTop = 3;
				}
				if (res.data.isDone) {
					this.pagefromData.documentStatus = 'c';
					this.isExmaineTop = 3;
				}
				this.isexamineBtns = false;
			} else {
				this.isexamineBtns = false;
				this.isExmaineTop = 3;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('ProduceOrder/Get/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.setpageDate(req);
						this.pagefromData.documentStatus =
							req.data.documentStatus;
						if (
							this.pagefromData.documentStatus === 'a' ||
							this.pagefromData.documentStatus === 'd'
						) {
							this.isEdit = false;
						}
						this.setExamine(r);
					}
				});
			// this.saveIds = r.data.id;
			// this.baseInfoForm = purGetOrderId(this.baseInfoForm, r);
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
		},

		handleSubmit(data) {
			this.isexamineBtns = true;
			this.$http
				.post(approvalFlowTrackingUpdate, data)
				.then((res) => {
					if (res.status === 200) {
						this.$message.success({
							message: '操作成功!',
							showClose: true,
						});
					}
					this.handleDetails(res);
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				})
				.finally(() => {
					// this.isexamineBtns = false;
				});
		},
		//顶部按钮点击
		handleBtns(vals) {
			if (vals.type === 'out') {
				this.$router.go(-1);
			} else {
				//
				let data = {
					approvalDetailsId: this.examineObj.approvalDetailsId,
					approvalOrderType: this.examineObj.sendOrderType,
					orderId: this.examineObj.sendOrderId,
					deptId: this.pagefromData.details[0].workShopId || 0,
					orgId: this.pagefromData.prdorgId,
					details: {
						trackId: this.examineObj.id,
						approverId: this.userId,
						approvalMethod: this.examineObj.currentApprovalMethod,
						approvalResult: vals.approvalResult,
						wayId: this.examineObj.currentWayId,
						remark: vals.remark,
						// upperId
					},
				};
				this.handleSubmit(data);
			}
		},
		//跳转到追踪页面
		handleOpen() {
			this.$router.push({
				path: '/examine/mange/examineFollow',
				query: { id: this.examineObj.id },
			});
		},
		//获取处理意见状态
		setApprovalFlowStatus() {
			this.radios = this.getApprovalResult;
		},

		//审批流-详情
		setApprovalFlowTrackingGetby(data) {
			if (
				this.$route.query.type === 'copy' &&
				this.pagefromData.produceNo === ''
			) {
				this.examineObj = {};
				return;
			}
			if (data.tracking && data.tracking.remark) {
				this.$message.error({
					message: `单据由-${data.tracking.remark}`,
					showClose: true,
					duration: 5000,
				});
			}
			if (
				data.documentStatus === 'a' ||
				data.documentStatus == 'd' ||
				this.$route.query.type === 'copy'
			) {
				this.examineObj = data.tracking;
				return;
			}
			let obj = {
				orderId: data.id,
				approvalOrderType: 13,
				deptId: data.details[0].workShopId || 0,
				orgId: data.prdorgId,
			};
			this.$http
				.post(approvalFlowTrackingGetby, obj)
				.then((res) => {
					this.setExamine(res);
					if (res.status === 200) {
						this.setExamine(res);
						let details = res.data.details || [];
						let length = details.length;

						// if (!length) {
						// 	return false;
						// }
						// if (details[0].approvalResult !== 2) {
						// 	return false;
						// }
						// this.$message.error({
						// 	message: `"单据由${details[0].approverName}"审核不通过，拒绝理由”${details[0].remark}”`,
						// 	showClose: true,
						// 	duration: 5000,
						// });
					}
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				});
		},
		//审批流-创建
		// setApprovalFlowTrackingCreate(data) {
		// 	let _this = this;
		// 	let obj = {
		// 		sendOrderId: data.id,
		// 		deptId: data.details[0].workShopId || 0,
		// 		sendId: this.userId,
		// 		sendOrderType: 13,
		// 		sendOrderBillNo: data.produceNo,
		// 		orgId: this.orgId,
		// 	};
		// 	this.$http
		// 		.post(approvalFlowTrackingCreate, obj)
		// 		.then((res) => {
		// 			this.setExamine(res);
		// 		})
		// 		.catch((err) => {
		// 			if (err) {
		// 				this.isExmaineTop = 3;
		// 			}
		// 		});
		// },
		Init() {
			this.getUnit();
			this.getStatus();
			this.InItEditorCopy();
			// 主要是判断下推用
			this.getRuterData();
		},
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 快粘贴
		pasteExcel(event, index, scope, key) {
			let rows = quikecopyValue(event);
			let recordAddIndex = index; // 记录行
			setTimeout(async () => {
				rows.forEach((it, idx) => {
					if (
						recordAddIndex + 1 <=
						this.pagefromData.details.length
					) {
						if (key == 'materialId') {
							this.matterCodeChange(it, 'number', recordAddIndex);
						}
						if (key === 'salOrderNo') {
							this.pagefromData.details[
								recordAddIndex
							].salOrderNo = it;
						}
						if (key === 'specification') {
							this.specificationChange(
								it,
								'specification',
								recordAddIndex
							);
						}
						if (key === 'number') {
							this.pagefromData.details[recordAddIndex].number =
								it;
						}
						recordAddIndex++;
					}
				});
			}, 100);
		},
		// 获取客户仓库数据
		getCoustomerChild(value, index) {
			this.$http
				.post('SysConfig/GetCustomerStock', {
					customerId: value
						? value
						: this.pagefromData.details[index].customerId,
					orgId: this.pagefromData.prdorgId,
					stockId: this.pagefromData.details[index].stockId,
				})
				.then((res) => {
					if (res.status === 200) {
						this.customeStockArrylist[index] =
							res.data && res.data.length > 0
								? oldstocklist(
										res.data.concat(
											oldstocklist(
												this.pagefromData.details
											).customerStockList
										),
										'retrieve'
								  )
								: oldstocklist(
										oldstocklist(this.pagefromData.details)
											.customerStockList,
										'retrieve'
								  );
					}
				});
		},
		// 改变客户的时候获取对应的客户仓库
		changecustomer(id, index, type) {
			if (type !== 'init' && id) {
				if (type === 'product') {
					this.pagefromData.details[index].customerStockId = '';
				}
			}
			if (id) {
				this.getCoustomerChild(id, index);
			}
		},
		bomChange(row, index) {
			let items = this.bomVersions[index].filter((item) => {
				return item.name === row.bomVersion;
			});
			this.pagefromData.details[index].bomVersion = items[0].name;
			this.pagefromData.details[index].bomId = items[0].id;
		},
		// 获取单位
		getUnit() {
			var unitlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.allUnit
					: [];
			if (
				JSON.stringify(
					this.$store.state && this.$store.state.storeData
						? this.$store.state.storeData.allUnit
						: []
				) === '[]'
			) {
				this.$http.get('SysConfig/GetUnitAllProperty').then((r) => {
					if (r.status === 200) {
						this.unitlist = this.$store.state.storeData.allUnit =
							r.data;
					}
				});
			} else {
				this.unitlist = unitlist;
			}
		},
		// 获取需要状态列表---[单据状态，领料状态，业务状态]
		getStatus() {
			var infoStatus =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.infoStatus
					: {};
			if (
				JSON.stringify(
					this.$store.state && this.$store.state.storeData
						? this.$store.state.storeData.infoStatus
						: {}
				) === '{}'
			) {
				this.$http.get('ProduceOrder/GetStatus').then((r) => {
					if (r.status === 200) {
						this.documentStatuslist = r.data.documentStatus;
						this.pickmtStatuslist = r.data.pickmtStatus;
						this.produceBusinessStatuslist =
							r.data.produceBusinessStatus;
						this.documentTypelist = r.data.documentType;
						this.dataSourcesList = r.data.dataSourceType;
						this.pagefromData.documentType = Object.keys(
							r.data.documentType
						)[0];
						this.$store.state.storeData.infoStatus = r.data;
					}
				});
			} else {
				this.documentStatuslist = infoStatus.documentStatus;
				this.pickmtStatuslist = infoStatus.pickmtStatus;
				this.produceBusinessStatuslist =
					infoStatus.produceBusinessStatus;
				this.documentTypelist = infoStatus.documentType;
				this.dataSourcesList = infoStatus.dataSourceType;
				this.pagefromData.documentType = Object.keys(
					infoStatus.documentType
				)[0];
			}
		},
		// 获取全部公司客户
		getAllcustomer() {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.customerlist
					: [];
			if (JSON.stringify(infocustomerlist) === '[]') {
				this.$http.get('SysConfig/GetCustomer').then((res) => {
					if (res.status === 200) {
						this.customerlist =
							this.$store.state.storeData.customerlist = res.data;
					}
				});
			} else {
				this.customerlist = infocustomerlist;
			}
		},
		// 获取路由传过来的值
		getRuterData() {
			if (
				this.$route.query.pushDownData &&
				this.$route.query.type === 'pushDown'
			) {
				this.setpageDate({
					data: JSON.parse(
						decodeURIComponent(this.$route.query.pushDownData)
					),
				});
			}
		},
		//确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = '';
				if (this.CXcheckVal === 7) {
					// 销售订单
					pathName = 'SaleOrder';
				}
				if (this.CXcheckVal === 10) {
					// 组织间需求单
					pathName = 'orgNeeds';
				}
				if (this.CXcheckVal === 19) {
					// 生产入库单
					pathName = 'ProductWarehousingOrder';
				}
				if (this.CXcheckVal === 17) {
					// 生产补料单
					pathName = 'ProductReplenishment';
				}
				if (this.CXcheckVal === 16) {
					// 生产领料单
					pathName = 'ProductPicking';
				}
				if (this.CXcheckVal === 18) {
					// 生产退料单
					pathName = 'ProductReturnMaterial';
				}
				if (this.CXcheckVal === 10) {
					// 组织间
					pathName = 'OrgNeeds';
				}
				let ary = [];
				ary = this.upOrDownList.filter((it) => {
					return it.orderType === this.CXcheckVal;
				});
				if (pathName) {
					this.$router.push({
						name: pathName,
						query: {
							detailsIds: JSON.stringify(
								ary.length > 0 ? ary[0].detailsIds : []
							),
							actionType:
								this.CXttile === '上查结果' ? 'up' : 'down',
							actionName: '生产订单',
							OrderNoNames: JSON.stringify(
								ary.length > 0 ? ary[0].billNos : []
							),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// 下推确定
		sumitPushdown() {
			if (this.pushdownVal) {
				let pathName = '';
				let routerName = '';
				if (this.pushdownVal === 1) {
					// 生产入库
					pathName = 'ProduceOrder/PushDownInStock';
					routerName = 'AddProductWarehouOrder';
				}
				if (this.pushdownVal === 2) {
					// 生产补料单
					pathName = 'ProduceOrder/PushDownFeed';
					routerName = 'AddProudtreplenishmentOrder';
				}
				if (this.pushdownVal === 3) {
					// 生产领料单
					pathName = 'ProduceOrder/PushDownPick';
					routerName = 'AddProductPickOrder';
				}
				if (this.pushdownVal === 4) {
					// 生产退料单
					pathName = 'ProduceOrder/PushDownReturn';
					routerName = 'AddProudtReturnOrder';
				}
				this.$http
					.post(pathName, { ids: this.OrdedetailIds })
					.then((res) => {
						if (res.status === 200) {
							this.$router.push({
								name: routerName,
								query: {
									type: 'pushDown',
									ids: encodeURIComponent(
										JSON.stringify(this.OrdedetailIds)
									),
								},
							});
							this.dialogxt = false;
						}
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		// 计划时间日期选择监听
		planDateTimechange(value, index) {
			if (value) {
				this.pagefromData.details[index].planStartDate = value[0];
				this.pagefromData.details[index].planFinishDate = value[1];
			}
		},
		// 用料清单-跳转到生产用料清单设置页面
		jumpUserMaterialSet(index, item) {
			if (this.pagefromData.documentStatus === 'c') {
				this.$router.push({
					path: '/production/productMange/useMaterialSet',
					query: { detailId: item.id },
				});
			}
		},
		// 保存或者提交的时候做数据处理
		arrangeData() {
			let newDetails = this.pagefromData.details.map((v, index) => {
				return { ...v, seq: index };
			});
			this.pagefromData.details = newDetails;
			if (this.pagefromData.details) {
				// 清空明细选中
				this.$refs.multipleTable.clearSelection();
				this.selectRowIndexArr = [];
			}
		},
		// 初始化时--编辑或者复制时处理
		InItEditorCopy() {
			// 如果是复制，编辑，查看--过来的新增订单
			if (
				this.$route.query &&
				this.$route.query.type !== 'add' &&
				this.$route.query.productId
			) {
				this.getProductInfo(this.$route.query.productId);
			} else if (this.$route.query.type === 'add') {
				this.pagefromData.prdorgId = this.orgId;
				this.customerWarehouseTaglist = [true];
				this.getWarehouse(this.pagefromData.prdorgId);
				this.getProductdept(this.orgId);
			}
			this.getAllcustomer();
		},
		// 生产组织下拉改变是 （会影响生产部门的数据）
		orgChange(value) {
			this.customerWarehouseTaglist = [true];
			this.getAllcustomer();
			this.getWarehouse(value);
			this.getProductdept(value);
			this.pagefromData.details = [];
			this.pagefromData.details = [
				JSON.parse(JSON.stringify(this.pageDetails)),
			];
		},
		// 获取每一条单位的精度和类型
		numberPrecisionMethods(index) {
			if (this.pagefromData.details[index].unitId) {
				let tempList = this.unitlist.filter(
					(it) => it.id === this.pagefromData.details[index].unitId
				);
				if (tempList && tempList.length > 0) {
					tempList[0].precision == 0
						? (this.isPrecision[index] = true)
						: (this.isPrecision[index] = false);
					tempList[0].precision == 0
						? (this.salePrecisionNumber[index] = 0)
						: (this.salePrecisionNumber[index] =
								tempList[0].precision);
				}
			}
			this.isPrecision[index] = this.isPrecision[index]
				? this.isPrecision[index]
				: false;
			this.salePrecisionNumber[index] =
				this.salePrecisionNumber[index] ||
				this.salePrecisionNumber[index] == 0
					? this.salePrecisionNumber[index]
					: 10;
			if (
				!this.pagefromData.details[index].materialId &&
				!this.$route.query.id
			) {
				this.isPrecision[index] = true;
			}
			if (!this.isCount[index]) {
				this.isCount[index] = 1;
			}
		},
		// 数量改变时
		numberChage(val, index, item, key) {
			// 输入规则
			if (val) {
				this.numberPrecisionMethods(index);
				if (val.toString().indexOf('.') !== -1) {
					let tempList = JSON.parse(
						JSON.stringify(
							this.unitlist.filter(
								(it) =>
									it.id ===
									this.pagefromData.details[index].unitId
							)
						)
					);
					if (tempList && tempList.length > 0) {
						tempList[0].roundoffType = 2;
					}
					let result = countMethodsUnitNumber(
						tempList,
						val,
						this.pagefromData.details[index][key],
						this.isCount[index],
						this.salePrecisionNumber[index]
					);
					this.pagefromData.details[index][key] = result.value * 1;
					this.isCount[index] = result.isDefault;
				}
				let numD = '';
				let count = '\\d';
				for (
					let ind = 0;
					ind < this.salePrecisionNumber[index];
					ind++
				) {
					numD = numD + count;
				}
				let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
				this.pagefromData.details[index][key] =
					this.pagefromData.details[index][key]
						.toString()
						.replace(/[^\d^\\.]+/g, '')
						.replace('.', '$#$')
						.replace(/\./g, '')
						.replace('$#$', '.')
						.replace(eval(reg), '$1$2.$3');
				this.pagefromData.details[index][key] =
					this.pagefromData.details[index][key] * 1;
				// 下推订单数量处理
				if (
					this.$route.query.type === 'pushDown' &&
					this.pagefromData.details[index].maxNumber
				) {
					if (
						Decimal(item.number ? item.number : 0).toNumber() >
						Decimal(
							this.pagefromData.details[index].maxNumber
						).toNumber()
					) {
						this.pagefromData.details[index].number =
							this.pagefromData.details[index].maxNumber;
					}
				}
				this.dataNumjd(index, 'number');
			}
		},
		// 初始对数据精度处理
		dataNumjd(index, key) {
			this.numberPrecisionMethods(index);
			let tempList = this.unitlist.filter(
				(it) => it.id === this.pagefromData.details[index].unitId
			);
			if (tempList && tempList.length > 0) {
				tempList[0].precision == 0
					? (this.isPrecision[index] = true)
					: (this.isPrecision[index] = false);
				tempList[0].precision == 0
					? (this.salePrecisionNumber[index] = 0)
					: (this.salePrecisionNumber[index] = tempList[0].precision);
			}
			let result = countMethodsUnitNumber(
				tempList,
				this.pagefromData.details[index][key],
				this.pagefromData.details[index][key],
				this.isCount[index],
				this.salePrecisionNumber[index],
				true
			);
			this.pagefromData.details[index][key] = result.value * 1;
			this.isCount[index] = result.isDefault;
			// 未入库数量 = 数量-合格入库数量
			this.pagefromData.details[index].noStockEligibleNumber = Decimal(
				Decimal(
					this.pagefromData.details[index].number
						? this.pagefromData.details[index].number
						: 0
				).sub(
					Decimal(
						this.pagefromData.details[index].stockEligibleNumber
							? this.pagefromData.details[index]
									.stockEligibleNumber * 1
							: 0
					)
				)
			).toNumber();
			this.pagefromData.details[index].noStockEligibleNumber =
				this.pagefromData.details[index].noStockEligibleNumber > 0
					? this.pagefromData.details[index].noStockEligibleNumber * 1
					: 0;
		},
		// 详情或者下推过来的数据处理
		async setpageDate(res, type) {
			if (res.data) {
				const names = [];
				const customerIds = [];
				this.pagefromData = JSON.parse(JSON.stringify(res.data));
				this.pagefromData.date = res.data.date
					? res.data.date
					: transformTimestamp(new Date()); //下单日期
				this.documentStatus = res.data.documentStatus;
				if (this.$route.query.type === 'copy' && !type) {
					this.actionType = 'copy';
					this.pagefromData.documentStatus = 'a';
					this.pagefromData.produceNo =
						this.actionType === 'copy' ? '' : res.data.produceNo;
					this.pagefromData.id =
						this.actionType === 'copy' ? 0 : res.data.id;
				} else {
					this.pagefromData.documentStatus = res.data.documentStatus
						? res.data.documentStatus
						: 'a';
				}
				this.pagefromData.documentType = res.data.documentType
					? res.data.documentType
					: 'instock';
				this.pagefromData.status = res.data.status
					? res.data.status + ''
					: '4';
				this.pagefromData.prdorgId = res.data.prdorgId;

				this.pagefromData.dataSources = res.data.dataSources
					? res.data.dataSources + ''
					: '2';
				this.matterallCodelist = [];
				this.customeStockArrylist = [];
				if (res.data.details && res.data.details.length > 0) {
					this.getWarehouse(res.data.prdorgId, res.data.details);
					res.data.details.forEach((it, index) => {
						if (this.$route.query.type === 'copy' && !type) {
							this.pagefromData.details[index].id = 0;
							this.pagefromData.details[index] = JSON.parse(
								JSON.stringify(this.pageDetails)
							);
							this.pagefromData.details[index].Description =
								it.description;
							// 克隆需要携带的字段
							let keylist = [
								'salOrderNo',
								'materialId',
								'materialName',
								'materialNumber',
								'specification',
								'unitId',
								'number',
								'bomId',
								'expectDate',
								'bomVersion',
								'stockId',
								'workShopId',
								'remark',
							];
							keylist.forEach((key) => {
								this.pagefromData.details[index][key] = it[key];
							});
						} else {
							this.pagefromData.details[index].Description =
								it.description || '';
							this.pagefromData.details[index].seq = index;
							this.pagefromData.details[index].status = it.status
								? it.status + ''
								: '1';
							this.pagefromData.details[index].pickmtNumber =
								it.pickmtNumber ? it.pickmtNumber : 0;
							this.pagefromData.details[
								index
							].noStockEligibleNumber = it.noStockEligibleNumber
								? it.noStockEligibleNumber
								: 0;
							this.pagefromData.details[index].planStartDate =
								this.pagefromData.details[index].planStartDate
									? this.pagefromData.details[index]
											.planStartDate
									: transformTimestamp(new Date());
							this.pagefromData.details[index].planFinishDate =
								this.pagefromData.details[index].planFinishDate
									? this.pagefromData.details[index]
											.planFinishDate
									: transformTimestamp(new Date());
							this.pagefromData.details[index].planDateTime =
								it.planStartDate && it.planFinishDate
									? [it.planStartDate, it.planFinishDate]
									: [
											transformTimestamp(new Date()),
											transformTimestamp(new Date()),
									  ];
						}
						this.pagefromData.details[index].seq = index;
						this.pagefromData.details[index].noStockEligibleNumber =
							Decimal(it.number).sub(
								Decimal(
									it.stockEligibleNumber
										? it.stockEligibleNumber
										: 0
								)
							);
						if (it.materialNumber) {
							names.push(it.materialNumber);
						}
						if (it.customerId) {
							customerIds.push(it.customerId);
						}
						this.changeWarehouse(
							this.pagefromData.details[index].stockId,
							index,
							'init'
						);
						// 下推、克隆数据重新获取数量、单价精度计算
						if (
							this.$route.query.type === 'pushDown' ||
							this.$route.query.type === 'copy'
						) {
							if (
								this.pagefromData.details[index].number
									.toString()
									.indexOf('.') !== -1
							) {
								this.dataNumjd(index, 'number');
								this.dataNumjd(index, 'noStockEligibleNumber');
							}
						}
					});
					if (customerIds.length > 0) {
						this.initCustomerstocklist(
							customerIds,
							res.data.details.length
						);
					}
					if (names.length > 0) {
						this.initMatterCode(names, res.data.details.length);
					}
				} else {
					this.customeStockArrylist.push([]);
					this.matterallCodelist.push([]);
					this.specificationalllist.push([]);
					this.pagefromData.details = [
						JSON.parse(JSON.stringify(this.pageDetails)),
					];
				}
				// 详情里面根据组织id去获取明细的生产部门数据
				this.getProductdept(res.data.prdorgId);
			}
		},
		// 获取生产订单详情
		getProductInfo(prodctId, type) {
			this.$http.get('ProduceOrder/Get/' + prodctId).then((res) => {
				let newdetails = [];

				if (
					this.$route.query.detailsIds &&
					this.$route.query.type == 'copy'
				) {
					if (
						JSON.parse(this.$route.query.detailsIds) &&
						this.pagefromData.documentStatus == 'a'
					) {
						JSON.parse(this.$route.query.detailsIds).forEach(
							(i) => {
								res.data.details.forEach((it) => {
									if (i == it.id) {
										newdetails.push(it);
									}
								});
							}
						);
					} else {
						newdetails = res.data.details;
					}
					res.data.details = newdetails;
				}
				this.setpageDate(res, type);
				this.setApprovalFlowTrackingGetby(res.data);
			});
		},
		// 物料/规格型号--下拉更新
		metterChange(val, index, type) {
			let metterInfo = [];
			if (type !== 'specification' && type !== 'number') {
				//物料
				metterInfo = this.matterallCodelist[index].filter((res) => {
					return val === res.id;
				})[0];
			} else {
				if (type === 'number') {
					//规格型号
					metterInfo = this.matterallCodelist[index].filter((res) => {
						return val === res.number;
					})[0];
				} else {
					//规格型号
					metterInfo = this.specificationalllist[index].filter(
						(res) => {
							return val === res.specifications;
						}
					)[0];
				}
			}
			if (type === 'specification' && metterInfo) {
				// 规格型号改变
				if (type !== 'number' && metterInfo.number) {
					this.matterCodeChange(metterInfo.number, type, index);
				}
			}
			if (metterInfo && !metterInfo.disable) {
				let keys = ['materialId'];
				this.getmetterInfo(index, metterInfo);
				let tempList = this.unitlist.filter(
					(it) => it.id === this.pagefromData.details[index].unitId
				);
				if (tempList && tempList.length > 0) {
					tempList[0].precision == 0
						? (this.isPrecision[index] = true)
						: (this.isPrecision[index] = false);
					tempList[0].precision == 0
						? (this.salePrecisionNumber[index] = 0)
						: (this.salePrecisionNumber[index] =
								tempList[0].precision);
				}
				this.pagefromData.details[index].number = '';
				// 精度处理
				this.dataNumjd(index, 'number');
				this.dataNumjd(index, 'noStockEligibleNumber');
				this.bomVersions[index] = metterInfo.bomList || [];
			}
			this.pagefromData.details[index].bomVersion =
				metterInfo.bomVersion || '';
			this.pagefromData.details[index].bomId = metterInfo.bomId || '';
		},
		// 物料循环
		getmetterInfo(index, metterInfo) {
			this.pagefromData.details[index].materialId = metterInfo.id;
			this.pagefromData.details[index].materialNumber = metterInfo.number;
			this.pagefromData.details[index].materialName = metterInfo.name;
			this.pagefromData.details[index].specification =
				metterInfo.specifications;
			this.pagefromData.details[index].unitId = metterInfo.baseUnitId;
			// this.pagefromData.details[index].bomId = metterInfo.bomId;
			this.pagefromData.details[index].is211 = metterInfo.is211;
			// this.pagefromData.details[index].bomVersion = metterInfo.bomVersion;
		},
		// 初始化一次性获取物料信息的接口
		initMatterCode(names, total) {
			this.$http
				.post('SysConfig/GetMaterialLikeList', {
					names: names,
					file: 'Number',
					orgId: this.pagefromData.prdorgId,
				})
				.then((res) => {
					if (res.status == 200) {
						const ids = {};
						if (total && total > 0) {
							for (let tag = 0; tag < total; tag++) {
								this.matterallCodelist[tag] = [];
								this.matterallCodelist[tag] = res.data;

								this.getmetterInfo(
									tag,
									res.data.filter((ir) => {
										return (
											ir.number ==
											this.pagefromData.details[tag]
												.materialNumber
										);
									})[0]
								);
								ids[res.data[tag].id] = res.data[tag];
							}
						}
						let length = this.pagefromData.details.length;
						for (let i = 0; i < length; i++) {
							this.bomVersions[i] =
								ids[
									this.pagefromData.details[i].materialId
								].bomList;
						}
						console.log(this.bomVersions, '=this.bomVersions=');
					}
				});
		},
		// 初始化获取客户仓库
		initCustomerstocklist(Customerids, total) {
			if (Customerids && Customerids.length > 0) {
				this.$http
					.post('SysConfig/GetCustomerStockList', {
						customerIds: Customerids,
						orgId: this.pagefromData.prdorgId,
					})
					.then((res) => {
						if (res.status == 200) {
							if (total && total > 0) {
								for (let tag = 0; tag < total; tag++) {
									this.customeStockArrylist[tag] = res.data;
								}
							}
						}
					});
			}
		},
		// 获取物料编码信息
		matterCodeChange(val, type, index) {
			if (val !== '') {
				this.loading = true;
				this.loading = false;
				this.$http
					.showLoading(false)
					.post('SysConfig/GetMaterial', {
						name: val,
						file: 'Number',
						orgId: this.pagefromData.prdorgId,
					})
					.then((res) => {
						if (res.status === 200) {
							if (index || index === 0) {
								this.matterallCodelist[index] = [];
								this.matterallCodelist[index] =
									res.data && res.data.length > 0
										? res.data
										: [];
								if (type === 'number') {
									this.metterChange(val, index, type);
								}
							}
							this.$forceUpdate();
						}
					});
			}
		},
		// 获取物料规格型号信息
		specificationChange(val, type, index) {
			if (val !== '') {
				this.loading = true;
				setTimeout(() => {
					this.loading = false;
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', {
							name: val,
							file: 'Specifications',
							orgId: this.pagefromData.prdorgId,
						})
						.then((res) => {
							if (res.status === 200) {
								this.specificationalllist[index] = [];
								this.specificationalllist[index] =
									res.data && res.data.length > 0
										? res.data
										: [];
								if (type === 'specification') {
									this.metterChange(val, index, type);
								}
							}
						});
				}, 200);
			}
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		//顶部按钮操作栏
		actionhandel(type) {
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			this.pageactionType = type;
			// 提取明细id
			let detailsIds = [];
			if (
				this.pagefromData.details &&
				this.pagefromData.details.length > 0
			) {
				detailsIds = [
					...new Set(
						this.multipleSelection
							.filter((item) => {
								if (item.id) {
									return item.id;
								}
							})
							.map((it) => {
								return it.id;
							})
					),
				];
			}
			// 取单据订单号
			let orderNoArry = [
				...new Set(
					this.multipleSelection.map((item) => {
						return item.produceNo;
					})
				),
			];
			this.OrderNoNames = [];
			this.OrderNoNames = orderNoArry;
			this.OrdedetailIds = detailsIds; // 勾选的明细id集合
			// 点击新增
			if (type === 'add') {
				this.$router.push({
					path: '/production/productMange/productOrderSet',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			//审批流追踪
			if (type == 'exDetails') {
				if (
					!this.examineObj ||
					JSON.stringify(this.examineObj) === '{}'
				) {
					this.$message.error('该单据不存在审批流!');
					return false;
				}
				this.$router.push({
					path: '/examine/mange/examineFollow',
					query: { id: this.examineObj.id },
				});
			}
			//点击保存
			if (type === 'save') {
				this.savePageData();
			}
			//点击提交
			if (type === 'submit') {
				this.submitPageData();
			}
			//点击撤销
			if (type === 'revoke') {
				this.toolarFn('ProduceOrder/Revoke');
			}
			//点击审核
			if (type === 'audit') {
				this.toolarFn('ProduceOrder/Check');
			}
			//点击反审核
			if (type === 'de-approval') {
				this.toolarFn('ProduceOrder/NoCheck');
			}
			// 点击下推
			if (type === 'push-down') {
				if (detailsIds.length > 0) {
					if (detailsIds.length <= 20) {
						if (this.pagefromData.documentStatus !== 'c') {
							this.$message.error({
								message:
									'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
								showClose: true,
							});
						} else {
							this.dialogxt = true;
						}
					} else {
						this.$message.warning({
							message: '最多一次性下推二十条明细',
							showClose: true,
						});
					}
				} else {
					this.$message.warning({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能下推',
						showClose: true,
					});
				}
			}
			if (this.multipleSelection.length > 0) {
				// 点击完工
				if (type === 'finish') {
					this.toolarFn('ProduceOrder/Finished', detailsIds);
				}
				// 点击结案
				if (type === 'close-case') {
					this.toolarFn('ProduceOrder/CaseClosed', detailsIds);
				}
				// 点击反执行至开工
				if (type === 'de-excute-start') {
					this.toolarFn('ProduceOrder/ToStart', detailsIds);
				}
				// 点击反执行至完工
				if (type === 'de-excute-finish') {
					this.toolarFn('ProduceOrder/ToFinished', detailsIds);
				}
			} else {
				if (
					type === 'finish' ||
					type === 'close-case' ||
					type === 'de-excute-start' ||
					type === 'de-excute-finish'
				) {
					this.$message.warning({
						message: '请先勾选明细,在操作',
						showClose: true,
					});
				}
			}
			// 点击查询--上查
			if (type === 'up-check') {
				if (detailsIds.length > 0) {
					this.$http
						.post('ProduceOrder/Upper', { ids: detailsIds })
						.then((res) => {
							if (res.status === 200) {
								this.upOrDownList = res.data;
								this.dialogCX =
									res.data && res.data.length > 0
										? true
										: false;
								this.CXttile = '上查结果';
								this.CXcheckVal =
									res.data && res.data.length === 1
										? res.data[0].orderType
										: null; //只有一个，就个默认值
							}
							console.log('上查', res, this.upOrDownList);
						});
				} else {
					this.$message.warning({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能上查',
						showClose: true,
					});
				}
			}
			// 点击查询--下查
			if (type === 'down-check') {
				if (detailsIds.length > 0) {
					this.$http
						.post('ProduceOrder/Lower', { ids: detailsIds })
						.then((res) => {
							if (res.status === 200) {
								this.upOrDownList = res.data;
								this.dialogCX =
									res.data && res.data.length > 0
										? true
										: false;
								this.CXttile = '下查结果';
								this.CXcheckVal =
									res.data && res.data.length === 1
										? res.data[0].orderType
										: null; //只有一个，就个默认值
							}
						});
				} else {
					this.$message.warning({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能下查',
						showClose: true,
					});
				}
			}
			//打印
			if (type === 'print-aterial-list') {
				if (!detailsIds.length) {
					this.$message.error({
						message: '请选择需要打印/预览的用料清单信息',
						showClose: true,
					});
					return false;
				}
				if (this.pagefromData.documentStatus === 'c') {
					this.$http
						.post('ProduceMaterial/ProduceMaterialQuery', {
							detailsIds: detailsIds,
						})
						.then((res) => {
							if (res.status === 200) {
								this.$http
									.post('ProduceOrder/PrintCountList', {
										ids: detailsIds,
									})
									.then((result) => {
										if (result.status === 200) {
											let list = []; //用于存储分子不是0的数据
											let ids = []; //list的outSourcOrderNo集合
											list = res.data.list.filter(
												(item) => {
													return item.numerator;
												}
											);

											let lLength = list.length;
											for (let i = 0; i < lLength; i++) {
												ids.push(
													list[i].produceMaterialNo
												);
											}
											this.printIds = [...new Set(ids)];

											let length = this.printIds.length;
											// 这里为什么要用双循环对比？因为要拿i塞数据
											for (let i = 0; i < length; i++) {
												this.printTablelist[i] = [];
												for (
													let j = 0;
													j < lLength;
													j++
												) {
													if (
														this.printIds[i] ==
														list[j]
															.produceMaterialNo
													) {
														this.printTablelist[
															i
														].push(list[j]);
													}
												}
											}
											if (
												this.printTablelist.length > 0
											) {
												this.$nextTick(() => {
													newprintPreview1(
														'生产用料清单',
														this.printIds.length,
														this.printTablelist
													);
												});
											} else {
												this.$message.error({
													message:
														'所选用料清单明细为空，无法打印!',
													showClose: true,
												});
											}
										}
									});
							}
						});
				} else {
					this.$message.error({
						message: '只能打印预览已经审核的用料清单信息',
						showClose: true,
					});
				}
			}
		},
		// 保存---[不需要做必填校验]
		savePageData() {
			this.arrangeData();
			this.$http
				.post('ProduceOrder/Save', this.pagefromData)
				.then((res) => {
					if (res.status === 200) {
						this.pagefromData = JSON.parse(
							JSON.stringify(res.data)
						);
						if (res.data.details && res.data.details.length > 0) {
							res.data.details.forEach((it, index) => {
								this.pagefromData.details[index].seq = index;
								this.pagefromData.details[index].planDateTime =
									[it.planStartDate, it.planFinishDate];
							});
						}
						this.pagefromData.dataSources =
							this.pagefromData.dataSources + '';
						this.$message.success({
							message: '保存成功',
							showClose: true,
						});
					}
				});
		},
		// 提交
		submitPageData() {
			this.arrangeData();
			this.$http
				.post('ProduceOrder/Commit', this.pagefromData)
				.then((res) => {
					if (res.status === 200) {
						this.pagefromData = JSON.parse(
							JSON.stringify(res.data)
						);
						this.setExamine({
							status: res.status,
							data: res.data.tracking,
						});
						if (res.data.details && res.data.details.length > 0) {
							res.data.details.forEach((it, index) => {
								this.pagefromData.details[index].seq = index;
								this.pagefromData.details[index].planDateTime =
									[it.planStartDate, it.planFinishDate];
								this.pagefromData.details[index].Description =
									it.description || '';
							});
						}
						this.pagefromData.dataSources =
							this.pagefromData.dataSources + '';
						this.$message.success({
							message: '提交成功',
							showClose: true,
						});
					}
				});
		},
		// 顶部操作方法-有公共的部分封装下
		toolarFn(path, detailsIds) {
			let formdata = detailsIds
				? {
						ids: [this.pagefromData.id],
						detailsIds: detailsIds,
				  }
				: { ids: [this.pagefromData.id] };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					if (res.data && !detailsIds) {
						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,
							  });
					} else {
						this.dialogVisible = true;
						this.tableInfo = res.data;
					}
					this.getProductInfo(this.pagefromData.id, 'Nocopy');
					this.pagefromData.documentStatus = res.data.documentStatus;
				}
			});
		},
		changeBomVersion($event, $index) {},
		// 仓库选择修改-仓位信息更新
		changeWarehouse(value, index, type) {
			// 如果是详情带过来的数据 要根据仓库去查找下对于的仓位下拉数据,初始不要智控对应的仓位id
			let wit = this.warehouse.filter((it) => {
				return it.id === value;
			});
			if (type !== 'init') {
				this.pagefromData.details[index].stockLocId = '';
				this.pagefromData.details[index].customerId = '';
				this.pagefromData.details[index].customerStockId = '';
				this.pagefromData.details[index].customerWarehouseTag =
					this.warehouse && wit && wit.length > 0
						? wit[0].customerWarehouseTag
						: false;
			}
			if (this.warehouse.length > 0) {
				this.customerWarehouseTaglist[index] = this.warehouse.filter(
					(it) => {
						return value === it.id;
					}
				)
					? this.warehouse.filter((it) => {
							return value === it.id;
					  })[0].customerWarehouseTag
					: false;
			}
		},
		// 获取仓库
		getWarehouse(id, res) {
			if (id) {
				this.$http
					.get('SysConfig/GetWarehouseByOrg/' + id)
					.then((r) => {
						if (r.status === 200) {
							this.warehouse =
								r.data && r.data.length > 0
									? oldstocklist(
											r.data.concat(
												oldstocklist(res).stockList
											),
											'retrieve'
									  )
									: oldstocklist(
											oldstocklist(res).stockList,
											'retrieve'
									  );
							if (res) {
								this.customerWarehouseTaglist = [];
								res.forEach((item, index) => {
									this.customerWarehouseTaglist.push(
										this.warehouse.filter((it) => {
											return item.stockId === it.id;
										}).length > 0
											? this.warehouse.filter((it) => {
													return (
														item.stockId === it.id
													);
											  })[0].customerWarehouseTag
											: true
									);
								});
							}
						}
					});
			}
		},
		// 星星--头部必填ico显示
		mustAfter(obj, type) {
			let arry = [3, 4, 7, 8, 10];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 获取生产部门数据
		getProductdept(orgId) {
			if (orgId) {
				this.$http.post('SysConfig/GetDept/' + orgId).then((res) => {
					if (res.status === 200) {
						this.productDeptList = res.data;
					}
				});
			}
		},
		// 失焦处理
		selectBlur() {
			this.pagefromData.details.forEach((el) => {
				el.issalOrderNoshow = false;
				el.isexpectDateshow = false;
				el.ismaterialshow = false;
				el.isspecificationshow = false;
				el.isnumbershow = false;
				el.isworkShopshow = false;
				el.isplanDateTimeshow = false;
				el.isBomVersionShow = false;
				el.isstockIdshow = false;
				el.iscustomerIdshow = false;
				el.iscustomerStockIdshow = false;
				el.isremarkshow = false;
				el.isDescriptionshow = false;
			});
		},
		// 插入的行
		getInsertInfo() {
			this.addRow.pushkey = false;
			this.pagefromData.details = bottomAddRow(
				this.pagefromData.details,
				JSON.parse(JSON.stringify(this.addRow))
			);
			this.matterallCodelist.splice(
				this.pagefromData.details.length,
				0,
				[]
			);
			this.specificationalllist.splice(
				this.pagefromData.details.length,
				0,
				[]
			);
			this.customeStockArrylist.splice(
				this.pagefromData.details.length,
				0,
				[]
			);
			this.customerWarehouseTaglist.splice(
				this.pagefromData.details.length,
				0,
				true
			);
			this.$nextTick(() => {
				this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
					this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
			});
			this.selectBlur();
			this.arrangeData();
		},
		// 向下复制行
		bottomCopyRow(data) {
			// 判断行数
			if (this.selectRowIndexArr.length > 0) {
				if (this.selectRowIndexArr.length == 1) {
					const tableArr = JSON.parse(
						JSON.stringify(
							this.pagefromData.details[this.selectRowIndex]
						)
					);
					tableArr.id = 0;
					tableArr.parentOrderId = null;
					tableArr.pushkey = false;
					var insertNum = this.selectRowIndex + 1;
					this.pagefromData.details.splice(insertNum, 0, tableArr);
					this.matterallCodelist.splice(
						insertNum,
						0,
						JSON.parse(
							JSON.stringify(
								this.matterallCodelist[this.selectRowIndex]
							)
						)
					);
					this.specificationalllist.splice(
						insertNum,
						0,
						JSON.parse(
							JSON.stringify(
								this.matterallCodelist[this.selectRowIndex]
							)
						)
					);
					this.customeStockArrylist.splice(
						insertNum,
						0,
						JSON.parse(
							JSON.stringify(
								this.customeStockArrylist[this.selectRowIndex]
									? this.customeStockArrylist[
											this.selectRowIndex
									  ]
									: []
							)
						)
					);
					this.customerWarehouseTaglist.splice(
						insertNum,
						0,
						JSON.parse(
							JSON.stringify(
								this.customerWarehouseTaglist[
									this.selectRowIndex
								]
									? this.customerWarehouseTaglist[
											this.selectRowIndex
									  ]
									: {}
							)
						)
					);
					this.salePrecisionNumber.splice(
						insertNum,
						0,
						this.salePrecisionNumber[this.selectRowIndex]
					);
					this.isPrecision.splice(
						insertNum,
						0,
						this.isPrecision[this.selectRowIndex]
					);
					this.isCount.splice(
						insertNum,
						0,
						this.isCount[this.selectRowIndex]
					);
				} else {
					// console.log('must copy')
					// 获取最后选择的行
					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.pagefromData.details[el])
						);
						tableArr.id = 0;
						tableArr.parentOrderId = null;
						tableArr.pushkey = false;
						this.pagefromData.details.splice(
							lastIndex,
							0,
							tableArr
						);
						this.matterallCodelist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(this.matterallCodelist[el])
							)
						);
						this.specificationalllist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(this.matterallCodelist[el])
							)
						);
						this.customeStockArrylist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(
									this.customeStockArrylist[el]
										? this.customeStockArrylist[el]
										: []
								)
							)
						);
						this.customerWarehouseTaglist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(
									this.customerWarehouseTaglist[el]
								)
							)
						);
						this.salePrecisionNumber.splice(
							lastIndex,
							0,
							this.salePrecisionNumber[el]
						);
						this.isPrecision.splice(
							lastIndex,
							0,
							this.isPrecision[el]
						);
						this.isCount.splice(lastIndex, 0, this.isCount[el]);
					});
				}
				this.selectBlur();
				this.arrangeData();
			} else {
				this.$message.error({
					message: '请勾选一条行,在操作',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			if (this.selectRowIndexArr.length <= 0) {
				this.$message.warning({
					message: '请选择要删除的行!',
					showClose: true,
				});
				return;
			}
			// 不能为空
			if (
				this.pagefromData.details.length > 1 &&
				this.selectRowIndexArr.length < this.pagefromData.details.length
			) {
				this.selectRowIndexArr.forEach((k) => {
					this.pagefromData.details.forEach((l, index) => {
						if (k === l.seq) {
							this.pagefromData.details.splice(index, 1);
							this.matterallCodelist.splice(index, 1);
							this.specificationalllist.splice(index, 1);
							this.customeStockArrylist.splice(index, 1);
							this.customerWarehouseTaglist.splice(index, 1);
							this.salePrecisionNumber.splice(index, 1);
							this.isPrecision.splice(index, 1);
							this.isCount.splice(index, 1);
						}
					});
				});
				this.selectBlur();
				this.arrangeData();
			} else {
				this.$message.warning({
					message: '至少保留一行!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn(data) {
			let batcharry = [
				'salOrderNo',
				'expectDate',
				'planDateTime',
				'workShopId',
				'stockId',
				'customerId',
				'number',
				'remark',
			];
			this.pagefromData = batchhandle(
				this.pagefromData,
				this.matterallCodelist,
				this.batchfill.romIndex,
				this.batchfill.columnkey,
				batcharry
			);
			for (
				let i = this.batchfill.romIndex + 1;
				i < this.pagefromData.details.length;
				i++
			) {
				// 重新判断数量精度
				if (this.batchfill.columnkey == 'number') {
					this.numberChage(
						this.pagefromData.details[i].number,
						i,
						this.pagefromData.details[i],
						'number',
						this.isPrecision
					);
				}
			}
			// 如果有或者仓库的客户仓库的处理
			let taglist = [
				'stockId',
				'customerId',
				'specification',
				'materialId',
			];
			if (taglist.includes(this.batchfill.columnkey)) {
				this.pagefromData.details.forEach((it, index) => {
					if (index > this.batchfill.romIndex) {
						if (
							this.batchfill.columnkey === 'specification' ||
							this.batchfill.columnkey === 'materialId'
						) {
							this.pagefromData.details[index].number = 0;
						}
						if (this.batchfill.columnkey === 'stockId') {
							this.changeWarehouse(it.stockId, index);
						}
						if (this.batchfill.columnkey === 'customerId') {
							if (this.customerWarehouseTaglist[index]) {
								this.changecustomer(
									it.customerId,
									index,
									'product'
								);
							} else {
								this.pagefromData.details[index].customerId =
									'';
								this.pagefromData.details[
									index
								].customerStockId = '';
							}
						}
					}
				});
			}
		},
		//注意这里是解构
		tableCellClassName({ row, column, rowIndex, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		getRowCol(row, column, cell, event) {
			this.batchfill.romIndex = row.index;
			this.batchfill.columnIndex = column.index;
			if (typeof cell === 'string') {
				this.batchfill.columnkey = cell;
			} else {
				this.batchfill.columnkey = column.property;
			}
			// 处理表格下拉框输入框显示隐藏
			this.pagefromData.details.forEach((it, index) => {
				Object.assign(it, {
					issalOrderNoshow: false,
					isexpectDateshow: false,
					ismaterialshow: false,
					isspecificationshow: false,
					isnumbershow: false,
					isworkShopshow: false,
					isplanDateTimeshow: false,
					isBomVersionShow: false,
					isstockIdshow: false,
					iscustomerIdshow: false,
					iscustomerStockIdshow: false,
					isremarkshow: false,
					isDescriptionshow: false,
				});
			});

			var showtagarry = [
				'issalOrderNoshow',
				'isexpectDateshow',
				'ismaterialshow',
				'isspecificationshow',
				'isnumbershow',
				'isworkShopshow',
				'isplanDateTimeshow',
				'isBomVersionShow',
				'isstockIdshow',
				'iscustomerIdshow',
				'iscustomerStockIdshow',
				'isremarkshow',
				'isDescriptionshow',
			];
			var parentshowtagarry = [
				'salOrderNo',
				'expectDate',
				'materialId',
				'specification',
				'number',
				'workShopId',
				'planDateTime',
				'bomVersion',
				'stockId',
				'customerId',
				'customerStockId',
				'remark',
				'Description',
			];

			showtagarry.forEach((k, idx) => {
				if (column.property == parentshowtagarry[idx]) {
					this.pagefromData.details[row.index][k] = true;
					this.$nextTick((_) => {
						if (
							document.getElementById(column.property + row.index)
						) {
							document
								.getElementById(column.property + row.index)
								.focus();
						}
					});
				}
			});
		},
		// 明细选择行的数据处理
		selectdataSet(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (row) {
				this.selectRowIndex = row.seq;
			}
			if (selection && selection.length > 0) {
				this.selectRowIndex = selection[0].seq;
			}
			if (selection.length != 0) {
				this.selectRowIndexArr = selection.map((it) => {
					return it.seq;
				});
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 选择全部明细(全选)
		selectRowAll(selection) {
			this.selectdataSet(selection);
		},
		// 选择的行（单选）
		selectRow(selection, row) {
			this.selectdataSet(selection);
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderDetails.scss';

@import '@/assets/style/saleOrder/common.scss';

::v-deep(.bz .el-textarea__inner) {
	height: 38px !important;
}

::v-deep(.div-col .el-input__inner) {
	padding: 0 30px 0 8px;
	width: 165px !important;
}

::v-deep(.item-date .el-input__inner) {
	padding: 0 16px 0 30px !important;
}

.copyBtn1 {
	position: absolute;
	left: 85%;
	top: 30%;
}
</style>
