<template>
	<div>
		<!-- 	 -->
		<transition name="bounce">
			<examineTop
				v-if="isExmaineTop === 2"
				:radios="radios"
				@handleBtns="handleBtns"
				@handleOpen="handleOpen"
				:isexamineBtns="isexamineBtns"
			/>
			<!-- 	:isexamineBtns="isexamineBtns" -->
		</transition>
	</div>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="order-create-container order-mc-bg main-container"
	>
		<div class="order-create-btn-group">
			<template v-if="isExmaineTop !== 2">
				<toolBtn
					:btnType="btnType"
					:isDisable="isDisable"
					@actionhandel="actionhandel"
					:isExmaineTop="isShow"
				></toolBtn>
			</template>
		</div>
		<div class="order-create-base-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				v-if="baseInfoForm.documentStatus === 'c'"
			/>
			<el-tabs
				style="margin-bottom: 8px"
				type="border-card"
				v-loading="isLoading"
			>
				<el-tab-pane label="基本信息">
					<div class="base-info-form-box">
						<el-form :model="baseInfoForm" label-width="80px">
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<div class="order-number-bx item-bt-s">
											<el-form-item
												class="Iisshow"
												label="退货单号"
											>
												<el-input
													:disabled="isEdit"
													:maxlength="100"
													@input="
														saleRexgu(
															baseInfoForm.billNo,
															'billNo'
														)
													"
													placeholder="(保存时自动生成)"
													v-model="
														baseInfoForm.billNo
													"
												></el-input>
												<div
													:data-clipboard-text="
														baseInfoForm.billNo
													"
													@click="copy"
													class="copyBtn"
												>
													<i
														class="el-icon-document-copy"
													/>
												</div>
											</el-form-item>
										</div>
										<el-form-item
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												placeholder="请选择单据状态"
												v-model="
													baseInfoForm.documentStatus
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.documentStatus"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s item-date"
											label="退回日期"
										>
											<el-date-picker
												:disabled="isEdit"
												@change="
													purchaseCom(
														baseInfoForm.date,
														'date'
													)
												"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
												type="date"
												v-model="
													baseInfoForm.returnDate
												"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="销售组织"
										>
											<el-select
												:disabled="isEdit || isPushDown"
												@change="
													purchaseCom(
														baseInfoForm.saleOrgId,
														'saleOrgId'
													)
												"
												class="click-cell-ipt-issue"
												filterable
												placeholder="请选择销售组织"
												v-model="baseInfoForm.saleOrgId"
											>
												<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.saleOrg"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="退货客户"
										>
											<el-select
												:disabled="isEdit || isPushDown"
												@change="clearCustmerStore"
												class="f_12"
												filterable
												placeholder="请输入关键词"
												remote
												reserve-keyword
												v-model="baseInfoForm.retcustId"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:value="item.id"
													@click="
														purchaseCom(
															item.id,
															'retcustId'
														)
													"
													v-for="item in statusForm.custList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="销售部门"
										>
											<el-cascader
												:disabled="isEdit"
												:options="statusForm.saleParts"
												:props="optionProps"
												:show-all-levels="false"
												@change="
													purchaseCom(
														baseInfoForm.saleDeptId,
														'saleDeptId',
														'type'
													)
												"
												class="click-cell-ipt-c"
												clearable
												placeholder="请选择部门"
												ref="cascader"
												style="font-size: 12px"
												v-model="
													baseInfoForm.saleDeptId
												"
											></el-cascader>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="销售员"
										>
											<el-select
												:disabled="isEdit"
												filterable
												placeholder="请选择销售员"
												remote
												reserve-keyword
												v-model="
													baseInfoForm.salesmanId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.salesmanId,
															'salesmanId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.salePerson"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="仓管员"
										>
											<el-select
												:disabled="isEdit"
												filterable
												placeholder="请选择仓管员"
												remote
												reserve-keyword
												v-model="
													baseInfoForm.stockStaff
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.stockStaff,
															'stockStaff'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.followPersons"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算组织"
										>
											<el-select
												:disabled="isEdit"
												class="click-cell-ipt-issue"
												placeholder="请选择结算组织"
												v-model="baseInfoForm.settleOrg"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.settleOrg,
															'settleOrg'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.settlementOrgList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算币别"
										>
											<el-select
												:disabled="isEdit || isPushDown"
												@change="settlecurrMethods"
												class="click-cell-ipt-issue"
												placeholder="请选择结算币别"
												v-model="
													baseInfoForm.settlecurrId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.settlecurrId,
															'settlecurrId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.setlementDifferences"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算方式"
										>
											<el-select
												:disabled="isEdit"
												class="click-cell-ipt-issue"
												placeholder="请选择结算方式"
												v-model="
													baseInfoForm.settlemodeId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.settlemodeId,
															'settlemodeId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.setlementMethod"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="收款条件"
										>
											<el-select
												:disabled="isEdit"
												class="click-cell-ipt-issue"
												placeholder="请选择收款条件"
												v-model="
													baseInfoForm.recconditionId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.recconditionId,
															'recconditionId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.reccondition"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s Iisshow"
											label="退货原因"
										>
											<el-input
												:disabled="isEdit"
												@input="
													purchaseCom(
														baseInfoForm.returnReason,
														'returnReason'
													)
												"
												placeholder=" "
												v-model="
													baseInfoForm.returnReason
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.returnReason
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s address-textarea"
											label="收货地址"
										>
											<el-input
												:autosize="{
													minRows: 3,
													maxRows: 3,
												}"
												:disabled="isEdit"
												@input="
													purchaseCom(
														baseInfoForm.receiveAddress,
														'receiveAddress'
													)
												"
												maxlength="50"
												placeholder=" "
												resize="none"
												type="textarea"
												v-model="
													baseInfoForm.receiveAddress
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="8"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<el-tab-pane label="操作记录">
					<div
						:style="{ height: '180px!important' }"
						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="
													baseInfoForm.createDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="最后修改人"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.modifyName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.modifyDate
												"
											></el-input>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="提交时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model="
													baseInfoForm.commitDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													:maxlength="50"
													class="item-bt-s"
													label="审核人"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model="
															baseInfoForm.checkName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model="
															baseInfoForm.checkDate
														"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="12"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<div class="order-create-tell-info">
			<div class="tell-info-row-title">
				<h3>明细信息</h3>
				<div class="long-line-bx">
					<div class="long-line"></div>
				</div>
			</div>
			<div class="tell-info-button-group">
				<DetailsOperation
					:detailBtn="detailBtn"
					:deviationSelectArr="selectRowIndexArr"
					:isEdit="isEdit"
					@copyCellcolumn="copyCellcolumn"
					@copyRow="bottomCopyRow"
					@deleteRow="selectDeleteRow"
					@insertObj="getInsertInfo"
				></DetailsOperation>
			</div>
			<div class="tell-info-table">
				<el-table
					:cell-style="disabledCellStyle"
					:data="baseInfoForm.details"
					:header-cell-class-name="mustAfter"
					:header-cell-style="headerBg"
					:max-height="tableHeight"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectAll"
					border
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
					v-loading="isLoading"
				>
					<el-table-column
						align="center"
						fixed
						type="selection"
						width="40"
					/>
					<el-table-column
						label="销售订单号"
						prop="parentOrderBillNo"
						width="187"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>销售订单号
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isParentOrderBillNo">{{
								scope.row.parentOrderBillNo
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isParentOrderBillNo"
							>
								<input
									:disabled="isEdit"
									autocomplete="off"
									:id="'parentOrderBillNo' + scope.$index"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'parentOrderBillNo'
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									v-model.lazy="scope.row.parentOrderBillNo"
								/>
								<!-- <div class="copyBtn copyBtn1" :data-clipboard-text="scope.row.parentOrderBillNo" @click="copy">
                  <i class="el-icon-document-copy" />
                </div>-->
							</div>
						</template>
					</el-table-column>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'materialId')" -->
					<el-table-column
						align="left"
						label="物料编码"
						prop="materialId"
						width="187"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope" class="matter-code-box">
							<span v-if="!scope.row.isMaterialId">{{
								scope.row.materialNumber
							}}</span>
							<el-select
								:disabled="isEdit || isPushDown"
								:id="'materialId' + scope.$index"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											scope.$index,
											'materialId'
										);
									}
								"
								@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
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:key="item.id + item.number"
									:label="item.number"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'materialId',
											scope.row,
											scope.column
										)
									"
									v-for="item in matterallCodelist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<!-- @paste="pasteExcel($event,scope.$index,scope,'specificationId')" -->
					<el-table-column
						align="left"
						id="sku"
						label="规格型号(SKU)"
						prop="specificationId"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>规格型号(SKU)
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSpecificationId">{{
								scope.row.specification
							}}</span>
							<el-select
								:disabled="isEdit || isPushDown"
								:id="'specificationId' + scope.$index"
								:remote-method="
									(query) => {
										skuCodeChange(
											query,
											scope.$index,
											'specification'
										);
									}
								"
								@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
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:key="item.id + item.specifications"
									:label="item.specifications"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'specificationId',
											scope.row,
											scope.column
										)
									"
									v-for="item in specificationalllist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料名称"
						prop="matterName"
						width="150"
					>
						<template #default="scope">
							<span>{{ scope.row.matterName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="库存单位"
						prop="unitName"
						width="81"
					>
						<template #default="scope">
							<span>{{ scope.row.unitName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="实退数量"
						prop="realQty"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>实退数量
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isRealQty">{{
								scope.row.realQty
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isRealQty"
							>
								<input
									:disabled="isEdit"
									:id="'realQty' + scope.$index"
									:maxlength="19"
									@blur="
										detailsCom(
											scope.row.realQty,
											'realQty',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'realQty'
										)
									"
									class="el-input__inner click-cell-ipt t-r"
									autocomplete="off"
									placeholder
									v-model.lazy="scope.row.realQty"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="含税单价"
						prop="taxPrice"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>含税单价
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isTaxPrice">{{
								scope.row.taxPrice
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isTaxPrice"
							>
								<input
									:disabled="isEdit || scope.row.isDisabled"
									:id="'taxPrice' + scope.$index"
									:maxlength="20"
									@blur="
										detailsCom(
											scope.row.taxPrice,
											'taxPrice',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									@paste="
										pasteExcel(
											$event,
											scope.$index,
											scope,
											'taxPrice'
										)
									"
									class="el-input__inner click-cell-ipt t-r"
									autocomplete="off"
									placeholder
									v-model.lazy="scope.row.taxPrice"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="税率%"
						prop="taxRate"
						width="120"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>税率%
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isTaxRate">{{
								scope.row.taxRate
							}}</span>
							<el-select
								:clearable="false"
								:disabled="isEdit || scope.row.isDisabled"
								:id="'taxRate' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'taxRate'
									)
								"
								class="click-cell-ipt t-r"
								placeholder="请选择"
								v-if="scope.row.isTaxRate"
								v-model="scope.row.taxRate"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:value="item.name"
									@click="
										detailsCom(
											item.name,
											'taxRate',
											scope.row,
											scope.column
										)
									"
									v-for="item in statusForm.taxRates"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="单价"
						prop="price"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.price }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="价税合计"
						prop="allAmount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.allAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="价税合计(本位币)"
						prop="allAmountLc"
						width="121"
					>
						<template #default="scope">
							<span>{{ scope.row.allAmountLc }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						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"
								v-if="scope.row.isDiscountRate"
							>
								<input
									:disabled="isEdit || scope.row.isDisabled"
									:id="'discountRate' + scope.$index"
									:maxlength="12"
									@blur="
										detailsCom(
											scope.row.discountRate,
											'discountRate',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									autocomplete="off"
									v-model.lazy="scope.row.discountRate"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						:disabled="true"
						align="right"
						label="折扣额"
						prop="disCount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.disCount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						:disabled="true"
						align="right"
						label="税额"
						prop="taxAmount"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.taxAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						:disabled="true"
						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="退货类型"
						prop="returnType"
						width="96"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>退货类型
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isReturnType">{{
								scope.row.returnTypeName
							}}</span>
							<el-select
								:clearable="false"
								:disabled="isEdit"
								:id="'returnType' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'returnType'
									)
								"
								class="click-cell-ipt"
								placeholder="请选择类型"
								v-if="scope.row.isReturnType"
								v-model="scope.row.returnType"
							>
								<el-option
									:key="key + index"
									:label="value"
									:value="key"
									@click="
										detailsCom(
											scope.row.returnType,
											'returnType',
											scope.row,
											scope.column,
											'',
											'',
											'',
											value
										)
									"
									v-for="(
										value, key, index
									) in statusForm.returnStockType"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="供应组织"
						prop="paezOrgName"
						width="172"
					>
						<template #default="scope">
							<span>{{ scope.row.paezOrgName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="默认供应商"
						prop="defaultSupplierName"
						width="172"
					>
						<template #default="scope">
							<span>{{ scope.row.defaultSupplierName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						:required="true"
						align="left"
						label="仓库"
						prop="stockId"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isStockId">{{
								scope.row.stockName
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'stockId' + scope.$index"
								@change="
									clearCustmerStore(scope.$index, 'inner')
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'stockId'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isStockId"
								v-model="scope.row.stockId"
							>
								<el-option
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'stockId',
											scope.row,
											scope.column,
											item.disabled,
											item.customerWarehouseTag,
											'',
											item.name
										)
									"
									v-for="item in statusForm.warehouse"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户仓库"
						prop="customerStock"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isCustomerStock">{{
								scope.row.customerStockName
							}}</span>
							<el-select
								:disabled="isEdit || scope.row.isCusHouse"
								:id="'customerStock' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerStock'
									)
								"
								class="click-cell-ipt"
								placeholder="请选择"
								v-if="scope.row.isCustomerStock"
								v-model="scope.row.customerStock"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'customerStock',
											scope.row,
											scope.column,
											item.disabled,
											'',
											'',
											item.name
										)
									"
									v-for="item in customeStockArrylist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="是否211"
						prop="is211"
						width="81"
					>
						<template #default="scope">
							<span>{{ scope.row.is211 ? '是' : '否' }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="是否赠品"
						prop="isFree"
						width="81"
					>
						<template #default="scope">
							<el-checkbox
								:disabled="isEdit || isPushDown"
								@change="
									isCheckBox(
										scope.row.isFree,
										scope.row.index,
										'isFree',
										scope.row,
										scope.column,
										'taxPrice'
									)
								"
								v-model="scope.row.isFree"
							></el-checkbox>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="线上订单号"
						prop="onlineOrderNo"
						width="172"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>线上订单号
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isOnlineOrderNo">{{
								scope.row.onlineOrderNo
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
							>
								<input
									:disabled="isEdit"
									:id="'onlineOrderNo' + scope.$index"
									:maxlength="100"
									@blur="
										detailsCom(
											scope.row.onlineOrderNo,
											'onlineOrderNo',
											scope.row,
											scope.column,
											'',
											'',
											scope.$index
										)
									"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									autocomplete="off"
									v-if="scope.row.isOnlineOrderNo"
									v-model.lazy="scope.row.onlineOrderNo"
								/>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="备注"
						prop="remark"
						width="280"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isRemark">{{
								scope.row.remark
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
							>
								<input
									:disabled="isEdit"
									:id="'remark' + scope.$index"
									class="el-input__inner click-cell-ipt"
									placeholder="请输入"
									autocomplete="off"
									v-if="scope.row.isRemark"
									v-model.lazy="scope.row.remark"
								/>
							</div>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<!-- 选择下推单据 -->
		<el-dialog
			:destroy-on-close="true"
			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
			:destroy-on-close="true"
			: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 {
	srSearchOrder,
	srSurePushDown,
	srMaterialCarry,
	srInsertRow,
	srSaveSubmitBackData,
	onLineOrderRexgu,
	srDetailsMaterSpecSearh,
	srOrgChangeClearData,
	srMaterSpecSearch,
	srCopyInnerClearData,
	getObjectName,
	filterMaterialData,
} from '@/utils/takeMethods';
// import { getStaffListApiUser } from '@/utils/api.js';
import { Decimal } from 'decimal.js';
import {
	getStatusType,
	getNowTime,
	getBaseCurrency,
	getTaxPrice,
	getStatusTypeQuery,
	removeChildren,
	splitJointList,
} from '@/utils/pubulic.js';
import { returnCountMethods, countMethodsUnitNumber } from '@/utils/count.js';
import { orderCopy } from '@/utils/takeMethods';
import examineTop from '@/components/examineTop/index.vue';
import toolBtn from '@/components/public/toolBtn/toolBtn.vue';

import {
	getStaffListApiUser,
	approvalFlowTrackingCreate,
	approvalFlowTrackingGetby,
	approvalFlowTrackingUpdate,
	// getStaffListApiUser,
} from '@/utils/api.js';

import {
	returnBtnAdd,
	returnBtnEdit,
	rCustomSearch,
	rDefaultTableInfo,
	is211s,
	optionProps,
	storeObj,
} from '@/utils/variable.js';
export default {
	name: 'CreateRuturnOrder',
	components: {
		examineTop,
		toolBtn,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			radios: {},
			examineObj: {},
			isLoading: false,
			salePrecisionNumber: [],
			isPrecision: [],
			unitData: [],
			pushDownPrice: [],
			isCount: [],
			isLockPrice: true,
			isDisable: false,
			statusForm: JSON.parse(JSON.stringify(rCustomSearch)),
			backUpForm: {}, // 备份
			baseInfoForm: JSON.parse(JSON.stringify(rDefaultTableInfo)),
			addRow: {},
			storeObj: JSON.parse(JSON.stringify(storeObj)),
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			loading: false, // loding
			isSetlementDifference: true,
			rowCurr: [], // 明细 物料、SKU 当前
			selectRowIndexArr: [],
			btnType: JSON.parse(JSON.stringify(returnBtnAdd)), // 不需要的按钮
			currRow: 0, // 表格 编辑 当前行
			currColumn: '', // 表格 编辑 当前列
			selectRowIndex: 0, // 选择的行
			heightNum: 0, // 容器高度
			saleOrigin: '',
			salePart: '',
			setlementDifference: '',
			isEdit: true, // 是否显示
			isToolTop: true, // 隐藏顶部虚线
			isProhibit: true, // 操作记录禁用样式
			getCustomerNumList: [], // 获取客户列表
			multipleSelection: [], // 选择的行
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrdedetailIds: [], // 勾选的明细id集合
			pushDownList: [], // 下推集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			tableHeight: 0, // 表格高度
			saveIds: '', // 得到订单id
			orderId: '', // 订单id
			is211s: JSON.parse(JSON.stringify(is211s)),
			isOutCusHouse: false,
			isPushDown: false,
			unitpriceAccuracy: 10,
			amountAccuracy: 10,
			detailBtn: [],
			customeStockArrylist: [], // 客户仓库集合
			matterallCodelist: [], // 物料下拉数据
			specificationalllist: [], // 规格型号（sku）下拉数据
			isOrder: true,
			timer: null,
			recordIndex: '',

			tempStoreWarehouse: [],
		};
	},
	methods: {
		Init() {
			let vuexKey = [
				'taxRate',
				'rateType',
				'dcurrency',
				'customer',
				'settletype',
				'recondtion',
				'unitAll',
			];
			let setVuexData = [
				'setTaxRate',
				'setRateType',
				'setDcurrency',
				'setCustomer',
				'setSettletype',
				'setRecondtion',
				'setAllUnit',
			];
			let requestQueryUrl = [
				'SysConfig/GetTaxRate',
				'SysConfig/GetRateType',
				'SysConfig/GetDcurrency',
				'SysConfig/GetCustomer',
				'SysConfig/GetSettletype',
				'SysConfig/GetReccondition',
				'SysConfig/GetUnitAllProperty',
			];
			let resDataQuery = [
				'taxRates',
				'exchangeRateTypes',
				'setlementDifferences',
				'custList',
				'setlementMethod',
				'reccondition',
				'saleUnits',
			];
			vuexKey.forEach((ele, ind) => {
				if (this[vuexKey[ind]] && this[vuexKey[ind]].length > 0) {
					if (typeof resDataQuery[ind] == 'string') {
						this.statusForm[resDataQuery[ind]] = JSON.parse(
							JSON.stringify(this[vuexKey[ind]])
						);
					} else {
						resDataQuery[ind].forEach((ele, index) => {
							this.statusForm[resDataQuery[ind][index]] =
								JSON.parse(JSON.stringify(this[vuexKey[ind]]));
						});
					}
					if (vuexKey[ind] == 'unitAll') {
						this.unitData = this.statusForm[resDataQuery[ind]];
					}
				} else {
					this.$http.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.taxRates.forEach((element) => {
									element.name = Number(element.name);
								});
								this.setTaxRate(this.statusForm.taxRates);
							}
						}
					});
				}
			});
			// 获取人员接口
			if (this.getAllUserList && this.getAllUserList.length > 0) {
				this.statusForm.followPersons = this.getAllUserList;
				this.statusForm.salePerson = this.getAllUserList;
			} else {
				getStaffListApiUser().then((r) => {
					r.status == 200 ? this.setGetAllUserList(r.data) : false;
					r.status == 200
						? (this.statusForm.followPersons = r.data)
						: (this.statusForm.followPersons = []);
					r.status == 200
						? (this.statusForm.salePerson = r.data)
						: (this.statusForm.salePerson = []);
				});
			}
			// 枚举 - 订单类型、状态
			if (this.statusType && JSON.stringify(this.statusType) !== '{}') {
				this.statusForm.returnStockType = JSON.parse(
					JSON.stringify(this.statusType.returnStockType)
				);
				this.statusForm.documentStatus = JSON.parse(
					JSON.stringify(this.statusType.documentStatus)
				);
			} else {
				this.$http.get('ReturnStockOrder/GetStatus').then((req) => {
					if (req.status == 200) {
						this.setStatusType(req.data);
						this.statusForm.returnStockType =
							req.data.returnStockType;
						this.statusForm.documentStatus =
							req.data.documentStatus;
					}
				});
			}
			var windowHeight = document.documentElement.clientHeight;
			this.heightNum = windowHeight - 102;
			this.tableHeight = windowHeight - 480;
			this.baseInfoForm.returnDate = getNowTime();
			this.statusForm.saleOrg = 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 === 'add' ||
				this.$route.query.type === 'copy'
			) {
				// 进入页面的方式
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.saleOrgId = this.$store.state.org.orgId;
				this.isEdit = false;
				if (this.$route.query.type === 'copy') {
					this.getPurChaseDetails();
				}
			}
			if (
				this.$route.query.type == 'pushDown' &&
				this.$route.query.pushDownData
			) {
				// 下推进入
				this.isEdit = false;
				this.isPushDown = true;
				this.getPurChaseDetails(
					JSON.parse(
						decodeURIComponent(this.$route.query.pushDownData)
					)
				);
			}
			if (
				this.$route.query.type == 'details' &&
				this.$route.query.id &&
				this.$route.query.status
			) {
				this.getPurChaseDetails();
			}
		},
		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;
				}
				// console.log(
				// 	this.baseInfoForm.documentStatus,
				// 	'=========this.baseInfoForm.documentStatus='
				// );
				// if (this.baseInfoForm.documentStatus !== 'b') {
				// 	this.isExmaineTop = 3;
				// }
				this.isexamineBtns = false;
			} else {
				this.isexamineBtns = false;
				this.isExmaineTop = 3;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('ReturnStockOrder/GetInfo/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.baseInfoForm = req.data;
						// this.setApprovalFlowTrackingGetby(req.data);
						this.baseInfoForm.documentStatus =
							req.data.documentStatus;
						if (
							this.baseInfoForm.documentStatus === 'a' ||
							this.baseInfoForm.documentStatus === 'd'
						) {
							this.isEdit = false;
						}
						this.setExamine(r);
					}
				});
		},

		handleSubmit(data) {
			this.isexamineBtns = true;
			this.$http
				.post(approvalFlowTrackingUpdate, data)
				.then((res) => {
					if (res.status === 200) {
						this.$message.success({
							message: '操作成功!',
							showClose: true,
						});
					}
					this.handleDetails(res);
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				})
				.finally(() => {
					// this.isexamineBtns = false;
				});
		},
		//顶部按钮点击
		handleBtns(vals) {
			if (vals.type === 'out') {
				this.$router.go(-1);
			} else {
				let data = {
					approvalDetailsId: this.examineObj.approvalDetailsId,
					approvalOrderType: this.examineObj.sendOrderType,
					orderId: this.examineObj.sendOrderId,
					orgId: this.baseInfoForm.saleOrgId,
					deptId: this.baseInfoForm.saleDeptId || 0,
					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;
			}
			console.log('走到了这里？？？？？？？？？？？');
			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.saleDeptId || 0,
				approvalOrderType: 3,
				orgId: data.saleOrgId,
			};
			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(data) {
		// 	let _this = this;
		// 	let obj = {
		// 		sendOrderId: data.id,
		// 		deptId: data.saleDeptId || 0,
		// 		sendId: this.userId,
		// 		sendOrderType: 3,
		// 		sendOrderBillNo: data.billNo,
		// 		orgId: data.saleorgId,
		// 	};
		// 	this.$http
		// 		.post(approvalFlowTrackingCreate, obj)
		// 		.then((res) => {
		// 			this.setExamine(res);
		// 		})
		// 		.catch((err) => {
		// 			if (err) {
		// 				this.isExmaineTop = 3;
		// 			}
		// 		});
		// },

		// 切换客户或仓库清空客户仓库
		clearCustmerStore(index, inner) {
			if (inner) {
				this.baseInfoForm.details[index].customerStockName = '';
				this.baseInfoForm.details[index].customerStock = '';
			} else {
				this.baseInfoForm.details.forEach((item) => {
					item.customerStockName = '';
					item.customerStock = '';
				});
			}
		},
		// 清0
		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];
			}
		},
		//复制
		copy() {
			var clipboard = new this.$clipboard('.copyBtn');
			clipboard.on('success', () => {
				this.$message.success({ message: '复制成功', showClose: true });
				clipboard.destroy();
			});
			clipboard.on('error', () => {
				this.$message.error({ message: '复制失败', showClose: true });
				clipboard.destroy();
			});
		},
		saleRexgu(val, key) {
			if (key === 'billNo') {
				if (val) {
					this.baseInfoForm.billNo = val
						.toString()
						.replace(/[^A-Za-z0-9\\-]/g, '');
				}
			}
		},
		async monitorOrg() {
			let saleDeptArr = await getStatusType(
				'SysConfig/GetDept/',
				this.baseInfoForm.saleOrgId,
				'post'
			); // 根据组织 获取部门
			this.statusForm.saleParts = removeChildren(saleDeptArr);
			if (this.$route.query.type === 'add') {
				this.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.saleOrgId
				); // 根据组织 获取仓库
				this.tempStoreWarehouse = JSON.parse(
					JSON.stringify(this.statusForm.warehouse)
				);
			}
		},
		async monitorCustomer(id) {
			// 根据客户 获取相关信息
			let customerInfo = await getStatusTypeQuery(
				'SysConfig/GetCustomerInfoById/',
				id,
				'post',
				{
					cusId: id,
					orgId: this.baseInfoForm.saleOrgId,
				}
			);
			this.baseInfoForm.recconditionId =
				(await customerInfo[0].reccondition) == null ||
				customerInfo[0].reccondition == 0
					? ''
					: customerInfo[0].reccondition; // 收款条件
			this.baseInfoForm.settlemodeId =
				(await customerInfo[0].settlemode) == null ||
				customerInfo[0].settlemode == 0
					? ''
					: customerInfo[0].settlemode; // 结算方式
			this.baseInfoForm.settlecurrId =
				(await customerInfo[0].settlecurr) == null ||
				customerInfo[0].settlecurr == 0
					? ''
					: customerInfo[0].settlecurr; // 结算币别
			this.baseInfoForm.saleDeptId =
				(await customerInfo[0].sellDept) == null
					? ''
					: customerInfo[0].sellDept; // 销售部门
			this.baseInfoForm.salesmanId =
				(await customerInfo[0].sellPerson) == null
					? ''
					: customerInfo[0].sellPerson; // 销售员
			this.baseInfoForm.stockStaff =
				(await customerInfo[0].salesMan) == null
					? ''
					: customerInfo[0].salesMan; // 仓管员
			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;
			}
			let localCurrId = await getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.saleOrgId
			); // 获取本位币
			let exchangeRate = await getTaxPrice(
				localCurrId,
				'SysConfig/GetRate',
				this.baseInfoForm.settlecurrId
			); // 通过本位币 结算币别 获取汇率
			this.baseInfoForm.details.forEach(async (el, ind) => {
				this.takeCountMethods(ind, 'taxPrice', exchangeRate);
			});
		},
		async monitorCustHouse(val, ind, type, init) {
			if (type) {
				this.baseInfoForm.details.forEach((el, index) => {
					if (
						this.baseInfoForm.retcustId &&
						this.baseInfoForm.details[index].stockId
					) {
						this.isOutCusHouse = true;
					} else {
						this.isOutCusHouse = false;
					}
				});
				let query = {};
				query.customerId = this.baseInfoForm.retcustId
					? parseInt(this.baseInfoForm.retcustId)
					: 0;
				query.orgId = this.baseInfoForm.saleOrgId
					? parseInt(this.baseInfoForm.saleOrgId)
					: 0;
				this.$http
					.showLoading(false)
					.post('SysConfig/GetCustomerStock', query)
					.then((r) => {
						if (r.status == 200) {
							this.baseInfoForm.details.forEach(
								(element, index) => {
									this.customeStockArrylist[index] = r.data;
									if (init == 'init') {
										this.customeStockArrylist =
											splitJointList(
												this.baseInfoForm.details,
												this.customeStockArrylist,
												'customerStockList'
											);
									}
								}
							);
						}
					});
			} else {
				if (
					this.baseInfoForm.retcustId &&
					this.baseInfoForm.details[ind].stockId
				) {
					this.isOutCusHouse = true;
				} else {
					this.isOutCusHouse = false;
				}
				let query = {};
				query.customerId = this.baseInfoForm.retcustId
					? parseInt(this.baseInfoForm.retcustId)
					: 0;
				query.orgId = this.baseInfoForm.saleOrgId
					? parseInt(this.baseInfoForm.saleOrgId)
					: 0;
				query.stockId = this.baseInfoForm.details[ind].stockId
					? parseInt(this.baseInfoForm.details[ind].stockId)
					: 0;
				this.$http
					.showLoading(false)
					.post('SysConfig/GetCustomerStock', query)
					.then((r) => {
						if (r.status == 200) {
							this.customeStockArrylist[ind] = r.data;
							if (init == 'init') {
								this.customeStockArrylist = splitJointList(
									this.baseInfoForm.details,
									this.customeStockArrylist,
									'customerStockList'
								);
							}
						}
					});
			}
		},
		async getPurChaseDetails(res) {
			if (res) {
				this.isLoading = true;
				this.baseInfoForm = res;
				this.baseInfoForm.documentStatus = 'a';
				if (this.baseInfoForm.isPushDown) {
					this.detailBtn = ['add', 'copy'];
				}
				this.baseInfoForm.details.forEach((el, ind) => {
					this.pushDownPrice[ind] = el.taxPrice;
				});
				if (this.baseInfoForm.settlecurrId) {
					await this.$http
						.get('SysConfig/GetDcurrency')
						.then(async (r) => {
							if (r.status === 200) {
								this.statusForm.setlementDifferences =
									await r.data;
								let content =
									this.statusForm.setlementDifferences.filter(
										(it) =>
											it.id ===
											this.baseInfoForm.settlecurrId
									);
								if (content.length !== 0) {
									this.unitpriceAccuracy =
										content[0].unitpriceAccuracy;
									this.amountAccuracy =
										content[0].amountAccuracy;
								}
							}
						});
				}
				this.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.saleOrgId
				); // 根据组织 获取仓库
				this.tempStoreWarehouse = JSON.parse(
					JSON.stringify(this.statusForm.warehouse)
				);
				await this.getMaterialCustomerDataAll('copy');
				let localCurrId = getBaseCurrency(
					this.orgIdArr,
					this.baseInfoForm.saleOrgId
				); // 获取本位币
				let exchangeRate = await getTaxPrice(
					localCurrId,
					'SysConfig/GetRate',
					this.baseInfoForm.settlecurrId
				); // 通过本位币 结算币别 获取汇率
				await this.baseInfoForm.details.forEach(async (el, ind) => {
					this.getUnitNumberCountCom(
						ind,
						this.baseInfoForm.details[ind].realQty.toString(),
						this.baseInfoForm.details[ind].realQty.toString(),
						false,
						'realQty'
					);
					// this.matterCodeChange(el.materialNumber, ind, 'getDate')
					this.baseInfoForm.details[ind].materialId = el.materialId;
					this.baseInfoForm.details[ind].specificationId =
						el.materialId;
					this.baseInfoForm.details[ind].isDisabled = false;
					this.baseInfoForm.details[ind].isCusHouse = false;
					this.baseInfoForm.details[ind].realQty = this.baseInfoForm
						.details[ind].realQty
						? this.baseInfoForm.details[ind].realQty
						: '';
					this.baseInfoForm.details[ind].taxPrice = this.baseInfoForm
						.details[ind].taxPrice
						? this.baseInfoForm.details[ind].taxPrice
						: '';
					this.baseInfoForm.details[ind].onlineOrderNo = this
						.baseInfoForm.details[ind].onlineOrderNo
						? this.baseInfoForm.details[ind].onlineOrderNo
						: '';
					this.takeCountMethods(ind, 'discountRate', exchangeRate);
					let rowObject = this.statusForm.warehouse.filter(
						(it) => it.id === el.stockId
					);
					this.baseInfoForm.details[ind].stockName =
						rowObject[0].name;
					this.baseInfoForm.details[ind].isCusHouse =
						!rowObject[0].customerWarehouseTag;
				});
				if (!this.baseInfoForm.returnDate) {
					this.baseInfoForm.returnDate = getNowTime();
				}
				this.isLoading = false;
			} else {
				this.statusForm.settlementOrgList = this.orgIdArr;
				this.isLoading = true;
				// let isClone = this.$route.query.type == 'copy' ? true : false
				// + '/' + isClone
				this.$http
					.showLoading(false)
					.get('ReturnStockOrder/GetInfo/' + this.$route.query.id)
					.then(async (req) => {
						if (req.status == 200) {
							this.baseInfoForm.documentStatus = '';
							this.baseInfoForm = req.data;
							this.setApprovalFlowTrackingGetby(req.data);
							if (this.baseInfoForm.isPushDown) {
								this.detailBtn = ['add', 'copy'];
							}
							if (this.$route.query.type === 'copy') {
								let spliceList = [];
								this.baseInfoForm.details.forEach(
									(element, index) => {
										if (
											this.$route.query.detailsIds.indexOf(
												element.id.toString()
											) !== -1
										) {
											spliceList.push(
												this.baseInfoForm.details[index]
											);
										}
									}
								);
								this.baseInfoForm.details = spliceList;
							}
							this.isPushDown =
								this.$route.query.type === 'copy'
									? false
									: req.data.isPushDown;
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
							} else {
								this.isEdit = true;
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							this.statusForm.warehouse = await getStatusType(
								'SysConfig/GetWarehouseByOrg/',
								this.baseInfoForm.saleOrgId
							); // 根据组织 获取仓库
							this.tempStoreWarehouse = JSON.parse(
								JSON.stringify(this.statusForm.warehouse)
							);
							if (this.$route.query.type === 'copy') {
								await this.getMaterialCustomerDataAll('copy');
							} else {
								await this.getMaterialCustomerDataAll();
							}
							await this.baseInfoForm.details.forEach(
								async (el, ind) => {
									this.baseInfoForm.details[ind].materialId =
										el.materialId;
									this.baseInfoForm.details[
										ind
									].specificationId = el.materialId;
									this.baseInfoForm.details[ind].returnType =
										this.baseInfoForm.details[ind]
											.returnType + '';
									this.baseInfoForm.details[
										ind
									].isDisabled = false;
									let rowObject =
										this.statusForm.warehouse.filter(
											(it) => it.id === el.stockId
										);
									this.baseInfoForm.details[ind].isCusHouse =
										rowObject.length > 0
											? !rowObject[0].customerWarehouseTag
											: true;
									el.isParentOrderBillNo = false;
									el.isMaterialId = false;
									el.isSpecificationId = false;
									el.isRealQty = false;
									el.isTaxPrice = false;
									el.isTaxRate = false;
									el.isDiscountRate = false;
									el.isReturnType = false;
									el.isStockId = false;
									el.isCustomerStock = false;
									el.isOnlineOrderNo = false;
									el.isRemark = false;
								}
							);
							if (this.$route.query.type === 'copy') {
								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.detailBtn = [];
								this.baseInfoForm = srCopyInnerClearData(
									this.baseInfoForm,
									this.unitpriceAccuracy
								);
								let localCurrId = getBaseCurrency(
									this.orgIdArr,
									this.baseInfoForm.saleOrgId
								); // 获取本位币
								let exchangeRate = await getTaxPrice(
									localCurrId,
									'SysConfig/GetRate',
									this.baseInfoForm.settlecurrId
								); // 通过本位币 结算币别 获取汇率
								this.baseInfoForm.details.forEach(
									async (element, ind) => {
										this.getUnitNumberCountCom(
											ind,
											this.baseInfoForm.details[
												ind
											].realQty.toString(),
											this.baseInfoForm.details[
												ind
											].realQty.toString(),
											true,
											'realQty'
										);
										this.takeCountMethods(
											ind,
											'realQty',
											exchangeRate
										);
									}
								);
								this.isOrder = true;
							}
							this.customeStockArrylist = splitJointList(
								this.baseInfoForm.details,
								this.customeStockArrylist,
								'customerStockList'
							);
							this.isLoading = false;
						}
						if (!this.baseInfoForm.returnDate) {
							this.baseInfoForm.returnDate = getNowTime();
						}
					});
			}
		},
		// 详情 - 克隆 - 下推进入 一次性获取物料编码 + 客户仓库数据
		async getMaterialCustomerDataAll(copy) {
			let materQuery = this.baseInfoForm.details.map((it) => {
				return it.materialNumber;
			});
			let houseQuery = [];
			this.baseInfoForm.details.forEach((el) => {
				houseQuery.push(this.baseInfoForm.custId);
			});
			let _result = await this.matterCodeChangeAll(
				materQuery,
				'Number',
				this.baseInfoForm.saleOrgId
			);
			// let _resultHouse = await this.getCustmerStoreAll(houseQuery,this.baseInfoForm.saleOrgId)
			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;
				});
				// this.customeStockArrylist[index] = _resultHouse.filter(item => {return item.id === el.customerStock})
				this.matterallCodelist[index].forEach((ele) => {
					this.baseInfoForm.details[index] = srMaterSpecSearch(
						this.baseInfoForm.details[index],
						ele,
						copy
					);
				});
			});
		},
		// 获取所有客户仓库信息
		async getCustmerStoreAll(query, id) {
			return this.$http
				.post('SysConfig/GetCustomerStockList', {
					customerIds: query,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data;
					} else {
						return [];
					}
				});
		},
		// 获取所有物料携带信息
		async matterCodeChangeAll(query, type, id) {
			return this.$http
				.post('SysConfig/GetMaterialLikeList', {
					names: query,
					file: type,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data.reverse();
					} else {
						return [];
					}
				});
		},
		// 匹配物料sku的方法
		async backMaterSkuMethods(val, key, id) {
			return this.$http
				.showLoading(false)
				.post('SysConfig/GetMaterial', {
					name: val,
					file: key,
					orgId: id,
					isIncludeServerorCost: true,
				})
				.then((res) => {
					if (res.status === 200) {
						return res.data;
					} else {
						return [];
					}
				});
		},
		// 获取物料编码信息
		async matterCodeChange(val, ind, type) {
			if (val && this.baseInfoForm.saleOrgId) {
				if (val.indexOf(' ') == -1) {
					let matterDate = await this.backMaterSkuMethods(
						val,
						'Number',
						this.baseInfoForm.saleOrgId
					);
					this.matterallCodelist[ind] = matterDate;
					this.specificationalllist[ind] = matterDate;
					if (type === 'getDate') {
						if (this.baseInfoForm.details[ind] !== undefined) {
							this.matterallCodelist[ind].forEach((el) => {
								this.baseInfoForm.details[ind] =
									srMaterSpecSearch(
										this.baseInfoForm.details[ind],
										el,
										'copy'
									);
							});
						}
					}
				}
			}
		},
		// 获取型号SKU信息
		async skuCodeChange(val, ind, type) {
			if (val && this.baseInfoForm.saleOrgId) {
				if (val.indexOf(' ') == -1) {
					let matterDate = await this.backMaterSkuMethods(
						val,
						'Specifications',
						this.baseInfoForm.saleOrgId
					);
					this.matterallCodelist[ind] = matterDate;
					this.specificationalllist[ind] = matterDate;
					if (type === 'getDate') {
						if (this.baseInfoForm.details[ind] !== undefined) {
							this.matterallCodelist[ind].forEach((el) => {
								this.baseInfoForm.details[ind] =
									srMaterSpecSearch(
										this.baseInfoForm.details[ind],
										el,
										'copy'
									);
							});
						}
					}
				}
			}
		},
		// 是否211、赠品
		async isCheckBox(val, index, key, row, column, taxPrice) {
			this.baseInfoForm.details[index][key] = val;
			if (val) {
				this.baseInfoForm.details[index].isDisabled = true;
				this.baseInfoForm.details[index].taxPrice = '0';
				let localCurrId = getBaseCurrency(
					this.orgIdArr,
					this.baseInfoForm.saleOrgId
				); // 获取本位币
				let exchangeRate = await getTaxPrice(
					localCurrId,
					'SysConfig/GetRate',
					this.baseInfoForm.settlecurrId
				); // 通过本位币 结算币别 获取汇率
				this.takeCountMethods(row.index, taxPrice, exchangeRate);
				this.takeCountMethods(row.index, 'taxRate', exchangeRate);
			} else {
				this.baseInfoForm.details[index].isDisabled = false;
			}
		},
		// 单据头公共fun
		async purchaseCom(value, key, type) {
			if (value && key) {
				this.baseInfoForm[key] = value;
			} else {
				delete this.baseInfoForm[key];
			}
			if (key === 'saleOrgId') {
				this.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.saleOrgId
				); // 根据组织 获取仓库
				this.statusForm.warehouse = splitJointList(
					this.baseInfoForm.details,
					this.statusForm.warehouse,
					'stockList'
				);
				this.baseInfoForm = srOrgChangeClearData(
					this.baseInfoForm,
					this.addRow
				);
				this.tempStoreWarehouse = JSON.parse(
					JSON.stringify(this.statusForm.warehouse)
				);
			}
			if (key === 'retcustId') {
				this.baseInfoForm.settlemodeId = '';
				this.baseInfoForm.recconditionId = '';
				this.monitorCustomer(this.baseInfoForm.retcustId);
				this.baseInfoForm.details.forEach((el) => {
					el.customerStock = '';
					el.customerStockName = '';
				});
			}
			if (key === 'settlecurrId') {
				let content = this.statusForm.setlementDifferences.filter(
					(it) => it.id === this.baseInfoForm.settlecurrId
				);
				let localCurrId = await getBaseCurrency(
					this.orgIdArr,
					this.baseInfoForm.saleOrgId
				); // 获取本位币
				let exchangeRate = await getTaxPrice(
					localCurrId,
					'SysConfig/GetRate',
					this.baseInfoForm.settlecurrId
				); // 通过本位币 结算币别 获取汇率
				if (content.length !== 0) {
					this.unitpriceAccuracy = content[0].unitpriceAccuracy;
					this.amountAccuracy = content[0].amountAccuracy;
				}
				this.baseInfoForm.details.forEach((el, ind) => {
					this.takeCountMethods(ind, 'taxPrice', exchangeRate);
				});
			}
			if (type) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		async detailsCom(
			value,
			key,
			row,
			column,
			disable,
			isOpen,
			index,
			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.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);
			}
			// 详情公共fun
			if (!disable) {
				this.currRow = row.index;
				this.storeObj.storeVal = value;
				this.storeObj.storekey = key;
				this.storeObj.storeRow = row.index;
				this.storeObj.storeCol = column.index;
				if (key === 'materialId' || key === 'specificationId') {
					this.matterallCodelist[row.index].forEach((el) => {
						if (value === el.id) {
							let result = srDetailsMaterSpecSearh(
								this.baseInfoForm.details[row.index],
								el,
								this.unitData,
								this.isPrecision[row.index],
								this.salePrecisionNumber[row.index]
							);
							this.baseInfoForm.details[row.index] =
								result.details;
							this.isPrecision[row.index] = result.isPrecision;
							this.salePrecisionNumber[row.index] =
								result.salePrecisionNumber;
							this.baseInfoForm.details[row.index].realQty = '0';
							this.baseInfoForm.details[row.index].taxPrice = '0';
							this.takeCountMethods(
								row.index,
								'taxPrice',
								this.baseInfoForm.exchangerate
							);
							this.baseInfoForm.details[
								row.index
							].isMaterialId = false;
							this.baseInfoForm.details[
								row.index
							].isSpecificationId = false;
							document.getElementById(key + row.index).blur();
						}
					});
				} else if (key === 'realQty') {
					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].realQty) {
						if (this.isPrecision[row.index]) {
							if (
								this.baseInfoForm.details[row.index].realQty
									.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].realQty
									.toString()
									.replace(/[^\d^\\.]+/g, '')
									.replace('.', '$#$')
									.replace(/\./g, '')
									.replace('$#$', '.')
									.replace(eval(reg), '$1$2.$3');
						}
					}
					if (this.baseInfoForm.isPushDown) {
						if (
							parseInt(
								this.baseInfoForm.details[row.index].realQty
							) >
							parseInt(
								this.baseInfoForm.details[row.index]
									.parentOrderNumber
							)
						) {
							this.baseInfoForm.details[row.index].realQty =
								this.baseInfoForm.details[
									row.index
								].parentOrderNumber;
						}
					}
					if (!this.isCount[row.index]) {
						this.isCount[row.index] = 1;
					}
					if (
						this.baseInfoForm.details[row.index].realQty
							.toString()
							.indexOf('.') !== -1
					) {
						this.getUnitNumberCountCom(
							row.index,
							this.baseInfoForm.details[row.index].realQty,
							this.baseInfoForm.details[row.index].realQty,
							false,
							'realQty',
							'copy'
						);
					} else {
						this.isCount[row.index] = 2;
					}
					this.getLocalCurrRate(row, key);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				} else {
					this.baseInfoForm.details[row.index][key] = value;
				}
				key !== 'stockId' ? false : (row.isCusHouse = !isOpen),
					(this.isOutCusHouse = true);
				if (key === 'discountRate') {
					if (this.baseInfoForm.details[row.index][key] > 100) {
						this.baseInfoForm.details[row.index][key] = 100;
					} else {
						this.baseInfoForm.details[row.index][key] =
							this.baseInfoForm.details[row.index][key]
								.toString()
								.replace(/[^\d^\\.]+/g, '')
								.replace('.', '$#$')
								.replace(/\./g, '')
								.replace('$#$', '.')
								.replace(
									/^(\\-)*(\d+)\.(\d\d\d\d).*$/,
									'$1$2.$3'
								);
					}
					this.getLocalCurrRate(row, key);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'taxRate') {
					await this.getLocalCurrRate(row, 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] = 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.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)
								  );
					}
					this.getLocalCurrRate(row, key);
					this.baseInfoForm.details[row.index][key] =
						this.valueRemoveZero(row, key);
					this.storeObj.storeVal =
						this.baseInfoForm.details[row.index][key];
				}
				if (key === 'onlineOrderNo') {
					this.baseInfoForm.details[row.index][key] =
						onLineOrderRexgu(
							this.baseInfoForm.details[row.index][key]
						);
				}
				if (key === 'returnType') {
					this.baseInfoForm.details[row.index].returnType = value;
					this.baseInfoForm.details[row.index].returnTypeName = name;
				}
				if (key === 'stockId') {
					this.baseInfoForm.details[row.index].stockId = value;
					this.baseInfoForm.details[row.index].stockName = name;
					this.baseInfoForm.details[row.index].customerStock = '';
					this.baseInfoForm.details[row.index].customerStockName = '';
				}
				if (key === 'customerStock') {
					this.baseInfoForm.details[row.index].customerStock = value;
					this.baseInfoForm.details[row.index].customerStockName =
						name;
				}
			}
		},
		// 获取本位币 结算币别
		async getLocalCurrRate(row, key) {
			let localCurrId = getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.saleOrgId
			); // 获取本位币
			let exchangeRate = await getTaxPrice(
				localCurrId,
				'SysConfig/GetRate',
				this.baseInfoForm.settlecurrId
			); // 通过本位币 结算币别 获取汇率
			this.takeCountMethods(row.index, key, exchangeRate);
		},
		// 顶部公共按钮
		actionhandel(type) {
			this.isDisable = true;
			let ids = [];
			let details = [];
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			if (this.$route.query.id) {
				ids = [this.$route.query.id];
			}
			if (this.saveIds != '') {
				ids = [this.saveIds];
			}
			if (
				this.baseInfoForm.details &&
				this.baseInfoForm.details.length > 0
			) {
				details = [
					...new Set(
						this.multipleSelection
							.filter((item) => {
								if (item.id) {
									return item.id;
								}
							})
							.map((it) => {
								return it.id;
							})
					),
				];
			}
			this.orderId = ids;
			this.OrdedetailIds = details;
			if (type === 'push-down' && this.multipleSelection.length == 0) {
				this.$message.error({
					message: '请先选择要下推的明细行!',
					showClose: true,
				});
				return;
			}
			if (type === 'up-check' || type === 'down-check') {
				if (this.multipleSelection.length == 0) {
					this.$message.error({
						message: '请先选择要查询的明细行!',
						showClose: true,
					});
					return;
				}
			}
			if (type == 'add') {
				this.$router.push({
					path: '/sale/salemange/createReturnOrder',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			//审批流追踪
			if (type == 'exDetails') {
				if (
					!this.examineObj ||
					JSON.stringify(this.examineObj) === '{}'
				) {
					this.$message.error('该单据不存在审批流!');
					return false;
				}
				this.$router.push({
					path: '/examine/mange/examineFollow',
					query: { id: this.examineObj.id },
				});
			}
			if (type === 'save') {
				this.saveSubPageCom(type);
			}
			if (type === 'submit') {
				this.saveSubPageCom(type);
			}
			if (type === 'revoke') {
				this.revokePageData(ids);
			}
			if (type === 'audit') {
				this.unAuditPageDateCom(ids, type);
			}
			if (type === 'de-approval') {
				this.unAuditPageDateCom(ids, type);
			}
			if (type === 'push-down') {
				if (details.length > 0) {
					if (details.length <= 20) {
						if (this.baseInfoForm.documentStatus !== 'c') {
							this.$message.error({
								message:
									'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
								showClose: true,
							});
						} else {
							this.$http
								.get('ReturnStockOrder/GetOrderType')
								.then((r) => {
									if (r.status == 200) {
										this.pushDownList = [];
										for (const key in r.data.orderType) {
											this.pushDownList.push({
												id: key,
												value: r.data.orderType[key],
											});
										}
									}
								});
							this.dialogxt = true;
						}
					} else {
						this.$message.error({
							message: '最多一次性下推二十条明细',
							showClose: true,
						});
					}
				} else {
					this.$message.error({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能下推',
						showClose: true,
					});
				}
			}
			if (type === 'up-check' || type === 'down-check') {
				let pathName =
					type === 'up-check'
						? 'ReturnStockOrder/GetUpNumber'
						: 'ReturnStockOrder/GetDownNumber';
				this.$http.post(pathName, { ids: details }).then((res) => {
					if (res.data.length === 0 || res.data === []) {
						this.$message.error({
							message:
								type === 'up-check'
									? '没有可上查的单据!'
									: '没有可下查的单据!',
							showClose: true,
						});
					} else {
						this.upOrDownList = res.data;
						this.dialogCX = true;
						type === 'up-check'
							? (this.CXttile = '上查结果')
							: (this.CXttile = '下查结果');
						this.CXcheckVal =
							res.data && res.data.length === 1
								? res.data[0].orderType
								: null; //只有一个，就个默认值
					}
				});
			}
			if (type === 'delet') {
				this.deleteOrder(ids);
			}
		},
		// 删除
		deleteOrder(ids) {
			if (!isNaN(ids[0])) {
				this.$http
					.post('ReturnStockOrder/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.$message.error({
					message: '不能删除此单据!',
					showClose: true,
				});
			}
		},
		// 审核 - 反审
		unAuditPageDateCom(ids, type) {
			let innerIfKey = type === 'audit' ? 'b' : 'c';
			let pathName =
				type === 'audit'
					? 'ReturnStockOrder/Check'
					: 'ReturnStockOrder/NoCheck';
			let msg = type === 'audit' ? '审核成功!' : '反审成功!';
			let changeDocKey = type === 'audit' ? 'c' : 'd';
			let booleanKey = type === 'audit' ? true : false;
			let msgO =
				type === 'audit'
					? '只能审核处于审核中的单据!'
					: '只能反审核处于已审核的单据!';
			if (this.baseInfoForm.documentStatus == innerIfKey) {
				this.$http.post(pathName, { ids: ids }).then((r) => {
					if (r.status === 200) {
						if (r.data[0].isSuccess) {
							this.$message.success({
								message: msg,
								showClose: true,
							});
							this.baseInfoForm.documentStatus = changeDocKey;
							this.isEdit = booleanKey;
							//   if (booleanKey) {
							this.$http
								.get(
									'ReturnStockOrder/GetInfo/' +
										this.baseInfoForm.id
								)
								.then((req) => {
									if (req.status == 200) {
										this.baseInfoForm =
											srSaveSubmitBackData(
												this.baseInfoForm,
												req
											);
									}
								});
							//   }
						} else {
							this.$message.error({
								message: r.data[0].msg,
								showClose: true,
							});
						}
					}
				});
			} else {
				this.$message.error({ message: msgO, showClose: true });
			}
		},
		// 撤消
		revokePageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http
					.post('ReturnStockOrder/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.success({
								message: r.data[0].msg,
								showClose: true,
							});
						}
					});
			} else {
				this.$message.error({
					message: '只能撤销审核中的单据!',
					showClose: true,
				});
			}
		},
		// 保存 提交
		saveSubPageCom(type) {
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				let pathName =
					type == 'save'
						? 'ReturnStockOrder/Save'
						: 'ReturnStockOrder/Commit';
				filterMaterialData(this.baseInfoForm);
				this.$http.post(pathName, this.baseInfoForm).then((r) => {
					if (r.status == 200) {
						this.saveOrSubmitData(r);
						this.$message.success({
							message: type == 'save' ? '保存成功!' : '提交成功!',
							showClose: true,
						});
						type == 'submit'
							? (this.baseInfoForm.documentStatus = 'b')
							: (this.baseInfoForm.documentStatus = 'a');
						type == 'submit'
							? (this.isEdit = true)
							: (this.isEdit = false);
					}
				});
			} else {
				this.$message.error({
					message: '只能保存或提交创建或重新审核的单据!',
					showClose: true,
				});
			}
		},
		// 处理保存、提交返回数据
		saveOrSubmitData(r) {
			if (r.status == 200) {
				this.$http
					.showLoading(true)
					.get('ReturnStockOrder/GetInfo/' + r.data.id)
					.then((req) => {
						if (req.status == 200) {
							this.baseInfoForm = srSaveSubmitBackData(
								this.baseInfoForm,
								req
							);
							this.setExamine({
								status: r.status,
								data: r.data.tracking,
							});
							// this.setApprovalFlowTrackingCreate(r.data);
						}
					});
				this.baseInfoForm.billNo = r.data.billNo;
				this.baseInfoForm.id = r.data.id;
				this.saveIds = r.data.id;
				r.data.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].id = el.id;
					this.baseInfoForm.details[ind].fid = el.fid;
				});
				this.$refs.multipleTable.clearSelection();
				this.multipleSelection = [];
				this.selectRowIndexArr = [];
			}
		},
		// 居右
		headerBg({ rowIndex, columnIndex }) {
			let arr = [5, 6, 7, 8, 9, 10, 11, 12, 13];
			if (arr.indexOf(columnIndex) !== -1) {
				return `text-align:right!important;`;
			}
		},
		// 星星
		mustAfter(obj) {
			let arry = [2, 3, 6, 7, 8, 16, 19];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 插入的行
		getInsertInfo(data) {
			let result = srInsertRow(
				data,
				this.baseInfoForm,
				this.customeStockArrylist,
				this.matterallCodelist,
				this.specificationalllist,
				this.addRow
			);
			this.baseInfoForm.details = result.baseInfoForm.details;
			this.customeStockArrylist = result.customeStockArrylist;
			this.matterallCodelist = result.matterallCodelist;
			this.specificationalllist = result.specificationalllist;
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
			this.selectBlur();
			this.$nextTick(() => {
				this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
					this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
			});
		},
		// 向下复制行
		bottomCopyRow() {
			if (this.selectRowIndexArr.length > 0) {
				if (this.selectRowIndexArr.length == 1) {
					const tableArr = JSON.parse(
						JSON.stringify(
							this.baseInfoForm.details[this.selectRowIndex]
						)
					);
					let insertNum = this.selectRowIndex + 1;
					this.baseInfoForm.details.splice(insertNum, 0, tableArr);
					this.customeStockArrylist.splice(
						insertNum,
						0,
						this.customeStockArrylist[this.selectRowIndex]
					);
					this.matterallCodelist.splice(
						insertNum,
						0,
						this.matterallCodelist[this.selectRowIndex]
					);
					this.specificationalllist.splice(
						insertNum,
						0,
						this.specificationalllist[this.selectRowIndex]
					);
					this.salePrecisionNumber.splice(
						insertNum,
						0,
						this.salePrecisionNumber[this.selectRowIndex]
					);
					this.isPrecision.splice(
						insertNum,
						0,
						this.isPrecision[this.selectRowIndex]
					);
					this.isCount.splice(
						insertNum,
						0,
						this.isCount[this.selectRowIndex]
					);
					this.baseInfoForm.details[insertNum].id = 0;
					this.selectBlur();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
				} else {
					// 获取最后选择的行
					let lastIndex = -1;
					this.selectRowIndexArr.forEach((el) => {
						el.index > lastIndex ? (lastIndex = el.index) : false;
					});
					// 添加行
					this.selectRowIndexArr.forEach((el) => {
						el.id = 0;
						lastIndex = lastIndex + 1;
						this.baseInfoForm.details.splice(
							lastIndex,
							0,
							JSON.parse(JSON.stringify(el))
						);
						this.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.selectBlur();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
					// console.log('lastIndex',lastIndex)
				}
			} else {
				this.$message.error({
					message: '请选择一行或多行复制!',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow() {
			if (
				this.baseInfoForm.details.length > 1 &&
				this.baseInfoForm.details.length !=
					this.multipleSelection.length
			) {
				if (this.selectRowIndexArr != 0) {
					this.selectRowIndexArr.sort(function (a, b) {
						return a.index - b.index;
					});
					for (let i = 0; i < this.selectRowIndexArr.length; i++) {
						this.baseInfoForm.details.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.customeStockArrylist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.matterallCodelist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.specificationalllist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.salePrecisionNumber.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isPrecision.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isCount.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
					}
					this.baseInfoForm.details.forEach((el, ind) => {
						this.matterCodeChange(el.materialNumber, ind);
						// this.skuCodeChange(el.specification, ind)
						this.baseInfoForm.details[ind].materialId =
							el.materialId;
						this.baseInfoForm.details[ind].specificationId =
							el.materialId;
					});
					this.selectBlur();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
					this.recordIndex = '';
				} else {
					this.$message.error({
						message: '请先选择要删除的行',
						showClose: true,
					});
				}
			} else {
				this.$message.error({
					message: '表格不能为空!',
					showClose: true,
				});
			}
		},
		// 批量填充
		async copyCellcolumn() {
			let nextRow = this.storeObj.storeRow + 1;
			let storeKey = this.storeObj.storekey;
			let localCurrId = getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.saleOrgId
			);
			let exchangeRate = await getTaxPrice(
				localCurrId,
				'SysConfig/GetRate',
				this.baseInfoForm.settlecurrId
			);
			if (this.storeObj.storekey !== 'customerStock') {
				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.details[i] =
											srMaterialCarry(
												this.baseInfoForm.details[i],
												el
											);
										this.takeCountMethods(
											i,
											'taxPrice',
											this.baseInfoForm.exchangerate
										);
									}
								});
							} else if (
								key === 'taxRate' ||
								key === 'discountRate' ||
								key === 'taxPrice'
							) {
								this.baseInfoForm.details[i][key] =
									this.storeObj.storeVal;
								this.takeCountMethods(i, key, exchangeRate);
							} else if (key === 'realQty') {
								if (this.baseInfoForm.details[i].unitId) {
									this.getUnitNumberCountCom(
										i,
										this.storeObj.storeVal,
										this.storeObj.storeVal,
										true,
										'realQty',
										'copy'
									);
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
								this.takeCountMethods(i, key, exchangeRate);
							} else {
								if (key === 'stockId') {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
									let rowObject =
										this.statusForm.warehouse.filter(
											(it) =>
												it.id ===
												this.baseInfoForm.details[i]
													.stockId
										);
									this.baseInfoForm.details[i].stockName =
										rowObject[0].name;
									this.baseInfoForm.details[i].isCusHouse =
										!rowObject[0].customerWarehouseTag;
									this.baseInfoForm.details[i].customerStock =
										'';
									this.baseInfoForm.details[
										i
									].customerStockName = '';
								} else if (key === 'returnType') {
									this.baseInfoForm.details[i].returnType =
										this.storeObj.storeVal;
									this.baseInfoForm.details[
										i
									].returnTypeName = getObjectName(
										this.statusForm.returnStockType,
										this.storeObj.storeVal
									);
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
							}
						}
					}
				}
			} else {
				this.$message.error({
					message: '客户仓库无法批量填充，请手动选择！',
					showClose: true,
				});
			}
		},
		// 单选
		selectRow(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndex = selection[0].index;
				this.selectRowIndexArr = selection;
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 失焦处理
		selectBlur() {
			let _that = this;
			_that.baseInfoForm.details.forEach((el) => {
				el.isParentOrderBillNo = false;
				el.isMaterialId = false;
				el.isSpecificationId = false;
				el.isRealQty = false;
				el.isTaxPrice = false;
				el.isTaxRate = false;
				el.isDiscountRate = false;
				el.isReturnType = false;
				el.isStockId = false;
				el.isCustomerStock = false;
				el.isOnlineOrderNo = false;
				el.isRemark = false;
			});
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 全选
		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
				].isParentOrderBillNo = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isMaterialId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSpecificationId = false;
				_that.baseInfoForm.details[_that.recordIndex].isRealQty = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isTaxPrice = false;
				_that.baseInfoForm.details[_that.recordIndex].isTaxRate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDiscountRate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isReturnType = false;
				_that.baseInfoForm.details[_that.recordIndex].isStockId = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isCustomerStock = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isOnlineOrderNo = false;
				_that.baseInfoForm.details[_that.recordIndex].isRemark = false;
			}

			switch (column.label) {
				case '销售订单号':
					row.isParentOrderBillNo = true;
					_that.recordIndex = row.index;
					break;
				case '物料编码':
					row.isMaterialId = true;
					_that.recordIndex = row.index;
					break;
				case '规格型号(SKU)':
					row.isSpecificationId = true;
					_that.recordIndex = row.index;
					break;
				case '实退数量':
					row.isRealQty = 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.isDiscountRate = true;
					_that.recordIndex = row.index;
					break;
				case '退货类型':
					row.isReturnType = true;
					_that.recordIndex = row.index;
					break;
				case '仓库':
					row.isStockId = true;
					_that.recordIndex = row.index;
					break;
				case '客户仓库':
					row.isCustomerStock = true;
					_that.recordIndex = row.index;
					break;
				case '线上订单号':
					row.isOnlineOrderNo = true;
					_that.recordIndex = row.index;
					break;
				case '备注':
					row.isRemark = 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;
		},
		// 下推确定
		sumitPushdown(id) {
			if (id) {
				let pathName = '';
				let routerName = '';
				let result = srSurePushDown(this.pushdownVal);
				pathName = result.pathName;
				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,
								},
							});
						} else {
							this.dialogxt = false;
						}
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		//确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let result = srSearchOrder(this.CXcheckVal, this.upOrDownList);
				let pathName = result.pathName;
				let ary = result.ary;
				if (pathName) {
					this.dialogCX = false;
					this.$router.push({
						name: pathName,
						query: {
							detailsIds: JSON.stringify(ary[0].detailsIds),
							actionType:
								this.CXttile === '上查结果' ? 'up' : 'down',
							actionName: '销售退货单',
							OrderNoNames: JSON.stringify(ary[0].billNos),
						},
					});
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// count计算
		takeCountMethods(index, key, exchangeRate) {
			let templateObject = returnCountMethods(
				this.baseInfoForm.details,
				index,
				key,
				exchangeRate,
				this.unitpriceAccuracy,
				this.amountAccuracy
			);
			this.baseInfoForm.details = templateObject.details;
		},
		// 单位数量换算精度
		getUnitNumberCountCom(i, valueO, valueT, isInner, key, copy) {
			let tempList = this.unitData.filter(
				(it) => it.id === this.baseInfoForm.details[i].unitId
			);
			tempList[0].precision == 0
				? (this.isPrecision[i] = true)
				: (this.isPrecision[i] = false);
			tempList[0].precision == 0
				? (this.salePrecisionNumber[i] = 0)
				: (this.salePrecisionNumber[i] = tempList[0].precision);
			if (copy === 'copy') {
				if (tempList && tempList.length > 0) {
					tempList[0].roundoffType = 2;
				}
			}
			let result = countMethodsUnitNumber(
				tempList,
				valueO,
				valueT,
				this.isCount[i],
				this.salePrecisionNumber[i],
				isInner
			);
			this.baseInfoForm.details[i][key] = result.value;
			this.isCount[i] = result.isDefault;
		},
		// 结算币别
		settlecurrMethods() {
			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;
			}
		},
		// 复制粘贴
		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 === 'realQty' || 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.takeCountMethods(recordAddIndex, key);
								} else {
									this.$message.error({
										message:
											'粘贴内容有误,请重新选择复制内容!',
										showClose: true,
									});
									return;
								}
							}
							if (key === 'realQty') {
								if (
									this.baseInfoForm.details[recordAddIndex]
										.unitId
								) {
									this.getUnitNumberCountCom(
										recordAddIndex,
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										this.baseInfoForm.details[
											recordAddIndex
										][key],
										true,
										'realQty'
									);
								} else {
									this.baseInfoForm.details[
										recordAddIndex
									].realQty = Decimal(
										this.baseInfoForm.details[
											recordAddIndex
										].realQty
									).toFixed(0, Decimal.ROUND_HALF_UP);
								}
							}
							recordAddIndex++;
						} else if (
							key === 'materialId' ||
							key === 'specificationId'
						) {
							let key = scope.column.property;
							if (key === 'materialId') {
								this.matterCodeChange(
									rows[i],
									recordAddIndex,
									'getDate'
								);
							}
							if (key === 'specificationId') {
								this.skuCodeChange(
									rows[i],
									recordAddIndex,
									'getDate'
								);
							}
							recordAddIndex++;
						} else if (key === 'parentOrderBillNo') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								this.baseInfoForm.details[recordAddIndex][key] =
									rows[i];
							}
							recordAddIndex++;
						}
					}
				}
			}, 0);
		},
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setRecondtion: 'storeData/setRecondtion',
			setSettletype: 'storeData/setSettletype',
			setDcurrency: 'storeData/setDcurrency',
			setRateType: 'storeData/setRateType',
			setTaxRate: 'storeData/setTaxRate',
			setCustomer: 'storeData/setCustomer',
			setStatusType: 'storeData/setStatusType',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),
	},
	computed: {
		...mapState({
			userId: (state) => state.user.userInfo.staffId || null,
			orgIdArr: (state) => state.user.orgIdArr,
			unitAll: (state) => state.storeData.allUnit,
			recondtion: (state) => state.storeData.recondtion,
			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,
			statusType: (state) => state.storeData.statusType,
			getAllUserList: (state) => state.storeData.getAllUserList,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
			isShow: function () {
				return this.isExmaineTop;
			},
		}),
	},
	created: function () {
		this.Init();
		this.setApprovalFlowStatus();
	},
	watch: {
		'baseInfoForm.saleOrgId': function () {
			this.monitorOrg();
			this.$route.query.type !== 'details'
				? this.monitorCustHouse(1, 1, 'all', 'init')
				: false;
		},
		'baseInfoForm.retcustId': function () {
			this.monitorCustHouse(1, 1, 'all');
		},
		'baseInfoForm.documentStatus': function () {
			console.log(
				this.baseInfoForm.documentStatus,
				'=this.baseInfoForm.documentStatus='
			);
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增销售退货单');
				this.btnType = returnBtnAdd;
			} else {
				this.$topNavTagRename('编辑销售退货单');
				this.btnType = returnBtnEdit;
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/createReturnOrder.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
