<template>
	<div>
		<transition name="bounce">
			<examineTop
				v-if="isExmaineTop === 2"
				:radios="radios"
				@handleBtns="handleBtns"
				@handleOpen="handleOpen"
				:isexamineBtns="isexamineBtns"
			/>
			<!-- 	:isexamineBtns="isexamineBtns" -->
		</transition>
		<!-- 	:isexamineBtns="isexamineBtns" -->
	</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"
							:show-message="false"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<div class="order-number-bx item-bt-s">
											<el-form-item
												label="订单号"
												class="Iisshow"
											>
												<el-input
													:disabled="isEdit"
													:maxlength="100"
													@input="
														saleRexgu(
															baseInfoForm.billNo,
															'billNo'
														)
													"
													class="isEisShow"
													placeholder="(保存时自动生成)"
													v-model="
														baseInfoForm.billNo
													"
												></el-input>
												<div
													:data-clipboard-text="
														baseInfoForm.billNo
													"
													@click="saleOrderCopy"
													class="copyBtn"
												>
													<i
														class="el-icon-document-copy"
													/>
												</div>
											</el-form-item>
										</div>
										<el-form-item
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												placeholder="请选择单据状态"
												v-model="
													baseInfoForm.documentStatus
												"
											>
												<el-option
													:key="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"
											label="单据类型"
										>
											<el-select
												:disabled="isEdit"
												@change="
													billTypeCha(
														baseInfoForm.billtypeId
													)
												"
												filterable
												placeholder="请选择单据类型"
												v-model="
													baseInfoForm.billtypeId
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														purchaseCom(
															baseInfoForm.billtypeId,
															'billtypeId'
														)
													"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.salOrderType"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s item-date"
											label="下单日期"
										>
											<el-date-picker
												:disabled="isEdit"
												@change="
													purchaseCom(
														baseInfoForm.date,
														'date'
													)
												"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
												type="date"
												v-model="baseInfoForm.date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
									</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"
												class="click-cell-ipt-issue"
												placeholder="请选择销售组织"
												v-model="baseInfoForm.saleorgId"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															item.id,
															'saleorgId',
															'',
															item.name
														)
													"
													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"
												@change="custmerCha"
												class="f_12"
												filterable
												placeholder="请输入关键词"
												remote
												reserve-keyword
												v-model="baseInfoForm.custId"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															item.id,
															'custId'
														)
													"
													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
											:required="true"
											class="item-bt-s"
											label="销售员"
										>
											<el-select
												:disabled="isEdit"
												filterable
												placeholder="请选择销售员"
												remote
												reserve-keyword
												v-model="baseInfoForm.salerId"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															baseInfoForm.salerId,
															'salerId'
														)
													"
													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.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.followPersons"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="8">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="12">
												<el-form-item
													:maxlength="50"
													class="item-bt-s Iisshow"
													label="物流/快递"
												>
													<el-input
														:disabled="isEdit"
														@input="
															purchaseCom(
																baseInfoForm.logistics,
																'logistics'
															)
														"
														maxlength="50"
														placeholder="请输入关键词"
														v-model="
															baseInfoForm.logistics
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.logistics
														"
														@click="saleOrderCopy"
														class="copyBtn"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="物流单号"
												>
													<el-input
														:disabled="isEdit"
														@input="
															purchaseCom(
																baseInfoForm.logisticsNo,
																'logisticsNo'
															)
														"
														placeholder="请输入关键词"
														v-model="
															baseInfoForm.logisticsNo
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.logisticsNo
														"
														@click="saleOrderCopy"
														class="copyBtn"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="联系人"
												>
													<el-input
														:disabled="isEdit"
														@input="
															purchaseCom(
																baseInfoForm.linkMan,
																'linkMan'
															)
														"
														placeholder="请输入联系人"
														v-model="
															baseInfoForm.linkMan
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.linkMan
														"
														@click="saleOrderCopy"
														class="copyBtn"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="联系电话"
												>
													<el-input
														:disabled="isEdit"
														@input="
															purchaseCom(
																baseInfoForm.linkPhone,
																'linkPhone'
															)
														"
														placeholder="请输入联系电话"
														v-model="
															baseInfoForm.linkPhone
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.linkPhone
														"
														@click="saleOrderCopy"
														class="copyBtn"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
											</el-col>
											<el-col :span="12">
												<el-form-item
													:required="true"
													class="item-bt-s"
													label="收款条件"
												>
													<el-select
														:disabled="isEdit"
														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>
												<el-form-item
													class="item-bt-s"
													label="结算方式"
												>
													<el-select
														:disabled="isEdit"
														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"
														@change="
															settlecurrChange
														"
														placeholder="请选择结算币别"
														v-model="
															baseInfoForm.settlecurrId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															@click="
																purchaseCom(
																	baseInfoForm.settlecurrId,
																	'settlecurrId'
																)
															"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.setlementDifferences"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="本位币"
												>
													<el-select
														:disabled="true"
														placeholder="请选择结算币别"
														v-model="
															baseInfoForm.localcurrId
														"
													>
														<el-option
															:key="item.id"
															:label="item.name"
															:value="item.id"
															style="
																font-size: 12px;
															"
															v-for="item in statusForm.localCurrType"
														></el-option>
													</el-select>
												</el-form-item>
											</el-col>
										</el-row>
										<el-row
											:gutter="10"
											class="custom-address-row"
										>
											<el-col
												:span="24"
												class="custom-address-col"
											>
												<el-form-item
													class="item-bt-s Iisshow"
													label="客户地址"
												>
													<el-input
														:disabled="isEdit"
														@input="
															purchaseCom(
																baseInfoForm.linkAdress,
																'linkAdress'
															)
														"
														placeholder="请输入客户地址"
														v-model="
															baseInfoForm.linkAdress
														"
													></el-input>
													<div
														:data-clipboard-text="
															baseInfoForm.linkAdress
														"
														@click="saleOrderCopy"
														class="copyBtn copyBtnA"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="汇率类型"
										>
											<el-select
												:disabled="true"
												placeholder="请选择结算币别获取汇率类型"
												v-model="
													baseInfoForm.exchangeTypeId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													@click="
														purchaseCom(
															baseInfoForm.exchangeTypeId,
															'exchangeTypeId'
														)
													"
													style="font-size: 12px"
													v-for="item in statusForm.exchangeRateTypes"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s Iisshow"
											label="汇率"
										>
											<el-input
												:disabled="true"
												placeholder=" "
												v-model="
													baseInfoForm.exchangeRate
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.exchangeRate
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s Iisshow"
											label="税额"
										>
											<el-input
												:disabled="true"
												placeholder=" "
												v-model="baseInfoForm.taxaMount"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.taxaMount
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s Iisshow"
											label="金额"
										>
											<el-input
												:disabled="true"
												placeholder=" "
												v-model="baseInfoForm.amount"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.amount
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											class="item-bt-s Iisshow"
											label="价税合计"
										>
											<el-input
												:disabled="true"
												placeholder=" "
												v-model="baseInfoForm.allAmount"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.allAmount
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<el-tab-pane label="操作记录">
					<div
						:style="{ height: '185px!important' }"
						class="base-info-form-box"
					>
						<el-form
							:model="baseInfoForm"
							label-width="80px"
							:show-message="false"
						>
							<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.modifierName
												"
											></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.approverName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model="
															baseInfoForm.approveDate
														"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<div class="order-create-tell-info">
			<div class="tell-info-row-title">
				<h3>明细信息</h3>
				<div class="long-line-bx">
					<div class="long-line"></div>
				</div>
			</div>
			<div class="tell-info-button-group">
				<DetailsOperation
					:detailBtn="detailBtn"
					:deviationSelectArr="selectRowIndexArr"
					:isEdit="isEdit"
					@copyCellcolumn="copyCellcolumn"
					@copyRow="bottomCopyRow"
					@deleteRow="selectDeleteRow"
					@insertObj="getInsertInfo"
				></DetailsOperation>
			</div>
			<div class="tell-info-table">
				<el-table
					:cell-style="disabledCellStyle"
					:data="baseInfoForm.details"
					:header-cell-class-name="mustAfter"
					:max-height="tableHeight"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectAll"
					border
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
					v-loading="isLoading"
				>
					<el-table-column
						align="center"
						fixed
						min-width="40"
						type="selection"
					/>
					<el-table-column
						align="left"
						label="物料编码"
						min-width="280"
						prop="materialId"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope" class="matter-code-box">
							<span v-if="!scope.row.isMaterialShow">{{
								scope.row.materialNumber
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'materialId' + scope.$index"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											scope.$index,
											'materialId'
										);
									}
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'materialId'
									)
								"
								class="click-cell-ipt"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isMaterialShow"
								v-model="scope.row.materialId"
							>
								<el-option
									:key="item.id"
									:label="item.number"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'materialId',
											scope.$index,
											scope.column
										)
									"
									v-for="item in matterallCodelist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						id="sku"
						label="规格型号(SKU)"
						min-width="280"
						prop="specificationId"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>规格型号(SKU)
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSkuShow">{{
								scope.row.specification
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'specificationId' + scope.$index"
								:remote-method="
									(query) => {
										skuCodeChange(
											query,
											scope.$index,
											'specification'
										);
									}
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'specificationId'
									)
								"
								class="click-cell-ipt"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.isSkuShow"
								v-model="scope.row.specificationId"
							>
								<el-option
									:key="item.id + item.specifications"
									:label="item.specifications"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									@click="
										detailsCom(
											item.id,
											'specificationId',
											scope.$index,
											scope.column
										)
									"
									v-for="item in specificationalllist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="物料名称"
						min-width="100"
						prop="matterName"
					>
						<template #default="scope">
							<span>{{ scope.row.matterName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="销售单位"
						min-width="80"
						prop="unitName"
					>
						<template #default="scope">
							<span>{{ scope.row.unitName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="销售数量"
						min-width="120"
						prop="salesNumber"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>销售数量
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSaleShow">{{
								scope.row.salesNumber
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isSaleShow"
							>
								<div
									class="el-input__wrapper"
									:class="{
										'is-focus': scope.row.isSaleShow,
									}"
								>
									<input
										:disabled="isEdit"
										:id="'salesNumber' + scope.$index"
										@blur="
											detailsCom(
												scope.row.salesNumber,
												'salesNumber',
												scope.$index,
												scope.column
											)
										"
										@paste="
											pasteExcel(
												$event,
												scope.$index,
												scope,
												'salesNumber'
											)
										"
										class="el-input__inner click-cell-ipt"
										maxlength="19"
										autocomplete="off"
										placeholder
										v-model.lazy="scope.row.salesNumber"
									/>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="含税单价"
						min-width="120"
						prop="taxPrice"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>含税单价
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isTaxPrice">{{
								scope.row.taxPrice
							}}</span>
							<div
								:class="{
									'is-disabled':
										isEdit || scope.row.isDisabled,
								}"
								class="el-input click-cell-ipt"
								v-if="scope.row.isTaxPrice"
							>
								<div
									class="el-input__wrapper"
									:class="{
										'is-focus': scope.row.isTaxPrice,
									}"
								>
									<input
										:disabled="
											isEdit || scope.row.isDisabled
										"
										:id="'taxPrice' + scope.$index"
										:maxlength="11"
										@blur="
											detailsCom(
												scope.row.taxPrice,
												'taxPrice',
												scope.$index,
												scope.column
											)
										"
										@paste="
											pasteExcel(
												$event,
												scope.$index,
												scope,
												'taxPrice'
											)
										"
										class="el-input__inner click-cell-ipt"
										placeholder
										autocomplete="off"
										v-model.lazy="scope.row.taxPrice"
									/>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="税率%"
						min-width="120"
						prop="taxRate"
					>
						<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
								:disabled="isEdit || scope.row.isDisabled"
								:id="'taxRate' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'taxRate'
									)
								"
								class="click-cell-ipt"
								placeholder="请选择"
								v-if="scope.row.isTaxRate"
								v-model="scope.row.taxRate"
							>
								<el-option
									:key="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:label="item.name"
									:value="item.name"
									@click="
										detailsCom(
											item.name,
											'taxRate',
											scope.$index,
											scope.column
										)
									"
									v-for="item in statusForm.taxRates"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						:required="true"
						align="left"
						label="仓库"
						min-width="112"
						prop="wareHouseId"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>仓库
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isWareHouse">{{
								scope.row.wareHouseName
							}}</span>
							<el-select
								:disabled="isEdit || scope.row.isHouse"
								:id="'wareHouseId' + scope.$index"
								@change="
									stockChange($event, scope.$index, 'product')
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'wareHouseId'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								reserve-keyword
								v-if="scope.row.isWareHouse"
								v-model="scope.row.wareHouseId"
							>
								<el-option
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'wareHouseId',
											scope.$index,
											scope.column,
											item.customerWarehouseTag,
											item.disabled,
											item.name
										)
									"
									v-for="item in statusForm.warehouse"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户仓库"
						min-width="112"
						prop="customerStock"
					>
						<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.disable"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'customerStock',
											scope.$index,
											scope.column,
											'no',
											item.disabled,
											item.name
										)
									"
									v-for="item in customeStockArrylist[
										scope.$index
									]"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="期望交期"
						min-width="130"
						prop="deliveryDate"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>期望交期
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isDeliveryDate">{{
								scope.row.deliveryDate
							}}</span>
							<el-date-picker
								:clearable="false"
								:disabled="isEdit"
								@change="
									detailsCom(
										scope.row.deliveryDate,
										'deliveryDate',
										scope.$index,
										scope.column
									)
								"
								class="lead-time-style"
								format="YYYY-MM-DD"
								placeholder="年-月-日"
								type="date"
								v-if="scope.row.isDeliveryDate"
								v-model="scope.row.deliveryDate"
								value-format="YYYY-MM-DD"
							></el-date-picker>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="是否赠品"
						min-width="80"
						prop="isFree"
					>
						<template #default="scope">
							<el-checkbox
								:disabled="isEdit"
								@change="
									isCheckBox(
										scope.row.isFree,
										scope.$index,
										'isFree',
										'taxPrice'
									)
								"
								v-model="scope.row.isFree"
							></el-checkbox>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="备注"
						min-width="280"
						prop="orderreMarks"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isOrderreMarks">{{
								scope.row.orderreMarks
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isOrderreMarks"
							>
								<div
									class="el-input__wrapper"
									:class="{
										'is-focus': scope.row.isOrderreMarks,
									}"
								>
									<input
										:disabled="isEdit"
										autocomplete="off"
										:id="'orderreMarks' + scope.$index"
										class="el-input__inner click-cell-ipt"
										placeholder="请输入"
										v-model.lazy="scope.row.orderreMarks"
									/>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="单价"
						min-width="120"
						prop="price"
					>
						<template #default="scope">
							<span>{{ scope.row.price }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="价税合计"
						min-width="120"
						prop="allAmount"
					>
						<template #default="scope">
							<span>{{ scope.row.allAmount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="价税合计(本位币)"
						min-width="121"
						prop="allAmountLc"
					>
						<template #default="scope">
							<span>{{ scope.row.allAmountLc }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="折扣率%"
						min-width="120"
						prop="discountRate"
					>
						<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 || scope.row.isDisabled,
								}"
								class="el-input click-cell-ipt"
								v-if="scope.row.isDiscountRate"
							>
								<div
									class="el-input__wrapper"
									:class="{
										'is-focus': scope.row.isDiscountRate,
									}"
								>
									<input
										:disabled="
											isEdit || scope.row.isDisabled
										"
										:id="'discountRate' + scope.$index"
										:maxlength="12"
										autocomplete="off"
										@blur="
											detailsCom(
												scope.row.discountRate,
												'discountRate',
												scope.$index,
												scope.column
											)
										"
										class="el-input__inner click-cell-ipt"
										placeholder="请输入"
										v-model.lazy="scope.row.discountRate"
									/>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						:disabled="true"
						align="left"
						label="折扣额"
						min-width="120"
						prop="disCount"
					>
						<template #default="scope">
							<span>{{ scope.row.disCount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						:disabled="true"
						align="left"
						label="税额"
						min-width="120"
						prop="taxaMount"
					>
						<template #default="scope">
							<span>{{ scope.row.taxaMount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						:disabled="true"
						align="right"
						label="金额"
						min-width="120"
						prop="amount"
					>
						<template #default="scope">
							<span>{{ scope.row.amount }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="center"
						label="是否211"
						min-width="80"
						prop="is211"
					>
						<template #default="scope">
							<span>{{ scope.row.is211 ? '是' : '否' }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="供应链"
						min-width="80"
						prop="supplyChainName"
					>
						<template #default="scope">
							<span>{{ scope.row.supplyChainName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="供应组织"
						min-width="220"
						prop="paezOrgName"
					>
						<template #default="scope">
							<span>{{ scope.row.paezOrgName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="结算组织"
						min-width="178"
						prop="settleOrg"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>结算组织
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isSettleOrgName">{{
								scope.row.settleOrgName
							}}</span>
							<el-select
								:disabled="isEdit"
								:id="'settleOrg' + scope.$index"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'settleOrg'
									)
								"
								class="click-cell-ipt"
								placeholder="请输入关键词"
								v-if="scope.row.isSettleOrgName"
								v-model="scope.row.settleOrg"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									:value="item.id"
									@click="
										detailsCom(
											item.id,
											'settleOrg',
											scope.$index,
											scope.column,
											'',
											'',
											item.name
										)
									"
									v-for="item in statusForm.settlementOrgList"
								></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="默认供应商"
						min-width="178"
						prop="defaultSupplierName"
					>
						<template #default="scope">
							<span>{{ scope.row.defaultSupplierName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="默认供应商税率"
						min-width="120"
						prop="defaultSupplierTaxRate"
					>
						<template #default="scope">
							<span>{{ scope.row.defaultSupplierTaxRate }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="线上订单号"
						min-width="118"
						prop="onlineOrderNo"
					>
						<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"
								v-if="scope.row.isOnlineOrderNo"
							>
								<div
									class="el-input__wrapper"
									:class="{
										'is-focus': scope.row.isOnlineOrderNo,
									}"
								>
									<input
										:disabled="isEdit"
										autocomplete="off"
										:id="'onlineOrderNo' + scope.$index"
										class="el-input__inner click-cell-ipt"
										placeholder="请输入"
										v-model.lazy="scope.row.onlineOrderNo"
									/>
								</div>
							</div>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="采购/排产数量"
						min-width="120"
						prop="purchaseNumber"
					>
						<template #default="scope">
							<span>{{ scope.row.purchaseNumber }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="产品生命周期"
						min-width="94"
						prop="lifeCycleName"
					>
						<template #default="scope">
							<span>{{ scope.row.lifeCycleName }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="条码"
						min-width="107"
						prop="barCode"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>条码
						</template>
						<template #default="scope">
							<span v-if="!scope.row.isBarCode">{{
								scope.row.barCode
							}}</span>
							<div
								:class="{ 'is-disabled': isEdit }"
								class="el-input click-cell-ipt"
								v-if="scope.row.isBarCode"
							>
								<div
									class="el-input__wrapper"
									:class="{ 'is-focus': scope.row.isBarCode }"
								>
									<input
										:disabled="isEdit"
										autocomplete="off"
										:id="'barCode' + scope.$index"
										class="el-input__inner click-cell-ipt"
										placeholder="请输入"
										v-model.lazy="scope.row.barCode"
									/>
								</div>
							</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 {
	orderRexgu,
	orderCopy,
	addRowCom,
	disRateRexgu,
	taxPriceNumberRexgu,
	searchOrder,
	pushDownSure,
	materSpecCarry,
	insertRow,
	saveSubmitBackData,
	changeCustomerClearData,
	materSpecSearh,
	orderCopyClearHeaderData,
	orderCopyClearInfoData,
	customerChangeCarryData,
	getNowTimeGlobal,
	filterMaterialData,
} from '@/utils/takeMethods';
import { Decimal } from 'decimal.js';
import {
	getStaffListApiUser,
	approvalFlowTrackingCreate,
	approvalFlowTrackingGetby,
	approvalFlowTrackingUpdate,
} from '@/utils/api.js';
import { ElMessageBox, ElMessage } from 'element-plus';

import {
	getStatusType,
	getBaseCurrency,
	getTaxPrice,
	getStatusTypeQuery,
	removeChildren,
	copyValueMethods,
	compareDateMethods,
	splitJointList,
} from '@/utils/pubulic.js';
import { countMethods, countMethodsUnitNumber } from '@/utils/count.js';
import {
	saleBtnAdd,
	saleBtnEdit,
	defaultTableInfo,
	customSearch,
	is211s,
	optionProps,
	storeObj,
} from '@/utils/variable.js';
import examineTop from '@/components/examineTop/index.vue';
import toolBtn from '@/components/public/toolBtn/toolBtn.vue';
export default {
	name: 'SaleOrderCreate',
	components: {
		examineTop,
		toolBtn,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			examineObj: {},
			isLoading: false,
			customerInfo: [],
			salePrecisionNumber: [], // 数量精度 位数
			isPrecision: [], // 数量精度 位数是否为0
			unitData: [], // 单位集合
			isCount: [], // 是否计算
			isLockPrice: true,
			statusForm: JSON.parse(JSON.stringify(customSearch)),
			customeStockArrylist: [], // 客户仓库集合
			matterallCodelist: [], // 物料下拉数据
			specificationalllist: [], // 规格型号（sku）下拉数据
			baseInfoForm: JSON.parse(JSON.stringify(defaultTableInfo)),
			addRow: {},
			storeObj: JSON.parse(JSON.stringify(storeObj)),
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			isEdit: true, // 禁止编辑
			selectRowIndexArr: [], // 选择行的数组
			btnType: JSON.parse(JSON.stringify(saleBtnAdd)), // 不需要的按钮
			currRow: 0, // 表格 编辑 当前行
			selectRowIndex: 0, // 选择的行
			heightNum: 0, // 容器高度
			multipleSelection: [], // 选择的行
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrdedetailIds: [], // 勾选的明细id集合
			pushDownList: [], // 下推集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			tableHeight: 0, // 表格高度
			saveIds: '', // 得到订单id
			is211s: JSON.parse(JSON.stringify(is211s)),
			unitpriceAccuracy: 10,
			amountAccuracy: 10,
			detailBtn: [],
			isB2C: false,
			isOrder: true,
			isDisable: false,
			timer: null,
			recordIndex: '',
			trackId: 0,
			radios: {},
			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',
				['localCurrType', '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;
								this[setVuexData[ind]](
									this.statusForm[resDataQuery[ind]]
								);
							} else {
								resDataQuery[ind].forEach((ele, index) => {
									this.statusForm[resDataQuery[ind][index]] =
										r.data;
									this[setVuexData[ind]](
										this.statusForm[
											resDataQuery[ind][index]
										]
									);
								});
							}
							// 单位
							if (vuexKey[ind] == 'unitAll') {
								this.unitData =
									this.statusForm[resDataQuery[ind]];
							}
							// 税率
							if (vuexKey[ind] == 'taxRate') {
								this.statusForm.taxRates.forEach((element) => {
									element.name = Number(element.name) * 1;
								});
								this.setTaxRate(this.statusForm.taxRates);
							}
						}
					});
				}
			});
			// 枚举 - 订单类型、状态
			if (this.enumType && JSON.stringify(this.enumType) !== '{}') {
				this.statusForm.salOrderType = JSON.parse(
					JSON.stringify(this.enumType.salOrderType)
				);
				this.statusForm.documentStatus = JSON.parse(
					JSON.stringify(this.enumType.documentStatus)
				);
			} else {
				this.$http.get('SalOrder/GetEnum').then((req) => {
					if (req.status == 200) {
						this.setEnumType(req.data);
						this.statusForm.salOrderType = req.data.salOrderType;
						this.statusForm.documentStatus =
							req.data.documentStatus;
					}
				});
			}

			// 获取人员接口
			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 = []);
				});
			}
			// 计算高度 - 获取时间 - 获取结算组织 - 获取添加对象
			let windowHeight = document.documentElement.clientHeight;
			this.heightNum = windowHeight - 102;
			this.tableHeight = windowHeight - 480;
			this.baseInfoForm.date = getNowTimeGlobal();
			this.statusForm.saleOrg = this.orgIdArr;
			this.statusForm.settlementOrgList = this.orgIdArr;
			this.addRow = addRowCom(
				this.baseInfoForm.details,
				this.baseInfoForm.saleorgName
			);
			// 新增、克隆
			if (
				this.$route.query.type === 'add' ||
				this.$route.query.type === 'copy'
			) {
				this.baseInfoForm.documentStatus = '';
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.saleorgId = this.$store.state.org.orgId;
				let tempList = this.statusForm.saleOrg.filter(
					(it) => it.id === this.baseInfoForm.saleorgId
				);
				this.baseInfoForm.saleorgName = tempList[0].name;
				this.isEdit = false;
				if (this.baseInfoForm.saleorgId) {
					this.baseInfoForm.details.forEach((el, ind) => {
						this.baseInfoForm.details[ind].settleOrg =
							this.baseInfoForm.saleorgId;
						this.baseInfoForm.details[ind].settleOrgName =
							this.baseInfoForm.saleorgName;
					});
				}
				if (this.$route.query.type === 'copy') {
					this.isEdit = false;
					this.getPurChaseDetails();
				}
			}
			if (
				this.$route.query.type == 'pushDown' &&
				this.$route.query.pushDownData
			) {
				this.isEdit = false;
				this.getPurChaseDetails(
					JSON.parse(
						decodeURIComponent(this.$route.query.pushDownData)
					)
				);
			}
			if (this.$route.query.type == 'details' && this.$route.query.id) {
				this.getPurChaseDetails();
			}
		},
		// 复制粘贴
		pasteExcel(event, index, scope, key) {
			let result = copyValueMethods(event, this.storeObj.storeVal);
			setTimeout(async () => {
				if (result.isPasteOneCol) {
					this.baseInfoForm.details[index][key] = result.oldVal;
					this.$message.error({
						message: '请选择一列复制粘贴!',
						showClose: true,
					});
					return;
				}
				let recordAddIndex = index;
				for (let i = 0; i < result.rows.length; i++) {
					if (result.rows[i] !== '') {
						if (key === 'salesNumber' || key === 'taxPrice') {
							if (
								this.baseInfoForm.details[recordAddIndex] ===
								undefined
							) {
								return;
							} else {
								let key = scope.column.property;
								let num = result.rows[i] * 1;
								if (!isNaN(num)) {
									this.baseInfoForm.details[recordAddIndex][
										key
									] = num + '';
									this.countMethodsCom(recordAddIndex, key);
								} else {
									this.$message.error({
										message:
											'粘贴内容有误,请重新选择复制内容!',
										showClose: true,
									});
									return;
								}
							}
							if (key === 'salesNumber') {
								this.saleNumberPrecision(
									recordAddIndex,
									key,
									'Y'
								);
							}
							recordAddIndex++;
						} else if (
							key === 'materialId' ||
							key === 'specificationId'
						) {
							let key = scope.column.property;
							if (key === 'materialId') {
								this.matterCodeChange(
									result.rows[i],
									recordAddIndex,
									'getDate'
								);
							}
							if (key === 'specificationId') {
								this.skuCodeChange(
									result.rows[i],
									recordAddIndex,
									'getDate'
								);
							}
							recordAddIndex++;
						}
					}
				}
			}, 0);
		},
		// 单据类型 == f
		billTypeCha(value) {
			if (value === 'f') {
				this.baseInfoForm.details.forEach((element) => {
					element.customerStock = '';
				});
			}
		},
		// 客户发生改变
		async custmerCha() {
			if (this.baseInfoForm.custId) {
				await this.monitorCustomer(this.baseInfoForm.custId);
			}
			// this.statusForm.setlementDifferences = await getStatusType('SysConfig/GetDcurrency') // 结算币别
			await this.getPriceAmountPrecision();
			await this.baseInfoForm.details.forEach((element, index) => {
				element.customerStock = '';
				this.countMethodsCom(index, 'taxPrice');
			});
		},
		// 客户改变影响的值
		async monitorCustomer(id, details) {
			this.customerInfo = await getStatusTypeQuery(
				'SysConfig/GetCustomerInfoById/',
				id,
				'post',
				{
					cusId: id,
					orgId: this.baseInfoForm.saleorgId,
				}
			);
			this.baseInfoForm = await customerChangeCarryData(
				this.baseInfoForm,
				this.customerInfo
			);
			if (!details) {
				if (this.baseInfoForm.custId) {
					if (
						this.baseInfoForm.localcurrId &&
						this.baseInfoForm.saleorgId &&
						this.baseInfoForm.settlecurrId
					) {
						let templateObj = await getTaxPrice(
							this.baseInfoForm.localcurrId,
							'SysConfig/GetRateInfo',
							this.baseInfoForm.settlecurrId
						);
						this.getExchangeType(templateObj);
					}
				}
			}
			this.baseInfoForm.details.forEach((el, ind) => {
				this.statusForm.taxRates.forEach((ele) => {
					if (ele.id === this.customerInfo[0].defaultRateId) {
						// 先取物料编码携带税率，再取供应商的
						if (this.baseInfoForm.details[ind].materialId) {
							let tempList = this.matterallCodelist[ind].filter(
								(it) =>
									it.id ==
									this.baseInfoForm.details[ind].materialId
							);
							if (
								tempList[0].taxRateId ||
								tempList[0].taxRateId == 0
							) {
								this.baseInfoForm.details[ind].taxRate =
									tempList[0].taxRateNmae;
								this.baseInfoForm.details[ind].taxRateId =
									tempList[0].taxRateId;
								this.addRow.taxRate = tempList[0].taxRateNmae;
								this.addRow.taxRateId = tempList[0].taxRateId;
							} else {
								ele.name
									? (this.baseInfoForm.details[ind].taxRate =
											ele.name)
									: (this.baseInfoForm.details[
											ind
									  ].taxRate = 0);
								ele.id
									? (this.baseInfoForm.details[
											ind
									  ].taxRateId = ele.id)
									: (this.baseInfoForm.details[
											ind
									  ].taxRateId = null);
								ele.name
									? (this.addRow.taxRate = ele.name)
									: (this.addRow.taxRate = 0);
								ele.id
									? (this.addRow.taxRateId = ele.id)
									: (this.addRow.taxRateId = null);
							}
						}
					} else {
						// 没有匹配到值就为空
						if (this.baseInfoForm.details[ind].taxRate == '') {
							this.baseInfoForm.details[ind].taxRate = '';
						}
						this.addRow.taxRate = '';
					}
				});
			});
		},
		// 组织改变时获取部门、仓库等影响的值
		async monitorOrg() {
			let saleDeptArr = await getStatusType(
				'SysConfig/GetDept/',
				this.baseInfoForm.saleorgId,
				'post'
			); // 根据组织 获取部门
			this.statusForm.saleParts = removeChildren(saleDeptArr);
			this.statusForm.warehouse = await getStatusType(
				'SysConfig/GetWarehouseByOrg/',
				this.baseInfoForm.saleorgId
			); // 根据组织 获取仓库
			this.baseInfoForm.details.forEach((element) => {
				let rowObj = this.statusForm.warehouse.filter(
					(it) => element.wareHouseId === it.id
				);
				if (element.wareHouseId) {
					element.isCusHouse =
						rowObj.length !== 0
							? !rowObj[0].customerWarehouseTag
							: false;
				}
			});
			let tempWareHouse = [];
			if (this.baseInfoForm.billtypeId !== 'f') {
				tempWareHouse = this.statusForm.warehouse.filter(
					(it) => it.name != '大促临时存放仓'
				);
				this.statusForm.warehouse = tempWareHouse;
			}
			this.tempStoreWarehouse = this.statusForm.warehouse;
		},

		// 仓库改变获取客户仓库集合
		async monitorCustHouse(id, index, type, el, isOpen) {
			this.customeStockArrylist[index] = [];
			if (this.baseInfoForm.billtypeId === 'f') {
				await this.getCustomerListSingle(index);
			} else {
				await this.getCustomerListSingle(index, 'Y');
			}
			if (isOpen) {
				this.customeStockArrylist = splitJointList(
					this.baseInfoForm.details,
					this.customeStockArrylist,
					'customerStockList'
				);
			}
		},
		// 仓库发生改变
		stockChange(id, index, type) {
			this.baseInfoForm.details[index].customerStockName = '';
			this.baseInfoForm.details[index].customerStock = '';
			let el = this.baseInfoForm.details[index];
			this.monitorCustHouse(id, index, type, el);
		},
		setExamine(res) {
			if (
				res.status === 200 &&
				res.data &&
				JSON.stringify(res.data) !== '{}'
			) {
				this.examineObj = res.data;
				//有审批流,但是自己不能审批则返回1,否则返回2,如果没有审批流或者报错为了不阻断流程返回3
				let isApprover = res.data.isApprover;
				this.isExmaineTop = isApprover ? 2 : 1;
				if (
					!res.data ||
					JSON.stringify(res.data) === '{}' ||
					this.baseInfoForm.documentStatus !== 'b'
				) {
					this.isExmaineTop = 3;
				}
				if (res.data.isDone) {
					this.baseInfoForm.documentStatus = 'c';
					this.isExmaineTop = 3;
				}
				this.isexamineBtns = false;
			} else {
				this.isExmaineTop = 3;
				this.isexamineBtns = false;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.post('SalOrder/GetInfo/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.baseInfoForm = saveSubmitBackData(
							this.baseInfoForm,
							req
						);
						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.examineObj.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;
			}
			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: 2,
				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;
						// }
						// 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 obj = {
		// 		sendOrderId: data.id,
		// 		deptId: data.saleDeptId || 0,
		// 		sendId: this.userId,
		// 		sendOrderType: 2,
		// 		sendOrderBillNo: data.billNo,
		// 		orgId: data.saleorgId,
		// 	};
		// 	this.$http
		// 		.post(approvalFlowTrackingCreate, obj)
		// 		.then((res) => {
		// 			this.setExamine(res);
		// 		})
		// 		.catch((err) => {
		// 			if (err) {
		// 				this.isExmaineTop = 3;
		// 			}
		// 		});
		// },
		// 根据进入方式 获取不同内容 详情
		async getPurChaseDetails(res) {
			if (res) {
				this.isLoading = true;
				this.matterallCodelist = [];
				this.specificationalllist = [];
				this.baseInfoForm = res;
				this.baseInfoForm.localcurrId = getBaseCurrency(
					this.orgIdArr,
					this.baseInfoForm.saleorgId
				);
				if (this.baseInfoForm.isPushDown) {
					this.detailBtn = ['add', 'copy'];
				} else {
					this.detailBtn = [];
				}
				if (!this.baseInfoForm.date) {
					this.baseInfoForm.date = getNowTimeGlobal();
				}
				this.baseInfoForm.documentStatus = 'a';
				if (this.baseInfoForm.settlecurrId) {
					this.getPriceAmountPrecision();
				}
				await this.getMaterialCustomerDataAll('copy');
				if (this.baseInfoForm.custId) {
					await this.monitorCustomer(this.baseInfoForm.custId);
				}
				let tempList = this.statusForm.saleOrg.filter(
					(it) => it.id === this.baseInfoForm.saleorgId
				);
				this.baseInfoForm.saleorgName = tempList[0].name;
				await this.baseInfoForm.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].materialId = el.materialId;
					this.baseInfoForm.details[ind].specificationId =
						el.materialId;
					this.baseInfoForm.details[ind].isDisabled = false;
					if (this.baseInfoForm.saleorgId) {
						this.baseInfoForm.details[ind].settleOrg =
							this.baseInfoForm.saleorgId;
					}
					this.baseInfoForm.details[ind].salesNumber == null
						? 0
						: this.baseInfoForm.details[ind].salesNumber;
					this.baseInfoForm.details[ind].taxPrice =
						this.baseInfoForm.details[ind].taxPrice == null
							? 0
							: this.baseInfoForm.details[ind].taxPrice;
					this.baseInfoForm.details[ind].settleOrg =
						this.baseInfoForm.saleorgId;
					this.baseInfoForm.details[ind].settleOrgName =
						this.baseInfoForm.saleorgName;
					this.countMethodsCom(ind, 'discountRate');
					el.isMaterialShow = false;
					el.isSkuShow = false;
					el.isSaleShow = false;
					el.isTaxPrice = false;
					el.isTaxRate = false;
					el.isWareHouse = false;
					el.isCustomerStock = false;
					el.isOrderreMarks = false;
					el.isDeliveryDate = false;
					el.isDiscountRate = false;
					el.isSettleOrgName = false;
					el.isOnlineOrderNo = false;
					el.isBarCode = false;
				});
				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)
					.post('SalOrder/GetInfo/' + this.$route.query.id)
					.then(async (req) => {
						if (req.status == 200) {
							// if (req.data.tracking && req.data.tracking.remark) {
							// 	this.$message.error({
							// 		message: `单据由-${req.data.tracking.remark}`,
							// 		showClose: true,
							// 		duration: 5000,
							// 	});
							// }

							this.baseInfoForm = req.data;

							if (this.baseInfoForm.isPushDown) {
								this.detailBtn = ['add', 'copy'];
							} else {
								this.detailBtn = [];
							}
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
							} else {
								this.isEdit = true;
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							if (
								this.baseInfoForm.date == '' ||
								this.baseInfoForm.date == null ||
								this.baseInfoForm.date == undefined
							) {
								this.baseInfoForm.date = getNowTimeGlobal();
							}
							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.unitpriceAccuracy =
								this.baseInfoForm.pricePrecision;
							if (this.$route.query.type === 'copy') {
								this.getMaterialCustomerDataAll('copy');
							} else {
								this.getMaterialCustomerDataAll();
							}
							await this.baseInfoForm.details.forEach(
								(el, ind) => {
									// this.matterCodeChange(el.materialNumber, ind, 'getDate', true)
									this.baseInfoForm.details[ind].materialId =
										el.materialId;
									this.baseInfoForm.details[
										ind
									].specificationId = el.materialId;
									this.baseInfoForm.details[
										ind
									].isDisabled = false;
									// this.monitorCustHouse(this.baseInfoForm.details[ind].wareHouseId, ind, 'on', el, true)
									this.baseInfoForm.details[ind].salesNumber =
										this.baseInfoForm.details[ind]
											.salesNumber == null
											? 0
											: this.baseInfoForm.details[ind]
													.salesNumber;
									this.baseInfoForm.details[ind].taxPrice =
										this.baseInfoForm.details[ind]
											.taxPrice == null
											? 0
											: this.baseInfoForm.details[ind]
													.taxPrice;
									if (this.baseInfoForm.billtypeId === 'f') {
										el.isHouse = true;
									}
									if (this.baseInfoForm.details[ind].isFree) {
										this.baseInfoForm.details[
											ind
										].isDisabled = true;
									} else {
										this.baseInfoForm.details[
											ind
										].isDisabled = false;
									}
									el.isMaterialShow = false;
									el.isSkuShow = false;
									el.isSaleShow = false;
									el.isTaxPrice = false;
									el.isTaxRate = false;
									el.isWareHouse = false;
									el.isCustomerStock = false;
									el.isOrderreMarks = false;
									el.isDeliveryDate = false;
									el.isDiscountRate = false;
									el.isSettleOrgName = false;
									el.isOnlineOrderNo = false;
									el.isBarCode = false;
								}
							);
							if (this.$route.query.type === 'copy') {
								this.detailBtn = [];
								this.isEdit = false;
								// this.statusForm.setlementDifferences = getStatusType('SysConfig/GetDcurrency') // 结算币别
								this.getPriceAmountPrecision();
								// this.settlecurrChange()
								this.baseInfoForm = orderCopyClearHeaderData(
									this.baseInfoForm
								);
								this.baseInfoForm.details.forEach(
									(element, ind) => {
										this.baseInfoForm.details[
											ind
										].taxPrice =
											Decimal(
												this.baseInfoForm.details[ind]
													.taxPrice
											).toFixed(this.unitpriceAccuracy) *
											1;
										this.saleNumberPrecision(
											ind,
											'salesNumber',
											'Y'
										);
										this.countMethodsCom(
											ind,
											'discountRate'
										);
										element =
											orderCopyClearInfoData(element);
									}
								);
								this.isOrder = true;
							}
							this.baseInfoForm.details.forEach((el, ind) => {
								let rowObj = this.statusForm.warehouse.filter(
									(it) =>
										this.baseInfoForm.details[ind]
											.wareHouseId === it.id
								);
								if (
									this.baseInfoForm.details[ind]
										.wareHouseId &&
									rowObj[0]
								) {
									this.baseInfoForm.details[ind].isCusHouse =
										!rowObj[0].customerWarehouseTag;
								}
							});
							//回调 审批流跟踪
							this.setApprovalFlowTrackingGetby(req.data);
							this.isLoading = false;
						}
					});
			}
		},
		// 详情 - 克隆 - 下推进入 一次性获取物料编码 + 客户仓库数据
		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.customeStockArrylist[index] = _resultHouse;
				this.matterallCodelist[index].forEach((ele) => {
					if (copy) {
						this.baseInfoForm = materSpecSearh(
							this.baseInfoForm,
							index,
							ele
						);
					} else {
						this.baseInfoForm = materSpecSearh(
							this.baseInfoForm,
							index,
							ele,
							'details'
						);
					}
				});
			});
		},
		// 获取所有客户仓库信息
		async getCustmerStoreAll(query, id) {
			if (query.length > 0) {
				return this.$http
					.post('SysConfig/GetCustomerStockList', {
						customerIds: query,
						orgId: id,
					})
					.then((res) => {
						if (res.status === 200) {
							return res.data;
						} else {
							return [];
						}
					});
			} else {
				return [];
			}
		},
		// 获取所有物料携带信息
		async matterCodeChangeAll(query, type, id) {
			if (query.length > 0) {
				return this.$http
					.post('SysConfig/GetMaterialLikeList', {
						names: query,
						file: type,
						orgId: id,
					})
					.then((res) => {
						if (res.status === 200) {
							return res.data.reverse();
						} else {
							return [];
						}
					});
			} else {
				return [];
			}
		},
		// 是否211、赠品
		isCheckBox(val, index, key, taxPrice) {
			this.baseInfoForm.details[index][key] = val;
			if (val === true) {
				this.baseInfoForm.details[index].isDisabled = true;
				this.baseInfoForm.details[index].taxRate = '';
				this.baseInfoForm.details[index].taxPrice = '0';
				this.countMethodsCom(index, taxPrice);
				this.countMethodsCom(index, 'taxRate');
			} else {
				this.baseInfoForm.details[index].isDisabled = false;
			}
		},
		// 匹配物料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 = materSpecSearh(
									this.baseInfoForm,
									ind,
									el
								);
							});
						}
					}
				}
			}
		},
		// 获取型号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 = materSpecSearh(
									this.baseInfoForm,
									ind,
									el
								);
							});
						}
					}
				}
			}
		},
		// 单据头输入框
		async purchaseCom(value, key, type, name) {
			if (!!value && !!key) {
				this.baseInfoForm[key] = value;
			}
			if (key === 'saleorgId') {
				this.baseInfoForm.saleorgName = name;
				this.addRow.settleOrgName = name;
				let result = changeCustomerClearData(
					this.baseInfoForm,
					this.statusForm,
					this.addRow
				);
				this.baseInfoForm = result.baseInfoForm;
				this.statusForm = result.statusForm;
			}
			if (type) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
			if (key === 'billtypeId') {
				this.statusForm.warehouse = await getStatusType(
					'SysConfig/GetWarehouseByOrg/',
					this.baseInfoForm.saleorgId
				); // 根据组织 获取仓库
				if (this.baseInfoForm.billtypeId === 'f') {
					let template = this.statusForm.warehouse.filter(
						(it) => it.name === '大促临时存放仓'
					);
					this.baseInfoForm.details.forEach((element, index) => {
						this.baseInfoForm.details[index].wareHouseId = '';
						this.baseInfoForm.details[index].isHouse = true;
						this.customeStockArrylist[index] = [];
						if (template.length > 0 && template[0].id) {
							element.wareHouseId = template[0].id;
							if (element.wareHouseId) {
								element.isCusHouse =
									!template[0].customerWarehouseTag;
								element.wareHouseName = template[0].name;
							} else {
								element.isCusHouse = true;
							}
						} else {
							element.isCusHouse = true;
						}
					});
					await this.getCustomerAllList();
					// this.getCustomerList()
				} else {
					this.baseInfoForm.details.forEach((element, index) => {
						this.baseInfoForm.details[index].wareHouseId = '';
						this.baseInfoForm.details[index].customerStock = '';
						element.wareHouseName = '';
						element.customerStockName = '';
						this.baseInfoForm.details[index].isHouse = false;
						this.baseInfoForm.details[index].isCusHouse = true;
						this.customeStockArrylist[index] = [];
					});
					this.getCustomerAllList();
				}
				this.baseInfoForm.details.forEach((el, ind) => {
					this.countMethodsCom(ind, 'taxPrice');
				});
				let billKey = '';
				for (const key in this.statusForm.salOrderType) {
					if (this.statusForm.salOrderType[key] === 'B2C定制') {
						billKey = key;
						if (this.baseInfoForm.billtypeId === key) {
							this.isB2C = true;
							this.getMaterialAllList();
							this.baseInfoForm.details.forEach((el, ind) => {
								if (el.materialId) {
									this.baseInfoForm.details[ind].taxPrice =
										this.matterallCodelist[ind][0].cost;
									this.countMethodsCom(ind, 'taxPrice');
								}
							});
						} else {
							this.isB2C = false;
						}
					}
				}
				this.tempStoreWarehouse = this.statusForm.warehouse;
			}
			if (key === 'settlecurrId') {
				this.getPriceAmountPrecision();
			}
			if (key === 'custId') {
				this.baseInfoForm.details.forEach((el, ind) => {
					el.customerStock = '';
					el.customerStockName = '';
				});
				this.getCustomerList();
			}
		},
		// 获取所有客户仓库
		async getCustomerAllList() {
			let houseQuery = [];
			this.baseInfoForm.details.forEach((el) => {
				if (this.baseInfoForm.custId) {
					houseQuery.push(this.baseInfoForm.custId);
				}
			});
			let _resultHouse = await this.getCustmerStoreAll(
				houseQuery,
				this.baseInfoForm.saleorgId
			);
			// console.log('_resultHouse',_resultHouse)
			this.baseInfoForm.details.forEach((el, index) => {
				if (this.baseInfoForm.billtypeId == 'f') {
					this.baseInfoForm.details[index].isHouse = true;
				} else {
					this.baseInfoForm.details[index].isHouse = false;
				}
				this.customeStockArrylist[index] = [];
				this.customeStockArrylist[index] = _resultHouse;
				// this.baseInfoForm.details[index].isCusHouse = true
			});
		},
		// 获取所有物料
		async getMaterialAllList() {
			let materQuery = [];
			let materQueryIndex = [];
			this.baseInfoForm.details.forEach((el, ind) => {
				if (el.materialNumber) {
					materQuery.push(el.materialNumber);
					materQueryIndex.push(ind);
				}
			});
			let _result = await this.matterCodeChangeAll(
				materQuery,
				'Number',
				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.matterallCodelist[index].forEach((ele) => {
					this.baseInfoForm = materSpecSearh(
						this.baseInfoForm,
						index,
						ele
					);
				});
			});
		},
		// 获取客户仓库信息single
		getCustomerListSingle(index, wareHouseId) {
			let query = {};
			query.customerId = this.baseInfoForm.custId
				? parseInt(this.baseInfoForm.custId)
				: null;
			query.orgId = this.baseInfoForm.saleorgId
				? parseInt(this.baseInfoForm.saleorgId)
				: null;
			if (wareHouseId) {
				query.stockId = this.baseInfoForm.details[index].wareHouseId
					? parseInt(this.baseInfoForm.details[index].wareHouseId)
					: null;
			}
			this.$http.post('SysConfig/GetCustomerStock', query).then((r) => {
				if (r.status == 200) {
					this.customeStockArrylist[index] = r.data;
				}
			});
		},
		// 获取客户仓库信息many
		getCustomerList() {
			let query = {};
			query.customerId = this.baseInfoForm.custId
				? parseInt(this.baseInfoForm.custId)
				: null;
			query.orgId = this.baseInfoForm.saleorgId
				? parseInt(this.baseInfoForm.saleorgId)
				: null;
			this.$http.post('SysConfig/GetCustomerStock', query).then((r) => {
				if (r.status == 200) {
					this.baseInfoForm.details.forEach((el, ind) => {
						this.customeStockArrylist[ind] = r.data;
					});
				}
			});
		},
		// 处理失焦
		selectBlur(index) {
			let _this = this;
			_this.baseInfoForm.details.forEach((el) => {
				el.isMaterialShow = false;
				el.isSkuShow = false;
				el.isSaleShow = false;
				el.isTaxPrice = false;
				el.isTaxRate = false;
				el.isWareHouse = false;
				el.isCustomerStock = false;
				el.isOrderreMarks = false;
				el.isDeliveryDate = false;
				el.isDiscountRate = false;
				el.isSettleOrgName = false;
				el.isOnlineOrderNo = false;
				el.isBarCode = false;
			});
		},
		// 明细信息输入框编辑
		async detailsCom(value, key, inde, column, isOpen, disabled, name) {
			console.log(value, '==========value================');
			let _this = this;
			this.getPriceAmountPrecision();
			this.saleNumberPrecision(inde);
			_this.baseInfoForm.details[inde].isSaleShow = false;
			_this.baseInfoForm.details[inde].isTaxPrice = false;
			_this.baseInfoForm.details[inde].isOrderreMarks = false;
			_this.baseInfoForm.details[inde].isDeliveryDate = false;
			_this.baseInfoForm.details[inde].isDiscountRate = false;
			_this.baseInfoForm.details[inde].isSettleOrgName = false;
			_this.baseInfoForm.details[inde].isOnlineOrderNo = false;
			_this.baseInfoForm.details[inde].isBarCode = false;

			if (!disabled) {
				this.currRow = inde;
				this.storeObj.storeVal = value;
				this.storeObj.storekey = key;
				this.storeObj.storeRow = inde;
				this.storeObj.storeCol = column.index;
				if (key === 'materialId' || key === 'specificationId') {
					this.matterallCodelist[inde].forEach((el) => {
						if (value === el.id) {
							this.baseInfoForm.details[inde] = materSpecCarry(
								this.baseInfoForm.details[inde],
								el,
								this.customerInfo
							);
							this.saleNumberPrecision(inde);
							if (this.isB2C) {
								this.baseInfoForm.details[inde].taxPrice =
									el.cost;
								this.baseInfoForm.details[inde].salesNumber =
									'0';
							} else {
								this.baseInfoForm.details[inde].taxPrice = '0';
								this.baseInfoForm.details[inde].salesNumber =
									'0';
							}
							this.countMethodsCom(inde, 'taxPrice');
							this.baseInfoForm.details[
								inde
							].isMaterialShow = false;
							this.baseInfoForm.details[inde].isSkuShow = false;
							document.getElementById(key + inde).blur();
						}
					});
				} else if (key === 'salesNumber') {
					if (this.baseInfoForm.isPushDown) {
						if (
							parseInt(
								this.baseInfoForm.details[inde].salesNumber
							) >
							parseInt(
								this.baseInfoForm.details[inde]
									.parentOrderNumber
							)
						) {
							this.baseInfoForm.details[inde].salesNumber =
								this.baseInfoForm.details[
									inde
								].parentOrderNumber;
						}
					}
				} else {
					this.baseInfoForm.details[inde][key] = value;
				}
				if (key === 'discountRate') {
					this.baseInfoForm.details[inde].discountRate = disRateRexgu(
						this.baseInfoForm.details[inde][key],
						key,
						inde
					);
					if (!this.baseInfoForm.details[inde][key]) {
						this.baseInfoForm.details[inde].disCount = '0';
					}
					this.baseInfoForm.details[inde][key] = this.valueRemoveZero(
						inde,
						key
					);
					this.storeObj.storeVal =
						this.baseInfoForm.details[inde][key];
					this.countMethodsCom(inde, key);
				}
				if (key === 'taxRate') {
					this.countMethodsCom(inde, key);
				}
				if (key === 'salesNumber') {
					this.isPrecision[inde] = this.isPrecision[inde]
						? this.isPrecision[inde]
						: false;
					console.log(
						this.isPrecision,
						'===========this.isPrecision[inde]========'
					);
					this.salePrecisionNumber[inde] =
						this.salePrecisionNumber[inde] ||
						this.salePrecisionNumber[inde] == 0
							? this.salePrecisionNumber[inde]
							: 10;
					console.log(
						this.salePrecisionNumber,
						'==========this.salePrecisionNumber[inde]==============='
					);
					if (
						!this.baseInfoForm.details[inde].materialId &&
						!this.$route.query.id
					) {
						this.isPrecision[inde] = true;
					}
					if (this.baseInfoForm.details[inde][key]) {
						if (this.isPrecision[inde]) {
							if (
								this.baseInfoForm.details[inde][key]
									.toString()
									.indexOf('.') !== -1
							) {
								this.baseInfoForm.details[inde][key] = parseInt(
									this.baseInfoForm.details[inde][key]
								);
							} else {
								this.baseInfoForm.details[inde][key] =
									this.baseInfoForm.details[inde][key] + '';
							}
							this.baseInfoForm.details[inde][key] =
								this.baseInfoForm.details[inde][key]
									.toString()
									.replace(/\D/g, '');
						} else {
							let numD = '';
							let count = '\\d';
							for (
								let ind = 0;
								ind < this.salePrecisionNumber[inde];
								ind++
							) {
								numD = numD + count;
							}
							let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
							this.baseInfoForm.details[inde][key] =
								this.baseInfoForm.details[inde][key]
									.toString()
									.replace(/[^\d^\\.]+/g, '')
									.replace('.', '$#$')
									.replace(/\./g, '')
									.replace('$#$', '.')
									.replace(eval(reg), '$1$2.$3');
						}
					} else {
						this.baseInfoForm.details[inde][key] = '0';
					}
					if (!this.isCount[inde]) {
						this.isCount[inde] = 1;
					}
					if (
						this.baseInfoForm.details[inde][key]
							.toString()
							.indexOf('.') !== -1
					) {
						this.saleNumberPrecision(inde, key, 'Y');
						this.countMethodsCom(inde, key);
					} else {
						this.isCount[inde] = 2;
						this.countMethodsCom(inde, key);
					}
					this.baseInfoForm.details[inde][key] = this.valueRemoveZero(
						inde,
						key
					);
					this.storeObj.storeVal =
						this.baseInfoForm.details[inde][key];
				}
				if (key === 'taxPrice') {
					this.baseInfoForm.details[inde].taxPrice =
						taxPriceNumberRexgu(
							this.baseInfoForm.details[inde][key],
							this.unitpriceAccuracy
						);
					if (
						this.baseInfoForm.details[inde][key]
							.toString()
							.indexOf('.') !== -1
					) {
						let indexTax =
							this.baseInfoForm.details[
								inde
							].taxPrice.lastIndexOf('.');
						let newValue = this.baseInfoForm.details[
							inde
						].taxPrice.substring(
							indexTax + 1,
							this.baseInfoForm.details[inde][key].length
						);
						this.baseInfoForm.details[inde].taxPrice =
							newValue.length <= this.unitpriceAccuracy
								? this.baseInfoForm.details[inde].taxPrice
								: this.baseInfoForm.details[
										inde
								  ].taxPrice.slice(
										0,
										this.baseInfoForm.details[inde].taxPrice
											.length -
											(newValue.length -
												this.unitpriceAccuracy)
								  );
						document.getElementById(key + inde).value =
							this.baseInfoForm.details[inde][key];
					}
					this.countMethodsCom(inde, key);
					this.baseInfoForm.details[inde][key] = this.valueRemoveZero(
						inde,
						key
					);
					this.storeObj.storeVal =
						this.baseInfoForm.details[inde][key];
				}
				if (key === 'deliveryDate') {
					let comparD = compareDateMethods(
						this.baseInfoForm.date,
						value
					);
					if (comparD == false) {
						this.$message.error({
							message: '期望交期不能大于下单日期,请重新选择',
							showClose: true,
						});
						this.baseInfoForm.details[inde].deliveryDate = '';
					}
				}
				if (key === 'wareHouseId') {
					this.baseInfoForm.details[inde].isCusHouse = !isOpen;
					this.baseInfoForm.details[inde].wareHouseName = name;
				}
				if (key === 'customerStock') {
					this.baseInfoForm.details[inde].customerStockName = name;
				}
				if (key === 'settleOrg') {
					this.baseInfoForm.details[inde].settleOrgName = name;
				}
			}
		},
		// 清0
		valueRemoveZero(index, key) {
			if (
				this.baseInfoForm.details[index][key]
					.toString()
					.charAt(
						this.baseInfoForm.details[index][key].toString()
							.length - 1
					) != '.'
			) {
				return this.baseInfoForm.details[index][key] * 1;
			} else {
				return this.baseInfoForm.details[index][key];
			}
		},
		// 顶部公共按钮
		actionhandel(type) {
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			let ids = [];
			if (this.$route.query.id) {
				ids = [this.$route.query.id];
			}
			if (this.saveIds != '') {
				ids = [this.saveIds];
			}
			let details = [];
			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.OrdedetailIds = details; // 勾选的明细id集合
			if (type === 'push-down' && this.multipleSelection.length == 0) {
				this.$message.error({
					message: '请先选择要下推的明细行!',
					showClose: true,
				});
				return;
			}
			if (type === 'up-check' || type === 'down-check') {
				if (this.multipleSelection.length == 0) {
					this.$message.error({
						message: '请先选择要查询的明细行!',
						showClose: true,
					});
					return;
				}
			}
			//审批流追踪
			if (type == '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 == 'add') {
				this.$router.push({
					path: '/sale/salemange/orderCreate',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			if (type === 'save' || type === 'submit') {
				this.saveSubPageCom(type);
			}
			if (type === 'revoke') {
				this.revokePageData(ids);
			}
			if (type === 'audit' || type === 'de-approval') {
				this.unAuditPageDataCom(ids, type);
			}
			if (type === 'close' || type === 'de-close') {
				this.unCloseOrderCom(details, 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
								.showLoading(false)
								.get('SalOrder/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'
						? 'SalOrder/GetUpNumber'
						: 'SalOrder/GetPushDownNumber';
				let msg =
					type === 'up-check'
						? '没有可上查的单据!'
						: '没有可下查的单据!';
				let msgT = type === 'up-check' ? '上查结果' : '下查结果';
				this.$http.post(pathName, { ids: details }).then((res) => {
					if (res.status === 200) {
						if (res.data.length === 0 || res.data === []) {
							this.$message.error({
								message: msg,
								showClose: true,
							});
						} else {
							this.upOrDownList = res.data;
							this.dialogCX = true;
							this.CXttile = msgT;
							this.CXcheckVal =
								res.data && res.data.length === 1
									? res.data[0].orderType
									: null; //只有一个，就个默认值
						}
					}
				});
			}
			if (type === 'delet') {
				this.deleteOrder(ids);
			}
		},
		// 点击关闭 - 反关闭
		unCloseOrderCom(ids, type) {
			let msgT =
				type === 'close'
					? '只能关闭已审核的单据!'
					: '只能反关闭已审核的单据!';
			let msgTi =
				type === 'close'
					? '你确认要关闭所选单据行'
					: '你确认要反关闭所选单据行';
			let msgClose = type === 'close' ? '关闭成功' : '反关闭成功';
			let msgCatch = type === 'close' ? '未关闭成功' : '未反关闭成功';
			let msgError =
				type === 'close'
					? '请先选择需要关闭的单据行!'
					: '请先选择需要反关闭的单据行!';
			let pathName =
				type === 'close' ? 'SalOrder/Close' : 'SalOrder/Reclose';
			if (this.baseInfoForm.documentStatus === 'c') {
				if (ids.length > 0) {
					ElMessageBox.confirm(msgTi, '操作确认', {
						confirmButtonText: '确认',
						cancelButtonText: '取消',
						type: 'Success',
					})
						.then(() => {
							this.$http
								.post(pathName, { ids: ids })
								.then((res) => {
									if (res.status == 200) {
										ElMessage({
											type: 'success',
											message: msgClose,
											showClose: true,
										});
									}
								});
						})
						.catch(() => {
							ElMessage({
								type: 'info',
								message: msgCatch,
								showClose: true,
							});
						});
				} else {
					this.$message.error({ message: msgError, showClose: true });
				}
			} else {
				this.$message.error({ message: msgT, showClose: true });
			}
		},
		// 删除
		deleteOrder(ids) {
			if (ids.length > 0) {
				this.$http.post('SalOrder/Delete', { ids: ids }).then((r) => {
					if (r.status === 200) {
						if (r.status == 200) {
							if (r.data[0].isSuccess == false) {
								this.$message.error({
									message: r.data[0].msg,
									showClose: true,
								});
							} else {
								this.$store.state.topNavTag.tags.splice(
									this.$store.state.topNavTag.tags.findIndex(
										(item) => item.path === this.$route.path
									),
									1
								);
								this.$router.push(
									this.$store.state.topNavTag.tags[
										this.$store.state.topNavTag.tags
											.length - 1
									].path
								);
							}
						}
					}
				});
			} else {
				this.$message.error({
					message: '不能删除此单据!',
					showClose: true,
				});
			}
		},
		// 审核 - 反审
		unAuditPageDataCom(ids, type) {
			let pathName =
				type === 'audit' ? 'SalOrder/Check' : 'SalOrder/NoCheck';
			let innerIfKey = type === 'audit' ? 'b' : 'c';
			let msg = type === 'audit' ? '审核成功!' : '反审成功!';
			let changeDocKey = type === 'audit' ? 'c' : 'd';
			let booleanKey = type === 'audit' ? true : false;
			let msgO =
				type === 'audit'
					? '只能审核处于审核中的单据!'
					: '只能反审核处于已审核的单据!';
			if (type === 'audit' && this.baseInfoForm.documentStatus !== 'b') {
				return this.$message.error({
					message: '只能审核处于审核中的单据!',
					showClose: true,
				});
			} else if (
				type === 'de-approval' &&
				this.baseInfoForm.documentStatus !== 'c'
			) {
				return this.$message.error({
					message: '只能反审核处于已审核的单据!',
					showClose: true,
				});
			}
			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
								.showLoading(false)
								.post(
									'SalOrder/GetInfo/' + this.baseInfoForm.id
								)
								.then((req) => {
									if (req.status == 200) {
										req.data.details.forEach((el, ind) => {
											this.baseInfoForm.details[
												ind
											].purchaseNumber =
												el.purchaseNumber;
										});
										this.baseInfoForm = saveSubmitBackData(
											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('SalOrder/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) {
			this.baseInfoForm.details.forEach((el, ind) => {
				if (el.discountRate == '') {
					this.baseInfoForm.details[ind].discountRate = 0;
				}
			});
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				filterMaterialData(this.baseInfoForm);
				let listObjZreo = this.baseInfoForm.details.filter(
					(it) => it.isFree == false
				);
				let listObj = listObjZreo.filter((it) => it.taxPrice == 0);
				if (listObj.length > 0) {
					this.$message.error({
						message: '非赠品含税单价不能为0!',
						showClose: true,
					});
				} else {
					let pathName =
						type == 'save' ? 'SalOrder/Save' : 'SalOrder/Commit';
					this.$http
						.showLoading(true)
						.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) : false;
							}
						});
				}
			} else {
				this.$message.error({
					message: '只能保存或提交创建或重新审核的单据!',
					showClose: true,
				});
			}
		},

		// 处理保存、提交返回数据
		saveOrSubmitData(r) {
			if (r.data) {
				this.$http
					.showLoading(false)
					.post('SalOrder/GetInfo/' + r.data.id)
					.then((req) => {
						if (req.status == 200) {
							this.baseInfoForm = saveSubmitBackData(
								this.baseInfoForm,
								req
							);
							this.setExamine({
								status: r.status,
								data: r.data.tracking,
							});
						}
					});
				this.baseInfoForm.billNo = r.data.billNo;
				this.baseInfoForm.id = r.data.id;
				this.saveIds = r.data.id;
				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 = [];
				//minfat userId
			}
		},
		// 下推确定
		sumitPushdown(id) {
			this.CXcheckVal = id;
			if (id) {
				let result = {};
				result = pushDownSure(this.CXcheckVal);
				this.$http
					.post(result.pathName, { ids: this.OrdedetailIds })
					.then((res) => {
						if (res.status === 200) {
							this.dialogxt = false;
							this.$router.push({
								name: result.routerName,
								query: {
									type: 'pushDown',
									pushDownData: JSON.stringify(res.data),
									sjtag: Math.random() * 36,
								},
							});
						}
						this.dialogxt = false;
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		// 确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = '';
				let ary = [];
				pathName = searchOrder(this.CXcheckVal);
				ary = this.upOrDownList.filter((it) => {
					return it.orderType === this.CXcheckVal;
				});
				if (pathName) {
					this.dialogCX = false;
					this.$router.push({
						name: pathName,
						query: {
							detailsIds: JSON.stringify(ary[0].detailsIds),
							actionType:
								this.CXttile === '上查结果' ? 'up' : 'down',
							actionName: '销售订单',
							OrderNoNames: JSON.stringify(ary[0].billNos),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// 单价精度、金额精度计算
		countMethodsCom(id, key) {
			// console.log('this.baseInfoForm.details',this.baseInfoForm.details)
			let templateObject = countMethods(
				this.baseInfoForm.details,
				id,
				key,
				this.baseInfoForm.exchangeRate,
				this.unitpriceAccuracy,
				this.amountAccuracy
			);
			//   console.log('copy ---> ',templateObject)
			this.baseInfoForm.details = templateObject.details;
			this.baseInfoForm.taxaMount =
				templateObject.baseTaxaMount == ''
					? 0
					: templateObject.baseTaxaMount;
			this.baseInfoForm.amount =
				templateObject.baseAmount == '' ? 0 : templateObject.baseAmount;
			this.baseInfoForm.allAmount =
				templateObject.baseAllAmount == ''
					? 0
					: templateObject.baseAllAmount;
		},
		disabledCellStyle({ row, rowIndex, column, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		// 单据头统计
		countOrderHeader() {
			let taxaMount = 0;
			let amount = 0;
			let allAmount = 0;
			this.baseInfoForm.details.forEach((el) => {
				taxaMount = Decimal.add(
					taxaMount,
					el.taxaMount ? el.taxaMount : 0
				);
				amount = Decimal.add(amount, el.amount ? el.amount : 0);
				allAmount = Decimal.add(
					allAmount,
					el.allAmount ? el.allAmount : 0
				);
			});
			this.baseInfoForm.taxaMount = taxaMount;
			this.baseInfoForm.amount = amount;
			this.baseInfoForm.allAmount = allAmount;
		},
		// 星星
		mustAfter({ row, column, rowIndex, columnIndex }) {
			let arry = [1, 2, 8, 10, 23, 5, 6, 7];
			if (arry.indexOf(columnIndex) !== -1) {
				return 'must';
			}
		},
		// 插入的行
		getInsertInfo(data) {
			let result = insertRow(
				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.countMethodsCom(insertNum, 'taxPrice')
					this.selectBlur();
					this.countOrderHeader();
					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.countMethodsCom(lastIndex, 'taxPrice')
					});
					this.selectBlur();
					this.countOrderHeader();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
				}
			} else {
				this.$message.error({
					message: '请选择一行或多行复制!',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow() {
			if (
				this.baseInfoForm.details.length > 1 &&
				this.baseInfoForm.details.length !=
					this.multipleSelection.length
			) {
				if (this.selectRowIndexArr != 0) {
					this.selectRowIndexArr.sort(function (a, b) {
						return a.index - b.index;
					});
					for (let i = 0; i < this.selectRowIndexArr.length; i++) {
						this.baseInfoForm.details.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.customeStockArrylist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.matterallCodelist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.specificationalllist.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.salePrecisionNumber.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isPrecision.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
						this.isCount.splice(
							this.selectRowIndexArr[i].index - i,
							1
						);
					}
					this.selectBlur();
					this.countOrderHeader();
					this.$refs.multipleTable.clearSelection();
					this.multipleSelection = [];
					this.selectRowIndexArr = [];
					this.recordIndex = '';
				} else {
					this.$message.error({
						message: '请先选择要删除的行',
						showClose: true,
					});
				}
			} else {
				this.$message.error({
					message: '表格不能为空!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn() {
			let nextRow = this.storeObj.storeRow + 1;
			let storeKey = this.storeObj.storekey;
			if (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] =
											materSpecCarry(
												this.baseInfoForm.details[i],
												el
											);
										if (this.baseInfoForm.billtypeId) {
											if (
												this.baseInfoForm.billtypeId ===
												'b'
											) {
												this.baseInfoForm.details[
													i
												].taxPrice = el.cost;
											} else {
												this.baseInfoForm.details[
													i
												].taxPrice = '0';
											}
										} else {
											this.baseInfoForm.details[
												i
											].taxPrice = '0';
										}
										this.countMethodsCom(i, 'taxPrice');
									}
								});
							} else {
								if (key === 'wareHouseId') {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
									this.baseInfoForm.details[i].customerStock =
										'';
									this.baseInfoForm.details[
										i
									].customerStockName = '';
									let rowObj =
										this.statusForm.warehouse.filter(
											(it) =>
												this.baseInfoForm.details[i]
													.wareHouseId === it.id
										);
									this.baseInfoForm.details[i].wareHouseName =
										rowObj[0].name;
									if (
										this.baseInfoForm.details[i].wareHouseId
									) {
										this.baseInfoForm.details[
											i
										].isCusHouse =
											!rowObj[0].customerWarehouseTag;
									}
								} else if (
									key === 'taxRate' ||
									key === 'discountRate' ||
									key === 'taxPrice'
								) {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;

									if (key === 'taxPrice') {
										if (
											this.baseInfoForm.details[i].isFree
										) {
											this.baseInfoForm.details[i][
												key
											] = 0;
											this.baseInfoForm.details[
												i
											].isDisabled = true;
										}
									}
									this.countMethodsCom(i, key);
								} else if (key === 'salesNumber') {
									if (this.baseInfoForm.details[i].unitId) {
										this.baseInfoForm.details[i][key] =
											this.storeObj.storeVal;
										this.saleNumberPrecision(
											i,
											'salesNumber',
											'Y',
											'copy'
										);
										this.countMethodsCom(i, key);
									} else {
										this.baseInfoForm.details[i][key] =
											this.storeObj.storeVal;
										this.countMethodsCom(i, key);
									}
								} else {
									this.baseInfoForm.details[i][key] =
										this.storeObj.storeVal;
								}
							}
						}
					}
				}
			} else {
				this.$message.error({
					message: '客户仓库无法批量填充，请手动选择！',
					showClose: true,
				});
			}
		},
		// 单元格被点击
		getRowCol(row, column, cell) {
			let _that = this;
			_that.currRow = row.index;
			_that.storeObj.storeRow = row.index;
			_that.storeObj.storeCol = column.index;
			if (typeof cell === 'string') {
				_that.storeObj.storekey = cell;
			} else {
				_that.storeObj.storekey = column.property;
			}
			_that.storeObj.storeVal = row[_that.storeObj.storekey];
			if (_that.recordIndex != '' || _that.recordIndex == '0') {
				_that.baseInfoForm.details[
					_that.recordIndex
				].isMaterialShow = false;
				_that.baseInfoForm.details[_that.recordIndex].isSkuShow = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSaleShow = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isTaxPrice = false;
				_that.baseInfoForm.details[_that.recordIndex].isTaxRate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isWareHouse = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isCustomerStock = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isOrderreMarks = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDeliveryDate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isDiscountRate = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isSettleOrgName = false;
				_that.baseInfoForm.details[
					_that.recordIndex
				].isOnlineOrderNo = false;
				_that.baseInfoForm.details[_that.recordIndex].isBarCode = false;
			}
			switch (column.label) {
				case '物料编码':
					row.isMaterialShow = true;
					_that.recordIndex = row.index;
					break;
				case '规格型号(SKU)':
					row.isSkuShow = true;
					_that.recordIndex = row.index;
					break;
				case '销售数量':
					row.isSaleShow = 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.isWareHouse = true;
					_that.recordIndex = row.index;
					break;
				case '客户仓库':
					row.isCustomerStock = true;
					_that.recordIndex = row.index;
					break;
				case '期望交期':
					row.isDeliveryDate = true;
					_that.recordIndex = row.index;
					break;
				case '备注':
					row.isOrderreMarks = true;
					_that.recordIndex = row.index;
					break;
				case '折扣率%':
					row.isDiscountRate = true;
					_that.recordIndex = row.index;
					break;
				case '结算组织':
					row.isSettleOrgName = true;
					_that.recordIndex = row.index;
					break;
				case '线上订单号':
					row.isOnlineOrderNo = true;
					_that.recordIndex = row.index;
					break;
				case '条码':
					row.isBarCode = true;
					_that.recordIndex = row.index;
					break;
			}
			this.$nextTick(() => {
				let strArr = [
					'销售数量',
					'物料编码',
					'规格型号(SKU)',
					'含税单价',
					'税率%',
					'仓库',
					'客户仓库',
					'备注',
					'折扣率%',
					'结算组织',
					'线上订单号',
					'条码',
				];
				if (strArr.indexOf(column.label) !== -1) {
					document
						.getElementById(column.property + row.index)
						.focus();
				}
			});
		},
		// 单选
		selectRow(selection) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndex = selection[0].index;
				this.selectRowIndexArr = selection;
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 全选
		selectAll(selection) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (selection.length != 0) {
				this.selectRowIndexArr = selection;
				if (selection.length == 1) {
					this.selectRowIndex = 0;
				}
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 订单号 规则 - 限制
		saleRexgu(val, key) {
			this.baseInfoForm.billNo = orderRexgu(val, key);
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 获取汇率类型、汇率
		getExchangeType(templateObj) {
			this.baseInfoForm.exchangeRate =
				templateObj && templateObj.directRate
					? templateObj.directRate
					: null;
			this.baseInfoForm.exchangeTypeId =
				templateObj && templateObj.issueInvoiceId
					? templateObj.issueInvoiceId
					: null;
		},
		// 获取单价精度、金额精度
		getPriceAmountPrecision() {
			console.log(
				this.statusForm.setlementDifferences,
				'============setlementDifferences============'
			);
			let content = this.statusForm.setlementDifferences.filter(
				(it) => it.id === this.baseInfoForm.settlecurrId
			);
			console.log(content, '============content===============');
			if (content.length !== 0) {
				this.unitpriceAccuracy = content[0].unitpriceAccuracy;
				this.amountAccuracy = content[0].amountAccuracy;
			}
		},
		// 销售数量 精度处理 type Y 获取精度并重新计算数据 type N 获取精度不重新计算
		saleNumberPrecision(index, key, type, copy) {
			if (this.baseInfoForm.details[index].unitId) {
				let tempList = this.unitData.filter(
					(it) => it.id === this.baseInfoForm.details[index].unitId
				);
				console.log(tempList, '==========tempList===========');
				if (tempList && tempList.length > 0) {
					tempList[0].precision == 0
						? (this.isPrecision[index] = true)
						: (this.isPrecision[index] = false);
					tempList[0].precision == 0
						? (this.salePrecisionNumber[index] = 0)
						: (this.salePrecisionNumber[index] =
								tempList[0].precision);

					if (copy === 'copy') {
						if (tempList && tempList.length > 0) {
							tempList[0].roundoffType = 2;
							console.log('走到了这里copy');
						}
					}
					if (key && type && type == 'Y') {
						let result = countMethodsUnitNumber(
							tempList,
							this.baseInfoForm.details[index][key],
							this.baseInfoForm.details[index][key],
							this.isCount[index],
							this.salePrecisionNumber[index],
							true
						);
						this.baseInfoForm.details[index][key] = result.value;
						this.isCount[index] = result.isDefault;
					}
					console.log('走到了这里123232');
				}
			} else {
				if (key) {
					this.baseInfoForm.details[index][key] = Decimal(
						this.baseInfoForm.details[index][key]
					).toFixed(0, Decimal.ROUND_HALF_UP);
				}
			}
		},
		// 结算币别 值发生改变时 获取本位币 - 通过本位币与结算币别获取汇率类型与汇率 - 获取结算币别携带出来的单价精度、金额精度 - 改变明细信息里面相对应的小位数(精度)
		async settlecurrChange() {
			this.baseInfoForm.localcurrId = getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.saleorgId
			);
			let templateObj = await getTaxPrice(
				this.baseInfoForm.localcurrId,
				'SysConfig/GetRateInfo',
				this.baseInfoForm.settlecurrId
			);
			this.getExchangeType(templateObj);
			this.getPriceAmountPrecision();
			this.baseInfoForm.details.forEach((el, ind) => {
				el.taxPrice =
					Decimal(el.taxPrice).toFixed(this.unitpriceAccuracy) * 1;
				this.countMethodsCom(ind, 'taxPrice');
			});
		},
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setRecondtion: 'storeData/setRecondtion',
			setSettletype: 'storeData/setSettletype',
			setDcurrency: 'storeData/setDcurrency',
			setRateType: 'storeData/setRateType',
			setTaxRate: 'storeData/setTaxRate',
			setCustomer: 'storeData/setCustomer',
			setEnumType: 'storeData/setEnumType',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),
	},
	computed: {
		...mapState({
			orgIdArr: (state) => state.user.orgIdArr,
			userId: (state) => state.user.userInfo.staffId,
			orgId: (state) =>
				state && state.org && state.org.orgId ? state.org.orgId : null,
			tags: (state) => state.topNavTag.tags,
			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,
			enumType: (state) => state.storeData.enumType,
			getAllUserList: (state) => state.storeData.getAllUserList,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
		}),
		isShow: function () {
			return this.isExmaineTop;
		},
	},
	created: function () {
		this.Init();
		this.baseInfoForm.documentStatus = '';
		this.baseInfoForm.documentStatus = 'a';
		this.setApprovalFlowStatus();
	},
	watch: {
		'baseInfoForm.saleorgId': async function () {
			await this.monitorOrg();
			this.baseInfoForm.localcurrId = getBaseCurrency(
				this.orgIdArr,
				this.baseInfoForm.saleorgId
			);
			if (this.baseInfoForm.settlecurrId) {
				let templateObj = await getTaxPrice(
					this.baseInfoForm.localcurrId,
					'SysConfig/GetRateInfo',
					this.baseInfoForm.settlecurrId
				);
				this.getExchangeType(templateObj);
			}
			let tempWareHouse = [];
			if (this.baseInfoForm.billtypeId !== 'f') {
				tempWareHouse = this.statusForm.warehouse.filter(
					(it) => it.name != '大促临时存放仓'
				);
				this.statusForm.warehouse = tempWareHouse;
			}

			this.statusForm.warehouse = splitJointList(
				this.baseInfoForm.details,
				this.statusForm.warehouse,
				'stockList'
			);
			this.tempStoreWarehouse = this.statusForm.warehouse;
		},
		'baseInfoForm.billtypeId': async function (newVal, oldVal) {
			// this.statusForm.warehouse = await getStatusType('SysConfig/GetWarehouseByOrg/', this.baseInfoForm.saleorgId) // 根据组织 获取仓库
			let tempWareHouse = [];
			if (this.baseInfoForm.billtypeId !== 'f') {
				tempWareHouse = this.statusForm.warehouse.filter(
					(it) => it.name != '大促临时存放仓'
				);
				this.statusForm.warehouse = tempWareHouse;
			}
			if (oldVal === 'f' && newVal !== oldVal) {
				this.baseInfoForm.details.forEach((el, ind) => {
					this.baseInfoForm.details[ind].wareHouseId = '';
					this.baseInfoForm.details[ind].customerStock = '';
				});
			}
			this.tempStoreWarehouse = this.statusForm.warehouse;
		},
		'baseInfoForm.documentStatus'() {
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增销售订单');
				this.btnType = saleBtnAdd;
			} else {
				this.$topNavTagRename('编辑销售订单');
				this.btnType = saleBtnEdit;
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderCreate.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
