<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="create-purchase-container order-mc-bg main-container"
	>
		<!-- 顶部按钮组 -->
		<template v-if="isExmaineTop !== 2">
			<toolBtn
				:btnType="btnType"
				:isDisable="isDisable"
				@actionhandel="actionhandel"
				:isExmaineTop="isShow"
			></toolBtn>
		</template>
		<div class="create-purchase-base-info">
			<img
				class="reviewIconImg-pur"
				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 order-com-r"
										>
											<el-form-item
												class="Iisshow"
												label="采购订单号"
											>
												<el-input
													:disabled="isEdit"
													:maxlength="100"
													@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"
												class="click-cell-ipt-issue"
												placeholder="请选择"
												v-model="
													baseInfoForm.documentStatus
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														purchaseCom(
															baseInfoForm.documentStatus,
															'documentStatus'
														)
													"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.bills"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="单据类型"
										>
											<el-select
												:disabled="isEdit || isTypeId"
												@change="
													clearCom(
														baseInfoForm.fillType,
														'fillType'
													)
												"
												class="click-cell-ipt-issue"
												placeholder="请选择"
												v-model="baseInfoForm.fillType"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														purchaseCom(
															key,
															'fillType'
														)
													"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.orders"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s item-date"
											label="采购日期"
										>
											<el-date-picker
												:clearable="false"
												:disabled="isEdit"
												@change="
													purchaseCom(
														baseInfoForm.date,
														'date'
													)
												"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
												type="date"
												v-model="baseInfoForm.date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="采购组织"
										>
											<el-select
												:disabled="
													isEdit ||
													isPurOrg ||
													isPushDownOrg
												"
												@change="
													purchaseCom(
														baseInfoForm.purchaseorgId,
														'purchaseorgId'
													)
												"
												class="click-cell-ipt-issue"
												filterable
												placeholder="请选择"
												v-model="
													baseInfoForm.purchaseorgId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:value="item.id"
													style="font-size: 12px"
													v-for="item in statusForm.purchaseorgIds"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="供应商"
										>
											<el-select
												:disabled="
													isEdit || isPushDownReturn
												"
												@change="
													clearCom(
														baseInfoForm.supplierId,
														'supplierId'
													)
												"
												class="click-cell-ipt-issue"
												filterable
												placeholder="请输入关键词"
												remote
												reserve-keyword
												v-model="
													baseInfoForm.supplierId
												"
											>
												<el-option
													:key="item.id + item.name"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:label="item.name"
													:value="item.id"
													@click="
														purchaseCom(
															item.id,
															'supplierId'
														)
													"
													v-for="item in statusForm.getCustomerNumList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="采购部门"
										>
											<el-cascader
												:disabled="isEdit"
												:options="statusForm.saleParts"
												:props="optionProps"
												:show-all-levels="false"
												@change="
													purchaseCom(
														baseInfoForm.deptId,
														'deptId',
														'ipt',
														'type'
													)
												"
												class="click-cell-ipt-c"
												clearable
												placeholder="请选择部门"
												ref="cascader"
												style="font-size: 12px"
												v-model="baseInfoForm.deptId"
											></el-cascader>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="采购员"
										>
											<el-select
												:disabled="isEdit"
												class="click-cell-ipt-issue"
												filterable
												placeholder="请选择"
												v-model="
													baseInfoForm.purchaserId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.purchaserId,
															'purchaserId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.salePersons"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s address-textarea order-com-r"
											label="收货地址"
										>
											<el-input
												:autosize="{
													minRows: 3,
													maxRows: 3,
												}"
												:disabled="isEdit"
												@input="
													purchaseCom(
														baseInfoForm.providerAddress,
														'providerAddress'
													)
												"
												maxlength="50"
												placeholder=" "
												resize="none"
												type="textarea"
												v-model="
													baseInfoForm.providerAddress
												"
											></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-select
														:disabled="true"
														placeholder="请选择"
														v-model="
															baseInfoForm.dataSources
														"
													>
														<el-option
															:key="key + index"
															:label="value"
															:value="key"
															style="
																font-size: 12px;
															"
															v-for="(
																value,
																key,
																index
															) in statusForm.dataSourcesList"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													:required="true"
													class="item-bt-s"
													label="付款条件"
												>
													<el-select
														:disabled="isEdit"
														@change="
															handleChooseTool(
																baseInfoForm.payConditionId
															)
														"
														placeholder="请选择收款条件"
														v-model="
															baseInfoForm.payConditionId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															:value="item.id"
															@click="
																purchaseCom(
																	baseInfoForm.payConditionId,
																	'payConditionId'
																)
															"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.collectionTermss"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													:required="true"
													class="item-bt-s"
													label="结算币别"
												>
													<el-select
														:disabled="
															isEdit ||
															isPushDownReturn
														"
														@change="
															settleCurrMethods
														"
														placeholder="请选择结算币别"
														v-model="
															baseInfoForm.settleCurrId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															:value="item.id"
															@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="true"
														placeholder="请选择结算币别"
														v-model="
															baseInfoForm.localCurrId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															@click="
																purchaseCom(
																	baseInfoForm.localCurrId,
																	'localCurrId'
																)
															"
															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="true"
														placeholder="请选择汇率"
														v-model="
															baseInfoForm.exchangeTypeId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.rateTypeList"
														></el-option>
													</el-select>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="结算方式"
										>
											<el-select
												:disabled="isEdit"
												@change="
													handleChooseTool(
														baseInfoForm.settleModeId
													)
												"
												class="click-cell-ipt-issue"
												placeholder="请选择"
												v-model="
													baseInfoForm.settleModeId
												"
											>
												<el-option
													:key="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:label="item.name"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.settleModeId,
															'settleModeId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.exchangeRateTypes"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s order-com-rr Iisshow"
											label="汇率"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.exchangerate
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.exchangerate
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s order-com-rr Iisshow"
											label="税额"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.billTaxAmount
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.billTaxAmount
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s order-com-rr Iisshow"
											label="金额"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.billAmount
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.billAmount
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s order-com-rr Iisshow"
											label="价税合计"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.billAllAmount
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.billAllAmount
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<el-form-item
										class="item-bt-s order-com-rr Iisshow"
										label="账户名称"
										style="margin-bottom: 8px"
									>
										<el-input
											:disabled="
												baseInfoForm.documentStatus ==
													'b' ||
												baseInfoForm.documentStatus ==
													'c'
											"
											placeholder
											:maxlength="255"
											v-model="baseInfoForm.accountName"
										></el-input>
										<div
											:data-clipboard-text="
												baseInfoForm.accountName
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
									<el-form-item
										class="item-bt-s order-com-rr Iisshow"
										label="开户银行"
										style="margin-bottom: 8px"
									>
										<el-input
											:disabled="
												baseInfoForm.documentStatus ==
													'b' ||
												baseInfoForm.documentStatus ==
													'c'
											"
											:maxlength="255"
											placeholder
											v-model="baseInfoForm.depositBank"
										></el-input>
										<div
											:data-clipboard-text="
												baseInfoForm.depositBank
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
									<el-form-item
										class="item-bt-s order-com-rr Iisshow"
										label="银行账号"
										style="margin-bottom: 8px"
									>
										<el-input
											:disabled="
												baseInfoForm.documentStatus ==
													'b' ||
												baseInfoForm.documentStatus ==
													'c'
											"
											placeholder
											v-model="baseInfoForm.bankAccount"
											:maxlength="255"
										></el-input>
										<div
											:data-clipboard-text="
												baseInfoForm.bankAccount
											"
											@click="saleOrderCopy"
											class="copyBtn"
										>
											<i class="el-icon-document-copy" />
										</div>
									</el-form-item>
								</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
											class="item-bt-s"
											label="创建人"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.creatorName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="创建时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.createDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											class="item-bt-s"
											label="最后修改人"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.modifierName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.modifyDate
												"
											></el-input>
										</el-form-item>
										<el-form-item
											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"
														maxlength="50"
														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">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="确认人"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.confirmerName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="确认时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													baseInfoForm.confirmeDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<div class="create-purchase-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"
					:disabled="true"
					:header-cell-class-name="mustAfter"
					:header-cell-style="headerBg"
					:max-height="tableHeight"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectAll"
					border
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
					v-loading="isLoading"
				>
					<el-table-column
						align="center"
						fixed
						type="selection"
						width="40"
					/>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'demandBillNo')" -->
					<el-table-column
						align="left"
						label="销售订单号"
						prop="demandBillNo"
						width="178"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>销售订单号
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDemandBillNo">{{
								scope.row.demandBillNo
							}}</span>
							<div
								:class="{
									'is-disabled': isEdit || isPushDownOrg,
								}"
								class="el-input click-cell-ipt"
								v-if="scope.row.isDemandBillNo"
							>
								<input
									:disabled="isEdit || isPushDownOrg"
									:id="'demandBillNo' + scope.$index"
									autocomplete="off"
									@blur="
										detailsCom(
											scope.row.demandBillNo,
											'demandBillNo',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.demandBillNo"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料编码"
						prop="materialId"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<!-- @paste="pasteExcel($event,scope.$index,scope,'materialId')" -->
						<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,
											scope.row.index
										)
									"
									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,
											'materialId',
											'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"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'specificationId',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									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="unitName"
						width="85"
					>
						<template #default="scope">
							<span>{{ scope.row.unitName }}</span>
						</template>
					</el-table-column>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'qty')" -->
					<el-table-column
						align="left"
						label="采购数量"
						prop="qty"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>采购数量
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isQty">{{
								scope.row.qty
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isQty"
							>
								<input
									:disabled="isEdit"
									:id="'qty' + scope.$index"
									:maxlength="16"
									autocomplete="off"
									@blur="
										detailsCom(
											scope.row.qty,
											'qty',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									class="el-input__inner click-cell-ipt t-r"
									placeholder="请输入"
									v-model.lazy="scope.row.qty"
								/>
							</div>
						</template>
					</el-table-column>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'taxPrice')" -->
					<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"
									autocomplete="off"
									@blur="
										detailsCom(
											scope.row.taxPrice,
											'taxPrice',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									class="el-input__inner click-cell-ipt t-r"
									placeholder="请输入"
									v-model.lazy="scope.row.taxPrice"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						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"
								placeholder="请选择"
								v-if="scope.row.isTaxRate"
								v-model="scope.row.taxRate"
							>
								<el-option
									:key="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:label="item.name"
									:value="item.name"
									@click="
										detailsCom(
											item.name,
											'taxRate',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									v-for="item in statusForm.getTaxRateList"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						:required="true"
						align="left"
						label="仓库"
						prop="soStock"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSoStock">{{
								scope.row.soStockName
							}}</span>
							<el-select
								:disabled="isEdit || isPushDownOrg"
								:id="'soStock' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'soStock'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isSoStock"
								v-model="scope.row.soStock"
							>
								<el-option
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:key="item.id + item.name"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'soStock',
											scope.row,
											scope.column,
											scope.row.index,
											item.customerWarehouseTag,
											item.disabled,
											item
										)
									"
									v-for="item in statusForm.warehouse"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="期望交期"
						prop="deliveryDate"
						width="130"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>期望交期
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDeliveryDate">{{
								scope.row.deliveryDate
							}}</span>
							<el-date-picker
								:clearable="false"
								:disabled="isEdit"
								@change="
									detailsCom(
										scope.row.deliveryDate,
										'deliveryDate',
										scope.row,
										scope.column
									)
								"
								class="lead-time-style"
								format="YYYY-MM-DD"
								placeholder="年-月-日"
								type="date"
								v-if="scope.row.isDeliveryDate"
								v-model="scope.row.deliveryDate"
								value-format="YYYY-MM-DD"
							></el-date-picker>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户"
						prop="customerId"
						width="172"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isCustomerId">{{
								scope.row.customerName
							}}</span>
							<el-select
								:disabled="
									isEdit ||
									isPushDownOrg ||
									scope.row.isCusHouse
								"
								:id="'customerId' + scope.$index"
								@change="
									clearBtn(
										scope.row.customerId,
										'customerId',
										scope.$index
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerId'
									)
								"
								class="click-cell-ipt click-cell-show"
								clearable
								placeholder="请输入关键词"
								v-if="scope.row.isCustomerId"
								v-model="scope.row.customerId"
							>
								<el-option
									:key="item.id + item.name"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'customerId',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.customers"
								></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">{{
								scope.row.customerStockName
							}}</span>
							<el-select
								:disabled="
									isEdit ||
									scope.row.isCusHouse ||
									isPushDownReturn ||
									isPushDownOrg
								"
								:id="'customerStockId' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerStockId'
									)
								"
								class="click-cell-ipt click-cell-show"
								clearable
								placeholder="请输入关键词"
								v-if="scope.row.isCustomerStockId"
								v-model="scope.row.customerStockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id + item.name"
									: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="left"
						label="已收数量"
						prop="stockinQty"
						width="120"
					>
						<template #default="scope">
							<span>{{
								scope.row.stockinQty ? scope.row.stockinQty : 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="未交数量"
						prop="remainstockinQty"
						width="120"
					>
						<template #default="scope">
							<span>{{
								scope.row.remainstockinQty
									? scope.row.remainstockinQty
									: 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="关闭状态"
						prop="mrpCloseStatus"
						width="106"
					>
						<template #default="scope">
							<span>{{
								scope.row.mrpCloseStatus == 'a'
									? '正常'
									: scope.row.mrpCloseStatus == 'b'
									? '已关闭'
									: ''
							}}</span>
						</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"
									@blur="
										detailsCom(
											scope.row.note,
											'note',
											scope.row,
											scope.column
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.note"
								/>
							</div>
						</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="right"
						label="价税合计(本位币)"
						prop="localCurrAllAmount"
						width="121"
					>
						<template #default="scope">
							<span>{{ scope.row.localCurrAllAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="折扣率%"
						prop="discountRate"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>折扣率%
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDiscountRate">{{
								scope.row.discountRate
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
							>
								<input
									:disabled="isEdit || scope.row.isDisabled"
									:id="'discountRate' + scope.$index"
									:maxlength="12"
									autocomplete="off"
									@blur="
										detailsCom(
											scope.row.discountRate,
											'discountRate',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-if="scope.row.isDiscountRate"
									v-model.lazy="scope.row.discountRate"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="折扣额"
						prop="discountAmount"
						width="120"
					>
						<template #default="socpe">
							<span>{{ socpe.row.discountAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="税额"
						prop="taxAmount"
						width="120"
					>
						<template #default="socpe">
							<span>{{ socpe.row.taxAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="金额"
						prop="amount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.amount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="是否211"
						prop="is211"
						width="72"
					>
						<template #default="scope">
							<span>{{ scope.row.is211 ? '是' : '否' }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="供应链"
						prop="supplyChainName"
						width="64"
					>
						<template #default="scope">
							<span>{{ scope.row.supplyChainName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="结算组织"
						prop="settleOrgId"
						width="200"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>结算组织
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSettleOrgId">{{
								getName(
									statusForm.settlementOrgList,
									scope.row.settleOrgId
								)
							}}</span>
							<el-select
								:disabled="isEdit || isPushDownReturn"
								:id="'settleOrgId' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'settleOrgId'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								v-if="scope.row.isSettleOrgId"
								v-model="scope.row.settleOrgId"
							>
								<el-option
									:key="item.id + item.name"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'settleOrgId',
											scope.row,
											scope.column,
											scope.row.index
										)
									"
									v-for="item in statusForm.settlementOrgList"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="是否赠品"
						prop="giveAway"
						width="70"
					>
						<template #default="scope">
							<el-checkbox
								:disabled="isEdit"
								@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="barCode"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.barCode }}</span>
						</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 { mapState, mapActions } from 'vuex';
import { Decimal } from 'decimal.js';
import { orderCopy } from '@/utils/takeMethods';
import {
	getStaffListApiUser,
	approvalFlowTrackingCreate,
	approvalFlowTrackingGetby,
	approvalFlowTrackingUpdate,
} from '@/utils/api.js';
import { ElMessageBox, ElMessage } from 'element-plus';
import examineTop from '@/components/examineTop/index.vue';
import toolBtn from '@/components/public/toolBtn/toolBtn.vue';
import {
	getStatusType,
	getBaseCurrency,
	getTaxPrice,
	getNowTime,
	adoptValGetInd,
	removeChildren,
	splitJointList,
} from '@/utils/pubulic.js';
import { countMethodsPur, countMethodsUnitNumber } from '@/utils/count.js';

import {
	purchaseBtnAdd,
	purchaseBtnEdit,
	purDefaultTableInfo,
	purCustomSearch,
	is211s,
	optionProps,
	storeObj,
	purPushDownList,
} from '@/utils/variable.js';
import {
	purSureUpDownSearch,
	purPushDownSure,
	purPushDownRequest,
	purMaterialSkuSearch,
	purCopyOrderClearData,
	purCopyOrderInfoClearData,
	purGetPrecisionNumberFrist,
	purGetBackDate,
	purGetOrderId,
	purCopyCellGetData,
	purMaterSkuSearchGetData,
	purDisCountRateReg,
	purChangeOrgClearData,
	orderRexgu,
	getArrayName,
	purInsertRow,
	filterMaterialData,
} from '@/utils/takeMethods.js';
export default {
	name: 'CreatePurchase',
	components: {
		examineTop,
		toolBtn,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			examineObj: {},
			radios: [],
			recordIndex: '',
			isLoading: false,
			timer: null,
			salePrecisionNumber: [],
			isPrecision: [],
			unitData: [],
			isCount: [],
			priceData: [],
			isLockPrice: true,
			isEdit: true, // 状态为:创建、重新审核可编辑，其它类型不可编辑
			orderArr: {},
			statusForm: JSON.parse(JSON.stringify(purCustomSearch)),
			baseInfoForm: JSON.parse(JSON.stringify(purDefaultTableInfo)),
			addRow: {}, // 明细列表
			storeObj: JSON.parse(JSON.stringify(storeObj)),
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			btnType: JSON.parse(JSON.stringify(purchaseBtnAdd)), // 不需要显示的顶部按钮类型
			selectArr: [], // 行   集合
			selectRowIndexArr: [],
			selectRowIndex: '', // 当前 选择行
			currRow: 0, // 编辑 当前行
			currColumn: 0, // 编辑 当前列
			heightNum: 0, // 表格高度
			multipleSelection: [], // 明细选择的行
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrdedetailIds: [], // 勾选的明细id集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			OrderNoNames: [], // 选择的单据订单号集合
			pushDownList: JSON.parse(JSON.stringify(purPushDownList)),
			is211s: JSON.parse(JSON.stringify(is211s)),
			isTypeId: false,
			saveIds: '',
			initKeyPay: 1,
			initKeySett: 1,
			isPurOrg: false,
			unitpriceAccuracy: 10,
			amountAccuracy: 10,
			isPushDownOrg: false,
			isPushDownReturn: false,
			detailBtn: [],
			customeStockArrylist: [], // 客户仓库集合
			matterallCodelist: [], // 物料下拉数据
			specificationalllist: [], // 规格型号（sku）下拉数据
			isOrder: true,
			isDisable: false,
			tableHeight: 400,
			supplierList: null,

			tempStoreWarehouse: [],
		};
	},
	computed: {
		...mapState({
			orgId: (state) => (state && state.user ? state.user.orgId : null),
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			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,
			statusGetType: (state) => state.storeData.statusGetType,
			getAllUserList: (state) => state.storeData.getAllUserList,
			userId: (state) => state.user.userInfo.staffId || null,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
		}),
		isShow: function () {
			return this.isExmaineTop;
		},
	},
	methods: {
		...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',
			setStatusGetType: 'storeData/setStatusGetType',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),

		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'
				) {
					this.isExmaineTop = 3;
				}
				if (res.data.isDone) {
					this.baseInfoForm.documentStatus = 'c';
					this.isExmaineTop = 3;
				}
				this.isexamineBtns = false;
			} else {
				this.isexamineBtns = false;
				this.isExmaineTop = 3;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('Purchase/get/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.baseInfoForm = purGetBackDate(
							this.baseInfoForm,
							req
						);
						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({ path: '' });
			} else {
				let data = {
					approvalDetailsId: this.examineObj.approvalDetailsId,
					approvalOrderType: this.examineObj.sendOrderType,
					orderId: this.examineObj.sendOrderId,
					deptId: this.statusForm.deptId || 0,
					orgId: this.statusForm.purchaseorgId,
					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.billNo === ''
			) {
				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.deptId || 0,
				orgId: data.purchaseorgId,
				approvalOrderType: 6,
			};
			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;
						// }
						// 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(res) {
		// 	let obj = {
		// 		sendOrderId: res.data.id,
		// 		deptId: res.data.deptId || 0,
		// 		sendId: this.userId,
		// 		sendOrderType: 6,
		// 		sendOrderBillNo: res.data.billNo,
		// 		orgId: res.data.purchaseorgId,
		// 	};
		// 	this.setExamine({
		// 		status: res.status,
		// 		data: res.data.tracking,
		// 	});
		// },

		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',
				'customers',
				'exchangeRateTypes',
				'units',
				'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);
							}
						}
					});
				}
			});

			// 获取人员接口
			if (this.getAllUserList && this.getAllUserList.length > 0) {
				this.statusForm.salePersons = this.getAllUserList;
			} else {
				getStaffListApiUser().then((r) => {
					r.status == 200 ? this.setGetAllUserList(r.data) : false;
					r.status == 200
						? (this.statusForm.salePersons = r.data)
						: (this.statusForm.salePersons = []);
				});
			}

			// 枚举 - 单据状态、订单类型、关闭状态、是否211、是否赠品、供应链、数据来源
			if (
				this.statusGetType &&
				JSON.stringify(this.statusGetType) !== '{}'
			) {
				this.statusForm.bills = JSON.parse(
					JSON.stringify(this.statusGetType.documentStatus)
				);
				this.statusForm.orders = JSON.parse(
					JSON.stringify(this.statusGetType.purchaseBillType)
				);
				this.statusForm.cloStatus = JSON.parse(
					JSON.stringify(this.statusGetType.closeStatus)
				);
				this.statusForm.is211 = JSON.parse(
					JSON.stringify(this.statusGetType.is211Type)
				);
				this.statusForm.isFree = JSON.parse(
					JSON.stringify(this.statusGetType.giveAwayType)
				);
				this.statusForm.supplyChain = JSON.parse(
					JSON.stringify(this.statusGetType.supplyChainType)
				);
				this.statusForm.dataSourcesList = JSON.parse(
					JSON.stringify(this.statusGetType.dataSourceType)
				);
			} else {
				this.$http.get('Purchase/status/get').then((req) => {
					if (req.status == 200) {
						this.setStatusGetType(req.data);
						this.statusForm.bills = req.data.documentStatus;
						this.statusForm.orders = req.data.purchaseBillType;
						this.statusForm.cloStatus = req.data.closeStatus;
						this.statusForm.is211 = req.data.is211Type;
						this.statusForm.isFree = req.data.giveAwayType;
						this.statusForm.supplyChain = req.data.supplyChainType;
						this.statusForm.dataSourcesList =
							req.data.dataSourceType;
					}
				});
			}
			this.baseInfoForm.documentStatus = '';
			let windowHeight = document.documentElement.clientHeight;
			this.heightNum = windowHeight - 102;
			this.tableHeight = windowHeight - 482;
			if (
				this.$route.query.type === 'add' ||
				this.$route.query.type === 'copy'
			) {
				this.baseInfoForm.date = getNowTime();
			}
			this.statusForm.purchaseorgIds = this.orgIdArr; // 获取组织
			this.statusForm.settleOrg = this.orgIdArr;
			this.statusForm.settlementOrgList = this.orgIdArr;
			let keys = Object.keys(this.baseInfoForm.details[0]); // 获取添加对象
			this.backUpForm = this.baseInfoForm;
			for (const key in this.baseInfoForm.details[0]) {
				if (keys.indexOf(key) > -1) {
					this.addRow[key] = this.baseInfoForm.details[0][key];
				}
			}

			if (
				this.$route.query.type == 'pushDown' &&
				this.$route.query.pushDownData
			) {
				this.$route.query.typeId === 2 ? (this.isPurOrg = true) : false;
				this.isEdit = false;
				this.isTypeId = true;
				this.getPurChaseDetails(
					JSON.parse(
						decodeURIComponent(this.$route.query.pushDownData)
					)
				);
				// this.baseInfoForm.billNo = JSON.parse(decodeURIComponent(this.$route.query.pushDownData.billNo())
			}
			if (
				this.$route.query.type === 'add' ||
				this.$route.query.type === 'copy'
			) {
				this.isEdit = false;
				this.baseInfoForm.purchaseorgId = this.$store.state.org.orgId;
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.dataSources = '1';
				this.baseInfoForm.billNo = '';
				if (this.$route.query.type === 'copy') {
					this.getPurChaseDetails();
				}
				let tempSettleOrgName =
					this.statusForm.settlementOrgList.filter(
						(it) => it.id === this.baseInfoForm.purchaseorgId
					);
				this.addRow.settleOrgName = tempSettleOrgName[0].name;
			}
			if (
				this.$route.query.type == 'details' &&
				this.$route.query.id &&
				this.$route.query.status
			) {
				this.getPurChaseDetails();
			}
		},

		getName(arr, val) {
			return getArrayName(arr, val);
		},
		async settleCurrMethods() {
			this.baseInfoForm.localCurrId = getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.purchaseorgId
			);
			if (
				this.baseInfoForm.settleCurrId != null &&
				this.baseInfoForm.settleCurrId != '' &&
				this.baseInfoForm.settleCurrId != undefined
			) {
				let templateObj = await getTaxPrice(
					this.baseInfoForm.localCurrId,
					'SysConfig/GetRateInfo',
					this.baseInfoForm.settleCurrId
				);
				if (
					templateObj != '' &&
					templateObj != null &&
					templateObj != undefined
				) {
					this.baseInfoForm.exchangerate = templateObj.directRate
						? templateObj.directRate
						: '';
					this.baseInfoForm.exchangeTypeId =
						templateObj.issueInvoiceId
							? 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.baseInfoForm.details.forEach((el, ind) => {
				if (this.unitpriceAccuracy === 0) {
					this.baseInfoForm.details[ind].taxPrice = this.baseInfoForm
						.details[ind].taxPrice
						? Decimal(
								this.baseInfoForm.details[ind].taxPrice
						  ).toFixed(0)
						: '0';
				} else {
					this.baseInfoForm.details[ind].taxPrice = this.baseInfoForm
						.details[ind].taxPrice
						? Decimal(
								this.baseInfoForm.details[ind].taxPrice
						  ).toFixed(this.unitpriceAccuracy) * 1
						: '0';
				}
				this.isCountPriceComMethods(el.taxPrice, ind, 'taxPrice');
			});
		},
		// 清空客户 + 客户仓库
		clearBtn(value, key, index) {
			if (!value) {
				this.baseInfoForm.details[index].customerStockId = '';
			}
			let tempName = this.statusForm.customers.filter(
				(it) => it.id == this.baseInfoForm.details[index].customerId
			);
			this.baseInfoForm.details[index].customerName = tempName[0].name;
			this.baseInfoForm.details[index].customerStockId = '';
			this.baseInfoForm.details[index].customerStockName = '';
		},
		// 复制粘贴
		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 === 'qty' || key === 'taxPrice') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								let num = rows[i] * 1;
								if (!isNaN(num)) {
									this.baseInfoForm.details[recordAddIndex][
										key
									] = rows[i];
									this.isCountPriceComMethods(
										row[i],
										recordAddIndex,
										key
									);
								} else {
									this.$message.error({
										message:
											'粘贴内容有误,请重新选择复制内容!',
										showClose: true,
									});
									return;
								}
							}
							if (key === 'qty') {
								if (
									this.baseInfoForm.details[recordAddIndex]
										.unitId
								) {
									this.comUnitPriceNumber(
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										recordAddIndex,
										key,
										true,
										'temp'
									);
								} else {
									this.baseInfoForm.details[
										recordAddIndex
									].qty = this.baseInfoForm.details[
										recordAddIndex
									].qty
										? Decimal(
												this.baseInfoForm.details[
													recordAddIndex
												].qty
										  ).toFixed(0, Decimal.ROUND_HALF_UP)
										: '0';
								}
							}
							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 === 'demandBillNo') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								this.baseInfoForm.details[recordAddIndex][key] =
									rows[i];
							}
							recordAddIndex++;
						}
					}
				}
			}, 0);
		},
		handleChooseTool(val) {
			if (val === null) {
				this.$forceUpdate();
			}
		},
		async monitorOrg() {
			let deptArr = await getStatusType(
				'SysConfig/GetDept/',
				this.baseInfoForm.purchaseorgId,
				'post'
			); // 根据组织 获取部门
			this.statusForm.saleParts = removeChildren(deptArr);
			if (this.$route.query.type === 'add') {
				this.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.purchaseorgId
				); // 根据组织 获取仓库
				this.tempStoreWarehouse = JSON.parse(
					JSON.stringify(this.statusForm.warehouse)
				);
			}
			//   this.statusForm.salePersons = await getStatusType('SysConfig/GetStaffList/', this.baseInfoForm.purchaseorgId) // 根据部门 采购员
		},
		// 表头公共
		async purchaseCom(value, key, ipt, type) {
			if (key == 'billNo') {
				this.baseInfoForm[key] = orderRexgu(value);
			} else {
				this.baseInfoForm[key] = value;
			}
			if (key === 'providerAddress') {
				this.baseInfoForm[key] = value;
			}
			if (key === 'purchaseorgId') {
				this.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.purchaseorgId
				); // 根据组织 获取仓库
				this.statusForm.warehouse = splitJointList(
					this.baseInfoForm.details,
					this.statusForm.warehouse,
					'stockList'
				);
				this.statusForm.warehouse =
					this.statusForm.warehouse.filter(Boolean);
				this.tempStoreWarehouse = JSON.parse(
					JSON.stringify(this.statusForm.warehouse)
				);
				let result = purChangeOrgClearData(
					this.baseInfoForm,
					this.statusForm,
					this.addRow
				);
				this.baseInfoForm = result.baseInfoForm;
				this.statusForm = result.statusForm;
				this.addRow = result.addRow;
				this.$http
					.showLoading(false)
					.get('SysConfig/GetCustomer')
					.then((r) => {
						if (r.status === 200) {
							this.statusForm.customers = r.data;
						}
					});
				if (this.baseInfoForm.supplierId) {
					let query = {
						orgId: this.baseInfoForm.purchaseorgId,
						supplerId: this.baseInfoForm.supplierId,
					};
					this.$http
						.post('Public/get/supplieraboutfor', query)
						.then((r) => {
							if (r.status === 200) {
								if (r.data) {
									this.supplierList = r.data;
									if (r.data.deptId) {
										this.baseInfoForm.deptId =
											r.data.deptId;
									}
									if (r.data.buyerId) {
										this.baseInfoForm.purchaserId =
											r.data.buyerId;
									}
								}
							}
						});
				}
			}
			if (key === 'supplierId') {
				this.baseInfoForm.settleCurrId = '';
				this.baseInfoForm.payConditionId = '';
				this.baseInfoForm.settleModeId = '';
				this.baseInfoForm.deptId = '';
				this.baseInfoForm.purchaserId = '';
				if (value) {
					let query = {
						orgId: this.baseInfoForm.purchaseorgId,
						supplerId: value,
					};
					this.$http
						.showLoading(false)
						.post('Public/get/supplieraboutfor', query)
						.then(async (r) => {
							if (r.status === 200) {
								if (r.data) {
									this.supplierList = r.data;
									//回填供应商银行信息
									this.baseInfoForm.bankAccount =
										r.data.bankAccount || '';
									this.baseInfoForm.accountName =
										r.data.accountName || '';
									this.baseInfoForm.depositBank =
										r.data.depositBank || '';

									if (r.data.settlementCurrency) {
										this.baseInfoForm.settleCurrId = await r
											.data.settlementCurrency;
									}
									if (r.data.paymentTerms) {
										this.baseInfoForm.payConditionId =
											await r.data.paymentTerms;
									}
									if (r.data.settlementMethod) {
										this.baseInfoForm.settleModeId = await r
											.data.settlementMethod;
									}
									// 1.11 更改需求 结算方式不影响结算币别获取汇率
									if (r.data.settlementCurrency) {
										this.baseInfoForm.localCurrId =
											await getBaseCurrency(
												this.orgIdArr,
												this.baseInfoForm.purchaseorgId
											);
										if (
											this.baseInfoForm.settleCurrId !=
												null &&
											this.baseInfoForm.settleCurrId !=
												'' &&
											this.baseInfoForm.settleCurrId !=
												undefined
										) {
											let templateObj = await getTaxPrice(
												this.baseInfoForm.localCurrId,
												'SysConfig/GetRateInfo',
												this.baseInfoForm.settleCurrId
											);
											if (
												templateObj != '' &&
												templateObj != null &&
												templateObj != undefined
											) {
												this.baseInfoForm.exchangerate =
													(await templateObj.directRate)
														? templateObj.directRate
														: '';
												this.baseInfoForm.exchangeTypeId =
													(await templateObj.issueInvoiceId)
														? templateObj.issueInvoiceId
														: '';
											} else {
												this.baseInfoForm.exchangerate =
													await '';
												this.baseInfoForm.exchangeTypeId =
													await '';
											}
										}
										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;
										}
									}
									if (r.data.deptId) {
										this.baseInfoForm.deptId =
											r.data.deptId;
									}
									if (r.data.buyerId) {
										this.baseInfoForm.purchaserId =
											r.data.buyerId;
									}
									if (
										r.data.defaultTaxRate !== '' &&
										r.data.defaultTaxRate !== null &&
										r.data.defaultTaxRate !== undefined
									) {
										this.baseInfoForm.details.forEach(
											(el, ind) => {
												if (
													this.unitpriceAccuracy === 0
												) {
													this.baseInfoForm.details[
														ind
													].taxPrice = this
														.baseInfoForm.details[
														ind
													].taxPrice
														? Decimal(
																this
																	.baseInfoForm
																	.details[
																	ind
																].taxPrice
														  ).toFixed(0)
														: '0';
												} else {
													this.baseInfoForm.details[
														ind
													].taxPrice = this
														.baseInfoForm.details[
														ind
													].taxPrice
														? Decimal(
																this
																	.baseInfoForm
																	.details[
																	ind
																].taxPrice
														  ).toFixed(
																this
																	.unitpriceAccuracy
														  ) * 1
														: '0';
												}
												if (el.materialId) {
													let tempList =
														this.matterallCodelist[
															ind
														].filter(
															(it) =>
																it.id ===
																el.materialId
														);
													if (
														tempList &&
														tempList.length > 0
													) {
														if (
															tempList[0]
																.taxRateId
														) {
															this.baseInfoForm.details[
																ind
															].taxRate =
																tempList[0].taxRateNmae;
														} else {
															this.statusForm.getTaxRateList.forEach(
																(ele) => {
																	if (
																		ele.id ===
																		r.data
																			.defaultTaxRate
																	) {
																		this.baseInfoForm.details[
																			ind
																		].taxRate =
																			ele.name;
																		// this.addRow.taxRate = ele.name
																	}
																}
															);
														}
													} else {
														this.statusForm.getTaxRateList.forEach(
															(ele) => {
																if (
																	ele.id ===
																	r.data
																		.defaultTaxRate
																) {
																	this.baseInfoForm.details[
																		ind
																	].taxRate =
																		ele.name;
																	// this.addRow.taxRate = ele.name
																}
															}
														);
													}
												}
												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.isCountPriceComMethods(
													el.taxPrice,
													ind,
													'taxPrice'
												);
											}
										);
									}
								}
							}
						});
				}
			}
			if (type) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		// 详情公共
		async detailsCom(
			value,
			key,
			row,
			column,
			index,
			isOpen,
			disabled,
			item
		) {
			this.baseInfoForm.details.forEach((element, ind) => {
				this.priceData[ind] = element.taxPrice;
			});
			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 (!disabled) {
				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((element) => {
						if (value == element.id) {
							let result = purMaterSkuSearchGetData(
								this.baseInfoForm,
								element,
								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].qty = '0';
							if (element.taxRateId) {
								this.baseInfoForm.details[
									this.currRow
								].taxRate = element.taxRateNmae;
							} else {
								if (this.supplierList) {
									let tempList =
										this.statusForm.getTaxRateList.filter(
											(it) =>
												it.id ===
												this.supplierList.defaultTaxRate
										);
									if (tempList && tempList.length > 0) {
										this.baseInfoForm.details[
											this.currRow
										].taxRate = tempList[0].name;
									} else {
										this.baseInfoForm.details[
											this.currRow
										].taxRate = 0;
									}
								} else {
									this.baseInfoForm.details[
										this.currRow
									].taxRate = 0;
								}
							}
							this.isCountPriceComMethods(
								this.baseInfoForm.details[this.currRow]
									.taxPrice,
								this.currRow,
								'taxPrice'
							);
						}
						this.baseInfoForm.details[index].isMaterialId = false;
						this.baseInfoForm.details[
							index
						].isSpecificationId = false;
						document.getElementById(key + index).blur();
					});
				} else {
					if (key !== 'qty' || key !== 'taxPrice') {
						this.baseInfoForm.details[this.currRow][key] = value;
					}
				}
				if (key === 'discountRate') {
					this.baseInfoForm.details[row.index][key] =
						purDisCountRateReg(
							this.baseInfoForm.details[row.index][key]
						);
					this.isCountPriceComMethods(
						this.baseInfoForm.details[row.index][key],
						index,
						key
					);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'taxRate') {
					this.isCountPriceComMethods(value, index, key);
				}
				if (key === 'taxPrice') {
					let numD = '';
					let count = '\\d';
					for (
						let index = 0;
						index < this.unitpriceAccuracy;
						index++
					) {
						numD = numD + count;
					}
					let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
					if (this.baseInfoForm.details[row.index][key]) {
						if (
							this.unitpriceAccuracy === 0 &&
							this.baseInfoForm.details[row.index][key] !== 0 &&
							this.baseInfoForm.details[row.index][key] !== '0' &&
							this.baseInfoForm.details[row.index][key]
								.toString()
								.indexOf('.') !== -1
						) {
							this.baseInfoForm.details[row.index][key] =
								this.baseInfoForm.details[row.index][key]
									.toString()
									.replace(/\D/g, '');
							this.baseInfoForm.details[row.index][key] = Number(
								this.baseInfoForm.details[row.index][key]
							).toFixed(0);
						} else {
							this.baseInfoForm.details[row.index][key] =
								this.baseInfoForm.details[row.index][key]
									.toString()
									.replace(/[^\d.]/g, '')
									.replace(/\.{2,}/g, '.')
									.replace(/^\./g, '')
									.replace('.', '$#$')
									.replace(/\./g, '')
									.replace('$#$', '.')
									.replace(eval(reg), '$1$2.$3');
						}
					}
					if (!this.isCount[row.index]) {
						this.isCount[row.index] = 1;
					}
					if (this.isCount[row.index] == 1) {
						this.baseInfoForm.details[row.index][key] = this
							.baseInfoForm.details[row.index][key]
							? Decimal(
									this.baseInfoForm.details[row.index][key]
							  ).toFixed(this.unitpriceAccuracy) * 1
							: '0';
						this.comUnitPriceNumber(
							this.baseInfoForm.details[row.index].qty,
							row.index,
							'qty',
							false
						);
					} 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.isCountPriceComMethods(
						this.baseInfoForm.details[row.index].taxPrice,
						index,
						key
					);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'demandBillNo' && value && value != null) {
					let templateObj = await adoptValGetInd(
						value,
						'Public/getcustomerby/'
					);
					if (templateObj != null) {
						this.baseInfoForm.details[row.index].customerId =
							templateObj.customerId;
						this.baseInfoForm.details[row.index].billNo =
							templateObj.billNo;
						this.baseInfoForm.details[row.index].customerName =
							templateObj.customerName;
					}
				}
				if (key === 'customerId') {
					if (
						value &&
						this.baseInfoForm.details[row.index].customerId
					) {
						this.getCustomerInfoCom(row.index);
					}
				}
				if (key === 'qty') {
					this.isPrecision[row.index] = this.isPrecision[row.index]
						? this.isPrecision[row.index]
						: false;
					this.salePrecisionNumber[row.index] =
						this.salePrecisionNumber[row.index] ||
						this.salePrecisionNumber[row.index] == 0
							? this.salePrecisionNumber[row.index]
							: 10;
					if (
						!this.baseInfoForm.details[row.index].materialId &&
						!this.$route.query.id
					) {
						this.isPrecision[row.index] = true;
					}
					if (this.baseInfoForm.details[row.index][key]) {
						if (
							this.isPrecision[row.index] &&
							this.isPrecision[row.index] !== 0
						) {
							if (
								this.baseInfoForm.details[row.index][key]
									.toString()
									.indexOf('.') !== -1
							) {
								this.baseInfoForm.details[row.index][key] =
									Decimal(
										this.baseInfoForm.details[row.index][
											key
										]
									).toFixed(0, Decimal.ROUND_DOWN) * 1;
							}
							this.baseInfoForm.details[row.index][key] =
								this.baseInfoForm.details[row.index][key]
									.toString()
									.replace(/\D/g, '');
						} else {
							let numD = '';
							let count = '\\d';
							for (
								let ind = 0;
								ind < this.salePrecisionNumber[row.index];
								ind++
							) {
								numD = numD + count;
							}
							let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
							this.baseInfoForm.details[row.index][key] =
								this.baseInfoForm.details[row.index][key]
									.toString()
									.replace(/[^\d^\\.]+/g, '')
									.replace('.', '$#$')
									.replace(/\./g, '')
									.replace('$#$', '.')
									.replace(eval(reg), '$1$2.$3');
						}
					}
					if (
						this.baseInfoForm.details[row.index].maxNumber ||
						(this.baseInfoForm.details[row.index].maxNumber == 0 &&
							this.baseInfoForm.details[row.index].parentOrderId)
					) {
						if (
							Number(this.baseInfoForm.details[row.index][key]) >
							Number(
								this.baseInfoForm.details[row.index].maxNumber
							)
						) {
							this.baseInfoForm.details[row.index].qty = this
								.baseInfoForm.details[row.index].qty
								? Decimal(
										this.baseInfoForm.details[row.index]
											.maxNumber
								  ).toFixed(
										this.salePrecisionNumber[row.index],
										Decimal.ROUND_DOWN
								  )
								: '0';
						} else {
							if (!this.isCount[row.index]) {
								this.isCount[row.index] = 1;
							}
							if (
								this.baseInfoForm.details[row.index][
									key
								].indexOf('.') !== -1
							) {
								this.comUnitPriceNumber(
									this.baseInfoForm.details[row.index][key],
									row.index,
									'qty',
									false,
									'copy'
								);
							} else {
								this.baseInfoForm.details[row.index].qty =
									this.baseInfoForm.details[row.index][key];
								this.isCount[row.index] = 2;
							}
						}
					} else {
						if (!this.isCount[row.index]) {
							this.isCount[row.index] = 1;
						}
						if (this.isCount[row.index] == 1) {
							if (
								this.baseInfoForm.details[row.index][key]
									.toString()
									.indexOf('.') !== -1
							) {
								this.comUnitPriceNumber(
									this.baseInfoForm.details[row.index][key],
									row.index,
									'qty',
									false,
									'copy'
								);
							} else {
								this.baseInfoForm.details[row.index].qty =
									this.baseInfoForm.details[row.index][key];
								this.isCount[row.index] = 2;
							}
							this.baseInfoForm.details[row.index].taxPrice = this
								.baseInfoForm.details[row.index].taxPrice
								? Decimal(this.priceData[row.index]).toFixed(
										this.unitpriceAccuracy
								  ) * 1
								: '0';
						} else {
							if (
								this.baseInfoForm.details[row.index][key]
									.toString()
									.indexOf('.') !== -1
							) {
								this.comUnitPriceNumber(
									this.baseInfoForm.details[row.index][key],
									row.index,
									'qty',
									false,
									'copy'
								);
							} else {
								this.baseInfoForm.details[row.index].qty =
									this.baseInfoForm.details[row.index][key];
								this.isCount[row.index] = 2;
							}
						}
					}
					if (!this.isCount[row.index]) {
						this.isCount[row.index] = 1;
					}
					if (
						this.baseInfoForm.details[row.index][key]
							.toString()
							.indexOf('.') !== -1
					) {
						if (this.baseInfoForm.details[row.index].unitId) {
							this.comUnitPriceNumber(
								this.baseInfoForm.details[row.index].qty,
								row.index,
								'qty',
								false,
								'copy'
							);
						}
					} else {
						this.isCount[row.index] = 2;
					}
					this.isCountPriceComMethods(
						this.baseInfoForm.details[row.index].qty,
						index,
						key
					);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'deliveryDate') {
					let comparD = this.compareDate(
						this.baseInfoForm.date,
						this.baseInfoForm.details[row.index].deliveryDate
					);
					if (comparD == false) {
						this.$message.error({
							message: '期望交期不能大于采购日期,请重新选择',
							showClose: true,
						});
						this.baseInfoForm.details[row.index].deliveryDate = '';
					}
				}
				if (key === 'soStock') {
					let tempName = this.statusForm.warehouse.filter(
						(it) =>
							it.id ==
							this.baseInfoForm.details[row.index].soStock
					);
					this.baseInfoForm.details[row.index].soStockName =
						tempName[0].name;
					this.baseInfoForm.details[row.index].isCusHouse = !isOpen;
					this.baseInfoForm.details[row.index].customerStockId = '';
					this.baseInfoForm.details[row.index].customerStockName = '';
					this.baseInfoForm.details[row.index].customerId = '';
					this.baseInfoForm.details[row.index].customerName = '';
					if (row.index === 0) {
						let providerAddress =
							item.contacts +
							'/' +
							item.contactsMobile +
							'，' +
							item.address;
						this.baseInfoForm.providerAddress = providerAddress;
					}
				}
				// if (key === 'customerId') {
				//   let tempName = this.statusForm.customers.filter(it => it.id == this.baseInfoForm.details[row.index].customerId)
				//   this.baseInfoForm.details[row.index].customerName = tempName[0].name
				//   this.baseInfoForm.details[row.index].customerStockId = ''
				//   this.baseInfoForm.details[row.index].customerStockName = ''
				// }
				if (key === 'customerStockId') {
					let tempName = this.customeStockArrylist[row.index].filter(
						(it) =>
							it.id ==
							this.baseInfoForm.details[row.index].customerStockId
					);
					this.baseInfoForm.details[row.index].customerStockName =
						tempName[0].name;
				}
				if (key === 'settleOrgId') {
					let tempSettleOrgName =
						this.statusForm.settlementOrgList.filter(
							(it) =>
								it.id ===
								this.baseInfoForm.details[row.index].settleOrgId
						);
					this.baseInfoForm.details[row.index].settleOrgName =
						tempSettleOrgName[0].name;
				}
				if (key === 'note') {
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
			}
		},
		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];
			}
		},
		// 日期对比
		compareDate(logintime, logouttime) {
			var arys1 = new Array();
			var arys2 = new Array();
			if (logintime != null && logouttime != null) {
				arys1 = logintime.split('-');
				var logindate = new Date(
					arys1[0],
					parseInt(arys1[1] - 1),
					arys1[2]
				);
				arys2 = logouttime.split('-');
				var logoutdate = new Date(
					arys2[0],
					parseInt(arys2[1] - 1),
					arys2[2]
				);
				if (logindate > logoutdate) {
					return false;
				} else {
					return true;
				}
			}
		},
		// 失焦处理
		selectBlur() {
			let _that = this;
			_that.baseInfoForm.details.forEach((el) => {
				el.isDemandBillNo = false;
				el.isMaterialId = false;
				el.isSpecificationId = false;
				el.isQty = false;
				el.isTaxPrice = false;
				el.isTaxRate = false;
				el.isSoStock = false;
				el.isDeliveryDate = false;
				el.isCustomerId = false;
				el.isCustomerStockId = false;
				el.isNote = false;
				el.isDiscountRate = false;
				el.isSettleOrgId = false;
			});
		},
		// 删除公共
		clearCom(value, key) {
			delete this.baseInfoForm[key];
		},
		// 插入的行
		getInsertInfo(data) {
			let result = purInsertRow(
				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(data) {
			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]
					);
					this.baseInfoForm.details[insertNum].id = 0;
					this.selectBlur();
					this.countOrderHeader();
					// this.isCountPriceComMethods(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]
						);
						// this.isCountPriceComMethods(this.baseInfoForm.details[insertNum].taxPrice, insertNum, 'taxPrice')
					});
					this.selectBlur();
					this.countOrderHeader();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
				}
			} else {
				this.$message.error({
					message: '请选择一行或多行复制!',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			if (
				this.baseInfoForm.details.length > 1 &&
				this.baseInfoForm.details.length !=
					this.multipleSelection.length
			) {
				if (this.selectRowIndexArr != 0) {
					this.selectRowIndexArr.sort(function (a, b) {
						return a.index - b.index;
					});
					for (let i = 0; i < this.selectRowIndexArr.length; i++) {
						this.baseInfoForm.details.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.customeStockArrylist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.matterallCodelist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.specificationalllist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.salePrecisionNumber.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isPrecision.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isCount.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.baseInfoForm.details.forEach((el, ind) => {
							this.matterCodeChange(el.materialNumber, ind);
							// this.isCountPriceComMethods(this.baseInfoForm.details[ind].taxPrice, ind, 'taxPrice')
							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(data) {
			let nextRow = this.storeObj.storeRow + 1;
			let storeKey = this.storeObj.storekey;
			if (storeKey === 'customerId') {
				let query = {};
				query.customerId = this.baseInfoForm.details[
					this.storeObj.storeRow
				].customerId
					? parseInt(
							this.baseInfoForm.details[this.storeObj.storeRow]
								.customerId
					  )
					: 0;
				query.orgId = this.baseInfoForm.purchaseorgId
					? parseInt(this.baseInfoForm.purchaseorgId)
					: 0;
				if (
					this.baseInfoForm.details[this.storeObj.storeRow]
						.customerId &&
					this.baseInfoForm.purchaseorgId
				) {
					this.$http
						.showLoading(false)
						.post('SysConfig/GetCustomerStock', query)
						.then((r) => {
							if (r.status == 200) {
								for (
									let index = nextRow;
									index < this.baseInfoForm.details.length;
									index++
								) {
									this.customeStockArrylist[index] = r.data;
								}
							}
						});
				}
			}
			if (this.storeObj.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 = purCopyCellGetData(
											this.baseInfoForm,
											el,
											i
										);
										this.isCountPriceComMethods(
											this.baseInfoForm.details[i]
												.taxPrice,
											i,
											'taxPrice'
										);
									}
								});
							} else if (
								key === 'discountRate' ||
								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.isCountPriceComMethods(
									this.baseInfoForm.details[i][key],
									i,
									key
								);
							} else if (key === 'qty') {
								if (this.baseInfoForm.details[i].unitId) {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
									this.comUnitPriceNumber(
										this.storeObj.storeVal,
										i,
										'qty',
										true,
										'temp',
										'copy'
									);
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
								this.isCountPriceComMethods(
									this.baseInfoForm.details[i][key],
									i,
									key
								);
							} else {
								if (key === 'soStock' || key === 'customerId') {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
									if (key === 'soStock') {
										let rowObject =
											this.statusForm.warehouse.filter(
												(it) =>
													it.id ===
													this.baseInfoForm.details[i]
														.soStock
											);
										this.baseInfoForm.details[
											i
										].soStockName = rowObject[0].name;
										this.baseInfoForm.details[
											i
										].isCusHouse =
											rowObject.length > 0
												? !rowObject[0]
														.customerWarehouseTag
												: true;
										this.baseInfoForm.details[
											i
										].customerId = '';
										this.baseInfoForm.details[
											i
										].customerName = '';
										this.baseInfoForm.details[
											i
										].customerStockId = '';
										this.baseInfoForm.details[
											i
										].customerStockName = '';
									}
									if (key === 'customerId') {
										let rowObject =
											this.statusForm.customers.filter(
												(it) =>
													it.id ===
													this.baseInfoForm.details[i]
														.customerId
											);
										this.baseInfoForm.details[
											i
										].customerName = rowObject[0].name;
										this.baseInfoForm.details[
											i
										].customerStockId = '';
										this.baseInfoForm.details[
											i
										].customerStockName = '';
									}
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
							}
						}
					}
				}
			} else {
				this.$message.error({
					message: '客户仓库无法批量填充，请手动选择！',
					showClose: true,
				});
			}
		},
		// 是否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].taxPrice = '0';
				this.isCountPriceComMethods('0', row.index, taxPrice);
				this.isCountPriceComMethods(row.taxRate, row.index, 'taxRate');
			} else {
				this.baseInfoForm.details[index].isDisabled = false;
			}
		},
		// 居右
		headerBg({ columnIndex }) {
			let arr = [6, 10];
			if (arr.indexOf(columnIndex) !== -1) {
				return `text-align:right!important;`;
			}
		},
		// 星星--头部必填ico显示
		mustAfter(obj) {
			let arry = [2, 3, 6, 7, 8, 9, 10];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 选择的行
		selectRow(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndex = selection[0].index;
				this.selectRowIndexArr = selection;
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 点击全选
		selectAll(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndexArr = selection;
				if (selection.length == 1) {
					this.selectRowIndex = 0;
				}
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 单元格被点击
		getRowCol(row, column, cell) {
			let _that = this;
			_that.currRow = row.index;
			_that.storeObj.storeRow = row.index;
			_that.storeObj.storeCol = column.index;
			if (typeof cell === 'string') {
				_that.storeObj.storekey = cell;
			} else {
				_that.storeObj.storekey = column.property;
			}
			_that.storeObj.storeVal = row[_that.storeObj.storekey];

			if (_that.recordIndex != '' || _that.recordIndex == '0') {
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDemandBillNo = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isMaterialId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSpecificationId = false;
				_that.baseInfoForm.details[_that.recordIndex].isQty = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isTaxPrice = false;
				_that.baseInfoForm.details[_that.recordIndex].isTaxRate = false;
				_that.baseInfoForm.details[_that.recordIndex].isSoStock = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDeliveryDate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isCustomerId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isCustomerStockId = false;
				_that.baseInfoForm.details[_that.recordIndex].isNote = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDiscountRate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSettleOrgId = false;
			}

			switch (column.label) {
				case '销售订单号':
					row.isDemandBillNo = true;
					_that.recordIndex = row.index;
					break;
				case '物料编码':
					row.isMaterialId = true;
					_that.recordIndex = row.index;
					break;
				case '规格型号(SKU)':
					row.isSpecificationId = true;
					_that.recordIndex = row.index;
					break;
				case '采购数量':
					row.isQty = true;
					_that.recordIndex = row.index;
					break;
				case '含税单价':
					row.isTaxPrice = true;
					_that.recordIndex = row.index;
					break;
				case '税率%':
					row.isTaxRate = true;
					_that.recordIndex = row.index;
					break;
				case '仓库':
					row.isSoStock = true;
					_that.recordIndex = row.index;
					break;
				case '期望交期':
					row.isDeliveryDate = 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;
				case '折扣率%':
					row.isDiscountRate = true;
					_that.recordIndex = row.index;
					break;
				case '结算组织':
					row.isSettleOrgId = true;
					_that.recordIndex = row.index;
					break;
			}
			this.$nextTick(() => {
				let strArr = [
					'销售订单号',
					'物料编码',
					'规格型号(SKU)',
					'采购数量',
					'含税单价',
					'税率%',
					'仓库',
					'客户',
					'客户仓库',
					'备注',
					'折扣率%',
					'结算组织',
				];
				if (strArr.indexOf(column.label) !== -1) {
					document
						.getElementById(column.property + row.index)
						.focus();
				}
			});
		},
		//禁用的列
		disabledCellStyle({ row, rowIndex, column, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		// 顶部公共按钮操作
		actionhandel(type) {
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			let ids = [];
			let detailsIds = [];
			if (this.$route.query.id) {
				ids = [this.$route.query.id];
			}
			if (this.saveIds != '') {
				ids = [this.saveIds];
			}
			if (
				this.baseInfoForm.details &&
				this.baseInfoForm.details.length > 0
			) {
				detailsIds = [
					...new Set(
						this.multipleSelection
							.filter((item) => {
								if (item.id) {
									return item.id;
								}
							})
							.map((it) => {
								return it.id;
							})
					),
				];
			}
			this.OrdedetailIds = detailsIds; // 勾选的明细id集合
			if (type === 'push-down') {
				if (this.multipleSelection.length == 0) {
					this.$message.error({
						message: '请先选择要下推的明细行!',
						showClose: true,
					});
					return;
				}
			}
			if (type === 'up-check' || type === 'down-check') {
				if (this.multipleSelection.length == 0) {
					this.$message.error({
						message: '请先选择要查询的明细行!',
						showClose: true,
					});
					return;
				}
			}
			if (type == 'add') {
				// 点击新增
				this.$router.push({
					path: '/purchase/demand/createPurchase',
					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.saveSubCom(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 === 'close') {
				// 点击关闭
				this.closeOrderCom(detailsIds, type);
			}
			if (type === 'de-close') {
				this.closeOrderCom(detailsIds, type); // 点击反关闭
			}
			if (type === 'push-down') {
				// 点击下推
				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,
					});
				}
			}
			if (type === 'up-check' || type === 'down-check') {
				// 点击查询 -- 上下查
				let pathName =
					type === 'up-check' ? 'Purchase/upper' : 'Purchase/lower';
				this.$http.post(pathName, { ids: detailsIds }).then((res) => {
					if (res.status === 200) {
						if (res.data.length === 0 || res.data === []) {
							this.$message.error({
								message:
									type === 'up-check'
										? '没有可上查的单据!'
										: '没有可下查的单据!',
								showClose: true,
							});
						} else {
							this.upOrDownList = res.data;
							this.dialogCX =
								res.data && res.data.length > 0 ? true : false;
							type === 'up-check'
								? (this.CXttile = '上查结果')
								: (this.CXttile = '下查结果');
							this.CXcheckVal =
								res.data && res.data.length === 1
									? res.data[0].orderType
									: null; //只有一个，就个默认值
						}
					}
				});
			}
		},
		// 关闭 反关闭
		closeOrderCom(ids, type) {
			if (this.baseInfoForm.documentStatus === 'c') {
				let lock = false;
				let typeDocu = type === 'close' ? 'b' : 'a';
				let newClose = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.mrpCloseStatus;
						})
					),
				];
				newClose.forEach((element) => {
					if (element === typeDocu) {
						lock = true;
					}
				});
				if (lock) {
					this.$message.error({
						message: '操作失败,所选明细存在关闭或已关闭明细行!',
						showClose: true,
					});
					return;
				} else {
					if (ids.length > 0) {
						let msg =
							type === 'close'
								? '你确认要反关闭所选单据行'
								: '你确认要反关闭所选单据行';
						let pathName =
							type === 'close'
								? 'Purchase/close'
								: 'Purchase/reclose';
						let tips = type === 'close' ? '关闭成功' : '反关闭成功';
						let unTips =
							type === 'close' ? '未关闭成功' : '未反关闭成功';
						ElMessageBox.confirm(msg, '操作确认', {
							confirmButtonText: '确认',
							cancelButtonText: '取消',
							type: 'Success',
						})
							.then(() => {
								this.$http
									.post(pathName, { ids: ids })
									.then((res) => {
										if (res.status == 200) {
											ElMessage({
												type: 'success',
												message: tips,
												showClose: true,
											});
											let newArry = [
												...new Set(
													this.multipleSelection.map(
														(item) => {
															return item.index;
														}
													)
												),
											];
											newArry.forEach((el) => {
												this.baseInfoForm.details[
													el
												].mrpCloseStatus = typeDocu;
											});
										}
									});
							})
							.catch(() => {
								ElMessage({
									type: 'info',
									message: unTips,
									showClose: true,
								});
							});
					} else {
						this.$message.error({
							message: '请先选择需要操作的单据行！',
							showClose: true,
						});
					}
				}
			} else {
				this.$message.error({
					message: '只能关闭或反关闭已审核的单据!',
					showClose: true,
				});
			}
		},
		// 点击删除 -- 关闭当前页签 -- 返回列表
		deleteOrder(ids) {
			if (
				this.baseInfoForm.documentStatus === 'b' ||
				this.baseInfoForm.documentStatus === 'c'
			) {
				this.$message.error({
					message: '不能删除已审核或审核中的单据!',
					showClose: true,
				});
			} else {
				if (!isNaN(ids[0])) {
					this.$http
						.post('Purchase/delete', { ids: ids })
						.then((r) => {
							if (r.status === 200) {
								if (r.data[0].isSuccess == false) {
									this.$message.error({
										message: r.data[0].msg,
										showClose: true,
									});
								} else {
									this.$store.state.topNavTag.tags.splice(
										this.$store.state.topNavTag.tags.findIndex(
											(item) =>
												item.path === this.$route.path
										),
										1
									);
									this.$router.push(
										this.$store.state.topNavTag.tags[
											this.$store.state.topNavTag.tags
												.length - 1
										].path
									);
								}
							}
						});
				} else {
					this.$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
					);
				}
			}
		},
		// 反审
		deApprovalPageDate(ids) {
			if (this.baseInfoForm.documentStatus == 'c') {
				this.$http.post('Purchase/recheck', { ids: ids }).then((r) => {
					if (r.status == 200) {
						r.data.forEach((element) => {
							if (element.isSuccess === false) {
								this.$message.error({
									message: element.msg,
									showClose: true,
								});
							} else {
								this.$message.success({
									message: '反审成功!',
									showClose: true,
								});
								this.baseInfoForm.documentStatus = 'd';
								this.isEdit = false;
								this.$http
									.showLoading(false)
									.get('Purchase/get/' + this.baseInfoForm.id)
									.then((req) => {
										if (req.status == 200) {
											this.baseInfoForm = purGetBackDate(
												this.baseInfoForm,
												req
											);
										}
									});
							}
						});
					}
				});
			} else {
				this.$message.error({
					message: '只能反审核处于已审核的单据!',
					showClose: true,
				});
			}
		},
		// 审核
		auditPageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http.post('Purchase/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('Purchase/get/' + this.baseInfoForm.id)
								.then((req) => {
									if (req.status == 200) {
										this.baseInfoForm = purGetBackDate(
											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('Purchase/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,
				});
			}
		},
		// 保存提交
		saveSubCom(type) {
			let pathName =
				type === 'save' ? 'Purchase/save' : 'Purchase/submit';
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				this.baseInfoForm.details.forEach((el, ind) => {
					delete this.baseInfoForm.details[ind].settleorg;
				});
				filterMaterialData(this.baseInfoForm);
				this.$http
					.showLoading(true)
					.post(pathName, this.baseInfoForm)
					.then((r) => {
						if (r.status == 200) {
							this.saveOrSubmitData(r, type);
							// if (type === 'submit') {
							// 	this.setExamine({
							// 		status: r.status,
							// 		data: r.data.tracking,
							// 	});
							// }
							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('Purchase/get/' + r.data.id)
					.then((req) => {
						if (req.status == 200) {
							this.baseInfoForm = purGetBackDate(
								this.baseInfoForm,
								req
							);
							if (type === 'submit') {
								this.setExamine({
									status: r.status,
									data: r.data.tracking,
								});
							}
						}
					});
				this.saveIds = r.data.id;
				this.baseInfoForm = purGetOrderId(this.baseInfoForm, r);
				this.$refs.multipleTable.clearSelection();
				this.multipleSelection = [];
				this.selectRowIndexArr = [];
			}
		},
		async getPurChaseDetails(res) {
			console.log(res, '==========res============');
			if (res) {
				this.isLoading = true;
				this.baseInfoForm = res;

				this.isPushDownOrg = res.isPushDown;
				if (this.baseInfoForm.isPushDown) {
					this.detailBtn = ['add', 'copy'];
				} else {
					this.detailBtn = [];
				}
				if (this.baseInfoForm.details[0].parentOrderType === 9) {
					this.isPushDownReturn = true;
					this.baseInfoForm.billNo = res.billNo;
				} else if (this.baseInfoForm.details[0].parentOrderType === 3) {
					this.isPushDownReturn = true;
					this.baseInfoForm.billNo = res.billNo;
				} else {
					this.baseInfoForm.billNo = res.billNo;
				}
				this.baseInfoForm.documentStatus = 'a'; // 下推等于创建
				this.baseInfoForm.dataSources = '1'; // 数据来源 系统生成
				// if (this.baseInfoForm.exchangeTypeId) {
				//   this.baseInfoForm.exchangeTypeId = parseInt(this.baseInfoForm.exchangeTypeId)
				// }
				if (
					this.baseInfoForm.fillType != null ||
					this.baseInfoForm.fillType != '' ||
					this.baseInfoForm.fillType != undefined
				) {
					this.baseInfoForm.fillType = res.fillType + '';
				}
				if (this.baseInfoForm.fillType == null) {
					this.baseInfoForm.fillType = '';
				}
				if (this.baseInfoForm.supplierId) {
					this.$http
						.showLoading(false)
						.post('Public/get/supplieraboutfor', {
							orgId: this.baseInfoForm.purchaseorgId,
							supplerId: this.baseInfoForm.supplierId,
						})
						.then(async (r) => {
							if (r.status === 200) {
								this.supplierList = r.data;
								this.baseInfoForm.payConditionId =
									r.data.paymentTerms;
								this.baseInfoForm.settleModeId =
									r.data.settlementMethod;
								if (
									this.baseInfoForm.details[0]
										.parentOrderType === 3
								) {
									this.baseInfoForm.deptId = r.data.deptId;
									this.baseInfoForm.purchaserId =
										r.data.buyerId;
								}
							}
						});
				}
				if (
					this.baseInfoForm.date == '' ||
					this.baseInfoForm.date == undefined ||
					this.baseInfoForm.date == null
				) {
					this.baseInfoForm.date = getNowTime();
				}
				if (this.baseInfoForm.settleCurrId) {
					await this.$http
						.get('SysConfig/GetDcurrency')
						.then(async (r) => {
							if (r.status === 200) {
								this.statusForm.setlementDifferences = 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.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.purchaseorgId
				); // 根据组织 获取仓库
				this.tempStoreWarehouse = JSON.parse(
					JSON.stringify(this.statusForm.warehouse)
				);

				await this.getMaterialCustomerDataAll();
				await this.baseInfoForm.details.forEach(async (el, ind) => {
					if (this.baseInfoForm.details[0].parentOrderType === 3) {
						let tempPrice = this.matterallCodelist[ind].filter(
							(it) => it.id == el.materialId
						);
						this.baseInfoForm.details[ind].taxPrice =
							tempPrice[0].purchasePrice;
					}

					this.baseInfoForm.details[ind].materialId = el.materialId;
					this.baseInfoForm.details[ind].specificationId =
						el.materialId;
					this.baseInfoForm.details[ind].isDisabled = false;

					let rowObject = this.statusForm.warehouse.filter(
						(it) => it.id === el.soStock
					);
					this.baseInfoForm.details[ind].soStockName =
						rowObject[0].name;
					this.baseInfoForm.details[ind].isCusHouse =
						rowObject.length > 0
							? !rowObject[0].customerWarehouseTag
							: true;

					let tempUnitName = this.statusForm.units.filter(
						(it) => it.id == el.unitId
					);
					if (tempUnitName.length > 0) {
						this.baseInfoForm.details[ind].unitName =
							tempUnitName[0].name;
					}

					let tempCustomerName = this.statusForm.customers.filter(
						(it) => it.id == el.customerId
					);
					if (tempCustomerName.length > 0) {
						this.baseInfoForm.details[ind].customerName =
							tempCustomerName[0].name;
					}

					let tempSettleOrgName =
						this.statusForm.settlementOrgList.filter(
							(it) =>
								it.id ===
								this.baseInfoForm.details[ind].settleOrgId
						);
					if (tempSettleOrgName.length > 0) {
						this.baseInfoForm.details[ind].settleOrgName =
							tempSettleOrgName[0].name;
					}

					if (el.customerStockList.length > 0) {
						this.baseInfoForm.details[ind].customerStockId =
							el.customerStockList[0].id;
						this.baseInfoForm.details[ind].customerStockName =
							el.customerStockList[0].name;
					}

					this.baseInfoForm.details[ind].qty =
						this.baseInfoForm.details[ind].qty == null
							? 0
							: this.baseInfoForm.details[ind].qty;
					this.baseInfoForm.details[ind].taxPrice =
						this.baseInfoForm.details[ind].taxPrice == null
							? 0
							: this.baseInfoForm.details[ind].taxPrice;
					this.baseInfoForm.details[ind].discountRate =
						this.baseInfoForm.details[ind].discountRate == null
							? 0
							: this.baseInfoForm.details[ind].discountRate;

					this.matterallCodelist[ind].forEach((element) => {
						if (element.taxRateId) {
							this.baseInfoForm.details[ind].taxRate =
								element.taxRateNmae;
						} else {
							if (this.supplierList) {
								let tempList =
									this.statusForm.getTaxRateList.filter(
										(it) =>
											it.id ===
											this.supplierList.defaultTaxRate
									);
								if (tempList && tempList.length > 0) {
									this.baseInfoForm.details[ind].taxRate =
										tempList[0].name;
								} else {
									this.baseInfoForm.details[ind].taxRate = 0;
								}
							} else {
								this.baseInfoForm.details[ind].taxRate = 0;
							}
						}
					});

					if (this.baseInfoForm.details[ind].giveAway) {
						this.baseInfoForm.details[ind].isDisabled = true;
						this.baseInfoForm.details[ind].taxPrice = 0;
					}
					this.comUnitPriceNumber(
						this.baseInfoForm.details[ind].qty,
						ind,
						'qty',
						true,
						'temp'
					);
					this.isCountPriceComMethods(
						this.baseInfoForm.details[ind].qty,
						ind,
						'qty'
					);
				});
				if (this.$route.query.typeId) {
					this.baseInfoForm.fillType = this.$route.query.typeId + '';
				}
				this.isLoading = false;
			} else {
				this.isLoading = true;
				this.$http
					.showLoading(false)
					.get('Purchase/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 = await req.data;
							this.setApprovalFlowTrackingGetby(req.data);
							if (this.baseInfoForm.supplierId) {
								this.$http
									.showLoading(false)
									.post('Public/get/supplieraboutfor', {
										orgId: this.baseInfoForm.purchaseorgId,
										supplerId: this.baseInfoForm.supplierId,
									})
									.then(async (r) => {
										if (r.status === 200) {
											this.supplierList = r.data;
										}
									});
							}

							let tempSettleOrgName =
								this.statusForm.settlementOrgList.filter(
									(it) =>
										it.id ===
										this.baseInfoForm.purchaseorgId
								);
							this.addRow.settleOrgName =
								tempSettleOrgName[0].name;

							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;
							}
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
							} else {
								this.isEdit = true;
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							this.isPushDownOrg = req.data.isPushDown;
							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;
							}
							if (
								this.baseInfoForm.details[0].parentOrderType ===
								9
							) {
								this.isPushDownReturn = true;
							}
							if (
								this.baseInfoForm.fillType != null ||
								this.baseInfoForm.fillType != '' ||
								this.baseInfoForm.fillType != undefined
							) {
								this.baseInfoForm.fillType =
									this.baseInfoForm.fillType + '';
							}
							if (this.baseInfoForm.fillType == 'null') {
								this.baseInfoForm.fillType = '';
							}
							this.baseInfoForm.dataSources =
								this.baseInfoForm.dataSources + '';
							// if (this.baseInfoForm.exchangeTypeId) {
							//   this.baseInfoForm.exchangeTypeId = parseInt(this.baseInfoForm.exchangeTypeId)
							// }
							if (this.baseInfoForm.dataSources === 'null') {
								this.baseInfoForm.dataSources = '2';
							}
							// if(this.baseInfoForm.dataSources == 2){
							//   this.baseInfoForm.settleModeId = req.data.settleModeId
							// }
							this.statusForm.warehouse = await getStatusType(
								'SysConfig/GetWarehouseByOrg/',
								this.baseInfoForm.purchaseorgId
							); // 根据组织 获取仓库
							this.tempStoreWarehouse = JSON.parse(
								JSON.stringify(this.statusForm.warehouse)
							);
							await this.getMaterialCustomerDataAll();
							this.baseInfoForm.details.forEach((el, ind) => {
								this.baseInfoForm.details[ind].materialId =
									el.materialId;
								this.baseInfoForm.details[ind].specificationId =
									el.materialId;

								let tempUnitName = this.statusForm.units.filter(
									(it) => it.id == el.unitId
								);
								if (tempUnitName.length > 0) {
									this.baseInfoForm.details[ind].unitName =
										tempUnitName[0].name;
								}
								let tempCustomerName =
									this.statusForm.customers.filter(
										(it) => it.id == el.customerId
									);
								if (tempCustomerName.length > 0) {
									this.baseInfoForm.details[
										ind
									].customerName = tempCustomerName[0].name;
								}
								this.baseInfoForm.details[ind].customerStockId =
									el.customerStockList[0].id;
								this.baseInfoForm.details[
									ind
								].customerStockName =
									el.customerStockList[0].name;
								let tempSettleOrgName =
									this.statusForm.settlementOrgList.filter(
										(it) =>
											it.id ===
											this.baseInfoForm.details[ind]
												.settleOrgId
									);
								if (tempSettleOrgName.length > 0) {
									this.baseInfoForm.details[
										ind
									].settleOrgName = tempSettleOrgName[0].name;
								}

								this.baseInfoForm.details[
									ind
								].isDisabled = false;
								let rowObject =
									this.statusForm.warehouse.filter(
										(it) => it.id === el.soStock
									);
								this.baseInfoForm.details[ind].isCusHouse =
									rowObject.length > 0
										? !rowObject[0].customerWarehouseTag
										: true;

								if (this.baseInfoForm.details[ind].giveAway) {
									this.baseInfoForm.details[
										ind
									].isDisabled = true;
									this.baseInfoForm.details[ind].taxPrice = 0;
								}

								this.isCountPriceComMethods(
									this.baseInfoForm.details[ind].qty,
									ind,
									'qty'
								);
							});
							if (this.$route.query.type === 'copy') {
								this.detailBtn = [];
								this.statusForm.setlementDifferences =
									await getStatusType(
										'SysConfig/GetDcurrency'
									); // 结算币别
								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.btnType = purchaseBtnAdd;
								this.baseInfoForm = purCopyOrderClearData(
									this.baseInfoForm
								);
								this.baseInfoForm.details.forEach(
									(element, ind) => {
										if (
											this.baseInfoForm.details[ind]
												.unitId
										) {
											console.log(
												this.baseInfoForm.details,
												'==============this.baseInfoForm.details=========='
											);
											let result =
												purGetPrecisionNumberFrist(
													this.salePrecisionNumber,
													this.isPrecision,
													this.unitData,
													ind,
													this.baseInfoForm.details[
														ind
													].unitId
												);
											this.isPrecision[ind] =
												result.isPrecision;
											this.salePrecisionNumber[ind] =
												result.salePrecisionNumber;
										}
										this.matterallCodelist[ind].forEach(
											(element) => {
												if (element.taxRateId) {
													this.baseInfoForm.details[
														ind
													].taxRate =
														element.taxRateNmae;
												} else {
													if (this.supplierList) {
														let tempList =
															this.statusForm.getTaxRateList.filter(
																(it) =>
																	it.id ===
																	this
																		.supplierList
																		.defaultTaxRate
															);
														if (
															tempList &&
															tempList.length > 0
														) {
															this.baseInfoForm.details[
																ind
															].taxRate =
																tempList[0].name;
														} else {
															this.baseInfoForm.details[
																ind
															].taxRate = 0;
														}
													} else {
														this.baseInfoForm.details[
															ind
														].taxRate = 0;
													}
												}
											}
										);
										if (
											this.baseInfoForm.details[ind]
												.giveAway
										) {
											this.baseInfoForm.details[
												ind
											].isDisabled = true;
											this.baseInfoForm.details[
												ind
											].taxPrice = 0;
										}
										this.baseInfoForm.details[
											ind
										].taxPrice = this.baseInfoForm.details[
											ind
										].taxPrice
											? Decimal(
													this.baseInfoForm.details[
														ind
													].taxPrice
											  ).toFixed(
													this.unitpriceAccuracy
											  ) * 1
											: '0';
										this.comUnitPriceNumber(
											this.baseInfoForm.details[ind].qty,
											ind,
											'qty',
											true,
											'temp'
										);
										this.isCount[ind] = 2;
										element =
											purCopyOrderInfoClearData(element);
										this.isCountPriceComMethods(
											element.discountRate,
											ind,
											'discountRate'
										);
									}
								);
								this.isOrder = true;
							}
							this.baseInfoForm.isPushDown
								? (this.detailBtn = ['add', 'copy'])
								: (this.detailBtn = []);

							// if (
							// 	res.data.documentStatus === 'a' ||
							// 	res.data.documentStatus == 'd'
							// ) {
							// 	return;
							// }
						}
						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.purchaseorgId
			);
			let _resultHouse = await this.getCustmerStoreAll(
				customerQuery,
				this.baseInfoForm.purchaseorgId
			);
			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 = purMaterialSkuSearch(
						this.baseInfoForm,
						ele,
						index
					);
				});
			});
		},
		// 获取所有客户仓库信息
		async getCustmerStoreAll(customerQuery, id) {
			if (customerQuery.length > 0) {
				return this.$http
					.post('SysConfig/GetCustomerStockList', {
						customerIds: customerQuery,
						orgId: id,
					})
					.then((res) => {
						if (res.status === 200) {
							return res.data;
						} else {
							return [];
						}
					});
			} else {
				return [];
			}
		},
		// 获取所有物料携带信息
		async matterCodeChangeAll(query, type, id) {
			return this.$http
				.post('SysConfig/GetMaterialLikeList', {
					names: query,
					file: type,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data.reverse();
					} else {
						return [];
					}
				});
		},
		// 匹配物料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, details) {
			if (val && this.baseInfoForm.purchaseorgId) {
				if (val.indexOf(' ') == -1) {
					let reqMethodsKey = details ? details : 'Number';
					let matterDate = await this.backMaterSkuMethods(
						val,
						reqMethodsKey,
						this.baseInfoForm.purchaseorgId
					);
					this.matterallCodelist[ind] = matterDate;
					this.specificationalllist[ind] = matterDate;
					if (type === 'getDate') {
						if (this.baseInfoForm.details[ind] !== undefined) {
							this.matterallCodelist[ind].forEach((element) => {
								this.baseInfoForm = purMaterialSkuSearch(
									this.baseInfoForm,
									element,
									ind
								);
								if (!details) {
									this.baseInfoForm.details[ind].taxPrice =
										element.purchasePrice;
									this.isCountPriceComMethods(
										this.baseInfoForm.details[ind].taxPrice,
										ind,
										'taxPrice'
									);
								}
							});
						}
					}
				}
			}
		},
		// 下推确定
		sumitPushdown(id) {
			this.CXcheckVal = id;
			if (this.CXcheckVal) {
				let result = purPushDownSure(this.CXcheckVal);
				let pathName = result.pathName;
				let routerName = result.routerName;
				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),
									sjtag: Math.random() * 36,
								},
							});
							this.dialogxt = false;
						} else if (res.status === 99999) {
							this.dialogxt = false;
							this.$message.error({
								message: '当前单据已关闭，请重新选择再试',
								showClose: true,
							});
							this.$http
								.showLoading(false)
								.get('Purchase/get/' + this.baseInfoForm.id)
								.then((req) => {
									if (req.status === 200) {
										if (res.message.indexOf('|') != -1) {
											let tempList = res.message
												.split('|')
												.map(Number);
											this.baseInfoForm.details.forEach(
												(element, ind) => {
													if (
														tempList.indexOf(
															element.id
														) !== -1
													) {
														this.baseInfoForm.details[
															ind
														] = purPushDownRequest(
															this.baseInfoForm
																.details[ind],
															req,
															element
														);
													}
												}
											);
										} else {
											let tempNum = Number(res.message);
											this.baseInfoForm.details.forEach(
												(element, ind) => {
													if (
														tempNum === element.id
													) {
														this.baseInfoForm.details[
															ind
														] = purPushDownRequest(
															this.baseInfoForm
																.details[ind],
															req,
															element
														);
													}
												}
											);
										}
									}
								});
						}
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		// 确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let ary = [];
				let pathName = purSureUpDownSearch(this.CXcheckVal);
				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,
				});
			}
		},
		// 单据头统计
		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;
		},
		// 金额单价计算
		isCountPriceComMethods(val, ind, key) {
			let templateObject = countMethodsPur(
				this.baseInfoForm.details,
				val,
				ind,
				key,
				this.statusForm.getTaxRateList,
				this.baseInfoForm.exchangerate,
				this.unitpriceAccuracy,
				this.amountAccuracy
			);
			this.baseInfoForm.details = templateObject.details;
			this.baseInfoForm.billTaxAmount =
				templateObject.baseTaxaMount == ''
					? 0
					: templateObject.baseTaxaMount;
			this.baseInfoForm.billAmount =
				templateObject.baseAmount == '' ? 0 : templateObject.baseAmount;
			this.baseInfoForm.billAllAmount =
				templateObject.baseAllAmount == ''
					? 0
					: templateObject.baseAllAmount;
		},
		// 单位数量精度处理
		comUnitPriceNumber(value, recordAddIndex, key, isIf, temp, copy) {
			let tempList = this.unitData.filter(
				(it) =>
					it.id === this.baseInfoForm.details[recordAddIndex].unitId
			);

			if (temp && Array.isArray(tempList) && tempList.length) {
				tempList[0].precision == 0
					? (this.isPrecision[recordAddIndex] = true)
					: (this.isPrecision[recordAddIndex] = false);
				tempList[0].precision == 0
					? (this.salePrecisionNumber[recordAddIndex] = 0)
					: (this.salePrecisionNumber[recordAddIndex] =
							tempList[0].precision);
			}
			if (copy === 'copy') {
				if (tempList && tempList.length > 0) {
					tempList[0].roundoffType = 2;
				}
			}
			let result = countMethodsUnitNumber(
				tempList,
				value,
				this.baseInfoForm.details[recordAddIndex][key],
				this.isCount[recordAddIndex],
				this.salePrecisionNumber[recordAddIndex],
				isIf
			);
			this.baseInfoForm.details[recordAddIndex][key] = result.value;
			this.isCount[recordAddIndex] = result.isDefault;
		},
		// 获取客户仓库等信息
		getCustomerInfoCom(ind, type) {
			let query = {};
			query.customerId = this.baseInfoForm.details[ind].customerId
				? parseInt(this.baseInfoForm.details[ind].customerId)
				: 0;
			query.orgId = this.baseInfoForm.purchaseorgId
				? parseInt(this.baseInfoForm.purchaseorgId)
				: 0;
			query.stockId = this.baseInfoForm.details[ind].soStock
				? parseInt(this.baseInfoForm.details[ind].soStock)
				: 0;
			if (
				this.baseInfoForm.details[ind].customerId &&
				this.baseInfoForm.purchaseorgId &&
				this.baseInfoForm.details[ind].soStock
			) {
				this.$http
					.showLoading(false)
					.post('SysConfig/GetCustomerStock', query)
					.then((r) => {
						if (r.status == 200) {
							this.customeStockArrylist[ind] = r.data;
							if (type) {
								this.customeStockArrylist = splitJointList(
									this.baseInfoForm.details,
									this.customeStockArrylist,
									'customerStockList'
								);
								this.customeStockArrylist =
									this.customeStockArrylist.filter(Boolean);
							}
						}
					});
			}
		},
	},
	created: function () {
		this.Init();
		this.setApprovalFlowStatus();
	},
	watch: {
		'baseInfoForm.purchaseorgId': async function () {
			this.monitorOrg();
			this.baseInfoForm.localCurrId = getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.purchaseorgId
			);
			if (
				this.baseInfoForm.settleCurrId != null &&
				this.baseInfoForm.settleCurrId != '' &&
				this.baseInfoForm.settleCurrId != undefined
			) {
				let templateObj = await getTaxPrice(
					this.baseInfoForm.localCurrId,
					'SysConfig/GetRateInfo',
					this.baseInfoForm.settleCurrId
				);
				if (
					templateObj != '' &&
					templateObj != null &&
					templateObj != undefined
				) {
					this.baseInfoForm.exchangerate = templateObj.directRate
						? templateObj.directRate
						: '';
					this.baseInfoForm.exchangeTypeId =
						templateObj.issueInvoiceId
							? templateObj.issueInvoiceId
							: '';
				} else {
					this.baseInfoForm.exchangerate = '';
					this.baseInfoForm.exchangeTypeId = '';
				}
			}
			this.addRow.settleOrgId = this.baseInfoForm.purchaseorgId;
			this.baseInfoForm.details.forEach((el, ind) => {
				this.baseInfoForm.details[ind].settleOrgId =
					this.baseInfoForm.purchaseorgId;
			});
		},
		'baseInfoForm.documentStatus'() {
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增采购订单');
				this.btnType = purchaseBtnAdd;
			} else {
				this.$topNavTagRename('编辑采购订单');
				this.btnType = purchaseBtnEdit;
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/purchase/purchaseCommon.scss';
@import '@/assets/style/purchase/createPurchase.scss';
@import '@/assets/style/purchase/common.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
