<template>
	<div>
		<transition name="bounce">
			<examineTop
				v-if="isExmaineTop === 2"
				:radios="radios"
				@handleBtns="handleBtns"
				@handleOpen="handleOpen"
				:isexamineBtns="isexamineBtns"
			/>
			<!-- 	:isexamineBtns="isexamineBtns" -->
		</transition>
	</div>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="order-create-container order-mc-bg main-container"
	>
		<div class="order-create-btn-group">
			<!-- 顶部按钮组 -->
			<template v-if="isExmaineTop !== 2">
				<toolBtn
					:btnType="btnType"
					:isDisable="isDisable"
					@actionhandel="actionhandel"
					:isExmaineTop="isShow"
				></toolBtn>
			</template>
		</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="50"
													@input="
														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
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												placeholder="请选择单据状态"
												v-model="
													baseInfoForm.documentStatus
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.documentStatus,
															'documentStatus'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.documentStatus"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="单据类型"
										>
											<el-select
												:disabled="isEdit"
												filterable
												placeholder="请选择调出类型"
												v-model="
													baseInfoForm.billTypeId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.billTypeId,
															'billTypeId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.billType"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s item-date time-input"
											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>
									</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 || isPushDownOrg
												"
												class="click-cell-ipt-issue"
												filterable
												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.stockDepts"
												:props="optionProps"
												:show-all-levels="false"
												@change="
													purchaseCom(
														baseInfoForm.returnMaterialDeptId,
														'returnMaterialDeptId',
														'ipt',
														'type'
													)
												"
												clearable
												placeholder="请选择部门"
												ref="cascader"
												style="font-size: 12px"
												v-model="
													baseInfoForm.returnMaterialDeptId
												"
											></el-cascader>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="仓管员"
										>
											<el-select
												:disabled="isEdit"
												filterable
												placeholder="请选择仓管员"
												remote
												reserve-keyword
												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.stockPersons"
												></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
													:required="true"
													class="item-bt-s"
													label="供应商"
												>
													<el-select
														:clearable="true"
														:disabled="
															isEdit ||
															isPushDownOrg
														"
														filterable
														placeholder="请输入关键词"
														remote
														reserve-keyword
														v-model="
															baseInfoForm.supplierId
														"
													>
														<el-option
															:key="
																item.id +
																item.name
															"
															:label="item.name"
															:value="item.id"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															@click="
																purchaseCom(
																	item.id,
																	'supplierId'
																)
															"
															v-for="item in statusForm.getCustomerNumList"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													:required="true"
													class="item-bt-s"
													label="退料方式"
												>
													<el-select
														:disabled="isEdit"
														placeholder="请选择方式"
														v-model="
															baseInfoForm.returnMaterialMode
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															@click="
																purchaseCom(
																	baseInfoForm.returnMaterialMode,
																	'returnMaterialMode'
																)
															"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.returnMaterialType"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="补料方式"
												>
													<el-select
														:disabled="isEdit"
														placeholder="请选择方式"
														v-model="
															baseInfoForm.replenishMode
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															@click="
																purchaseCom(
																	baseInfoForm.replenishMode,
																	'replenishMode'
																)
															"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.feedSupplementType"
														></el-option>
													</el-select>
												</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">
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算组织"
										>
											<el-select
												:disabled="
													isEdit || isPushDownOrg
												"
												@change="
													settleCurrMethods(true)
												"
												filterable
												placeholder="请选择组织"
												v-model="
													baseInfoForm.settleOrgId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.settleOrgId,
															'settleOrgId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.saleOrg"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算币别"
										>
											<el-select
												:disabled="
													isEdit || isPushDownOrg
												"
												@change="settleCurrMethods"
												placeholder="请选择结算币别"
												v-model="
													baseInfoForm.settleCurrId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.settleCurrId,
															'settleCurrId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.setlementDifferences"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="结算方式"
										>
											<el-select
												:disabled="isEdit"
												placeholder="请选择结算方式"
												v-model="
													baseInfoForm.settleTypeId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.settleTypeId,
															'settleTypeId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.exchangeRateTypes"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="付款条件"
										>
											<el-select
												:disabled="isEdit"
												placeholder="请选择收款条件"
												v-model="
													baseInfoForm.payconditionId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.payconditionId,
															'payconditionId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.collectionTermss"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											class="item-bt-s"
											label="本位币"
										>
											<el-select
												:disabled="true"
												placeholder="请选择结算币别"
												v-model="
													baseInfoForm.localCurrId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in statusForm.setlementDifferences"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="汇率类型"
										>
											<el-select
												:disabled="isEdit"
												placeholder="请选择汇率"
												v-model="
													baseInfoForm.exchangeTypeId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.exchangeTypeId,
															'exchangeTypeId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.rateTypeList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="汇率"
										>
											<el-input
												:disabled="true"
												placeholder=" "
												v-model="
													baseInfoForm.exchangeRate
												"
											></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
													class="item-bt-s"
													label="税额"
												>
													<el-input
														:disabled="true"
														placeholder=" "
														v-model="
															baseInfoForm.billTaxAmount
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="金额"
												>
													<el-input
														:disabled="true"
														placeholder=" "
														v-model="
															baseInfoForm.billAmount
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="价税合计"
												>
													<el-input
														:disabled="true"
														placeholder=" "
														v-model="
															baseInfoForm.billAllAmount
														"
													></el-input>
												</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.createName
												"
											></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.modifiyName
												"
											></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.submitDate
												"
											></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.approverName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model.trim="
															baseInfoForm.approveDate
														"
													></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"
					: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="parentOrderBillNo"
						width="187"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>采购订单号
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isParentOrderBillNo">{{
								scope.row.parentOrderBillNo
							}}</span>
							<div
								:class="{
									'is-disabled':
										isEdit || scope.row.isReturnQty,
								}"
								class="el-input click-cell-ipt"
								v-if="scope.row.isParentOrderBillNo"
							>
								<input
									:disabled="isEdit || scope.row.isReturnQty"
									:id="'parentOrderBillNo' + scope.$index"
									@blur="
										detailsCom(
											scope.row.parentOrderBillNo,
											'parentOrderBillNo',
											scope.row,
											scope.column
										)
									"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'parentOrderBillNo'
										)
									"
									autocomplete="off"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.parentOrderBillNo"
								/>
							</div>
						</template>
					</el-table-column>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'materialId')" -->
					<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="
									(query) => {
										matterCodeChange(
											query,
											scope.$index,
											'materialId',
											'Number'
										);
									}
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'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>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'specificationId')" -->
					<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="
									(query) => {
										matterCodeChange(
											query,
											scope.$index,
											'specification',
											'Specifications'
										);
									}
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'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="150"
					>
						<template #default="scope">
							<el-tooltip
								:content="scope.row.materialName"
								effect="dark"
								placement="top"
							>
								<span>{{ scope.row.materialName }}</span>
							</el-tooltip>
						</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>
					<el-table-column
						align="left"
						label="实退数量"
						prop="returnRealQty"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>实退数量
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isReturnRealQty">{{
								scope.row.returnRealQty
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isReturnRealQty"
							>
								<input
									:disabled="isEdit"
									:id="'returnRealQty' + scope.$index"
									:maxlength="19"
									@blur="
										detailsCom(
											scope.row.returnRealQty,
											'returnRealQty',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'returnRealQty'
										)
									"
									autocomplete="off"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.returnRealQty"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="补料数量"
						prop="replenishQty"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>补料数量
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isReplenishQty">{{
								scope.row.replenishQty
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit || isReplen }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isReplenishQty"
							>
								<input
									:disabled="isEdit || isReplen"
									:id="'replenishQty' + scope.$index"
									:maxlength="19"
									:ref="'replenishQty' + scope.$index"
									@blur="
										detailsCom(
											scope.row.replenishQty,
											'replenishQty',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									autocomplete="off"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.replenishQty"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="含税单价"
						prop="taxPrice"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>含税单价
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isTaxPrice">{{
								scope.row.taxPrice
							}}</span>
							<div
								:class="{
									'is-disabled':
										isEdit || scope.row.isDisabled,
								}"
								class="el-input click-cell-ipt"
								v-if="scope.row.isTaxPrice"
							>
								<input
									:disabled="isEdit || scope.row.isDisabled"
									:id="'taxPrice' + scope.$index"
									:maxlength="12"
									@blur="
										detailsCom(
											scope.row.taxPrice,
											'taxPrice',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'taxPrice'
										)
									"
									autocomplete="off"
									class="el-input__inner click-cell-ipt"
									placeholder
									v-model.lazy="scope.row.taxPrice"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="税率%"
						prop="taxRate"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>税率%
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isTaxRate">{{
								scope.row.taxRate
							}}</span>
							<el-select
								:clearable="false"
								:disabled="isEdit || scope.row.isDisabled"
								:id="'taxRate' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'taxRate'
									)
								"
								class="click-cell-ipt t-r"
								placeholder="请选择"
								v-if="scope.row.isTaxRate"
								v-model="scope.row.taxRate"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.name"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.name,
											'taxRate',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.getTaxRateList"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="单价"
						prop="price"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.price }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="价税合计"
						prop="allAmount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.allAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="税额"
						prop="taxAmount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.taxAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="金额"
						prop="amount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.amount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="仓库"
						prop="stockId"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isStockId">{{
								getName(statusForm.warehouse, scope.row.stockId)
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'stockId' + scope.$index"
								@change="clearCustomerInfo(scope.row.index)"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'stockId'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isStockId"
								v-model="scope.row.stockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'stockId',
											scope.row,
											scope.column,
											item.disabled,
											item.customerWarehouseTag
										)
									"
									v-for="item in statusForm.warehouse"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户"
						prop="customerId"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isCustomerId">{{
								getName(
									statusForm.custList,
									scope.row.customerId
								)
							}}</span>
							<el-select
								:disabled="isEdit || scope.row.isCustomer"
								:id="'customerId' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerId'
									)
								"
								class="f_12"
								placeholder="请选择"
								remote
								reserve-keyword
								v-if="scope.row.isCustomerId"
								v-model="scope.row.customerId"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'customerId',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.custList"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户仓库"
						prop="customerStockId"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isCustomerStockId">{{
								getName(
									customeStockArrylist[scope.$index],
									scope.row.customerStockId
								)
							}}</span>
							<el-select
								:disabled="isEdit || scope.row.isCustomer"
								:id="'customerStockId' + scope.$index"
								class="click-cell-ipt"
								placeholder="请选择"
								remote
								reserve-keyword
								v-if="scope.row.isCustomerStockId"
								v-model="scope.row.customerStockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'customerStockId',
											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="center"
						label="是否赠品"
						prop="giveAway"
						width="72"
					>
						<template #default="scope">
							<el-checkbox
								:disabled="isEdit || isPushDownOrg"
								@change="
									isCheckBox(
										scope.row.giveAway,
										scope.row.index,
										'giveAway',
										scope.row,
										scope.column,
										'taxPrice'
									)
								"
								v-model="scope.row.giveAway"
							></el-checkbox>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="备注"
						prop="note"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isNote">{{
								scope.row.note
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isNote"
							>
								<input
									:disabled="isEdit"
									:id="'note' + scope.$index"
									autocomplete="off"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.note"
								/>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<!-- 选择下推单据 -->
		<el-dialog
			title="选择下推单据"
			top="15%"
			v-model="dialogxt"
			width="20%"
		>
			<el-radio-group v-model="pushdownVal">
				<el-radio
					:key="item.id"
					:label="item.id"
					:value="item.id"
					v-for="item in pushDownList"
					>{{ item.value }}</el-radio
				>
			</el-radio-group>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="dialogxt = false" size="small"
						>取 消</el-button
					>
					<el-button
						@click="sumitPushdown(pushdownVal)"
						size="small"
						type="primary"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择上下查单据 -->
		<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 toolBtn from '@/components/public/toolBtn/toolBtn.vue';
