<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="order-com-rr Iisshow"
												label="分步式调入单号"
											>
												<el-input
													:disabled="isEdit"
													:maxlength="100"
													@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 || isPushDownOrg
												"
												@change="stockinChange"
												class="click-cell-ipt-issue"
												filterable
												placeholder="请选择组织"
												v-model="
													baseInfoForm.stockinOrgId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.stockinOrgId,
															'stockinOrgId'
														)
													"
													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-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"
													@click="
														purchaseCom(
															baseInfoForm.stockerId,
															'stockerId'
														)
													"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in statusForm.salePerson"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												class="click-cell-ipt-issue"
												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="true"
												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
											:required="true"
											class="item-bt-s"
											label="调出库存组织"
										>
											<el-select
												:disabled="
													isEdit || isPushDownOrg
												"
												@change="stockOrgChange"
												class="click-cell-ipt-issue"
												placeholder="请选择单据状态"
												v-model="
													baseInfoForm.stockOrgId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													@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 || isPushDownOrg
												"
												: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>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													:maxlength="50"
													:required="true"
													class="item-bt-s input-width icon-sty"
													label="调拨类型"
												>
													<el-select
														:disabled="
															isEdit ||
															isPushDownOrg
														"
														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>
												<el-form-item
													:required="true"
													class="item-bt-s item-date input-width"
													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-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="12"></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
					:detailBtn="detailBtn"
					: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"
					:header-cell-style="headerBg"
					: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="200"
					>
						<!-- <template #header>
              <span class="iconfont icon-bianji1 iconfont-mg"></span>销售订单号
            </template>-->
						<template #default="scope" class="Iisshow">
							<span v-if="!scope.row.isSalOrderBillNo">{{
								scope.row.salOrderBillNo
							}}</span>
							<el-input
								:disabled="isEdit || isPushDownOrg"
								:id="'salOrderBillNo' + scope.$index"
								@input="
									detailsCom(
										scope.row.salOrderBillNo,
										'salOrderBillNo',
										scope.row,
										scope.column
									)
								"
								class="click-cell-ipt"
								placeholder="请输入"
								v-if="scope.row.isSalOrderBillNo"
								v-model.trim="scope.row.salOrderBillNo"
							></el-input>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="分步式调出单号"
						prop="parentOrderBillNo"
						width="200"
					>
						<!-- <template #header>
              <span class="iconfont icon-bianji1 iconfont-mg"></span>分步式调出单号
            </template>-->
						<template #default="scope" class="Iisshow">
							<span v-if="!scope.row.isParentOrderBillNo">{{
								scope.row.parentOrderBillNo
							}}</span>
							<el-input
								:disabled="isEdit || isPushDownOrg"
								:id="'parentOrderBillNo' + scope.$index"
								@input="
									detailsCom(
										scope.row.parentOrderBillNo,
										'parentOrderBillNo',
										scope.row,
										scope.column
									)
								"
								class="click-cell-ipt"
								placeholder="请输入"
								v-if="scope.row.isParentOrderBillNo"
								v-model.trim="scope.row.parentOrderBillNo"
							></el-input>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料编码"
						prop="materialId"
						width="200"
					>
						<!-- <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 || isPushDownOrg"
								:id="'materialId' + scope.$index"
								:remote-method="matterCodeChange"
								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"
									@click="
										detailsCom(
											item.id,
											'materialId',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.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 || isPushDownOrg"
								:id="'specificationId' + scope.$index"
								:remote-method="skuCodeChange"
								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"
									@click="
										detailsCom(
											item.id,
											'specificationId',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm
										.specificationalllist[scope.$index]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="150"
					>
						<template #default="scope">
							<span>{{ scope.row.materialName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="单位"
						prop="unitId"
						width="72"
					>
						<template #default="scope">
							<span>{{
								getName(statusForm.saleUnits, scope.row.unitId)
							}}</span>
						</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="19"
									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
						:required="true"
						align="center"
						label="备品"
						prop="isFree"
						width="81"
					>
						<template #default="scope">
							<span>{{ scope.row.isFree ? '是' : '否' }}</span>
							<!-- <el-checkbox
                v-model="scope.row.isFree"
                :disabled="isEdit || isPushDownOrg"
                @change="isCheckBox(scope.row.isFree,scope.row.index,'isFree')"
              ></el-checkbox>-->
						</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 || isPushDownOrg"
								:id="'srcStockId' + scope.$index"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								reserve-keyword
								v-if="scope.row.isSrcStockId"
								v-model="scope.row.srcStockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'srcStockId',
											scope.row,
											scope.column
										)
									"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									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
								:disabled="
									$route.query.type === 'pushDown'
										? true
										: isEdit || scope.row.isInnerCusHouse
								"
								:id="'srcCustomer' + scope.$index"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isSrcCustomer"
								v-model="scope.row.srcCustomer"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'srcCustomer',
											scope.row,
											scope.column
										)
									"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									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(
									statusForm.wareOutOptions[scope.$index],
									scope.row.srcCustomerStock
								)
							}}</span>
							<el-select
								:disabled="
									$route.query.type === 'pushDown'
										? true
										: isEdit || scope.row.isInnerCusHouse
								"
								:id="'srcCustomerStock' + scope.$index"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isSrcCustomerStock"
								v-model="scope.row.srcCustomerStock"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'srcCustomerStock',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.wareOutOptions[
										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 || isPushDownOrg"
								:id="'destStockId' + scope.$index"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isDestStockId"
								v-model="scope.row.destStockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'destStockId',
											scope.row,
											scope.column
										)
									"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									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
								:disabled="
									$route.query.type === 'pushDown'
										? true
										: isEdit || scope.row.isInnerCusHouse
								"
								:id="'destCustomer' + scope.$index"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isDestCustomer"
								v-model="scope.row.destCustomer"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'destCustomer',
											scope.row,
											scope.column
										)
									"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									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(
									statusForm.wareInsetOptions[scope.$index],
									scope.row.destCustomerStock
								)
							}}</span>
							<el-select
								:disabled="
									$route.query.type === 'pushDown'
										? true
										: isEdit || scope.row.isInnerCusHouse
								"
								:id="'destCustomerStock' + scope.$index"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isDestCustomerStock"
								v-model="scope.row.destCustomerStock"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'destCustomerStock',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.wareInsetOptions[
										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"
									@blur="
										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>
		<!-- 选择上下查单据 -->
		<el-dialog :title="CXttile" top="15%" 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 { mapState, mapActions } from 'vuex';
import { Decimal } from 'decimal.js';
import { getStaffListApiUser } from '@/utils/api.js';
import { countMethodsUnitNumber } from '@/utils/count.js';
import {
	enterMaterialSearch,
	enterSaveSubmitCom,
	enterMaterialInfoGetData,
	getNowTimeGlobal,
	getArrayName,
	orderCopy,
} from '@/utils/takeMethods.js';
import { removeChildren, splitJointList } from '@/utils/pubulic';
import {
	entryBtnAdd,
	entryBtnEdit,
	entryDefaultTableInfo,
	entryStatusForm,
	storeObj,
	optionProps,
} from '@/utils/variable.js';
export default {
	name: 'ActiveEntryOrder',
	components: {
		examineTop,
	},
	data() {
		return {
			isLoading: false,
			timer: null,
			salePrecisionNumber: [],
			isPrecision: [],
			unitData: [],
			isCount: [],
			isDisableTop: false,
			statusForm: JSON.parse(JSON.stringify(entryStatusForm)),
			baseInfoForm: JSON.parse(JSON.stringify(entryDefaultTableInfo)),
			addRow: {},
			storeObj: JSON.parse(JSON.stringify(storeObj)),
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			loading: false, // loding
			isEdit: true, // 禁止编辑
			isSetlementDifference: true,
			rowArr: [], // 明细 当前行
			selectRowIndexArr: [],
			btnType: JSON.parse(JSON.stringify(entryBtnAdd)), // 不需要的按钮
			saleUnits: [],
			currRow: '', // 表格 编辑 当前行
			currColumn: '', // 表格 编辑 当前列
			selectRowIndex: 0, // 选择的行
			heightNum: 0, // 容器高度
			txtVal: 0, // 字数显示
			multipleSelection: [], // 选择的行
			OrdedetailIds: [], // 勾选的明细id集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			detailBtn: [],
			isPushDownOrg: false,
			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.stktransInst &&
				JSON.stringify(this.stktransInst) !== '{}'
			) {
				this.statusForm.allocatingType = JSON.parse(
					JSON.stringify(this.stktransInst.allocatingType)
				);
				this.statusForm.billType = JSON.parse(
					JSON.stringify(this.stktransInst.billType)
				);
				this.statusForm.documentStatus = JSON.parse(
					JSON.stringify(this.stktransInst.documentStatus)
				);
			} else {
				this.$http
					.showLoading(false)
					.get('StktransferInst/GetStatus')
					.then((req) => {
						if (req.status == 200) {
							this.setStktransInst(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 - 444;
			this.statusForm.saleOrg = this.orgIdArr;
			this.baseInfoForm.billTypeId = 'b';
			this.statusForm.settlementOrgList = this.orgIdArr;
			let keys = Object.keys(this.baseInfoForm.details[0]); // 获取添加对象
			this.detailBtn = ['add', 'copy', 'delet'];
			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.isEdit = false;
				if (this.$route.query.type === 'copy') {
					this.getPurChaseDetails();
				}
			}
			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.getPurChaseDetails();
			}
		},
		getName(arr, val) {
			return getArrayName(arr, val);
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 调出库存组织改变时
		stockOrgChange() {
			this.getOutInsertStoreCom(
				this.baseInfoForm.stockOrgId,
				'warehouse',
				false
			);
			this.getOutInsertCustomerCom('custmers');
		},
		// 调入库存组织改变时
		stockinChange() {
			this.getOutInsertStoreCom(
				this.baseInfoForm.stockinOrgId,
				'warehouseInset',
				false
			);
			this.getOutInsertCustomerCom('deCustmers');
		},
		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, '');
				}
			}
		},
		// 复制粘贴
		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++) {
					console.log('i', i);
					if (rows[i] !== '') {
						if (
							this.baseInfoForm.details[recordAddIndex] ===
							undefined
						) {
							return;
						}
						if (this.baseInfoForm.details[recordAddIndex].unitId) {
							this.getUnitPriceNumberCom(
								recordAddIndex,
								rows[i],
								rows[i],
								true,
								'qty'
							);
						} else {
							this.baseInfoForm.details[recordAddIndex].qty =
								Decimal(
									this.baseInfoForm.details[recordAddIndex]
										.qty
								).toFixed(0, Decimal.ROUND_HALF_UP);
						}
						recordAddIndex++;
					}
				}
			}, 0);
		},
		verificationNum(val, index, key, isPrecision) {
			this.baseInfoForm.details[index].materialId
				? false
				: (isPrecision[index] = true);
			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] =
							Number(val).toFixed(0);
					}
					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');
				}
			}
		},
		// getUnitPriceNumberCom(recordAddIndex, valueO, valueT, isInner, key) {
		async getPurChaseDetails(res) {
			if (res) {
				this.isLoading = true;
				this.baseInfoForm = res;
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.id = 0;
				this.isPushDownOrg = res.isPushDown;
				await this.getOutInsertStoreCom(
					this.baseInfoForm.stockOrgId,
					'warehouse',
					true,
					'outStockList'
				);
				await this.getOutInsertStoreCom(
					this.baseInfoForm.stockinOrgId,
					'warehouseInset',
					true,
					'inStockList'
				);
				await this.getMaterialCustomerDataAll();
				this.baseInfoForm.details.forEach((el, ind) => {
					this.getUnitPriceNumberCom(
						ind,
						this.baseInfoForm.details[ind].qty,
						this.baseInfoForm.details[ind].qty,
						true,
						'qty'
					);
					this.getUnitPriceNumberCom(
						ind,
						this.baseInfoForm.details[ind].parentOrderNumber,
						this.baseInfoForm.details[ind].parentOrderNumber,
						true,
						'parentOrderNumber'
					);
					this.baseInfoForm.details[ind].id = 0;
					this.baseInfoForm.details[ind].fid = 0;
					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 rowObject = this.statusForm.warehouse.filter(
						(it) => it.id === el.srcStockId
					);
					el.isOutCusHouse =
						rowObject.length > 0
							? !rowObject[0].customerWarehouseTag
							: true;
					let rowObject1 = this.statusForm.warehouseInset.filter(
						(it) => it.id === el.destStockId
					);
					el.isInnerCusHouse =
						rowObject1.length > 0
							? !rowObject1[0].customerWarehouseTag
							: true;
				});
				if (
					this.baseInfoForm.date == '' ||
					this.baseInfoForm.date == null ||
					this.baseInfoForm.date == undefined
				) {
					this.baseInfoForm.date = getNowTimeGlobal();
				}
				this.baseInfoForm.billTypeId = 'b';
				this.isLoading = false;
			} else {
				this.statusForm.settlementOrgList = this.orgIdArr;
				this.isLoading = true;
				this.$http
					.showLoading(false)
					.post('StktransferInst/GetInfo/' + this.$route.query.id)
					.then(async (req) => {
						if (req.status == 200) {
							this.baseInfoForm = req.data;
							this.saveIds = req.data.id;
							this.baseInfoForm.billTypeId = 'b';
							this.isPushDownOrg = req.data.isPushDown;
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
							} else {
								this.isEdit = true;
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							await this.getOutInsertStoreCom(
								this.baseInfoForm.stockOrgId,
								'warehouse',
								true,
								'outStockList'
							);
							await this.getOutInsertStoreCom(
								this.baseInfoForm.stockinOrgId,
								'warehouseInset',
								true,
								'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 rowObject =
									this.statusForm.warehouse.filter(
										(it) => it.id === el.srcStockId
									);
								el.isOutCusHouse =
									rowObject.length > 0
										? !rowObject[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.isParentOrderBillNo = 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.baseInfoForm.details.forEach((el, ind) => {
									this.baseInfoForm.details[ind].id = 0;
									this.baseInfoForm.details[ind].fid = 0;
								});
								this.baseInfoForm.documentStatus = 'a';
								this.isOrder = true;
							}
							this.isLoading = false;
						}
						if (
							this.baseInfoForm.date == '' ||
							this.baseInfoForm.date == null ||
							this.baseInfoForm.date == undefined
						) {
							this.baseInfoForm.date = getNowTimeGlobal();
						}
					});
			}
		},
		// 详情 - 克隆 - 下推进入 一次性获取物料编码 + 客户仓库数据
		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.stockinOrgId
			);
			let _resultHouse = await this.getCustmerStoreAll(
				customerQuery,
				this.baseInfoForm.stockOrgId
			);
			let _resultHouseInner = await this.getCustmerStoreAll(
				customerQueryInner,
				this.baseInfoForm.stockinOrgId
			);
			this.baseInfoForm.details.forEach((el, index) => {
				this.statusForm.matterallCodelist[index] = _result.filter(
					(item) => {
						return item.number === el.materialNumber;
					}
				);
				this.statusForm.specificationalllist[index] = _result.filter(
					(item) => {
						return item.number === el.materialNumber;
					}
				);
				if (customerListIndex.length > 0) {
					customerListIndex.forEach((el) => {
						if (el == index) {
							this.statusForm.wareOutOptions[index] =
								_resultHouse;
						}
					});
				}
				if (customerListIndexInner.length > 0) {
					customerListIndexInner.forEach((el) => {
						if (el == index) {
							this.statusForm.wareInsetOptions[index] =
								_resultHouseInner;
						}
					});
				}
				this.statusForm.matterallCodelist[index].forEach((ele) => {
					this.baseInfoForm = enterMaterialSearch(
						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 (type) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		// 单元格被点击
		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
				].isParentOrderBillNo = 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.isParentOrderBillNo = 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();
				}
			});
		},
		// 详情公共fun
		detailsCom(value, key, row, column) {
			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);
			}
			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.rowArr.forEach((el) => {
					if (value === el.id) {
						this.baseInfoForm = enterMaterialInfoGetData(
							this.baseInfoForm,
							el,
							this.currRow
						);
						if (key === 'materialId') {
							this.$http
								.showLoading(false)
								.post('SysConfig/GetMaterial', {
									name: el.specifications,
									file: 'Specifications',
									orgId: this.baseInfoForm.stockinOrgId,
								})
								.then((res) => {
									if (res.status === 200) {
										this.statusForm.specificationalllist[
											row.index
										] = res.data;
									}
								});
						}
						if (key === 'specificationId') {
							this.$http
								.showLoading(false)
								.post('SysConfig/GetMaterial', {
									name: el.number,
									file: 'Number',
									orgId: this.baseInfoForm.stockinOrgId,
								})
								.then((res) => {
									if (res.status === 200) {
										this.statusForm.matterallCodelist[
											row.index
										] = res.data;
									}
								});
						}
					}
				});
			} else {
				this.baseInfoForm.details[this.currRow][key] = value;
			}
			if (key === 'srcCustomer') {
				if (value && this.baseInfoForm.stockOrgId) {
					this.baseInfoForm.details[row.index].srcCustomerStock = '';
					let query = {
						customerId: value,
						orgId: this.baseInfoForm.stockOrgId,
					};
					this.$http
						.post('SysConfig/GetCustomerStock', query)
						.then((r) => {
							if (r.status === 200) {
								this.statusForm.wareOutOptions[row.index] =
									r.data;
							}
						});
				}
			}
			if (key === 'destCustomer') {
				if (value && this.baseInfoForm.stockinOrgId) {
					this.baseInfoForm.details[row.index].destCustomerStock = '';
					let query = {
						customerId: value,
						orgId: this.baseInfoForm.stockinOrgId,
					};
					this.$http
						.post('SysConfig/GetCustomerStock', query)
						.then((r) => {
							if (r.status === 200) {
								this.statusForm.wareInsetOptions[row.index] =
									r.data;
							}
						});
				}
			}
			if (key === 'qty') {
				this.verificationNum(
					this.baseInfoForm.details[row.index][key],
					row.index,
					'qty',
					this.isPrecision
				);
				if (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.getUnitPriceNumberCom(
							row.index,
							this.baseInfoForm.details[row.index][key],
							this.baseInfoForm.details[row.index].qty,
							false,
							'qty'
						);
					} else {
						this.isCount[row.index] = 2;
					}
					if (
						Number(this.baseInfoForm.details[this.currRow][key]) >
						Number(
							this.baseInfoForm.details[this.currRow]
								.parentOrderNumber
						)
					) {
						this.baseInfoForm.details[this.currRow][key] =
							this.baseInfoForm.details[
								this.currRow
							].parentOrderNumber;
					}
				}

				this.baseInfoForm.details[row.index][key] =
					this.valueRemoveZero(row, key);
				this.storeObj.storeVal =
					this.baseInfoForm.details[row.index][key];
			}
			if (key === 'remarks') {
				this.storeObj.storeVal =
					this.baseInfoForm.details[row.index][key];
			}
			if (key === 'srcStockId') {
				let rowObject = this.statusForm.warehouse.filter(
					(it) => it.id === value
				);
				this.baseInfoForm.details[row.index].isOutCusHouse =
					rowObject.length > 0
						? !rowObject[0].customerWarehouseTag
						: true;
				this.baseInfoForm.details[row.index].srcCustomer = '';
				this.baseInfoForm.details[row.index].srcCustomerStock = '';
			}
			if (key === 'destStockId') {
				let rowObject = this.statusForm.warehouseInset.filter(
					(it) => it.id === value
				);
				this.baseInfoForm.details[row.index].isInnerCusHouse =
					rowObject.length > 0
						? !rowObject[0].customerWarehouseTag
						: true;
				this.baseInfoForm.details[row.index].destCustomer = '';
				this.baseInfoForm.details[row.index].destCustomerStock = '';
			}
		},
		// 匹配物料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) {
						this.rowArr = res.data;
						return res.data;
					} else {
						return [];
					}
				});
		},
		// 获取物料编码信息
		async matterCodeChange(val, ind) {
			if (val && this.baseInfoForm.stockinOrgId) {
				this.statusForm.matterallCodelist[ind] =
					await this.backMaterSkuMethods(
						val,
						'Number',
						this.baseInfoForm.stockinOrgId
					);
				if (ind || ind == 0) {
					this.statusForm.matterallCodelist[ind].forEach((el) => {
						this.baseInfoForm = enterMaterialSearch(
							this.baseInfoForm,
							el,
							ind
						);
					});
				}
			} else {
				this.statusForm.matterallCodelist[ind] = [];
			}
		},
		// 获取型号SKU信息
		async skuCodeChange(val) {
			if (val && this.baseInfoForm.stockinOrgId) {
				this.statusForm.specificationalllist[ind] =
					await this.backMaterSkuMethods(
						val,
						'Specifications',
						this.baseInfoForm.stockinOrgId
					);
			} else {
				this.statusForm.specificationalllist[ind] = [];
			}
		},
		// 顶部公共按钮
		actionhandel(type) {
			let ids = [];
			let detailsIds = [];
			this.isDisableTop = true;
			setTimeout(() => {
				this.isDisableTop = false;
			}, 2000);
			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 === 'push-down') {
				if (this.multipleSelection.length == 0) {
					this.$message.error({
						message: '请先选择要下推的明细行!',
						showClose: true,
					});
					return;
				}
			}
			if (type === 'up-check' || type === 'down-check') {
				if (this.multipleSelection.length == 0) {
					this.$message.error({
						message: '请先选择要查询的明细行!',
						showClose: true,
					});
					return;
				}
			}
			if (type === 'save') {
				this.saveSubmitCom(type);
			}
			if (type === 'submit') {
				this.saveSubmitCom(type);
			}
			if (type === 'revoke') {
				this.revokePageData(ids);
			}
			if (type === 'audit') {
				this.auditPageData(ids);
			}
			if (type === 'de-approval') {
				this.deApprovalPageDate(ids);
			}
			if (type === 'delet') {
				this.deleteOrder(ids);
			}
			if (type === 'up-check') {
				// 点击查询--上查
				this.$http
					.post('StktransferInst/GetUpNumber', { ids: detailsIds })
					.then((res) => {
						if (res.status === 200) {
							if (res.data.length === 0 || res.data === []) {
								this.$message.warning({
									message: '没有可上查的单据！',
									showClose: true,
								});
							} else {
								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; //只有一个，就个默认值
							}
						}
					});
			}
		},
		// 删除
		deleteOrder(ids) {
			if (ids.length > 0) {
				this.$http
					.post('StktransferInst/Delete', { ids: ids })
					.then((r) => {
						if (r.status === 200) {
							if (r.status == 200) {
								if (r.data[0].isSuccess == false) {
									this.$message.error({
										message: r.data[0].msg,
										showClose: true,
									});
								} else {
									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.warning({
					message: '不能删除此单据!',
					showClose: true,
				});
			}
		},
		// 反审
		deApprovalPageDate(ids) {
			if (this.baseInfoForm.documentStatus == 'c') {
				this.$http
					.post('StktransferInst/NoCheck', { ids: ids })
					.then((r) => {
						if (r.status == 200) {
							if (r.data[0].isSuccess) {
								this.$message.success({
									message: '反审成功!',
									showClose: true,
								});
								this.baseInfoForm.documentStatus = 'd';
								this.isEdit = false;
								this.$http
									.showLoading(false)
									.post(
										'StktransferInst/GetInfo/' +
											this.saveIds
									)
									.then((req) => {
										if (req.status == 200) {
											this.baseInfoForm =
												enterSaveSubmitCom(
													this.baseInfoForm,
													req
												);
										}
									});
							} else {
								this.$message.error({
									message: r.data[0].msg,
									showClose: true,
								});
							}
						}
					});
			} else {
				this.$message.error({
					message: '只能反审核处于已审核的单据!',
					showClose: true,
				});
			}
		},
		// 审核
		auditPageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http
					.post('StktransferInst/Check', { ids: ids })
					.then((r) => {
						if (r.status == 200) {
							if (r.data[0].isSuccess) {
								this.$message.success({
									message: '审核成功!',
									showClose: true,
								});
								this.baseInfoForm.documentStatus = 'c';
								this.isEdit = true;
								this.$http
									.showLoading(false)
									.post(
										'StktransferInst/GetInfo/' +
											this.saveIds
									)
									.then((req) => {
										if (req.status == 200) {
											this.baseInfoForm =
												enterSaveSubmitCom(
													this.baseInfoForm,
													req
												);
										}
									});
							} else {
								this.$message.error({
									message: r.data[0].msg,
									showClose: true,
								});
							}
						}
					});
			} else {
				this.$message.error({
					message: '只能审核处于审核中的单据!',
					showClose: true,
				});
			}
		},
		// 撤消
		revokePageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http
					.post('StktransferInst/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'
					? 'StktransferInst/Save'
					: 'StktransferInst/Commit';
			let msg = type === 'save' ? ' 保存成功!' : '提交成功!';
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				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;
					}
				});
			} else {
				this.$message.error({
					message: '只能保存、提交创建或重新审核的单据!',
					showClose: true,
				});
			}
		},
		// 处理保存、提交返回数据
		saveOrSubmitData(r) {
			if (r.data) {
				this.$http
					.showLoading(false)
					.post('StktransferInst/GetInfo/' + r.data.id)
					.then((req) => {
						if (req.status == 200) {
							this.baseInfoForm = enterSaveSubmitCom(
								this.baseInfoForm,
								req
							);
						}
					});
				this.baseInfoForm.billNo = r.data.billNo;
				this.baseInfoForm.id = r.data.id;
				this.saveIds = 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 = [];
			}
		},
		// 居右
		headerBg({ rowIndex, columnIndex }) {
			let arry = [];
			if (arry.indexOf(columnIndex) !== -1) {
				return `text-align:right!important;`;
			}
		},
		// 星星
		mustAfter(obj) {
			let arry = [7];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 插入的行
		getInsertInfo(data) {
			if (data.insertTopVal != 0 && data.insertTopVal != '') {
				for (let i = 0; i < data.insertTopVal; i++) {
					preparaMaterial;
					this.baseInfoForm.details.splice(
						this.selectRowIndex,
						0,
						JSON.parse(JSON.stringify(this.addRow))
					);
					this.selectRowIndex = parseInt(this.selectRowIndex) + 1;
				}
			}
			if (data.insertBottomVal != 0 && data.insertBottomVal != '') {
				for (let i = 0; i < data.insertBottomVal; i++) {
					this.selectRowIndex = parseInt(this.selectRowIndex) + 1;
					this.baseInfoForm.details.splice(
						this.selectRowIndex,
						0,
						JSON.parse(JSON.stringify(this.addRow))
					);
				}
				this.selectRowIndex =
					this.selectRowIndex - data.insertBottomVal; // 回朔
			}
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
		},
		// 向下复制行
		bottomCopyRow(data) {
			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.baseInfoForm.details[insertNum].id = 0;
				this.$refs.multipleTable.clearSelection();
				this.multipleSelection = [];
				this.selectRowIndexArr = [];
			} else {
				this.$message.warning({
					message: '只能选择一行进复制!',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			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.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.multipleSelection = [];
					this.selectRowIndexArr = [];
				} else {
					this.$message.warning({
						message: '请先选择要删除的行',
						showClose: true,
					});
				}
			} else {
				this.$message.warning({
					message: '表格不能为空!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn(data) {
			let nextRow = this.storeObj.storeRow + 1;
			let storeKey = this.storeObj.storekey;
			if (
				this.storeObj.storekey !== 'destCustomerStock' &&
				this.storeObj.storekey !== 'srcCustomerStock'
			) {
				for (
					let i = nextRow;
					i < this.baseInfoForm.details.length;
					i++
				) {
					for (const key in this.baseInfoForm.details[i]) {
						if (key === storeKey) {
							if (key === 'remarks') {
								this.salePrecisionNumber[i] =
									this.salePrecisionNumber[i - 1];
								this.isPrecision[i] = this.isPrecision[i - 1];
								this.isCount[i] = this.isCount[i - 1];
								this.baseInfoForm.details[i][key] =
									this.storeObj.storeVal;
							}
							if (key === 'qty') {
								if (this.baseInfoForm.details[i].unitId) {
									this.getUnitPriceNumberCom(
										i,
										this.storeObj.storeVal,
										this.storeObj.storeVal,
										true,
										'qty',
										'copy'
									);
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
							}
						}
					}
				}
			} else {
				this.$message.error({
					message: '调入和调出客户仓库无法批量填充，请手动选择！!',
					showClose: true,
				});
			}
		},
		// 单选
		selectRow(selection, row) {
			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 = [];
			}
		},
		// 禁止操作单元格
		disabledCellStyle({ row, rowIndex, column, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		// 确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = '';
				if (this.CXcheckVal === 20) {
					pathName = 'WarehouseAllocationkissue';
				}
				let ary = [];
				ary = this.upOrDownList.filter((it) => {
					return it.orderType === this.CXcheckVal;
				});
				if (pathName) {
					this.dialogCX = false;
					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[0].billNos),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// 获取调入 - 调出客户仓库
		getOutInsertCustomerStoreCom(
			ind,
			queryKey,
			queryId,
			resKey,
			strKey,
			isJoin
		) {
			let query = {
				customerId: this.baseInfoForm.details[ind][queryKey],
				orgId: queryId,
			};
			this.$http.post('SysConfig/GetCustomerStock', query).then((r) => {
				if (r.status === 200) {
					this.statusForm[resKey][ind] = r.data;
					if (isJoin) {
						this.statusForm[resKey][ind] = splitJointList(
							this.baseInfoForm.details,
							this.statusForm[resKey][ind],
							strKey,
							false,
							true
						);
					}
				}
			});
		},
		// 获取调入 - 调出仓库
		getOutInsertStoreCom(id, key, join, joinKey) {
			this.$http
				.showLoading(false)
				.get('SysConfig/GetWarehouse/' + id)
				.then((res) => {
					if (res.status === 200) {
						this.statusForm[key] = res.data;
						if (join) {
							this.statusForm[key] = splitJointList(
								this.baseInfoForm.details,
								this.statusForm[key],
								joinKey
							);
							this.statusForm[key] =
								this.statusForm[key].filter(Boolean);
						}
					}
				});
		},
		// 获取调入 - 调出客户
		getOutInsertCustomerCom(key) {
			this.$http.get('SysConfig/GetCustomer').then((r) => {
				if (r.status === 200) {
					this.statusForm[key] = r.data;
				}
			});
		},
		// 单位数量 - 精度
		getUnitPriceNumberCom(
			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;
			}
		},
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setCustomer: 'storeData/setCustomer',
			setStktransInst: 'storeData/setStktransInst',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),
	},
	computed: {
		...mapState({
			orgIdArr: (state) => state.user.orgIdArr,
			unitAll: (state) => state.storeData.allUnit,
			customer: (state) => state.storeData.customer,
			stktransInst: (state) => state.storeData.stktransInst,
			getAllUserList: (state) => state.storeData.getAllUserList,
		}),
		orgIdChange() {
			return this.$store.state && this.$store.state.org
				? this.$store.state.org.orgId
				: null;
		},
	},
	mounted: function () {},
	created: function () {
		this.Init();
	},
	watch: {
		'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.stockinOrgId': function () {
			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'(newvalue, oldvalue) {
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增分步式调入单');
				this.btnType = entryBtnAdd;
			} else {
				this.$topNavTagRename('编辑分步式调入单');
				this.btnType = entryBtnEdit;
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/issueDetails.scss';
@import '@/assets/style/saleOrder/stepByStepCom.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
