<template>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="order-create-container order-mc-bg main-container"
	>
		<div class="order-create-btn-group">
			<toolBtn
				:btnType="btnType"
				:isDisable="isDisableTop"
				@actionhandel="actionhandel"
			></toolBtn>
		</div>
		<div class="order-create-base-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				v-if="baseInfoForm.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="baseInfoForm" label-width="80px">
							<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="isEdit"
													:maxlength="255"
													@input="
														saleRexgu(
															baseInfoForm.billNo,
															'billNo'
														);
														purchaseCom(
															baseInfoForm.billNo,
															'billNo'
														);
													"
													placeholder="(保存时自动生成)"
													v-model.trim="
														baseInfoForm.billNo
													"
												></el-input>
												<div
													:data-clipboard-text="
														baseInfoForm.billNo
													"
													@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="isEdit"
												filterable
												placeholder="请选择调出类型"
												v-model="
													baseInfoForm.billTypeId
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														purchaseCom(
															baseInfoForm.billTypeId,
															'billTypeId'
														)
													"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.billType"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												placeholder="请选择单据状态"
												v-model="
													baseInfoForm.documentStatus
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														purchaseCom(
															baseInfoForm.documentStatus,
															'documentStatus'
														)
													"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.documentStatus"
												></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="isEdit"
												@change="stockOrgChange"
												class="click-cell-ipt-issue"
												placeholder="请选择单据状态"
												v-model="
													baseInfoForm.stockOrgId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.stockOrgId,
															'stockOrgId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.saleOrg"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="部门"
										>
											<el-cascader
												:disabled="isEdit"
												:options="statusForm.saleParts"
												:props="optionProps"
												:show-all-levels="false"
												@change="
													purchaseCom(
														baseInfoForm.deptId,
														'deptId',
														'type'
													)
												"
												class="click-cell-ipt-c"
												clearable
												placeholder="请选择部门"
												ref="cascader"
												style="font-size: 12px"
												v-model="baseInfoForm.deptId"
											></el-cascader>
										</el-form-item>
										<el-form-item
											:maxlength="50"
											:required="true"
											class="item-bt-s"
											label="调拨类型"
										>
											<el-select
												:disabled="true"
												filterable
												placeholder="请选择调出类型"
												v-model="
													baseInfoForm.allocatingType
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														purchaseCom(
															baseInfoForm.allocatingType,
															'allocatingType'
														)
													"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.allocatingType"
												></el-option>
											</el-select>
										</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
													class="item-bt-s Iisshow"
													label="收货人"
												>
													<el-input
														:disabled="isEdit"
														:maxlength="15"
														@input="
															saleRexgu(
																baseInfoForm.consignee,
																'consignee'
															);
															purchaseCom(
																baseInfoForm.consignee,
																'consignee'
															);
														"
														placeholder="请输入联系人"
														v-model="
															baseInfoForm.consignee
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.consignee
														"
														@click="saleOrderCopy"
														class="copyBtn"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="电话"
												>
													<el-input
														:disabled="isEdit"
														:maxlength="11"
														@input="
															saleRexgu(
																baseInfoForm.phone,
																'phone'
															);
															purchaseCom(
																baseInfoForm.phone,
																'phone'
															);
														"
														placeholder=" "
														v-model="
															baseInfoForm.phone
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.phone
														"
														@click="saleOrderCopy"
														class="copyBtn"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="仓管员"
												>
													<el-select
														:clearable="true"
														:disabled="isEdit"
														class="click-cell-ipt-issue"
														placeholder="请选择仓管员"
														v-model="
															baseInfoForm.stockerId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															@click="
																purchaseCom(
																	baseInfoForm.stockerId,
																	'stockerId'
																)
															"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.salePerson"
														></el-option>
													</el-select>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											:required="true"
											class="item-bt-s item-date"
											label="下单日期"
										>
											<el-date-picker
												:disabled="isEdit"
												@change="
													purchaseCom(
														baseInfoForm.date,
														'date'
													)
												"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
												type="date"
												v-model="baseInfoForm.date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="地址"
										>
											<el-input
												:autosize="{
													minRows: 3,
													maxRows: 3,
												}"
												:disabled="isEdit"
												@input="
													purchaseCom(
														baseInfoForm.address,
														'address'
													)
												"
												maxlength="150"
												placeholder=" "
												resize="none"
												type="textarea"
												v-model.trim="
													baseInfoForm.address
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="8"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<el-tab-pane label="操作记录">
					<div class="base-info-form-box">
						<el-form
							:model="baseInfoForm"
							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="true"
												placeholder
												v-model.trim="
													baseInfoForm.creatorName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="创建日期"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.createDate
												"
											></el-input>
										</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-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.modifyName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.modifyDate
												"
											></el-input>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="提交时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.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="true"
														placeholder
														v-model.trim="
															baseInfoForm.checkName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model.trim="
															baseInfoForm.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="order-create-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="isEdit"
					@copyCellcolumn="copyCellcolumn"
					@copyRow="bottomCopyRow"
					@deleteRow="selectDeleteRow"
					@insertObj="getInsertInfo"
				></DetailsOperation>
			</div>
			<div class="tell-info-table">
				<el-table
					:cell-style="disabledCellStyle"
					:data="baseInfoForm.details"
					:header-cell-class-name="mustAfter"
					:max-height="tableHeight"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectAll"
					border
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
					v-loading="isLoading"
				>
					<el-table-column
						align="center"
						fixed
						type="selection"
						width="40"
					/>
					<el-table-column
						align="left"
						label="销售订单号"
						prop="salOrderBillNo"
						width="180"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>销售订单号
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSalOrderBillNo">{{
								scope.row.salOrderBillNo
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isSalOrderBillNo"
							>
								<input
									:disabled="isEdit"
									:id="'salOrderBillNo' + scope.$index"
									autocomplete="off"
									@input="
										detailsCom(
											scope.row.salOrderBillNo,
											'salOrderBillNo',
											scope.row,
											scope.column
										)
									"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'salOrderBillNo'
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.salOrderBillNo"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料编码"
						prop="materialId"
						width="180"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope" class="matter-code-box">
							<span v-if="!scope.row.isMaterialId">{{
								scope.row.materialNumber
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'materialId' + scope.$index"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											scope.$index,
											'materialId'
										);
									}
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'materialId'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'materialId'
									)
								"
								class="click-cell-ipt"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isMaterialId"
								v-model="scope.row.materialId"
							>
								<el-option
									:key="item.id + item.number"
									:label="item.number"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'materialId',
											scope.row,
											scope.column
										)
									"
									v-for="item in matterallCodelist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						id="sku"
						label="规格型号(SKU)"
						prop="specificationId"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>规格型号(SKU)
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSpecificationId">{{
								scope.row.specification
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'specificationId' + scope.$index"
								:remote-method="
									(query) => {
										skuCodeChange(
											query,
											scope.$index,
											'specification'
										);
									}
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'specificationId'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'specificationId'
									)
								"
								class="click-cell-ipt"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isSpecificationId"
								v-model="scope.row.specificationId"
							>
								<el-option
									:key="item.id + item.specifications"
									:label="item.specifications"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'specificationId',
											scope.row,
											scope.column
										)
									"
									v-for="item in specificationalllist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="180"
					>
						<template #default="scope">
							<span>{{ scope.row.materialName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="单位"
						prop="unitId"
						width="84"
					>
						<template #default="scope">
							<span>{{
								getName(statusForm.saleUnits, scope.row.unitId)
							}}</span>
							<!-- <el-select :disabled="true" :clearable="false" v-model="scope.row.unitId" class="click-cell-ipt" placeholder="请选择">
                <el-option v-for="item in statusForm.saleUnits" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>-->
						</template>
					</el-table-column>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'qty')" -->
					<el-table-column
						align="left"
						label="调拨数量"
						prop="qty"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调拨数量
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isQty">{{
								scope.row.qty
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isQty"
							>
								<input
									:disabled="isEdit"
									:id="'qty' + scope.$index"
									:maxlength="8"
									autocomplete="off"
									@blur="
										detailsCom(
											scope.row.qty,
											'qty',
											scope.row,
											scope.column
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.qty"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="调出仓库"
						prop="srcStockId"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调出仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSrcStockId">{{
								getName(
									statusForm.warehouse,
									scope.row.srcStockId
								)
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'srcStockId' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'srcStockId'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isSrcStockId"
								v-model="scope.row.srcStockId"
							>
								<el-option
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'srcStockId',
											scope.row,
											scope.column,
											item.disabled
										)
									"
									v-for="item in statusForm.warehouse"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="调出客户"
						prop="srcCustomer"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调出客户
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSrcCustomer">{{
								getName(
									statusForm.custmers,
									scope.row.srcCustomer
								)
							}}</span>
							<el-select
								:clearable="true"
								:disabled="isEdit || scope.row.isOutCusHouse"
								:id="'srcCustomer' + scope.$index"
								@clear="
									clearCom(
										scope.row.srcCustomer,
										'srcCustomer',
										scope.row,
										scope.column
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'srcCustomer'
									)
								"
								class="click-cell-ipt-issue"
								placeholder="请输入关键词"
								v-if="scope.row.isSrcCustomer"
								v-model="scope.row.srcCustomer"
							>
								<el-option
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'srcCustomer',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.custmers"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="调出客户仓库"
						prop="srcCustomerStock"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调出客户仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSrcCustomerStock">{{
								getName(
									customeStockArrylist[scope.$index],
									scope.row.srcCustomerStock
								)
							}}</span>
							<el-select
								:clearable="true"
								:disabled="isEdit || scope.row.isOutCusHouse"
								:id="'srcCustomerStock' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'srcCustomerStock'
									)
								"
								class="click-cell-ipt-issue"
								placeholder="请输入关键词"
								v-if="scope.row.isSrcCustomerStock"
								v-model="scope.row.srcCustomerStock"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'srcCustomerStock',
											scope.row,
											scope.column,
											item.disabled
										)
									"
									v-for="item in customeStockArrylist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="调入仓库"
						prop="destStockId"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调入仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDestStockId">{{
								getName(
									statusForm.warehouseInset,
									scope.row.destStockId
								)
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'destStockId' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'destStockId'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isDestStockId"
								v-model="scope.row.destStockId"
							>
								<el-option
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'destStockId',
											scope.row,
											scope.column,
											item.disabled
										)
									"
									v-for="item in statusForm.warehouseInset"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="调入客户"
						prop="destCustomer"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调入客户
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDestCustomer">{{
								getName(
									statusForm.deCustmers,
									scope.row.destCustomer
								)
							}}</span>
							<el-select
								:clearable="true"
								:disabled="isEdit || scope.row.isInnerCusHouse"
								:id="'destCustomer' + scope.$index"
								@clear="
									clearCom(
										scope.row.destCustomer,
										'destCustomer',
										scope.row,
										scope.column
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'destCustomer'
									)
								"
								class="click-cell-ipt-issue"
								placeholder="请输入关键词"
								v-if="scope.row.isDestCustomer"
								v-model="scope.row.destCustomer"
							>
								<el-option
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'destCustomer',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.deCustmers"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="调入客户仓库"
						prop="destCustomerStock"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>调入客户仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDestCustomerStock">{{
								getName(
									customeStockArrylistInner[scope.$index],
									scope.row.destCustomerStock
								)
							}}</span>
							<el-select
								:clearable="true"
								:disabled="isEdit || scope.row.isInnerCusHouse"
								:id="'destCustomerStock' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'destCustomerStock'
									)
								"
								class="click-cell-ipt-issue"
								placeholder="请输入关键词"
								v-if="scope.row.isDestCustomerStock"
								v-model="scope.row.destCustomerStock"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'destCustomerStock',
											scope.row,
											scope.column,
											item.disabled
										)
									"
									v-for="item in customeStockArrylistInner[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="备注"
						prop="remarks"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isRemarks">{{
								scope.row.remarks
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isRemarks"
							>
								<input
									:disabled="isEdit"
									:id="'remarks' + scope.$index"
									autocomplete="off"
									@input="
										detailsCom(
											scope.row.remarks,
											'remarks',
											scope.row,
											scope.column
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.remarks"
								/>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
	</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import { countMethodsUnitNumber } from '@/utils/count.js';
import { getStaffListApiUser } from '@/utils/api.js';
import examineTop from '@/components/examineTop/index.vue';
import {
	activeChangeOrgClearData,
	activeMaterialSkuSelctGetData,
	activeCopyMaterialGetData,
	activeInsertUpDownData,
	activeMaterialSkuSearchGetData,
	activeSaveSubmitGetData,
	getArrayName,
	orderCopy,
	filterMaterialData,
} from '@/utils/takeMethods.js';
import { removeChildren, splitJointList } from '@/utils/pubulic';
import {
	directBtnAdd,
	directBtnEdit,
	directDefaultTableInfo,
	directStatusForm,
	optionProps,
	storeObj,
} from '@/utils/variable.js';
import Decimal from 'decimal.js';
export default {
	name: 'ActiveDirect',
	components: {
		examineTop,
	},
	data() {
		return {
			salePrecisionNumber: [],
			isLoading: false,
			timer: null,
			isPrecision: [],
			unitData: [],
			isCount: [],
			isDisableTop: false,
			statusForm: JSON.parse(JSON.stringify(directStatusForm)),
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			baseInfoForm: JSON.parse(JSON.stringify(directDefaultTableInfo)),
			addRow: {},
			storeObj: JSON.parse(JSON.stringify(storeObj)),
			loading: false, // loding
			isEdit: true, // 禁止编辑
			isSetlementDifference: true,
			selectRowIndexArr: [],
			btnType: JSON.parse(JSON.stringify(directBtnAdd)), // 不需要的按钮
			saleUnits: [],
			currRow: '', // 表格 编辑 当前行
			currColumn: '', // 表格 编辑 当前列
			selectRowIndex: 0, // 选择的行
			heightNum: 0, // 容器高度
			multipleSelection: [], // 选择的行
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrdedetailIds: [], // 勾选的明细id集合
			pushDownList: [], // 下推集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			deleteId: '', // del id
			saveIds: '',
			templateList: [],
			customeStockArrylist: [], // 调出客户仓库集合
			customeStockArrylistInner: [], // 调入客户仓库
			matterallCodelist: [], // 物料下拉数据
			specificationalllist: [], // 规格型号（sku）下拉数据
			tableHeight: 0,
			isOrder: true,
			recordIndex: '',
		};
	},
	methods: {
		Init() {
			// 初始化
			let vuexKey = ['customer', 'unitAll'];
			let setVuexData = ['setCustomer', 'setAllUnit'];
			let requestQueryUrl = [
				'SysConfig/GetCustomer',
				'SysConfig/GetUnitAllProperty',
			];
			let resDataQuery = [['deCustmers', 'custmers'], 'saleUnits'];
			vuexKey.forEach((ele, ind) => {
				if (this[vuexKey[ind]] && this[vuexKey[ind]].length > 0) {
					if (typeof resDataQuery[ind] == 'string') {
						this.statusForm[resDataQuery[ind]] = JSON.parse(
							JSON.stringify(this[vuexKey[ind]])
						);
					} else {
						resDataQuery[ind].forEach((ele, index) => {
							this.statusForm[resDataQuery[ind][index]] =
								JSON.parse(JSON.stringify(this[vuexKey[ind]]));
						});
					}
					if (vuexKey[ind] == 'unitAll') {
						this.unitData = this.statusForm[resDataQuery[ind]];
					}
				} else {
					this.$http
						.showLoading(false)
						.get(requestQueryUrl[ind])
						.then((r) => {
							if (r.status === 200) {
								if (typeof resDataQuery[ind] == 'string') {
									this.statusForm[resDataQuery[ind]] = r.data;
									this[setVuexData[ind]](
										this.statusForm[resDataQuery[ind]]
									);
								} else {
									resDataQuery[ind].forEach((ele, index) => {
										this.statusForm[
											resDataQuery[ind][index]
										] = r.data;
										this[setVuexData[ind]](
											this.statusForm[
												resDataQuery[ind][index]
											]
										);
									});
								}
								// 单位
								if (vuexKey[ind] == 'unitAll') {
									this.unitData =
										this.statusForm[resDataQuery[ind]];
								}
							}
						});
				}
			});

			// 公共人员接口 - 'SysConfig/GetUserList','testUserPerson','setGetAllUserList' 'getAllUserList'
			if (this.getAllUserList && this.getAllUserList.length > 0) {
				this.statusForm.salePerson = this.getAllUserList;
			} else {
				getStaffListApiUser().then((r) => {
					r.status == 200 ? this.setGetAllUserList(r.data) : false;
					r.status == 200
						? (this.statusForm.salePerson = r.data)
						: (this.statusForm.salePerson = []);
				});
			}

			if (
				this.stkdirecttrStatus &&
				JSON.stringify(this.stkdirecttrStatus) !== '{}'
			) {
				this.statusForm.allocatingType = JSON.parse(
					JSON.stringify(this.stkdirecttrStatus.allocatingType)
				);
				this.statusForm.billType = JSON.parse(
					JSON.stringify(this.stkdirecttrStatus.billType)
				);
				this.statusForm.documentStatus = JSON.parse(
					JSON.stringify(this.stkdirecttrStatus.documentStatus)
				);
			} else {
				this.$http
					.showLoading(false)
					.get('Stkdirecttransfers/GetStatus')
					.then((req) => {
						if (req.status == 200) {
							this.setStkdirecttrStatus(req.data);
							this.statusForm.allocatingType =
								req.data.allocatingType; // 调拨类型
							this.statusForm.billType = req.data.billType; // 分步式调出单类型
							this.statusForm.documentStatus =
								req.data.documentStatus; // 订单状态
						}
					});
			}

			var windowHeight = document.documentElement.clientHeight;
			this.heightNum = windowHeight - 102;
			this.tableHeight = windowHeight - 420;
			this.baseInfoForm.date = this.getNowTime();
			this.statusForm.saleOrg = this.orgIdArr;
			this.statusForm.settlementOrgList = this.orgIdArr;
			this.baseInfoForm.allocatingType = 'b';
			let keys = Object.keys(this.baseInfoForm.details[0]); // 获取添加对象
			for (const key in this.baseInfoForm.details[0]) {
				if (keys.indexOf(key) > -1) {
					this.addRow[key] = this.baseInfoForm.details[0][key];
				}
			}
			if (
				this.$route.query.type === 'add' ||
				this.$route.query.type === 'copy'
			) {
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.stockOrgId =
					this.$store.state && this.$store.state.org
						? this.$store.state.org.orgId
						: null;
				this.baseInfoForm.billTypeId = 'c';
				this.isEdit = false;
				if (this.$route.query.type === 'copy') {
					this.getPurChaseDetails();
				}
			}
			if (this.$route.query.type === 'add') {
				this.$http
					.showLoading(false)
					.get(
						'SysConfig/GetWarehouseByOrg/' +
							this.baseInfoForm.stockOrgId
					)
					.then((res) => {
						if (res.status === 200) {
							res.data.forEach((el) => {
								this.statusForm.warehouse = res.data;
								this.statusForm.warehouseInset = res.data;
							});
						}
					});
			}
			if (
				this.$route.query.type == 'pushDown' &&
				this.$route.query.pushDownData
			) {
				this.isEdit = false;
				this.getPurChaseDetails(
					JSON.parse(
						decodeURIComponent(this.$route.query.pushDownData)
					)
				);
			}
			if (
				this.$route.query.type == 'details' &&
				this.$route.query.id &&
				this.$route.query.status
			) {
				this.getPurChaseDetails();
			}
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		stockOrgChange() {
			this.$http
				.get(
					'SysConfig/GetWarehouseByOrg/' +
						this.baseInfoForm.stockOrgId
				)
				.then((res) => {
					if (res.status === 200) {
						res.data.forEach((el) => {
							this.statusForm.warehouse = res.data;
							this.statusForm.warehouseInset = res.data;
						});
					}
				});
		},
		getName(arr, val) {
			return getArrayName(arr, val);
		},
		clearCom(value, key, row, column) {
			if (value === '') {
				if (key === 'srcCustomer') {
					this.baseInfoForm.details[row.index].srcCustomerStock = '';
					this.customeStockArrylist[row.index] = [];
				}
				if (key === 'destCustomer') {
					this.baseInfoForm.details[row.index].destCustomerStock = '';
					this.customeStockArrylistInner[row.index] = [];
				}
			}
		},
		verificationNum(val, index, key, isPrecision) {
			isPrecision[index] = isPrecision[index]
				? isPrecision[index]
				: false;
			this.salePrecisionNumber[index] =
				this.salePrecisionNumber[index] ||
				this.salePrecisionNumber[index] == 0
					? this.salePrecisionNumber[index]
					: 10;
			if (
				!this.baseInfoForm.details[index].materialId &&
				!this.$route.query.id
			) {
				isPrecision[index] = true;
			}
			if (val) {
				if (isPrecision[index]) {
					if (val.toString().indexOf('.') !== -1) {
						this.baseInfoForm.details[index][key] = Decimal(
							val
						).toFixed(0, Decimal.ROUND_DOWN);
					}
					this.baseInfoForm.details[index][key] =
						this.baseInfoForm.details[index][key]
							.toString()
							.replace(/\D/g, '');
				} else {
					let numD = '';
					let count = '\\d';
					for (
						let ind = 0;
						ind < this.salePrecisionNumber[index];
						ind++
					) {
						numD = numD + count;
					}
					let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
					this.baseInfoForm.details[index][key] =
						this.baseInfoForm.details[index][key]
							.toString()
							.replace(/[^\d^\\.]+/g, '')
							.replace('.', '$#$')
							.replace(/\./g, '')
							.replace('$#$', '.')
							.replace(eval(reg), '$1$2.$3');
				}
			}
		},
		valueRemoveZero(row, key) {
			if (
				this.baseInfoForm.details[row.index][key]
					.toString()
					.charAt(
						this.baseInfoForm.details[row.index][key].toString()
							.length - 1
					) != '.'
			) {
				return this.baseInfoForm.details[row.index][key] * 1;
			} else {
				return this.baseInfoForm.details[row.index][key];
			}
		},
		saleRexgu(val, key) {
			if (key === 'billNo') {
				if (val) {
					this.baseInfoForm.billNo = val
						.toString()
						.replace(/[^A-Za-z0-9\\-]/g, '');
				}
			}
			if (key === 'linkMan') {
				if (val) {
					this.baseInfoForm.linkMan = val
						.toString()
						.replace(/[^\\a-zA-Z\u4E00-\u9FA5]/g, '');
				}
			}
			if (key === 'phone') {
				if (val) {
					this.baseInfoForm.phone = val
						.toString()
						.replace(/^\.+|[^\d]+/g, '');
				}
			}
		},
		getPurChaseDetails(res) {
			if (res) {
				this.isLoading = true;
				this.baseInfoForm = res;
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.id = 0;
				if (!this.baseInfoForm.billTypeId) {
					this.baseInfoForm.billTypeId = 'c';
				}
				this.getMaterialCustomerDataAll();
				this.baseInfoForm.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].materialId = el.materialId;
					this.baseInfoForm.details[ind].specificationId =
						el.materialId;
					this.baseInfoForm.details[ind].isDisabled = false;
					this.baseInfoForm.details[ind].isCusHouse = true;
					this.baseInfoForm.details[ind].id = 0;
					this.baseInfoForm.details[ind].fid = 0;
				});
				this.isLoading = false;
			} else {
				this.statusForm.settlementOrgList = this.orgIdArr;
				this.deleteId = this.$route.query.id;
				this.isLoading = true;
				this.$http
					.showLoading(false)
					.post('Stkdirecttransfers/GetInfo/' + this.$route.query.id)
					.then(async (req) => {
						if (req.status == 200) {
							this.baseInfoForm = req.data;
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
							} else {
								this.isEdit = true;
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							if (this.$route.query.type === 'copy') {
								this.templateList = [];
								this.baseInfoForm.details.forEach(
									(element, index) => {
										if (
											this.$route.query.detailsIds.indexOf(
												element.id.toString()
											) !== -1
										) {
											this.templateList.push(
												this.baseInfoForm.details[index]
											);
										}
									}
								);
								this.baseInfoForm.details = this.templateList;
							}
							if (!this.baseInfoForm.billTypeId) {
								this.baseInfoForm.billTypeId = 'c';
							}
							await this.$http
								.showLoading(false)
								.get(
									'SysConfig/GetWarehouseByOrg/' +
										this.baseInfoForm.stockOrgId
								)
								.then((res) => {
									if (res.status === 200) {
										res.data.forEach((el) => {
											this.statusForm.warehouse =
												res.data;
											// this.statusForm.warehouse = splitJointList(this.baseInfoForm.details, this.statusForm.warehouse, 'outStockList')
											this.statusForm.warehouseInset =
												res.data;
											// this.statusForm.warehouseInset = splitJointList(
											//   this.baseInfoForm.details,
											//   this.statusForm.warehouseInset,
											//   'inStockList'
											// )
										});
									}
								});
							await this.getMaterialCustomerDataAll();
							this.baseInfoForm.details.forEach((el, ind) => {
								this.baseInfoForm.details[ind].materialId =
									el.materialId;
								this.baseInfoForm.details[ind].specificationId =
									el.materialId;
								this.baseInfoForm.details[
									ind
								].isDisabled = false;
								this.baseInfoForm.details[
									ind
								].isCusHouse = true;
								let rowObejct =
									this.statusForm.warehouse.filter(
										(it) => it.id === el.srcStockId
									);
								el.isOutCusHouse =
									rowObejct.length > 0
										? !rowObejct[0].customerWarehouseTag
										: true;
								let rowObject1 =
									this.statusForm.warehouseInset.filter(
										(it) => it.id === el.destStockId
									);
								el.isInnerCusHouse =
									rowObject1.length > 0
										? !rowObject1[0].customerWarehouseTag
										: true;
								el.isSalOrderBillNo = false;
								el.isMaterialId = false;
								el.isSpecificationId = false;
								el.isQty = false;
								el.isSrcStockId = false;
								el.isSrcCustomer = false;
								el.isSrcCustomerStock = false;
								el.isDestStockId = false;
								el.isDestCustomer = false;
								el.isDestCustomerStock = false;
								el.isRemarks = false;
							});
							if (this.$route.query.type === 'copy') {
								this.detailBtn = [];
								this.baseInfoForm.billNo = '';
								this.baseInfoForm.id = 0;
								this.isEdit = false;
								this.baseInfoForm.details.forEach((el, ind) => {
									this.isCount[ind] = 1;
									this.getCountUnitCom(
										ind,
										this.baseInfoForm.details[ind].qty,
										this.baseInfoForm.details[ind].qty,
										true,
										'qty'
									);
									this.baseInfoForm.details[ind].id = 0;
									this.baseInfoForm.details[ind].fid = 0;
								});
								this.baseInfoForm.documentStatus = 'a';
								this.isOrder = true;
							}
						}
						this.isLoading = false;
					});
			}
		},
		// 详情 - 克隆 - 下推进入 一次性获取物料编码 + 客户仓库数据
		async getMaterialCustomerDataAll() {
			let materQuery = this.baseInfoForm.details.map((it) => {
				return it.materialNumber;
			});
			let customerQuery = [];
			let customerListIndex = [];
			let customerQueryInner = [];
			let customerListIndexInner = [];
			this.baseInfoForm.details.forEach((el, ind) => {
				if (el.srcCustomer) {
					customerQuery.push(el.srcCustomer);
					customerListIndex.push(ind);
				}
				if (el.destCustomer) {
					customerQueryInner.push(el.destCustomer);
					customerListIndexInner.push(ind);
				}
			});
			let _result = await this.matterCodeChangeAll(
				materQuery,
				'Number',
				this.baseInfoForm.stockOrgId
			);
			let _resultHouse = await this.getCustmerStoreAll(
				customerQuery,
				this.baseInfoForm.stockOrgId
			);
			let _resultHouseInner = await this.getCustmerStoreAll(
				customerQueryInner,
				this.baseInfoForm.stockOrgId
			);
			this.baseInfoForm.details.forEach((el, index) => {
				this.matterallCodelist[index] = _result.filter((item) => {
					return item.number === el.materialNumber;
				});
				this.specificationalllist[index] = _result.filter((item) => {
					return item.number === el.materialNumber;
				});
				if (customerListIndex.length > 0) {
					customerListIndex.forEach((el) => {
						if (el == index) {
							this.customeStockArrylist[index] = _resultHouse;
						}
					});
				}
				if (customerListIndexInner.length > 0) {
					customerListIndexInner.forEach((el) => {
						if (el == index) {
							this.customeStockArrylistInner[index] =
								_resultHouseInner;
						}
					});
				}
				this.matterallCodelist[index].forEach((ele) => {
					this.baseInfoForm = activeMaterialSkuSearchGetData(
						this.baseInfoForm,
						ele,
						index
					);
				});
			});
		},
		// 获取所有客户仓库信息
		async getCustmerStoreAll(customerQuery, id) {
			if (customerQuery.length > 0) {
				return this.$http
					.post('SysConfig/GetCustomerStockList', {
						customerIds: customerQuery,
						orgId: id,
					})
					.then((res) => {
						if (res.status === 200) {
							return res.data;
						} else {
							return [];
						}
					});
			} else {
				return [];
			}
		},
		// 获取所有物料携带信息
		async matterCodeChangeAll(query, type, id) {
			return this.$http
				.post('SysConfig/GetMaterialLikeList', {
					names: query,
					file: type,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data.reverse();
					} else {
						return [];
					}
				});
		},
		// 是否211、赠品
		isCheckBox(val, index, key) {
			this.baseInfoForm.details[index][key] = val;
		},
		// 单据头公共fun
		purchaseCom(value, key, type) {
			if (!!value && !!key) {
				this.baseInfoForm[key] = value;
				if (key === 'address') {
					this.baseInfoForm[key] = value;
				}
			} else {
				if (key === 'address') {
					this.baseInfoForm[key] = '';
				} else {
					delete this.baseInfoForm[key];
				}
			}
			if (key === 'stockOrgId') {
				this.customeStockArrylist[0] = [];
				this.customeStockArrylistInner[0] = [];
				this.baseInfoForm = activeChangeOrgClearData(
					this.baseInfoForm,
					this.addRow
				);
			}
			if (type) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		// 详情公共fun
		detailsCom(value, key, row, column, disable) {
			if (this.baseInfoForm.details[row.index].unitId) {
				let tempList = this.unitData.filter(
					(it) =>
						it.id === this.baseInfoForm.details[row.index].unitId
				);
				tempList[0].precision == 0
					? (this.isPrecision[row.index] = true)
					: (this.isPrecision[row.index] = false);
				tempList[0].precision == 0
					? (this.salePrecisionNumber[row.index] = 0)
					: (this.salePrecisionNumber[row.index] =
							tempList[0].precision);
			}
			if (!disable) {
				this.currRow = row.index;
				this.storeObj.storeVal = value;
				this.storeObj.storekey = key;
				this.storeObj.storeRow = row.index;
				this.storeObj.storeCol = column.index;
				if (key === 'materialId' || key === 'specificationId') {
					this.matterallCodelist[row.index].forEach((el) => {
						if (value === el.id) {
							let result = activeMaterialSkuSelctGetData(
								this.baseInfoForm,
								el,
								this.currRow,
								this.unitData,
								this.isPrecision,
								this.salePrecisionNumber
							);
							this.baseInfoForm = result.baseInfoForm;
							this.precision = result.precision;
							this.salePrecisionNumber =
								result.salePrecisionNumber;
							this.baseInfoForm.details[row.index].qty = '0';

							this.baseInfoForm.details[
								row.index
							].isMaterialId = false;
							this.baseInfoForm.details[
								row.index
							].isSpecificationId = false;
							document.getElementById(key + row.index).blur();
						}
					});
				} else {
					this.baseInfoForm.details[this.currRow][key] = value;
				}
				if (key === 'srcStockId' || key === 'destStockId') {
					let warehouseKey =
						key === 'srcStockId' ? 'warehouse' : 'warehouseInset';
					let resKey =
						key === 'srcStockId'
							? 'isOutCusHouse'
							: 'isInnerCusHouse';
					let clearKeyO =
						key === 'srcStockId' ? 'srcCustomer' : 'destCustomer';
					let clearKeyT =
						key === 'srcStockId'
							? 'srcCustomerStock'
							: 'destCustomerStock';
					let rowObejct = this.statusForm[warehouseKey].filter(
						(it) => it.id === value
					);
					this.baseInfoForm.details[row.index][resKey] =
						rowObejct.length > 0
							? !rowObejct[0].customerWarehouseTag
							: true;
					this.baseInfoForm.details[row.index][clearKeyO] = '';
					this.baseInfoForm.details[row.index][clearKeyT] = '';
				}
				if (key === 'srcCustomer' || key === 'destCustomer') {
					let clearKey =
						key === 'srcCustomer'
							? 'srcCustomerStock'
							: 'destCustomerStock';
					let queryKey =
						key === 'srcCustomer'
							? 'customeStockArrylist'
							: 'customeStockArrylistInner';
					this.baseInfoForm.details[row.index][clearKey] = '';
					if (value && this.baseInfoForm.stockOrgId) {
						this.getCustomerStoreCom(
							value,
							this.baseInfoForm.stockOrgId,
							row.index,
							queryKey
						);
					}
				}
				if (key === 'qty') {
					this.verificationNum(
						this.baseInfoForm.details[row.index][key],
						row.index,
						'qty',
						this.isPrecision
					);
					if (this.baseInfoForm.details[row.index][key]) {
						if (!isNaN(this.baseInfoForm.details[row.index][key])) {
							if (!this.isCount[row.index]) {
								this.isCount[row.index] = 1;
							}
							if (
								this.baseInfoForm.details[row.index][
									key
								].indexOf('.') !== -1
							) {
								this.getCountUnitCom(
									row.index,
									this.baseInfoForm.details[row.index][key],
									this.baseInfoForm.details[row.index].qty,
									false,
									'qty',
									'copy'
								);
							} else {
								this.isCount[row.index] = 2;
							}
						}
					}
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'salOrderBillNo' || key === 'remarks') {
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
			}
		},
		// 顶部公共按钮
		actionhandel(type) {
			this.isDisableTop = true;
			setTimeout(() => {
				this.isDisableTop = false;
			}, 2000);
			let ids = [];
			let detailsIds = []; // 提取明细id
			if (this.$route.query.id) {
				ids = [this.$route.query.id];
			}
			if (this.saveIds != '') {
				ids = [this.saveIds];
			}
			if (
				this.baseInfoForm.details &&
				this.baseInfoForm.details.length > 0
			) {
				detailsIds = [
					...new Set(
						this.multipleSelection
							.filter((item) => {
								if (item.id) {
									return item.id;
								}
							})
							.map((it) => {
								return it.id;
							})
					),
				];
			}
			this.OrdedetailIds = detailsIds; // 勾选的明细id集合
			if (type == 'add') {
				this.$router.push({
					path: '/warehouse/allocation/activeDirect',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			if (type === 'save') {
				this.saveSubmitCom(type);
			}
			if (type === 'submit') {
				this.saveSubmitCom(type);
			}
			if (type === 'revoke') {
				this.revokePageData(ids);
			}
			if (type === 'audit') {
				this.unAuditPageDataCom(ids, type);
			}
			if (type === 'de-approval') {
				this.unAuditPageDataCom(ids, type);
			}
			if (type === 'delet') {
				this.deleteOrder(ids);
			}
		},
		// 删除
		deleteOrder(ids) {
			if (!isNaN(ids[0])) {
				this.$http
					.post('Stkdirecttransfers/Delete', { ids: ids })
					.then((res) => {
						if (res.status === 200) {
							if (res.data[0].isSuccess) {
								if (
									this.$store.state &&
									this.$store.state.topNavTag
								) {
									this.$store.state.topNavTag.tags.splice(
										this.$store.state.topNavTag.tags.findIndex(
											(item) =>
												item.path === this.$route.path
										),
										1
									);
									this.$router.push(
										this.$store.state.topNavTag.tags[
											this.$store.state.topNavTag.tags
												.length - 1
										].path
									);
								}
							} else {
								this.$message.error({
									message: res.data[0].msg,
									showClose: true,
								});
							}
						}
					});
			} else {
				this.$message.error({
					message: '不能删除此单据!',
					showClose: true,
				});
			}
		},
		// 审核 - 反审
		unAuditPageDataCom(ids, type) {
			let pathName =
				type === 'audit'
					? 'Stkdirecttransfers/Check'
					: 'Stkdirecttransfers/NoCheck';
			let msg = type === 'audit' ? '审核成功!' : '反审成功!';
			let msgO =
				type === 'audit'
					? '只能审核处于审核中的单据!'
					: '只能反审核处于已审核的单据!';
			let docVal = type === 'audit' ? 'c' : 'd';
			let ifDocVal = type === 'audit' ? 'b' : 'c';
			let isIfEdit = type === 'audit' ? true : false;
			if (this.baseInfoForm.documentStatus == ifDocVal) {
				this.$http.post(pathName, { ids: ids }).then((r) => {
					if (r.status == 200) {
						if (r.data[0].isSuccess) {
							this.$message.success({
								message: msg,
								showClose: true,
							});
							this.baseInfoForm.documentStatus = docVal;
							this.isEdit = isIfEdit;
							//   if (isIfEdit) {
							this.$http
								.post(
									'Stkdirecttransfers/GetInfo/' + this.saveIds
								)
								.then((req) => {
									if (req.status == 200) {
										this.baseInfoForm =
											activeSaveSubmitGetData(
												this.baseInfoForm,
												req
											);
									}
								});
							//   }
						} else {
							this.$message.error({
								message: r.data[0].msg,
								showClose: true,
							});
						}
					}
				});
			} else {
				this.$message.error({ message: msgO, showClose: true });
			}
		},
		// 撤消
		revokePageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http
					.post('Stkdirecttransfers/Revoke', { ids: ids })
					.then((r) => {
						this.$message.success({
							message: '撤消成功!',
							showClose: true,
						});
						this.baseInfoForm.documentStatus = 'a';
						this.isEdit = false;

						this.$refs.multipleTable.clearSelection();
						this.multipleSelection = [];
						this.selectRowIndexArr = [];
					});
			} else {
				this.$message.error({
					message: '只能撤销审核中的单据!',
					showClose: true,
				});
			}
		},
		// 保存提交
		saveSubmitCom(type) {
			let pathName =
				type === 'save'
					? 'Stkdirecttransfers/Save'
					: 'Stkdirecttransfers/Commit';
			let msg = type === 'save' ? '保存成功!' : '提交成功!';
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				filterMaterialData(this.baseInfoForm);
				this.$http.post(pathName, this.baseInfoForm).then((r) => {
					if (r.status == 200) {
						this.saveOrSubmitData(r);
						this.$message.success({
							message: msg,
							showClose: true,
						});
						type === 'submit'
							? (this.baseInfoForm.documentStatus = 'b')
							: false;
						type === 'submit' ? (this.isEdit = true) : false;
					}
				});
			}
		},
		// 处理保存、提交返回数据
		saveOrSubmitData(r) {
			if (r.data) {
				this.$http
					.post('Stkdirecttransfers/GetInfo/' + r.data.id)
					.then((req) => {
						if (req.status == 200) {
							this.baseInfoForm = activeSaveSubmitGetData(
								this.baseInfoForm,
								req
							);
						}
					});
				this.baseInfoForm.billNo = r.data.billNo;
				this.baseInfoForm.id = r.data.id;
				this.saveIds = r.data.id;
				this.deleteId = r.data.id;
				r.data.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].id = el.id;
					this.baseInfoForm.details[ind].fid = el.fid;
				});
				this.$refs.multipleTable.clearSelection();
				this.multipleSelection = [];
				this.selectRowIndexArr = [];
			}
		},
		// 匹配物料sku的方法
		async backMaterSkuMethods(val, key, id) {
			return this.$http
				.showLoading(false)
				.post('SysConfig/GetMaterial', {
					name: val,
					file: key,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data;
					} else {
						return [];
					}
				});
		},
		// 获取物料编码信息
		async matterCodeChange(val, ind, type) {
			if (val && this.baseInfoForm.stockOrgId) {
				if (val.indexOf(' ') == -1) {
					let matterDate = await this.backMaterSkuMethods(
						val,
						'Number',
						this.baseInfoForm.stockOrgId
					);
					this.matterallCodelist[ind] = matterDate;
					this.specificationalllist[ind] = matterDate;
					if (type === 'getDate') {
						if (this.baseInfoForm.details[ind] !== undefined) {
							this.matterallCodelist[ind].forEach((el) => {
								this.baseInfoForm =
									activeMaterialSkuSearchGetData(
										this.baseInfoForm,
										el,
										ind
									);
							});
						}
					}
				}
			}
		},
		// 获取型号SKU信息
		async skuCodeChange(val, ind) {
			if (val && this.baseInfoForm.stockOrgId) {
				if (val.indexOf(' ') == -1) {
					let matterDate = await this.backMaterSkuMethods(
						val,
						'Specifications',
						this.baseInfoForm.stockOrgId
					);
					this.matterallCodelist[ind] = matterDate;
					this.specificationalllist[ind] = matterDate;
					// if (this.baseInfoForm.details[ind] !== undefined) {
					//   this.matterallCodelist[ind].forEach(el => {
					//     this.baseInfoForm = activeMaterialSkuSearchGetData(this.baseInfoForm, el, ind)
					//   })
					// }
				}
			}
		},
		// 失焦处理
		selectBlur() {
			let _that = this;
			_that.baseInfoForm.details.forEach((el) => {
				el.isSalOrderBillNo = false;
				el.isMaterialId = false;
				el.isSpecificationId = false;
				el.isQty = false;
				el.isSrcStockId = false;
				el.isSrcCustomer = false;
				el.isSrcCustomerStock = false;
				el.isDestStockId = false;
				el.isDestCustomer = false;
				el.isDestCustomerStock = false;
				el.isRemarks = false;
			});
		},
		// 星星
		mustAfter(obj) {
			let arry = [2, 3, 6, 7, 10];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 插入的行
		getInsertInfo(data) {
			let result = activeInsertUpDownData(
				data,
				this.baseInfoForm,
				this.customeStockArrylistInner,
				this.customeStockArrylist,
				this.matterallCodelist,
				this.specificationalllist,
				this.addRow
			);
			this.baseInfoForm = result.baseInfoForm;
			this.customeStockArrylistInner = result.customeStockArrylistInner;
			this.customeStockArrylist = result.customeStockArrylist;
			this.matterallCodelist = result.matterallCodelist;
			this.specificationalllist = result.specificationalllist;
			this.$nextTick(() => {
				this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
					this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
			});
			this.selectBlur();
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
		},
		// 向下复制行
		bottomCopyRow() {
			if (this.selectRowIndexArr.length > 0) {
				if (this.selectRowIndexArr.length == 1) {
					const tableArr = JSON.parse(
						JSON.stringify(
							this.baseInfoForm.details[this.selectRowIndex]
						)
					);
					let insertNum = this.selectRowIndex + 1;
					this.baseInfoForm.details.splice(insertNum, 0, tableArr);
					this.customeStockArrylistInner.splice(
						insertNum,
						0,
						this.customeStockArrylist[this.selectRowIndex]
					);
					this.customeStockArrylist.splice(
						insertNum,
						0,
						this.customeStockArrylist[this.selectRowIndex]
					);
					this.matterallCodelist.splice(
						insertNum,
						0,
						this.matterallCodelist[this.selectRowIndex]
					);
					this.specificationalllist.splice(
						insertNum,
						0,
						this.specificationalllist[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]
					);
					this.baseInfoForm.details[insertNum].id = 0;
					this.selectBlur();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
				} else {
					// 获取最后选择的行
					let lastIndex = -1;
					this.selectRowIndexArr.forEach((el) => {
						el.index > lastIndex ? (lastIndex = el.index) : false;
					});
					// 添加行
					this.selectRowIndexArr.forEach((el) => {
						el.id = 0;
						lastIndex = lastIndex + 1;
						this.baseInfoForm.details.splice(
							lastIndex,
							0,
							JSON.parse(JSON.stringify(el))
						);
						this.customeStockArrylistInner.splice(
							lastIndex,
							0,
							this.customeStockArrylist[el.index]
						);
						this.customeStockArrylist.splice(
							lastIndex,
							0,
							this.customeStockArrylist[el.index]
						);
						this.matterallCodelist.splice(
							lastIndex,
							0,
							this.matterallCodelist[el.index]
						);
						this.specificationalllist.splice(
							lastIndex,
							0,
							this.specificationalllist[el.index]
						);
						this.salePrecisionNumber.splice(
							lastIndex,
							0,
							this.salePrecisionNumber[el.index]
						);
						this.isPrecision.splice(
							lastIndex,
							0,
							this.isPrecision[el.index]
						);
						this.isCount.splice(
							lastIndex,
							0,
							this.isCount[el.index]
						);
						this.baseInfoForm.details[lastIndex].id = 0;
					});

					this.$refs.multipleTable.clearSelection();
					this.selectBlur();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
				}
			} else {
				this.$message.error({
					message: '请选择一行或多行复制!',
					showClose: true,
				});
			}
		},
		// 单元格被点击
		getRowCol(row, column, cell) {
			let _that = this;
			_that.currRow = row.index;
			_that.storeObj.storeRow = row.index;
			_that.storeObj.storeCol = column.index;
			if (typeof cell === 'string') {
				_that.storeObj.storekey = cell;
			} else {
				_that.storeObj.storekey = column.property;
			}
			_that.storeObj.storeVal = row[_that.storeObj.storekey];

			if (_that.recordIndex != '' || _that.recordIndex == '0') {
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSalOrderBillNo = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isMaterialId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSpecificationId = false;
				_that.baseInfoForm.details[_that.recordIndex].isQty = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSrcStockId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSrcCustomer = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSrcCustomerStock = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDestStockId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDestCustomer = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDestCustomerStock = false;
				_that.baseInfoForm.details[_that.recordIndex].isRemarks = false;
			}

			switch (column.label) {
				case '销售订单号':
					row.isSalOrderBillNo = true;
					_that.recordIndex = row.index;
					break;
				case '物料编码':
					row.isMaterialId = true;
					_that.recordIndex = row.index;
					break;
				case '规格型号(SKU)':
					row.isSpecificationId = true;
					_that.recordIndex = row.index;
					break;
				case '调拨数量':
					row.isQty = true;
					_that.recordIndex = row.index;
					break;
				case '调出仓库':
					row.isSrcStockId = true;
					_that.recordIndex = row.index;
					break;
				case '调出客户':
					row.isSrcCustomer = true;
					_that.recordIndex = row.index;
					break;
				case '调出客户仓库':
					row.isSrcCustomerStock = true;
					_that.recordIndex = row.index;
					break;
				case '调入仓库':
					row.isDestStockId = true;
					_that.recordIndex = row.index;
					break;
				case '调入客户':
					row.isDestCustomer = true;
					_that.recordIndex = row.index;
					break;
				case '调入客户仓库':
					row.isDestCustomerStock = true;
					_that.recordIndex = row.index;
					break;
				case '备注':
					row.isRemarks = true;
					_that.recordIndex = row.index;
					break;
			}

			this.$nextTick(() => {
				let strArr = [
					'销售订单号',
					'物料编码',
					'规格型号(SKU)',
					'调拨数量',
					'调出仓库',
					'调出客户',
					'调出客户仓库',
					'调入仓库',
					'调入客户',
					'调入客户仓库',
					'备注',
				];
				if (strArr.indexOf(column.label) !== -1) {
					document
						.getElementById(column.property + row.index)
						.focus();
				}
			});
		},
		// 删除行
		selectDeleteRow() {
			if (
				this.baseInfoForm.details.length > 1 &&
				this.baseInfoForm.details.length !=
					this.multipleSelection.length
			) {
				if (this.selectRowIndexArr != 0) {
					this.selectRowIndexArr.sort(function (a, b) {
						return a.index - b.index;
					});
					for (let i = 0; i < this.selectRowIndexArr.length; i++) {
						this.baseInfoForm.details.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.customeStockArrylistInner.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.customeStockArrylist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.matterallCodelist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.specificationalllist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.salePrecisionNumber.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isPrecision.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isCount.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
					}
					this.baseInfoForm.details.forEach((el, ind) => {
						this.matterCodeChange(el.materialNumber, ind);
						// this.skuCodeChange(el.specification, ind)
						this.baseInfoForm.details[ind].materialId =
							el.materialId;
						this.baseInfoForm.details[ind].specificationId =
							el.materialId;
					});
					this.$refs.multipleTable.clearSelection();
					this.selectBlur();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
					this.recordIndex = '';
				} else {
					this.$message.error({
						message: '请先选择要删除的行',
						showClose: true,
					});
				}
			} else {
				this.$message.error({
					message: '表格不能为空!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn() {
			let nextRow = this.storeObj.storeRow + 1;
			let storeKey = this.storeObj.storekey;
			if (
				storeKey !== 'srcCustomerStock' &&
				storeKey !== 'destCustomerStock'
			) {
				for (
					let i = nextRow;
					i < this.baseInfoForm.details.length;
					i++
				) {
					for (const key in this.baseInfoForm.details[i]) {
						if (key === storeKey) {
							if (
								key === 'materialId' ||
								key === 'specificationId'
							) {
								this.baseInfoForm.details[i][key] =
									this.storeObj.storeVal;
								this.matterallCodelist[i] =
									this.matterallCodelist[i - 1];
								this.specificationalllist[i] =
									this.specificationalllist[i - 1];
								this.salePrecisionNumber[i] =
									this.salePrecisionNumber[i - 1];
								this.isPrecision[i] = this.isPrecision[i - 1];
								this.isCount[i] = this.isCount[i - 1];
								this.matterallCodelist[i].forEach((el) => {
									if (
										el.id ===
										this.baseInfoForm.details[i - 1]
											.materialId
									) {
										this.baseInfoForm =
											activeCopyMaterialGetData(
												this.baseInfoForm,
												el,
												i
											);
									}
								});
							} else if (
								key === 'srcStockId' ||
								key === 'destStockId'
							) {
								let clearKeyO =
									key === 'srcStockId'
										? 'srcCustomer'
										: 'destCustomer';
								let clearKeyT =
									key === 'srcStockId'
										? 'srcCustomerStock'
										: 'destCustomerStock';
								let warehouseList =
									key === 'srcStockId'
										? 'warehouse'
										: 'warehouseInset';
								let isCustomerKey =
									key === 'srcStockId'
										? 'isOutCusHouse'
										: 'isInnerCusHouse';
								this.baseInfoForm.details[i][key] =
									this.storeObj.storeVal;
								this.baseInfoForm.details[i][clearKeyO] = '';
								this.baseInfoForm.details[i][clearKeyT] = '';
								let rowObejct = this.statusForm[
									warehouseList
								].filter(
									(it) =>
										it.id ===
										this.baseInfoForm.details[i][key]
								);
								this.baseInfoForm.details[i][isCustomerKey] =
									rowObejct.length > 0
										? !rowObejct[0].customerWarehouseTag
										: true;
							} else if (key === 'qty') {
								if (this.baseInfoForm.details[i].unitId) {
									this.getCountUnitCom(
										i,
										this.storeObj.storeVal,
										this.storeObj.storeVal,
										true,
										'qty',
										'copy'
									);
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
							} else {
								if (
									storeKey !== 'srcCustomer' &&
									storeKey !== 'destCustomer'
								) {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
							}
						}
						if (
							storeKey === 'srcCustomer' ||
							storeKey === 'destCustomer'
						) {
							let isIfKey =
								storeKey === 'srcCustomer'
									? 'isOutCusHouse'
									: 'isInnerCusHouse';
							let detailsKey =
								storeKey === 'srcCustomer'
									? 'srcCustomer'
									: 'destCustomer';
							let listKey =
								storeKey === 'srcCustomer'
									? 'customeStockArrylist'
									: 'customeStockArrylistInner';
							let clearKey =
								storeKey === 'srcCustomer'
									? 'srcCustomerStock'
									: 'destCustomerStock';
							this.baseInfoForm.details[i][isIfKey]
								? (this.baseInfoForm.details[i][detailsKey] =
										'')
								: (this.baseInfoForm.details[i][detailsKey] =
										this.storeObj.storeVal),
								(this.baseInfoForm.details[i][clearKey] = '');
							if (
								this.baseInfoForm.details[i][detailsKey] &&
								this.baseInfoForm.stockOrgId
							) {
								this.getCustomerStoreCom(
									this.baseInfoForm.details[i][detailsKey],
									this.baseInfoForm.stockOrgId,
									i,
									listKey
								);
							}
						}
					}
				}
			} else {
				this.$message.error({
					message: '客户仓库无法批量填充，请手动选择！',
					showClose: true,
				});
			}
		},
		// 单选
		selectRow(selection) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndex = selection[0].index;
				this.selectRowIndexArr = selection;
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 全选
		selectAll(selection) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndexArr = selection;
				if (selection.length == 1) {
					this.selectRowIndex = 0;
				}
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 获取时间
		getNowTime() {
			var date = new Date();
			var year = date.getFullYear();
			var month =
				date.getMonth() + 1 < 10
					? '0' + (date.getMonth() + 1)
					: date.getMonth() + 1;
			var day =
				date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
			return year + '-' + month + '-' + day;
		},
		// 编辑表格
		cellDblClick(row, column, cell, event) {
			this.currRow = row.index;
			this.currColumn = column.index;
			this.baseInfoForm.details = this.baseInfoForm.details.filter(
				(item) => {
					return item;
				}
			);
		},
		// 禁止操作单元格
		disabledCellStyle({ row, rowIndex, column, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		// 获取客户仓库
		getCustomerStoreCom(customerId, orgId, ind, key, isJoint, jointKey) {
			let query = {
				customerId: customerId,
				orgId: orgId,
			};
			this.$http.post('SysConfig/GetCustomerStock', query).then((r) => {
				if (r.status === 200) {
					this[key][ind] = r.data;
					if (isJoint) {
						// this[key] = splitJointList(this.baseInfoForm.details, this[key], jointKey)
						this[key] = r.data;
					}
				}
			});
		},
		// 单位数量计算
		getCountUnitCom(recordAddIndex, valueO, valueT, isInner, key, copy) {
			let tempList = this.unitData.filter(
				(it) =>
					it.id === this.baseInfoForm.details[recordAddIndex].unitId
			);
			if (tempList.length > 0) {
				tempList[0].precision == 0
					? (this.isPrecision[recordAddIndex] = true)
					: (this.isPrecision[recordAddIndex] = false);
				tempList[0].precision == 0
					? (this.salePrecisionNumber[recordAddIndex] = 0)
					: (this.salePrecisionNumber[recordAddIndex] =
							tempList[0].precision);
				if (copy == 'copy') {
					if (tempList && tempList.length > 0) {
						tempList[0].roundoffType = 2;
					}
				}
				let result = countMethodsUnitNumber(
					tempList,
					valueO,
					valueT,
					this.isCount[recordAddIndex],
					this.salePrecisionNumber[recordAddIndex],
					isInner
				);
				this.baseInfoForm.details[recordAddIndex][key] = result.value;
				this.isCount[recordAddIndex] = result.isDefault;
			}
		},
		// 复制粘贴
		pasteExcel(event, index, scope, key) {
			let pastedText = undefined; // 定义变量
			let isPasteOneCol = false; // 锁
			let oldVal = this.storeObj.storeVal; // 记录当前的值
			if (event.clipboardData && event.clipboardData.getData) {
				pastedText = event.clipboardData.getData('Text');
			} else {
				pastedText = event.originalEvent.clipboardData.getData('Text');
			}
			let rows = pastedText.split('\r\n'); // 分割字符
			rows.forEach((el) => {
				if (el.indexOf('\t') !== -1) {
					isPasteOneCol = true;
				}
			});
			setTimeout(async () => {
				if (isPasteOneCol) {
					this.baseInfoForm.details[index][key] = oldVal;
					this.$message.error({
						message: '请选择一列复制粘贴!',
						showClose: true,
					});
					return;
				}
				let recordAddIndex = index; // 记录行
				for (let i = 0; i < rows.length; i++) {
					if (rows[i] !== '') {
						if (key === 'materialId' || key === 'specificationId') {
							let key = scope.column.property;
							if (key === 'materialId') {
								this.matterCodeChange(
									rows[i],
									recordAddIndex,
									'getDate'
								);
							}
							if (key === 'specificationId') {
								this.skuCodeChange(
									rows[i],
									recordAddIndex,
									'getDate'
								);
							}
							recordAddIndex++;
						} else if (key === 'salOrderBillNo') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								this.baseInfoForm.details[recordAddIndex][key] =
									rows[i];
							}
							recordAddIndex++;
						} else if (key === 'qty') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								let num = rows[i] * 1;
								if (!isNaN(num)) {
									this.baseInfoForm.details[recordAddIndex][
										key
									] = rows[i];
								} else {
									this.$message.error({
										message:
											'粘贴内容有误,请重新选择复制内容!',
										showClose: true,
									});
									return;
								}
							}
							if (key === 'qty') {
								if (
									this.baseInfoForm.details[recordAddIndex]
										.unitId
								) {
									this.getCountUnitCom(
										recordAddIndex,
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										true,
										'qty'
									);
								} else {
									this.baseInfoForm.details[
										recordAddIndex
									].qty = Decimal(
										this.baseInfoForm.details[
											recordAddIndex
										].realQty
									).toFixed(0, Decimal.ROUND_HALF_UP);
								}
							}
							recordAddIndex++;
						}
					}
				}
			}, 0);
		},
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setCustomer: 'storeData/setCustomer',
			setStkdirecttrStatus: 'storeData/setStkdirecttrStatus',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),
	},
	computed: {
		...mapState({
			// 取出页面标签
			orgIdArr: (state) => state.user.orgIdArr,
			unitAll: (state) => state.storeData.allUnit,
			customer: (state) => state.storeData.customer,
			stkdirecttrStatus: (state) => state.storeData.stkdirecttrStatus,
			getAllUserList: (state) => state.storeData.getAllUserList,
		}),
		orgIdChange() {
			// 监听ID
			return this.$store.state && this.$store.state.org
				? this.$store.state.org.orgId
				: null;
		},
	},
	created: function () {
		this.Init();
	},
	watch: {
		orgIdChange: function () {
			this.baseInfoForm.stockerId = '';
		},
		'baseInfoForm.stockOrgId': function () {
			this.$http
				.showLoading(false)
				.post('SysConfig/GetDept/' + this.baseInfoForm.stockOrgId)
				.then((req) => {
					if (req.status == 200) {
						let deptArr = req.data;
						this.statusForm.saleParts = removeChildren(deptArr);
					}
				});
			if (
				this.baseInfoForm.stockOrgId === this.baseInfoForm.stockinOrgId
			) {
				this.baseInfoForm.allocatingType = 'b';
			} else {
				if (
					this.baseInfoForm.stockOrgId &&
					this.baseInfoForm.stockinOrgId
				) {
					this.baseInfoForm.allocatingType = 'a';
				}
			}
		},
		'baseInfoForm.documentStatus'() {
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增直接调拨单');
				this.btnType = directBtnAdd;
			} else {
				this.$topNavTagRename('编辑直接调拨单');
				this.btnType = directBtnEdit;
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderCreate.scss';
@import '@/assets/style/activeDirect.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