import {
	getStaffListApiUser,
	approvalFlowTrackingCreate,
	approvalFlowTrackingGetby,
	approvalFlowTrackingUpdate,
} from '@/utils/api.js';
import { mapState, mapActions } from 'vuex';
import { Decimal } from 'decimal.js';
// import { getStaffListApiUser } from '@/utils/api.js';
import { countMethodsPurHoRe, countMethodsUnitNumber } from '@/utils/count.js';
import {
	getTaxPrice,
	removeChildren,
	splitJointList,
} from '@/utils/pubulic.js';
import {
	activeReturnBtnAdd,
	activeReturnBtnEdit,
	reDefaultTableInfo,
	reStatusForm,
	storeObj,
	optionProps,
} from '@/utils/variable.js';
import {
	numberPrecisionCom,
	pricePrecisionNumberCom,
	orderRexgu,
	purReCopyClearData,
	purReMaterialSkuSearch,
	getNowTimeGlobal,
	purReCopyMaterialGetValue,
	purReInsertRowCom,
	purReSaveSubmitRequestGetData,
	purReTableInfoMaterialSkuGetData,
	purReChangeOrgClearData,
	getArrayName,
	orderCopy,
	filterMaterialData,
} from '@/utils/takeMethods.js';
export default {
	name: 'ActiveReturnOrder',
	components: {
		examineTop,
		toolBtn,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			radios: [],
			examineObj: {},
			salePrecisionNumber: [],
			isPrecision: [],
			unitData: [],
			isCount: [],
			pushDownPrice: [],
			isLockPrice: true,
			isCustomerWarehouseTag: true,
			isDisableTop: false,
			isOrder: true,
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			statusForm: JSON.parse(JSON.stringify(reStatusForm)),
			baseInfoForm: JSON.parse(JSON.stringify(reDefaultTableInfo)),
			addRow: {},
			storeObj: JSON.parse(JSON.stringify(storeObj)),
			loading: false, // loding
			isEdit: true, // 禁止编辑
			isSetlementDifference: true,
			selectRowIndexArr: [],
			btnType: JSON.parse(JSON.stringify(activeReturnBtnAdd)), // 不需要的按钮
			saleUnits: [],
			currRow: '', // 表格 编辑 当前行
			currColumn: '', // 表格 编辑 当前列
			selectRowIndex: 0, // 选择的行
			heightNum: 0, // 容器高度
			multipleSelection: [], // 选择的行
			OrdedetailIds: [], // 勾选的明细id集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrderNoNames: [], // 选择的单据订单号集合
			saveIds: '',
			pushDownList: [{ id: 1, value: '采购订单' }],
			isReplen: true,
			isPushDownOrg: false,
			unitpriceAccuracy: 6,
			amountAccuracy: 2,
			detailBtn: [],
			customeStockArrylist: [], // 客户仓库集合
			matterallCodelist: [], // 物料下拉数据
			specificationalllist: [], // 规格型号（sku）下拉数据
			tableHeight: 400,
			isLoading: false,
			recordIndex: '',
			supplierList: null,
		};
	},
	methods: {
		setExamine(res) {
			if (
				res.status === 200 &&
				res.data &&
				JSON.stringify(res.data) !== '{}'
			) {
				this.examineObj = res.data;
				//有审批流,但是自己不能审批则返回1,否则返回2,如果没有审批流或者报错为了不阻断流程返回3
				let isApprover = res.data.isApprover;
				this.isExmaineTop = isApprover ? 2 : 1;
				if (
					!res.data ||
					JSON.stringify(res.data) === '{}' ||
					this.baseInfoForm.documentStatus !== 'b'
				) {
					console.log('走到这里来了吗？');
					this.isExmaineTop = 3;
				}
				if (res.data.isDone) {
					this.baseInfoForm.documentStatus = 'c';
					this.isExmaineTop = 3;
				}
				this.isexamineBtns = false;
			} else {
				this.isExmaineTop = 3;
				this.isexamineBtns = false;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('PurchaseReturnMaterial/get/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.baseInfoForm = req.data;
						this.baseInfoForm.documentStatus =
							req.data.documentStatus;
						if (
							this.baseInfoForm.documentStatus === 'a' ||
							this.baseInfoForm.documentStatus === 'd'
						) {
							this.isEdit = false;
						}
						this.setExamine(r);
					}
				});
			// this.saveIds = r.data.id;
			// this.baseInfoForm = purGetOrderId(this.baseInfoForm, r);
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
		},
		handleSubmit(data) {
			this.isexamineBtns = true;
			this.$http
				.post(approvalFlowTrackingUpdate, data)
				.then((res) => {
					if (res.status === 200) {
						this.$message.success({
							message: '操作成功!',
							showClose: true,
						});
					}
					this.handleDetails(res);
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				})
				.finally(() => {
					// this.isexamineBtns = false;
				});
		},
		//顶部按钮点击
		handleBtns(vals) {
			if (vals.type === 'out') {
				this.$router.go(-1);
			} else {
				let data = {
					approvalDetailsId: this.examineObj.approvalDetailsId,
					approvalOrderType: this.examineObj.sendOrderType,
					orderId: this.examineObj.sendOrderId,
					deptId: this.baseInfoForm.returnMaterialDeptId,
					orgId: this.baseInfoForm.stockOrgId,
					details: {
						trackId: this.examineObj.id,
						approverId: this.userId,
						approvalMethod: this.examineObj.currentApprovalMethod,
						approvalResult: vals.approvalResult,
						wayId: this.examineObj.currentWayId,
						remark: vals.remark,
						// upperId
					},
				};
				this.handleSubmit(data);
			}
		},
		//跳转到追踪页面
		handleOpen() {
			this.$router.push({
				path: '/examine/mange/examineFollow',
				query: { id: this.examineObj.id },
			});
		},
		//获取处理意见状态
		setApprovalFlowStatus() {
			this.radios = this.getApprovalResult;
		},

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

						// if (!length) {
						// 	return false;
						// }
						// if (details[0].approvalResult !== 2) {
						// 	return false;
						// }
						// this.$message.error({
						// 	message: `"单据由${res.data.details[0].approverName}"审核不通过，拒绝理由”${res.data.details[0].remark}”`,
						// 	showClose: true,
						// 	duration: 5000,
						// });
					}
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				});
		},
		//审批流-创建
		// setApprovalFlowTrackingCreate(data) {
		// 	let _this = this;
		// 	let obj = {
		// 		sendOrderId: data.id,
		// 		deptId: data.sellDept || 0,
		// 		sendId: this.userId,
		// 		sendOrderType: 5,
		// 		sendOrderBillNo: data.billNO,
		// 		orgId: data.sellOrg,
		// 	};
		// 	this.$http
		// 		.post(approvalFlowTrackingCreate, obj)
		// 		.then((res) => {
		// 			this.setExamine(res);
		// 		})
		// 		.catch((err) => {
		// 			if (err) {
		// 				this.isExmaineTop = 3;
		// 			}
		// 		});
		// },

		// 初始化
		Init() {
			let vuexKey = [
				'taxRate',
				'rateType',
				'dcurrency',
				'customer',
				'settletype',
				'unitAll',
				'paymentTerm',
				'supplierSelect',
			];
			let setVuexData = [
				'setTaxRate',
				'setRateType',
				'setDcurrency',
				'setCustomer',
				'setSettletype',
				'setAllUnit',
				'setPaymentTerm',
				'setSupplierSelect',
			];
			let requestQueryUrl = [
				'SysConfig/GetTaxRate',
				'SysConfig/GetRateType',
				'SysConfig/GetDcurrency',
				'SysConfig/GetCustomer',
				'SysConfig/GetSettletype',
				'SysConfig/GetUnitAllProperty',
				'SysConfig/GetPaymentTerm',
				'SysConfig/supplier/select',
			];
			let resDataQuery = [
				'getTaxRateList',
				'rateTypeList',
				'setlementDifferences',
				'custList',
				'exchangeRateTypes',
				'saleUnits',
				'collectionTermss',
				'getCustomerNumList',
			];
			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.get(requestQueryUrl[ind]).then((r) => {
						if (r.status === 200) {
							if (typeof resDataQuery[ind] == 'string') {
								this.statusForm[resDataQuery[ind]] = r.data;
							} else {
								resDataQuery[ind].forEach((ele, index) => {
									this.statusForm[resDataQuery[ind][index]] =
										r.data;
								});
							}
							this[setVuexData[ind]](
								this.statusForm[resDataQuery[ind]]
							);
							// 单位
							if (vuexKey[ind] == 'unitAll') {
								this.unitData =
									this.statusForm[resDataQuery[ind]];
							}
							// 税率
							if (vuexKey[ind] == 'taxRate') {
								this.statusForm.getTaxRateList.forEach(
									(element) => {
										element.name = Number(element.name);
									}
								);
								this.setTaxRate(this.statusForm.getTaxRateList);
							}
						}
					});
				}
			});

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

			if (
				this.returnMatType &&
				JSON.stringify(this.returnMatType) !== '{}'
			) {
				for (const key in this.returnMatType.documentStatus) {
					this.statusForm.documentStatus.push({
						id: key,
						name: this.returnMatType.documentStatus[key],
					});
				}
				for (const key in this.returnMatType.billTypeId) {
					this.statusForm.billType.push({
						id: key,
						name: this.returnMatType.billTypeId[key],
					});
				}
				for (const key in this.returnMatType.returnMaterialMode) {
					this.statusForm.returnMaterialType.push({
						id: key,
						name: this.returnMatType.returnMaterialMode[key],
					});
				}
				for (const key in this.returnMatType.replenishMode) {
					this.statusForm.feedSupplementType.push({
						id: key,
						name: this.returnMatType.replenishMode[key],
					});
				}
			} else {
				// 获取 枚举状态
				this.$http
					.get('PurchaseReturnMaterial/status/get')
					.then((req) => {
						if (req.status == 200) {
							this.setReturnMatType(req.data);
							for (const key in req.data.documentStatus) {
								this.statusForm.documentStatus.push({
									id: key,
									name: req.data.documentStatus[key],
								});
							}
							for (const key in req.data.billTypeId) {
								this.statusForm.billType.push({
									id: key,
									name: req.data.billTypeId[key],
								});
							}
							for (const key in req.data.returnMaterialMode) {
								this.statusForm.returnMaterialType.push({
									id: key,
									name: req.data.returnMaterialMode[key],
								});
							}
							for (const key in req.data.replenishMode) {
								this.statusForm.feedSupplementType.push({
									id: key,
									name: req.data.replenishMode[key],
								});
							}
						}
					});
			}

			var windowHeight = document.documentElement.clientHeight;
			this.heightNum = windowHeight - 102;
			this.tableHeight = windowHeight - 444;
			this.baseInfoForm.date = this.getNowTime();
			this.statusForm.saleOrg = this.orgIdArr;
			if (
				this.$store.state &&
				this.$store.state.org &&
				this.$store.state.org.orgId
			) {
				this.baseInfoForm.stockOrgId = this.$store.state.org.orgId;
			}
			if (!this.baseInfoForm.settleOrgId) {
				this.baseInfoForm.settleOrgId = this.baseInfoForm.stockOrgId;
			}
			this.statusForm.settlementOrgList = this.orgIdArr;
			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];
				}
			}
			this.addRow.note = '';

			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 === 'add') {
					if (this.baseInfoForm.stockOrgId) {
						this.$http
							.get(
								'SysConfig/GetWarehouseByOrg/' +
									this.baseInfoForm.stockOrgId
							)
							.then((req) => {
								if (req.status == 200) {
									this.statusForm.warehouse = req.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.getPurChaseDetails();
			}
		},
		getName(arr, val) {
			return getArrayName(arr, val);
		},
		async settleCurrMethods(type) {
			if (type) {
				this.orgIdArr.forEach((element) => {
					if (element.id === this.baseInfoForm.settleOrgId) {
						this.baseInfoForm.localCurrId = element.standardCoinId;
					}
				});
			}
			let templateObj = await getTaxPrice(
				this.baseInfoForm.localCurrId,
				'SysConfig/GetRateInfo',
				this.baseInfoForm.settleCurrId
			);
			if (templateObj) {
				this.baseInfoForm.exchangeRate = templateObj.directRate;
				this.baseInfoForm.exchangeTypeId = templateObj.issueInvoiceId;
				let content = this.statusForm.setlementDifferences.filter(
					(it) => it.id === this.baseInfoForm.settleCurrId
				);
				if (content.length !== 0) {
					this.unitpriceAccuracy = content[0].unitpriceAccuracy;
					this.amountAccuracy = content[0].amountAccuracy;
					console.log(
						this.unitpriceAccuracy,
						'==this.unitpriceAccuracy =='
					);
					console.log(
						this.amountAccuracy,
						'=====this.amountAccuracy======'
					);
				}
			} else {
				this.baseInfoForm.exchangeRate = '';
				this.baseInfoForm.exchangeTypeId = '';
			}
		},
		clearCustomerInfo(index) {
			this.baseInfoForm.details[index].customerId = '';
			this.baseInfoForm.details[index].customerStockId = '';
		},
		// 复制粘贴
		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 === 'returnRealQty' || key === 'taxPrice') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								this.baseInfoForm.details[recordAddIndex][key] =
									rows[i];
								let num = rows[i] * 1;
								if (!isNaN(num)) {
									this.getPriceNumberCountCom(
										rows[i],
										recordAddIndex,
										key
									);
								} else {
									this.$message.error({
										message:
											'粘贴内容有误,请重新选择复制内容!',
										showClose: true,
									});
									return;
								}
							}
							if (key === 'returnRealQty') {
								if (
									this.baseInfoForm.details[recordAddIndex]
										.unitId
								) {
									this.getNumberPrecisionMethods(
										recordAddIndex,
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										true,
										'returnRealQty'
									);
								} else {
									this.baseInfoForm.details[
										recordAddIndex
									].returnRealQty = Decimal(
										this.baseInfoForm.details[
											recordAddIndex
										].qty
									).toFixed(0, Decimal.ROUND_HALF_UP);
								}
							}
							recordAddIndex++;
						} else if (
							key === 'materialId' ||
							key === 'specificationId'
						) {
							let key = scope.column.property;
							if (key === 'materialId') {
								this.matterCodeChange(
									rows[i],
									recordAddIndex,
									'getDate',
									'Number'
								);
							}
							if (key === 'specificationId') {
								this.matterCodeChange(
									rows[i],
									recordAddIndex,
									'getDate',
									'Specifications'
								);
							}
							recordAddIndex++;
						} else if (key === 'parentOrderBillNo') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								this.baseInfoForm.details[recordAddIndex][key] =
									rows[i];
							}
							recordAddIndex++;
						}
					}
				}
			}, 0);
		},
		// 单元格被点击
		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;
			}
			if (_that.storeObj.storekey === 'note') {
				_that.storeObj.storeVal = row.note;
			} else {
				_that.storeObj.storeVal = row[_that.storeObj.storekey];
			}
			if (_that.recordIndex != '' || _that.recordIndex == '0') {
				_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
				].isReturnRealQty = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isReplenishQty = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isTaxPrice = false;
				_that.baseInfoForm.details[_that.recordIndex].isTaxRate = false;
				_that.baseInfoForm.details[_that.recordIndex].isStockId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isCustomerId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isCustomerStockId = false;
				_that.baseInfoForm.details[_that.recordIndex].isNote = false;
			}
			switch (column.label) {
				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.isReturnRealQty = true;
					_that.recordIndex = row.index;
					break;
				case '补料数量':
					row.isReplenishQty = true;
					_that.recordIndex = row.index;
					break;
				case '含税单价':
					row.isTaxPrice = true;
					_that.recordIndex = row.index;
					break;
				case '税率%':
					row.isTaxRate = true;
					_that.recordIndex = row.index;
					break;
				case '仓库':
					row.isStockId = true;
					_that.recordIndex = row.index;
					break;
				case '客户':
					row.isCustomerId = true;
					_that.recordIndex = row.index;
					break;
				case '客户仓库':
					row.isCustomerStockId = true;
					_that.recordIndex = row.index;
					break;
				case '备注':
					row.isNote = true;
					_that.recordIndex = row.index;
					break;
			}
			this.$nextTick(() => {
				let strArr = [
					'采购订单号',
					'物料编码',
					'规格型号(SKU)',
					'实退数量',
					'补料数量',
					'含税单价',
					'税率%',
					'仓库',
					'客户',
					'客户仓库',
					'备注',
				];
				if (strArr.indexOf(column.label) !== -1) {
					document
						.getElementById(column.property + row.index)
						.focus();
				}
			});
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 含税单价输入限制
		saleNum(index, val, 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) {
				this.baseInfoForm.details[index][key] = pricePrecisionNumberCom(
					this.baseInfoForm,
					this.salePrecisionNumber,
					this.isPrecision,
					index,
					key,
					val
				);
			}
		},
		// 数量输入限制
		taxPriceNumberRex(val, row, key) {
			this.baseInfoForm.details[row.index][key] = numberPrecisionCom(
				this.unitpriceAccuracy,
				val
			);
		},
		// 获取客户
		getCustomerMeth() {
			this.$http
				.showLoading(false)
				.get('SysConfig/GetCustomer')
				.then((res) => {
					if (res.status === 200) {
						this.statusForm.custList = res.data;
					}
				});
		},
		async getStatusType(url, type) {
			// 获取状态
			if (type === 'get') {
				return this.$http
					.showLoading(false)
					.get(url)
					.then((res) => {
						if (res.status === 200) {
							return res.data;
						} else {
							return [];
						}
					});
			}
		},
		async getPurChaseDetails(res) {
			if (res) {
				this.isLoading = true;
				this.baseInfoForm = res;
				this.baseInfoForm.details.forEach((el, ind) => {
					if (!el.note) {
						this.baseInfoForm.details[ind].note = '';
					}
					this.pushDownPrice[ind] = el.taxPrice;
				});
				if (this.baseInfoForm.stockOrgId) {
					this.$http
						.get(
							'SysConfig/GetWarehouseByOrg/' +
								this.baseInfoForm.stockOrgId
						)
						.then((req) => {
							// 获取仓库
							if (req.status == 200) {
								this.statusForm.warehouse = req.data;
								this.statusForm.warehouse = splitJointList(
									this.baseInfoForm.details,
									this.statusForm.warehouse,
									'stockList'
								);
								this.statusForm.warehouse =
									this.statusForm.warehouse.filter(Boolean);
							}
						});
				}
				this.isPushDownOrg = res.isPushDown;
				if (this.baseInfoForm.isPushDown) {
					this.detailBtn = ['add', 'copy'];
					this.baseInfoForm.details.forEach((el, ind) => {
						if (
							el.parentOrderBillNo !== '' ||
							el.parentOrderBillNo != null ||
							el.parentOrderBillNo != undefined
						) {
							el.isReturnQty = true;
						} else {
							el.isReturnQty = false;
						}
					});
				} else {
					this.detailBtn = [];
				}
				this.baseInfoForm.billTypeId
					? (this.baseInfoForm.billTypeId =
							this.baseInfoForm.billTypeId + '')
					: false;
				this.baseInfoForm.returnMaterialMode
					? (this.baseInfoForm.returnMaterialMode =
							this.baseInfoForm.returnMaterialMode + '')
					: false;
				this.baseInfoForm.replenishMode
					? (this.baseInfoForm.replenishMode =
							this.baseInfoForm.replenishMode + '')
					: false;
				if (this.baseInfoForm.settleCurrId) {
					await this.$http
						.showLoading(false)
						.get('SysConfig/GetDcurrency')
						.then(async (r) => {
							if (r.status === 200) {
								this.statusForm.setlementDifferences =
									await r.data;
								let content =
									this.statusForm.setlementDifferences.filter(
										(it) =>
											it.id ===
											this.baseInfoForm.settleCurrId
									);
								if (content.length !== 0) {
									this.unitpriceAccuracy =
										content[0].unitpriceAccuracy;
									this.amountAccuracy =
										content[0].amountAccuracy;
								}
							}
						});
				}
				this.supplierChange(this.baseInfoForm.supplierId);
				await this.getMaterialCustomerDataAll();
				await this.baseInfoForm.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].taxPrice =
						Decimal(this.pushDownPrice[ind]).toFixed(
							this.unitpriceAccuracy
						) * 1;
					this.isCount[ind] = 2;
					// this.matterCodeChange(el.materialNumber, ind, 'getDate', 'Number')
					this.baseInfoForm.details[ind].id = 0;
					this.baseInfoForm.details[ind].materialId = el.materialId;
					this.baseInfoForm.details[ind].specificationId =
						el.materialId;
					if (this.baseInfoForm.details[ind].giveAway) {
						this.baseInfoForm.details[ind].taxPrice = 0;
						this.baseInfoForm.details[ind].isDisabled = true;
					} else {
						this.baseInfoForm.details[ind].giveAway = false;
					}
					this.baseInfoForm.details[ind].returnRealQty = 0;
					this.baseInfoForm.details[ind].replenishQty = 0;
					this.getPriceNumberCountCom(
						el.returnRealQty,
						ind,
						'returnRealQty'
					);
					// this.getCustomerStockInfoCom(ind, 'y')
					if (el.stockId) {
						let rowObject = this.statusForm.warehouse.filter(
							(it) => it.id === el.stockId
						);
						el.isCustomer =
							rowObject.length > 0
								? !rowObject[0].customerWarehouseTag
								: true;
					} else {
						el.isCustomer = true;
					}
				});
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.date = this.getNowTime();
				this.isLoading = false;
			} else {
				this.statusForm.settlementOrgList = this.orgIdArr;
				this.isLoading = true;
				await this.$http
					.showLoading(false)
					.get('PurchaseReturnMaterial/get/' + this.$route.query.id)
					.then(async (req) => {
						if (req.status == 200) {
							// if (req.data.tracking && req.data.tracking.remark) {
							// 	this.$message.error({
							// 		message: `单据由-${req.data.tracking.remark}`,
							// 		showClose: true,
							// 		duration: 5000,
							// 	});
							// }
							this.baseInfoForm = req.data;
							this.setApprovalFlowTrackingGetby(req.data);
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
								this.baseInfoForm.details.forEach((el, ind) => {
									this.baseInfoForm.details[
										ind
									].isReturnQty = false;
								});
							} else {
								this.isEdit = true;
								this.baseInfoForm.details.forEach((el, ind) => {
									this.baseInfoForm.details[
										ind
									].isReturnQty = true;
								});
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							this.baseInfoForm.details.forEach((el, ind) => {
								if (!el.note) {
									this.baseInfoForm.details[ind].note = '';
								}
							});
							if (this.baseInfoForm.stockOrgId) {
								this.$http
									.showLoading(false)
									.get(
										'SysConfig/GetWarehouseByOrg/' +
											this.baseInfoForm.stockOrgId
									)
									.then((req) => {
										if (req.status == 200) {
											this.statusForm.warehouse =
												req.data;
											this.statusForm.warehouse =
												splitJointList(
													this.baseInfoForm.details,
													this.statusForm.warehouse,
													'stockList'
												);
											this.statusForm.warehouse =
												this.statusForm.warehouse.filter(
													Boolean
												);
										}
									});
							}
							this.settleCurrMethods();
							if (this.$route.query.type === 'copy') {
								let spliceList = [];
								this.baseInfoForm.details.forEach(
									(element, index) => {
										if (
											this.$route.query.detailsIds.indexOf(
												element.id.toString()
											) !== -1
										) {
											spliceList.push(
												this.baseInfoForm.details[index]
											);
										}
									}
								);
								this.baseInfoForm.details = spliceList;
							}
							this.isPushDownOrg = req.data.isPushDown;
							this.baseInfoForm.billTypeId
								? (this.baseInfoForm.billTypeId =
										this.baseInfoForm.billTypeId + '')
								: false;
							this.baseInfoForm.returnMaterialMode
								? (this.baseInfoForm.returnMaterialMode =
										this.baseInfoForm.returnMaterialMode +
										'')
								: false;
							this.baseInfoForm.replenishMode
								? (this.baseInfoForm.replenishMode =
										this.baseInfoForm.replenishMode + '')
								: false;
						}
						await this.getMaterialCustomerDataAll();
						await this.baseInfoForm.details.forEach((el, ind) => {
							// this.matterCodeChange(el.materialNumber, ind, 'getDate', 'Number')
							this.baseInfoForm.details[ind].materialId =
								el.materialId;
							this.baseInfoForm.details[ind].specificationId =
								el.materialId;
							if (!this.baseInfoForm.details[ind].giveAway) {
								this.baseInfoForm.details[ind].giveAway = false;
							}
							!this.baseInfoForm.details[ind].returnRealQty
								? (this.baseInfoForm.details[
										ind
								  ].returnRealQty = 0)
								: false;
							!this.baseInfoForm.details[ind].replenishQty
								? (this.baseInfoForm.details[
										ind
								  ].replenishQty = 0)
								: false;
							// this.getCustomerStockInfoCom(ind, 'y')
							let rowObject = this.statusForm.warehouse.filter(
								(it) => it.id === el.stockId
							);
							el.isCustomer =
								rowObject.length > 0
									? !rowObject[0].customerWarehouseTag
									: true;
							el.isParentOrderBillNo = false;
							el.isMaterialId = false;
							el.isSpecificationId = false;
							el.isReturnRealQty = false;
							el.isReplenishQty = false;
							el.isTaxPrice = false;
							el.isTaxRate = false;
							el.isStockId = false;
							el.isCustomerId = false;
							el.isCustomerStockId = false;
							el.isNote = false;
						});
						if (this.$route.query.type === 'copy') {
							this.detailBtn = [];
							this.statusForm.setlementDifferences =
								await this.getStatusType(
									'SysConfig/GetDcurrency',
									'get'
								); // 结算币别
							let content =
								this.statusForm.setlementDifferences.filter(
									(it) =>
										it.id === this.baseInfoForm.settleCurrId
								);
							if (content.length !== 0) {
								this.unitpriceAccuracy =
									content[0].unitpriceAccuracy;
								this.amountAccuracy = content[0].amountAccuracy;
							}
							this.isEdit = false;
							this.isPushDownOrg = false;
							this.baseInfoForm = purReCopyClearData(
								this.baseInfoForm
							);
							this.baseInfoForm.details.forEach((el, ind) => {
								this.getNumberPrecisionMethods(
									ind,
									this.baseInfoForm.details[ind]
										.returnRealQty,
									this.baseInfoForm.details[ind]
										.returnRealQty,
									true,
									'returnRealQty'
								);
								this.baseInfoForm.details[ind].taxPrice =
									Decimal(
										this.baseInfoForm.details[ind].taxPrice
									).toFixed(this.unitpriceAccuracy) * 1;
								// this.isCount[ind] = result.isDefault
								this.baseInfoForm.details[ind].id = 0;
								this.baseInfoForm.details[
									ind
								].isReturnQty = false;
							});
							this.isOrder = true;
							this.supplierChange(
								this.baseInfoForm.supplierId,
								'detailsCopy'
							);

							// let result = purReTableInfoMaterialSkuGetData(
							//   this.baseInfoForm,
							//   el,
							//   this.currRow,
							//   this.unitData,
							//   this.isPrecision,
							//   this.salePrecisionNumber,
							//   this.supplierList,
							//   this.statusForm.getTaxRateList
							// )
							// this.baseInfoForm = result.baseInfoForm
							// this.isPrecision = result.isPrecision
							// this.salePrecisionNumber = result.salePrecisionNumber
						}
						this.baseInfoForm.isPushDown
							? (this.detailBtn = ['add', 'copy'])
							: (this.detailBtn = []);
						this.isLoading = false;
					});
			}
		},
		// 详情 - 克隆 - 下推进入 一次性获取物料编码 + 客户仓库数据
		async getMaterialCustomerDataAll() {
			let materQuery = this.baseInfoForm.details.map((it) => {
				return it.materialNumber;
			});
			let customerQuery = [];
			let customerListIndex = [];
			this.baseInfoForm.details.forEach((el, ind) => {
				if (el.customerId) {
					customerQuery.push(el.customerId);
					customerListIndex.push(ind);
				}
			});
			let _result = await this.matterCodeChangeAll(
				materQuery,
				'Number',
				this.baseInfoForm.stockOrgId
			);
			let _resultHouse = await this.getCustmerStoreAll(
				customerQuery,
				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;
						}
					});
				}
				this.matterallCodelist[index].forEach((ele) => {
					this.baseInfoForm = purReMaterialSkuSearch(
						this.baseInfoForm,
						ele,
						index
					);
				});
			});
		},
		// 获取所有客户仓库信息
		async getCustmerStoreAll(query, id) {
			return this.$http
				.post('SysConfig/GetCustomerStockList', {
					customerIds: query,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data;
					} 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, row, column, taxPrice) {
			this.baseInfoForm.details[index][key] = val;
			if (val === true) {
				this.baseInfoForm.details[index].isDisabled = true;
				this.baseInfoForm.details[index].taxRate = '0';
				this.baseInfoForm.details[index].taxPrice = '0';
				this.getPriceNumberCountCom('0', row.index, taxPrice);
				this.getPriceNumberCountCom(row.taxRate, row.index, 'taxRate');
			} else {
				this.baseInfoForm.details[index].isDisabled = false;
			}
		},
		// 单据头公共fun
		async purchaseCom(value, key, ipt, type) {
			if (!!value && !!key) {
				if (key === 'billNo') {
					this.baseInfoForm[key] = orderRexgu(value);
				} else {
					this.baseInfoForm[key] = value;
				}
				if (key === 'stockOrgId') {
					this.getCustomerMeth();
					if (this.baseInfoForm.stockOrgId) {
						this.$http
							.get(
								'SysConfig/GetWarehouseByOrg/' +
									this.baseInfoForm.stockOrgId
							)
							.then((req) => {
								if (req.status == 200) {
									this.statusForm.warehouse = req.data;
								}
							});
					}
					this.baseInfoForm = purReChangeOrgClearData(
						this.baseInfoForm,
						this.addRow
					);
					this.baseInfoForm.settleOrgId =
						this.baseInfoForm.stockOrgId;
					this.baseInfoForm.exchangeRate = '';
					this.baseInfoForm.exchangeTypeId = '';
				}
				if (key === 'settleCurrId') {
					let content = this.statusForm.setlementDifferences.filter(
						(it) => it.id === this.baseInfoForm.settleCurrId
					);
					if (content.length !== 0) {
						this.unitpriceAccuracy = content[0].unitpriceAccuracy;
						this.amountAccuracy = content[0].amountAccuracy;
					}
					this.baseInfoForm.details.forEach((el, ind) => {
						this.getPriceNumberCountCom(
							el.taxPrice,
							ind,
							'taxPrice'
						);
					});
				}
				if (key === 'supplierId') {
					this.supplierChange(value, 'yes');
				}
			} else {
				delete this.baseInfoForm[key];
			}
			if (type) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		supplierChange(value, detailsCopy) {
			if (value) {
				let query = {
					orgId: this.baseInfoForm.stockOrgId,
					supplerId: value,
				};
				this.$http
					.showLoading(false)
					.post('Public/get/supplieraboutfor', query)
					.then(async (r) => {
						if (r.status == 200) {
							this.supplierList = r.data;
							this.baseInfoForm.settleCurrId =
								r.data.settlementCurrency;
							this.baseInfoForm.payconditionId =
								r.data.paymentTerms;
							this.baseInfoForm.settleTypeId =
								r.data.settlementMethod;
							if (detailsCopy) {
								let content =
									this.statusForm.setlementDifferences.filter(
										(it) =>
											it.id ===
											this.baseInfoForm.settleCurrId
									);
								if (content.length !== 0) {
									this.unitpriceAccuracy =
										content[0].unitpriceAccuracy;
									this.amountAccuracy =
										content[0].amountAccuracy;
								}
								this.baseInfoForm.details.forEach(
									(ele, index) => {
										if (this.matterallCodelist[index]) {
											this.matterallCodelist[
												index
											].forEach((el) => {
												if (ele.materialId === el.id) {
													let result =
														purReTableInfoMaterialSkuGetData(
															this.baseInfoForm,
															el,
															index,
															this.unitData,
															this.isPrecision,
															this
																.salePrecisionNumber,
															this.supplierList,
															this.statusForm
																.getTaxRateList
														);
													this.baseInfoForm =
														result.baseInfoForm;
													this.isPrecision =
														result.isPrecision;
													this.salePrecisionNumber =
														result.salePrecisionNumber;
												}
											});
											this.getPriceNumberCountCom(
												this.baseInfoForm.details[index]
													.taxPrice,
												index,
												'taxPrice'
											);
										}
									}
								);
							}
							this.settleCurrMethods(true);
						}
					});
			}
		},
		// 详情操作
		async detailsCom(value, key, row, column, disable, isOpen, index) {
			if (this.isLockPrice) {
				let templateObj = await getTaxPrice(
					this.baseInfoForm.localCurrId,
					'SysConfig/GetRateInfo',
					this.baseInfoForm.settleCurrId
				);
				if (templateObj) {
					this.baseInfoForm.exchangeRate = templateObj.directRate;
					this.baseInfoForm.exchangeTypeId =
						templateObj.issueInvoiceId;
				} else {
					this.baseInfoForm.exchangeRate = '';
					this.baseInfoForm.exchangeTypeId = '';
				}
				let content = this.statusForm.setlementDifferences.filter(
					(it) => it.id === this.baseInfoForm.settleCurrId
				);
				if (content.length !== 0) {
					this.unitpriceAccuracy = content[0].unitpriceAccuracy;
					this.amountAccuracy = content[0].amountAccuracy;
					this.isLockPrice = false;
				}
			}
			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 = purReTableInfoMaterialSkuGetData(
								this.baseInfoForm,
								el,
								this.currRow,
								this.unitData,
								this.isPrecision,
								this.salePrecisionNumber,
								this.supplierList,
								this.statusForm.getTaxRateList
							);
							this.baseInfoForm = result.baseInfoForm;
							this.isPrecision = result.isPrecision;
							this.salePrecisionNumber =
								result.salePrecisionNumber;

							this.baseInfoForm.details[row.index].returnRealQty =
								'0';
							this.baseInfoForm.details[row.index].taxPrice = '0';
							this.getPriceNumberCountCom(
								'0',
								row.index,
								'taxPrice'
							);
							this.baseInfoForm.details[
								row.index
							].isMaterialId = false;
							this.baseInfoForm.details[
								row.index
							].isSpecificationId = false;
							document.getElementById(key + row.index).blur();
						}
					});
				} else {
					key === 'note'
						? (this.baseInfoForm.details[this.currRow].note = value)
						: (this.baseInfoForm.details[this.currRow][key] =
								value);
				}
				if (key === 'taxRate') {
					this.getPriceNumberCountCom(value, row.index, key);
				}
				if (key === 'returnRealQty') {
					// this.saleNum(row.index,_value,'returnRealQty',this.isPrecision);
					if (this.isPrecision[index]) {
						if (
							this.baseInfoForm.details[index][key]
								.toString()
								.indexOf('.') !== -1
						) {
							this.baseInfoForm.details[index][key] = Decimal(
								this.baseInfoForm.details[index][key]
							).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');
					}
					if (!this.isCount[row.index]) {
						this.isCount[row.index] = 1;
					}
					if (
						this.baseInfoForm.details[row.index][key]
							.toString()
							.indexOf('.') !== -1
					) {
						this.getNumberPrecisionMethods(
							row.index,
							this.baseInfoForm.details[row.index][key],
							this.baseInfoForm.details[row.index][key],
							false,
							key,
							'copy'
						);
					} else {
						this.isCount[row.index] = 2;
					}
					this.getPriceNumberCountCom(
						this.baseInfoForm.details[row.index][key],
						row.index,
						key
					);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);

					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
					if (
						Number(this.baseInfoForm.details[row.index][key]) <
						Number(
							this.baseInfoForm.details[row.index].replenishQty
						)
					) {
						this.baseInfoForm.details[row.index].replenishQty =
							this.baseInfoForm.details[row.index][key];
					}
				}
				if (key === 'taxPrice') {
					this.taxPriceNumberRex(row.taxPrice, row, 'taxPrice');
					if (!this.isCount[row.index]) {
						this.isCount[row.index] = 1;
					}
					if (this.isCount[row.index] == 1) {
						this.baseInfoForm.details[row.index][key] =
							Decimal(
								this.baseInfoForm.details[row.index][key]
							).toFixed(this.unitpriceAccuracy) * 1;
						this.getNumberPrecisionMethods(
							row.index,
							this.baseInfoForm.details[row.index].qty,
							this.baseInfoForm.details[row.index].qty,
							false,
							'qty'
						);
					} else {
						if (
							this.baseInfoForm.details[row.index][key]
								.toString()
								.indexOf('.') !== -1
						) {
							let indexTax =
								this.baseInfoForm.details[row.index][
									key
								].lastIndexOf('.');
							let newValue = this.baseInfoForm.details[row.index][
								key
							].substring(
								indexTax + 1,
								this.baseInfoForm.details[row.index][key].length
							);
							this.baseInfoForm.details[row.index].taxPrice =
								newValue.length <= this.unitpriceAccuracy
									? this.baseInfoForm.details[row.index][key]
									: this.baseInfoForm.details[row.index][
											key
									  ].slice(
											0,
											this.baseInfoForm.details[
												row.index
											][key].length -
												(newValue.length -
													this.unitpriceAccuracy)
									  );
						} else {
							this.baseInfoForm.details[row.index].taxPrice =
								this.baseInfoForm.details[row.index][key];
						}
						this.isCount[row.index] = 2;
					}
					this.getPriceNumberCountCom(
						this.baseInfoForm.details[row.index].taxPrice,
						row.index,
						key
					);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'replenishQty') {
					this.saleNum(
						row.index,
						this.baseInfoForm.details[row.index][key],
						'replenishQty',
						this.isPrecision
					);
					if (
						Number(this.baseInfoForm.details[row.index][key]) >
						Number(
							this.baseInfoForm.details[row.index].returnRealQty
						)
					) {
						this.baseInfoForm.details[row.index][key] =
							this.baseInfoForm.details[row.index].returnRealQty;
					}
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);

					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'customerId' || key === 'stockId') {
					this.getCustomerStockInfoCom(row.index);
				}
				if (key === 'stockId') {
					this.baseInfoForm.details[row.index].isCustomer = !isOpen;
				}
				if (key === 'customerId') {
					this.baseInfoForm.details[row.index].customerStockId = '';
				}
			}
		},
		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];
			}
		},
		// 顶部公共按钮
		actionhandel(type) {
			this.isDisableTop = true;
			setTimeout(() => {
				this.isDisableTop = false;
			}, 2000);
			let ids = [];
			if (this.$route.query.id) {
				ids = [this.$route.query.id];
			}
			if (this.saveIds != '') {
				ids = [this.saveIds];
			}
			let detailsIds = [];
			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' && 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 == 'add') {
				this.$router.push({
					path: '/warehouse/purchase/activeReturnOrder',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			if (type == 'exDetails') {
				if (
					!this.examineObj ||
					JSON.stringify(this.examineObj) === '{}'
				) {
					this.$message.error('该单据不存在审批流!');
					return false;
				}
				this.$router.push({
					path: '/examine/mange/examineFollow',
					query: { id: this.examineObj.id },
				});
			}
			if (type === 'save' || type === 'submit') {
				this.saveSubmitComMethods(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' || type === 'down-check') {
				let pathName =
					type === 'up-check'
						? 'PurchaseReturnMaterial/upper'
						: 'PurchaseReturnMaterial/lower';
				let msg =
					type === 'up-check'
						? '没有可上查的单据!'
						: '没有可下查的单据!';
				let msgT = type === 'up-check' ? '上查结果' : '下查结果';
				this.$http.post(pathName, { ids: detailsIds }).then((res) => {
					if (res.status === 200) {
						if (res.data.length === 0 || res.data === []) {
							this.$message.error({
								message: msg,
								showClose: true,
							});
						} else {
							this.upOrDownList = res.data;
							this.dialogCX =
								res.data && res.data.length > 0 ? true : false;
							this.CXttile = msgT;
							this.CXcheckVal =
								res.data && res.data.length === 1
									? res.data[0].orderType
									: null; //只有一个，就个默认值
						}
					}
				});
			}
			// 点击下推
			if (type === 'push-down') {
				if (detailsIds.length > 0) {
					if (detailsIds.length <= 20) {
						if (this.baseInfoForm.documentStatus !== 'c') {
							this.$message.error({
								message:
									'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
								showClose: true,
							});
						} else {
							this.dialogxt = true;
						}
					} else {
						this.$message.error({
							message: '最多一次性下推二十条明细',
							showClose: true,
						});
					}
				} else {
					this.$message.error({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能下推',
						showClose: true,
					});
				}
			}
		},
		// 下推确定
		sumitPushdown(id) {
			this.CXcheckVal = id;
			if (this.CXcheckVal) {
				let pathName = '';
				let routerName = '';
				if (this.CXcheckVal === 1) {
					pathName = 'PurchaseReturnMaterial/push';
					routerName = 'CreatePurchase';
				}
				this.$http
					.post(pathName, { ids: this.OrdedetailIds })
					.then((res) => {
						if (res.status === 200) {
							this.dialogxt = false;
							this.$router.push({
								name: routerName,
								query: {
									type: 'pushDown',
									pushDownData: JSON.stringify(res.data),
									typeId: 3,
									sjtag: Math.random() * 36,
								},
								sjtag: Math.random() * 36,
							});
							this.dialogxt = false;
						}
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		// 删除
		deleteOrder(ids) {
			if (!isNaN(ids[0])) {
				this.$http
					.post('PurchaseReturnMaterial/delete', { ids: ids })
					.then((res) => {
						if (res.status === 200) {
							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: '不能删除此单据!',
					showClose: true,
				});
			}
		},
		// 反审
		deApprovalPageDate(ids) {
			if (this.baseInfoForm.documentStatus == 'c') {
				this.$http
					.post('PurchaseReturnMaterial/recheck', { 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)
									.get(
										'PurchaseReturnMaterial/get/' +
											this.baseInfoForm.id
									)
									.then((req) => {
										if (req.status == 200) {
											this.baseInfoForm =
												purReSaveSubmitRequestGetData(
													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('PurchaseReturnMaterial/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)
									.get(
										'PurchaseReturnMaterial/get/' +
											this.baseInfoForm.id
									)
									.then((req) => {
										if (req.status == 200) {
											this.baseInfoForm =
												purReSaveSubmitRequestGetData(
													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('PurchaseReturnMaterial/revoke', { ids: ids })
					.then((r) => {
						if (r.data[0].isSuccess) {
							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: r.data[0].msg,
								showClose: true,
							});
						}
					});
			} else {
				this.$message.error({
					message: '只能撤销审核中的单据!',
					showClose: true,
				});
			}
		},
		// 保存、提交
		saveSubmitComMethods(type) {
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				let pathName =
					type === 'save'
						? 'PurchaseReturnMaterial/save'
						: 'PurchaseReturnMaterial/submit';
				filterMaterialData(this.baseInfoForm);
				this.$http
					.showLoading(true)
					.post(pathName, this.baseInfoForm)
					.then((r) => {
						if (r.status == 200) {
							this.saveOrSubmitData(r, type);
							this.$message.success({
								message:
									type === 'save' ? '保存成功!' : '提交成功!',
								showClose: true,
							});
							type === 'submit'
								? (this.baseInfoForm.documentStatus = 'b')
								: false;
							type === 'submit'
								? (this.isEdit = true)
								: (this.isEdit = false);
						}
					});
			} else {
				this.$message.error({
					message: '只能保存和提交创建或重新审核的单据!',
					showClose: true,
				});
			}
		},
		// 处理保存、提交返回数据
		saveOrSubmitData(r, type) {
			if (r.data) {
				this.$http
					.showLoading(false)
					.get('PurchaseReturnMaterial/get/' + r.data.id)
					.then((req) => {
						if (req.status == 200) {
							this.baseInfoForm = purReSaveSubmitRequestGetData(
								this.baseInfoForm,
								req,
								'y'
							);
							if (type === 'submit') {
								this.setExamine({
									status: r.status,
									data: r.data.tracking,
								});
							}
						}
					});
				this.baseInfoForm.billNo = r.data.billNo;
				this.baseInfoForm.id = r.data.id;
				this.saveIds = r.data.id;
				this.$refs.multipleTable.clearSelection();
				this.multipleSelection = [];
				this.selectRowIndexArr = [];
			}
		},
		// 失焦处理
		selectBlur() {
			let _that = this;
			_that.baseInfoForm.details.forEach((el) => {
				el.isParentOrderBillNo = false;
				el.isMaterialId = false;
				el.isSpecificationId = false;
				el.isReturnRealQty = false;
				el.isReplenishQty = false;
				el.isTaxPrice = false;
				el.isTaxRate = false;
				el.isStockId = false;
				el.isCustomerId = false;
				el.isCustomerStockId = false;
				el.isNote = false;
			});
		},
		// 星星
		mustAfter(obj) {
			let arry = [2, 3, 6, 8, 9, 14];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 插入的行
		getInsertInfo(data) {
			let result = purReInsertRowCom(
				data,
				this.baseInfoForm,
				this.customeStockArrylist,
				this.matterallCodelist,
				this.specificationalllist,
				this.addRow
			);
			this.baseInfoForm = result.baseInfoForm;
			this.customeStockArrylist = result.customeStockArrylist;
			this.matterallCodelist = result.matterallCodelist;
			this.specificationalllist = result.specificationalllist;
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
			this.selectBlur();
			this.$nextTick(() => {
				this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
					this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
			});
		},
		// 向下复制行
		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.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]
					);
					delete this.baseInfoForm.details[insertNum].id;
					this.selectBlur();
					this.countOrderHeader();
					// this.getPriceNumberCountCom(this.baseInfoForm.details[insertNum].taxPrice, insertNum, 'taxPrice')
					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.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]
						);
						delete this.baseInfoForm.details[lastIndex].id;
					});
					this.selectBlur();
					this.countOrderHeader();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
				}
			} else {
				this.$message.error({
					message: '请选择一行或多行复制!',
					showClose: true,
				});
			}
		},
		// 删除行
		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.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, 'materialId', 'Number')
					//   this.matterCodeChange(el.materialNumber, ind, 'sku', 'Specifications')
					//   this.baseInfoForm.details[ind].materialId = el.materialId
					//   this.baseInfoForm.details[ind].specificationId = el.materialId
					// })
					this.selectBlur();
					this.countOrderHeader();
					this.$refs.multipleTable.clearSelection();
					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 !== 'customerStockId') {
				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 = purReCopyMaterialGetValue(this.baseInfoForm, el, i)
										let result =
											purReTableInfoMaterialSkuGetData(
												this.baseInfoForm,
												el,
												i,
												this.unitData,
												this.isPrecision,
												this.salePrecisionNumber,
												this.supplierList,
												this.statusForm.getTaxRateList
											);
										this.baseInfoForm = result.baseInfoForm;
										this.isPrecision = result.isPrecision;
										this.salePrecisionNumber =
											result.salePrecisionNumber;

										this.baseInfoForm.details[
											i
										].returnRealQty = '0';
										this.baseInfoForm.details[i].taxPrice =
											'0';
										this.baseInfoForm.details[
											i
										].isMaterialId = false;
										this.baseInfoForm.details[
											i
										].isSpecificationId = false;

										this.getPriceNumberCountCom(
											this.baseInfoForm.details[i]
												.taxPrice,
											i,
											'taxPrice'
										);
									}
								});
							} else if (
								key === 'taxRate' ||
								key === 'taxPrice'
							) {
								this.baseInfoForm.details[i][key] =
									this.storeObj.storeVal;
								if (key === 'taxPrice') {
									if (this.baseInfoForm.details[i].giveAway) {
										this.baseInfoForm.details[i][key] = 0;
										this.baseInfoForm.details[
											i
										].isDisabled = true;
									}
								}
								this.getPriceNumberCountCom(
									this.baseInfoForm.details[i][key],
									i,
									key
								);
							} else if (key === 'returnRealQty') {
								if (this.baseInfoForm.details[i].unitId) {
									this.getNumberPrecisionMethods(
										i,
										this.storeObj.storeVal,
										this.storeObj.storeVal,
										true,
										key,
										'copy'
									);
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
								this.getPriceNumberCountCom(
									this.baseInfoForm.details[i][key],
									i,
									key
								);
							} else if (
								key === 'stockId' ||
								key === 'customerId'
							) {
								if (key === 'customerId') {
									if (
										this.baseInfoForm.details[i].isCustomer
									) {
										this.baseInfoForm.details[
											i
										].customerId = '';
									} else {
										this.baseInfoForm.details[
											i
										].customerId = this.storeObj.storeVal;
										this.baseInfoForm.details[
											i
										].customerStockId = '';
									}
								}
								if (key === 'stockId') {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
									let rowObject =
										this.statusForm.warehouse.filter(
											(it) =>
												it.id ===
												this.baseInfoForm.details[i][
													key
												]
										);
									this.baseInfoForm.details[i].isCustomer =
										rowObject.length > 0
											? !rowObject[0].customerWarehouseTag
											: true;
									this.baseInfoForm.details[i].customerId =
										'';
									this.baseInfoForm.details[
										i
									].customerStockId = '';
								}
								this.getCustomerStockInfoCom(i);
							} else {
								this.baseInfoForm.details[i][key] =
									this.storeObj.storeVal;
							}
						}
					}
				}
			}
			this.selectBlur();
		},
		// 单据头统计
		countOrderHeader() {
			let taxaMount = 0;
			let amount = 0;
			let allAmount = 0;
			this.baseInfoForm.details.forEach((el) => {
				taxaMount = Decimal.add(
					taxaMount,
					el.taxAmount ? el.taxAmount : 0
				);
				amount = Decimal.add(amount, el.amount ? el.amount : 0);
				allAmount = Decimal.add(
					allAmount,
					el.allAmount ? el.allAmount : 0
				);
			});
			this.baseInfoForm.billTaxAmount = taxaMount;
			this.baseInfoForm.billAmount = amount;
			this.baseInfoForm.billAllAmount = allAmount;
		},
		// 单选
		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() {
			return getNowTimeGlobal();
		},
		// 禁止操作单元格
		disabledCellStyle({ row, rowIndex, column, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		// 确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = '';
				if (this.CXcheckVal === 2) {
					// "采购订单"
					pathName = 'DemandOrder';
				}
				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,
				});
			}
		},
		// 匹配物料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 [];
					}
				});
		},
		// 获取物料编码 - SKU 信息
		async matterCodeChange(val, ind, type, diff) {
			if (val && this.baseInfoForm.stockOrgId) {
				if (val.indexOf(' ') == -1) {
					let matterDate = await this.backMaterSkuMethods(
						val,
						diff,
						this.baseInfoForm.stockOrgId
					);
					this.matterallCodelist[ind] = matterDate;
					this.specificationalllist[ind] = matterDate;
					if (type === 'getDate') {
						if (this.baseInfoForm.details[ind]) {
							this.matterallCodelist[ind].forEach((el) => {
								this.baseInfoForm = purReMaterialSkuSearch(
									this.baseInfoForm,
									el,
									ind
								);
							});
						}
					}
				}
			}
		},
		// 获取客户仓库信息
		getCustomerStockInfoCom(i, type) {
			let query = {};
			query.customerId = this.baseInfoForm.details[i].customerId
				? parseInt(this.baseInfoForm.details[i].customerId)
				: null;
			query.orgId = this.baseInfoForm.stockOrgId
				? parseInt(this.baseInfoForm.stockOrgId)
				: null;
			query.stockId = this.baseInfoForm.details[i].stockId
				? parseInt(this.baseInfoForm.details[i].stockId)
				: null;
			if (
				this.baseInfoForm.details[i].customerId &&
				this.baseInfoForm.stockOrgId &&
				this.baseInfoForm.details[i].stockId
			) {
				this.$http
					.showLoading(false)
					.post('SysConfig/GetCustomerStock', query)
					.then((r) => {
						if (r.status == 200) {
							this.customeStockArrylist[i] = r.data;
							if (type) {
								this.customeStockArrylist = splitJointList(
									this.baseInfoForm.details,
									this.customeStockArrylist,
									'customerStockList'
								);
								this.customeStockArrylist =
									this.customeStockArrylist.filter(Boolean);
							}
						}
					});
			}
		},
		// 金额、单价计算公共方法
		getPriceNumberCountCom(value, i, key) {
			let templateObject = countMethodsPurHoRe(
				this.baseInfoForm.details,
				value,
				i,
				key,
				this.statusForm.getTaxRateList,
				this.baseInfoForm.exchangeRate,
				this.unitpriceAccuracy,
				this.amountAccuracy
			);
			this.baseInfoForm.details = templateObject.details;
			this.baseInfoForm.billTaxAmount =
				templateObject.baseTaxaMount == ''
					? this.baseInfoForm.billTaxAmount
					: templateObject.baseTaxaMount;
			this.baseInfoForm.billAmount =
				templateObject.baseAmount == ''
					? this.baseInfoForm.billAmount
					: templateObject.baseAmount;
			this.baseInfoForm.billAllAmount =
				templateObject.baseAllAmount == ''
					? this.baseInfoForm.billAllAmount
					: templateObject.baseAllAmount;
		},
		// 数量精度处理共公方法
		getNumberPrecisionMethods(i, valueO, valueT, isInner, key, copy) {
			// console.log('null yes inner')
			let tempList = this.unitData.filter(
				(it) => it.id === this.baseInfoForm.details[i].unitId
			);
			if (tempList.length > 0) {
				tempList[0].precision == 0
					? (this.isPrecision[i] = true)
					: (this.isPrecision[i] = false);
				tempList[0].precision == 0
					? (this.salePrecisionNumber[i] = 0)
					: (this.salePrecisionNumber[i] = tempList[0].precision);
				if (copy === 'copy') {
					if (tempList && tempList.length > 0) {
						tempList[0].roundoffType = 2;
					}
				}
				let result = countMethodsUnitNumber(
					tempList,
					valueO,
					valueT,
					this.isCount[i],
					this.salePrecisionNumber[i],
					isInner
				);
				this.baseInfoForm.details[i][key] = result.value;
				// console.log('null yes inner',result.value)
				this.isCount[i] = result.isDefault;
			}
		},
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setSettletype: 'storeData/setSettletype',
			setDcurrency: 'storeData/setDcurrency',
			setRateType: 'storeData/setRateType',
			setTaxRate: 'storeData/setTaxRate',
			setCustomer: 'storeData/setCustomer',
			setPaymentTerm: 'storeData/setPaymentTerm',
			setSupplierSelect: 'storeData/setSupplierSelect',
			setReturnMatType: 'storeData/setReturnMatType',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),
	},
	computed: {
		...mapState({
			userId: (state) => state.user.userInfo.staffId || null,
			orgIdArr: (state) => state.user.orgIdArr,
			unitAll: (state) => state.storeData.allUnit,
			settletype: (state) => state.storeData.settletype,
			dcurrency: (state) => state.storeData.dcurrency,
			rateType: (state) => state.storeData.rateType,
			taxRate: (state) => state.storeData.taxRate,
			customer: (state) => state.storeData.customer,
			paymentTerm: (state) => state.storeData.paymentTerm,
			supplierSelect: (state) => state.storeData.supplierSelect,
			returnMatType: (state) => state.storeData.returnMatType,
			getAllUserList: (state) => state.storeData.getAllUserList,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
		}),
		isShow: function () {
			return this.isExmaineTop;
		},
	},
	created: function () {
		this.Init();
		this.setApprovalFlowStatus();
	},
	watch: {
		'baseInfoForm.stockOrgId': function () {
			if (this.baseInfoForm.stockOrgId) {
				this.$http
					.showLoading(false)
					.post('SysConfig/GetDept/' + this.baseInfoForm.stockOrgId)
					.then((req) => {
						if (req.status == 200) {
							let deptArr = req.data;
							this.statusForm.stockDepts =
								removeChildren(deptArr);
						}
					});
			}
		},
		'baseInfoForm.documentStatus': function () {
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增采购退料单');
				this.btnType = activeReturnBtnAdd;
			} else {
				this.$topNavTagRename('编辑采购退料单');
				this.btnType = activeReturnBtnEdit;
			}
		},
		'baseInfoForm.settleOrgId': async function () {
			this.orgIdArr.forEach((element) => {
				if (element.id === this.baseInfoForm.settleOrgId) {
					this.baseInfoForm.localCurrId = element.standardCoinId;
				}
			});
			let templateObj = await getTaxPrice(
				this.baseInfoForm.localCurrId,
				'SysConfig/GetRateInfo',
				this.baseInfoForm.settleCurrId
			);
			if (templateObj) {
				this.baseInfoForm.exchangeRate = templateObj.directRate;
				this.baseInfoForm.exchangeTypeId = templateObj.issueInvoiceId;
			} else {
				this.baseInfoForm.exchangeRate = '';
				this.baseInfoForm.exchangeTypeId = '';
			}
		},
		'baseInfoForm.returnMaterialMode': function () {
			if (this.baseInfoForm.returnMaterialMode == 1) {
				this.isReplen = false;
			} else {
				this.isReplen = true;
				this.baseInfoForm.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].replenishQty = '';
				});
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderCreate.scss';
@import '@/assets/style/purchase/common.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
