<!--仓库---销售发货--发货通知单的编辑设置 -->
<template>
	<div>
		<transition name="bounce">
			<examineTop
				v-if="isExmaineTop === 2"
				:radios="radios"
				@handleBtns="handleBtns"
				@handleOpen="handleOpen"
				:isexamineBtns="isexamineBtns"
			/>
			<!-- 	:isexamineBtns="isexamineBtns" -->
		</transition>
	</div>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="sale-details-container order-mc-bg main-container"
	>
		<div class="sale-details-btn-group">
			<!-- 顶部按钮 -->
			<template v-if="isExmaineTop !== 2">
				<toolBtn
					:btnType="btnType"
					:isDisable="isDisable"
					@actionhandel="actionhandel"
					:isExmaineTop="isShow"
				></toolBtn>
			</template>
		</div>
		<div class="sale-details-base-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				v-if="pagefromData.documentStatus === 'c'"
			/>
			<el-tabs style="margin-bottom: 8px" type="border-card">
				<!-- 基本信息 -->
				<el-tab-pane label="基本信息">
					<div class="base-info-form-box">
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<div class="order-number-bx item-bt-s">
											<el-form-item
												class="item-bt-s Iisshow"
												label="单据编号"
											>
												<el-input
													:maxlength="255"
													disabled
													placeholder="(保存时自动生成)"
													v-model.trim="
														pagefromData.billNO
													"
												></el-input>
												<div
													:data-clipboard-text="
														pagefromData.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="
													pagefromData.documentStatus
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in documentStatuslist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="单据类型"
										>
											<el-select
												disabled
												filterable
												v-model="
													pagefromData.documentType
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in documentTypelist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s item-date"
											label="下单日期"
										>
											<el-date-picker
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												format="YYYY-MM-DD"
												type="date"
												v-model="pagefromData.orderDate"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="发货组织"
										>
											<el-select
												disabled
												filterable
												placeholder="请选择组织"
												v-model="
													pagefromData.deliveryOrg
												"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													v-for="item in orgIdArr"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="销售组织"
										>
											<el-select
												@change="saleorgChange"
												disabled
												filterable
												placeholder="请选择组织"
												v-model="pagefromData.sellOrg"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in orgIdArr"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="客户"
										>
											<el-select
												@change="customersChange"
												disabled
												filterable
												placeholder="请选择客户"
												v-model="pagefromData.customers"
											>
												<el-option
													:key="item.id + 'a'"
													:label="item.name"
													:value="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in customerlist1"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="销售部门"
										>
											<el-cascader
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												:options="productDeptList"
												:props="optionProps"
												:show-all-levels="false"
												@change="saledeptorgChange"
												clearable
												placeholder="请选择部门"
												v-model="pagefromData.sellDept"
											></el-cascader>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="销售员"
										>
											<el-select
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												filterable
												placeholder="请选择"
												v-model="pagefromData.sellStaff"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in allPepolelist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="跟单员"
										>
											<el-select
												:disabled="
													(pagefromData.documentStatus !==
														'a' &&
														pagefromData.documentStatus !==
															'd') ||
													!pagefromData.sellDept
												"
												filterable
												placeholder="请选择"
												v-model="
													pagefromData.merchandiser
												"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in allPepolelist"
												></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="
															pagefromData.documentStatus !==
																'a' &&
															pagefromData.documentStatus !==
																'd'
														"
														maxlength="50"
														placeholder="请输入关键词"
														v-model.trim="
															pagefromData.logistics
														"
													></el-input>
													<div
														:data-clipboard-text="
															pagefromData.logistics
														"
														@click="saleOrderCopy"
														class="copyBtn copyBtnB"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="物流单号"
												>
													<el-input
														:disabled="
															pagefromData.documentStatus !==
																'a' &&
															pagefromData.documentStatus !==
																'd'
														"
														placeholder="请输入关键词"
														v-model="
															pagefromData.logisticsNo
														"
													></el-input>
													<div
														:data-clipboard-text="
															pagefromData.logisticsNo
														"
														@click="saleOrderCopy"
														class="copyBtn copyBtnB"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="联系人"
												>
													<el-input
														:disabled="
															pagefromData.documentStatus !==
																'a' &&
															pagefromData.documentStatus !==
																'd'
														"
														placeholder="请输入联系人"
														v-model="
															pagefromData.linkMan
														"
													></el-input>
													<div
														:data-clipboard-text="
															pagefromData.linkMan
														"
														@click="saleOrderCopy"
														class="copyBtn copyBtnB"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
												<el-form-item
													class="item-bt-s Iisshow"
													label="联系电话"
												>
													<el-input
														:disabled="
															pagefromData.documentStatus !==
																'a' &&
															pagefromData.documentStatus !==
																'd'
														"
														placeholder="请输入联系电话"
														v-model="
															pagefromData.linkPhone
														"
													></el-input>
													<div
														:data-clipboard-text="
															pagefromData.linkPhone
														"
														@click="saleOrderCopy"
														class="copyBtn copyBtnB"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
											</el-col>
										</el-row>
										<el-row
											:gutter="10"
											class="custom-address-row"
										>
											<el-col
												:span="12"
												class="custom-address-col"
											>
												<el-form-item
													class="item-bt-s Iisshow"
													label="客户地址"
												>
													<el-input
														:disabled="
															pagefromData.documentStatus !==
																'a' &&
															pagefromData.documentStatus !==
																'd'
														"
														placeholder="请输入客户地址"
														v-model.trim="
															pagefromData.linkAdress
														"
													></el-input>
													<div
														:data-clipboard-text="
															pagefromData.linkAdress
														"
														@click="saleOrderCopy"
														class="copyBtn copyBtnB"
													>
														<i
															class="el-icon-document-copy"
														/>
													</div>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<!-- 财务信息 -->
				<el-tab-pane label="财务信息">
					<div class="base-info-form-box">
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算组织"
										>
											<el-select
												disabled
												filterable
												placeholder="请选择组织"
												v-model="pagefromData.settleOrg"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in orgIdArr"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="结算币别"
										>
											<el-select
												disabled
												v-model="
													pagefromData.settleCurrency
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in dcurrencyList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="结算方式"
										>
											<el-select
												v-model="
													pagefromData.settleMode
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in settletypeList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="收款条件"
										>
											<el-select
												v-model="
													pagefromData.collectionTerms
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in recconditionList"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											class="item-bt-s"
											label="本位币"
										>
											<el-select
												:disabled="true"
												placeholder="请选择结算币别"
												v-model="
													pagefromData.localcurrId
												"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in dcurrencyList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="汇率类型"
										>
											<el-select
												disabled
												v-model="
													pagefromData.exchangeTypeId
												"
											>
												<el-option
													:key="item.value"
													:label="item.name"
													:value="item.id"
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in rateTypeList"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="汇率"
										>
											<el-input
												disabled
												placeholder
												v-model="
													pagefromData.exchangeRate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<!-- 操作记录 -->
				<el-tab-pane :disabled="!pagefromData.id" label="操作记录">
					<div
						:style="{ height: '185px!important' }"
						class="base-info-form-box"
					>
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="pagefromData1"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="创建人"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													pagefromData.createName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="创建日期"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													pagefromData.createDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											class="item-bt-s"
											label="最后修改人"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													pagefromData.modifyName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													pagefromData.modifyDate
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="提交时间"
										>
											<el-input
												disabled
												placeholder
												v-model.trim="
													pagefromData.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
														placeholder
														v-model.trim="
															pagefromData.checkName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														disabled
														placeholder
														v-model.trim="
															pagefromData.checkDate
														"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<!-- 明细信息 -->
		<div class="sale-details-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="
						pagefromData.documentStatus !== 'a' &&
						pagefromData.documentStatus !== 'd'
					"
					@copyCellcolumn="copyCellcolumn"
					@copyRow="bottomCopyRow"
					@deleteRow="selectDeleteRow"
					@insertObj="getInsertInfo"
				></DetailsOperation>
			</div>
			<!-- 表格信息-->
			<div class="tell-info-table">
				<el-table
					:cell-class-name="tableCellClassName"
					:data="pagefromData.details"
					:header-cell-class-name="mustAfter"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectRowAll"
					border
					max-height="400"
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
				>
					<el-table-column
						align="center"
						fixed
						type="selection"
						width="40"
					/>
					<el-table-column
						align="left"
						label="销售订单号"
						prop="parentOrderBillNo"
						width="190"
					/>
					<el-table-column
						align="left"
						label="物料编码"
						prop="materialNumber"
						width="190"
					/>
					<el-table-column
						align="left"
						label="规格型号(SKU)"
						prop="specification"
						width="190"
					/>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="190"
					/>
					<el-table-column
						align="left"
						label="销售单位"
						prop="unit"
						width="108"
					>
						<template #default="scope">
							<span>{{
								publicidbyname(unitlist, scope.row.unit)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						prop="salesNumber"
						width="130"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>销售数量
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'salesNumber' + scope.$index"
								@blur="
									numberChage(
										scope.row.salesNumber,
										scope.$index,
										scope.row,
										'salesNumber'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'salesNumber'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'salesNumber'
									)
								"
								maxlength="11"
								placeholder
								v-if="scope.row.issalesNumbershow"
								v-model="scope.row.salesNumber"
							></el-input>
							<span v-else>{{ scope.row.salesNumber }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="累计出库数量"
						prop="stockOutNumber"
						width="130"
					>
						<template #default="scope">
							<span>{{
								scope.row.stockOutNumber
									? scope.row.stockOutNumber
									: 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="剩余未出数量"
						prop="remainOutNumber"
						width="130"
					>
						<template #default="scope">
							<span>{{
								scope.row.remainOutNumber
									? scope.row.remainOutNumber
									: 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" label="含税单价" width="130">
						<template #default="scope">
							<span>{{
								numAccuracy(
									scope.row.taxPrice,
									unitpriceAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="税率%"
						prop="taxRate"
						width="130"
					>
						<template #default="scope">
							<span>{{ numAccuracy(scope.row.taxRate, 4) }}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="stockId" width="150">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>出货仓库
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'stockId'
									)
								"
								filterable
								placeholder="请选择"
								v-if="scope.row.isstockIdshow"
								v-model="scope.row.stockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in warehouse"
								></el-option>
							</el-select>
							<span v-else>{{
								publicidbyname(warehouse, scope.row.stockId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户仓库"
						prop="customerStockName"
						width="150"
					/>
					<el-table-column
						align="left"
						prop="deliveryDate"
						width="200"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>期望交期
						</template>
						<template #default="scope">
							<el-date-picker
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'deliveryDate'
									)
								"
								class="date-input"
								format="YYYY-MM-DD"
								placeholder="选择日期"
								type="date"
								v-if="scope.row.isdeliveryDateshow"
								v-model="scope.row.deliveryDate"
								value-format="YYYY-MM-DD"
							></el-date-picker>
							<span v-else>{{ scope.row.deliveryDate }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="是否赠品"
						prop="isFree"
						width="108"
					>
						<template #default="scope">
							<span>{{ scope.row.isFree ? '是' : '否' }}</span>
						</template>
					</el-table-column>
					<!--含税单价/(1+税率) -->
					<el-table-column
						align="left"
						label="单价"
						prop="price"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									parseFloat(scope.row.taxPrice) /
										(1 + scope.row.taxRate / 100),
									unitpriceAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<!-- 含税单价×数量-折扣额-->
					<el-table-column
						align="left"
						label="价税合计"
						prop="allAmount"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									parseFloat(
										scope.row.salesNumber
											? scope.row.salesNumber
											: 0
									) *
										scope.row.taxPrice -
										scope.row.disCount,
									amountAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="价税合计(本位币)"
						prop="allAmountLc"
						width="140"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									(parseFloat(
										scope.row.salesNumber
											? scope.row.salesNumber
											: 0
									) *
										scope.row.taxPrice -
										scope.row.disCount) *
										pagefromData.exchangeRate,
									amountAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="折扣率%"
						prop="discountRate"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									parseFloat(scope.row.discountRate),
									4
								)
							}}</span>
						</template>
					</el-table-column>
					<!-- 折扣额=折扣率×含税单价×数量-->
					<el-table-column
						align="left"
						label="折扣额"
						prop="disCount"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									(scope.row.discountRate / 100) *
										scope.row.taxPrice *
										parseFloat(
											scope.row.salesNumber
												? scope.row.salesNumber
												: 0
										),
									amountAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<!-- 税额 = 价税合计×税率/(1+税率)-->
					<el-table-column
						align="left"
						label="税额"
						prop="taxaMount"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									((parseFloat(
										scope.row.salesNumber
											? scope.row.salesNumber
											: 0
									) *
										scope.row.taxPrice -
										(scope.row.discountRate / 100) *
											scope.row.taxPrice *
											parseFloat(
												scope.row.salesNumber
													? scope.row.salesNumber
													: 0
											)) *
										(scope.row.taxRate / 100)) /
										(1 + scope.row.taxRate / 100),
									amountAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="金额"
						prop="amount"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									(parseFloat(
										scope.row.salesNumber
											? scope.row.salesNumber
											: 0
									) *
										scope.row.taxPrice -
										(scope.row.discountRate / 100) *
											scope.row.taxPrice *
											parseFloat(
												scope.row.salesNumber
													? scope.row.salesNumber
													: 0
											)) /
										(1 + scope.row.taxRate / 100),
									amountAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="金额(本位币)"
						prop="amountLc"
						width="108"
					>
						<template #default="scope">
							<span>{{
								numAccuracy(
									((parseFloat(
										scope.row.salesNumber
											? scope.row.salesNumber
											: 0
									) *
										scope.row.taxPrice -
										(scope.row.discountRate / 100) *
											scope.row.taxPrice *
											parseFloat(
												scope.row.salesNumber
													? scope.row.salesNumber
													: 0
											)) /
										(1 + scope.row.taxRate / 100)) *
										pagefromData.exchangeRate,
									amountAccuracy
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="是否211"
						prop="is211"
						width="108"
					>
						<template #default="scope">
							<span>{{ scope.row.is211 ? '是' : '否' }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="供应链"
						prop="supplyChainName"
						width="108"
					/>
					<el-table-column
						align="left"
						label="销售订单下单日期"
						prop="salDate"
						width="150"
					/>
					<el-table-column
						align="left"
						label="供应组织"
						prop="supplyOriginName"
						width="150"
					/>
					<el-table-column
						align="left"
						label="默认供应商"
						prop="defaultSupplierName"
						width="200"
					></el-table-column>
					<el-table-column
						align="left"
						prop="onlineOrderNo"
						width="255"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>线上/客户订单号
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'onlineOrderNo' + scope.$index"
								:maxlength="255"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'onlineOrderNo'
									)
								"
								v-if="scope.row.isonlineOrderNoshow"
								v-model="scope.row.onlineOrderNo"
							></el-input>
							<span v-else>{{ scope.row.onlineOrderNo }}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="barcode" width="255">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>条码
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'barcode' + scope.$index"
								:maxlength="255"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'barcode'
									)
								"
								v-if="scope.row.isbarcodeshow"
								v-model="scope.row.barcode"
							></el-input>
							<span v-else>{{ scope.row.barcode }}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="remark" width="300">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'remark' + scope.$index"
								:maxlength="2000"
								@click="
									getRowCol(scope.row, scope.column, 'remark')
								"
								v-if="scope.row.isremarkshow"
								v-model.trim="scope.row.remark"
							></el-input>
							<span v-else>{{ scope.row.remark }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="关闭人"
						prop="closeStaff"
						width="150"
					/>
					<el-table-column
						align="left"
						label="关闭时间"
						prop="closeDate"
						width="150"
					/>
				</el-table>
			</div>
		</div>
		<!-- 操作结果 -->
		<el-dialog title="操作结果" v-model="dialogVisible" width="40%">
			<div class="sale-page-table-body">
				<el-table
					:data="tableInfo"
					:header-cell-class-name="headerRigthMethod"
					border
					class="table-box"
					height="300"
					id="tableInfo-table"
				>
					<el-table-column label="序号" prop="date" width="50">
						<template #default="scope">
							<span>{{ scope.$index + 1 }}</span>
						</template>
					</el-table-column>
					<el-table-column
						label="订单单号"
						prop="orderNo"
						width="200"
					></el-table-column>
					<el-table-column label="指令" prop="a" width="110">
						<template #default>
							<span>{{
								actionType === 'submit'
									? '提交'
									: actionType === 'revoke'
									? '撤销'
									: actionType === 'audit'
									? '审核'
									: actionType === 'de-approval'
									? '反审'
									: actionType === 'delet'
									? '删除'
									: actionType === 'finish'
									? '完工'
									: actionType === 'close-case'
									? '结案'
									: actionType === 'de-excute-start'
									? '反执行至开工'
									: actionType === 'de-approval'
									? '反审'
									: actionType === 'delet'
									? '删除'
									: actionType === 'finish'
									? '完工'
									: actionType === 'close-case'
									? '结案'
									: actionType === 'de-excute-finish'
									? '反执行至完工'
									: ''
							}}</span>
						</template>
					</el-table-column>
					<el-table-column label="结果" width="80">
						<template #default="scope">
							<span :style="{ 'txt-Red': scope.row.isSuccess }">{{
								scope.row.isSuccess ? '成功' : '失败'
							}}</span>
						</template>
					</el-table-column>
					<el-table-column label="信息" prop="msg">
						<template #default="scope">
							<span class="txt-Red">{{ scope.row.msg }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<span
						class="f-12 ext-black-light"
						style="margin-right: 25px"
						>共{{
							tableInfo && tableInfo.length > 0
								? tableInfo.length
								: 0
						}}条</span
					>
					<el-button
						@click="
							handelhtmlToExcel('tableInfo-table', '操作结果');
							dialogVisible = false;
						"
						size="small"
						>导 出</el-button
					>
					<el-button
						@click="dialogVisible = false"
						size="small"
						type="primary"
						>关 闭</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择下推单据 -->
		<el-dialog
			title="选择下推单据"
			top="15%"
			v-model="dialogxt"
			width="20%"
		>
			<div class="sale-page-table-body">
				<el-radio-group v-model="pushdownVal">
					<el-radio :label="1">销售出库单</el-radio>
				</el-radio-group>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="dialogxt = false" size="small"
						>取 消</el-button
					>
					<el-button
						@click="sumitPushdown"
						size="small"
						type="primary"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择上下查单据 -->
		<el-dialog :title="CXttile" top="15%" v-model="dialogCX" width="20%">
			<div class="sale-page-table-body">
				<el-radio-group
					v-if="CXttile === '上查结果'"
					v-model="CXcheckVal"
				>
					<el-radio
						:key="index"
						:label="it.orderType"
						v-for="(it, index) in upOrDownList"
						>{{ it.orderName }}({{ it.orderCount }})</el-radio
					>
				</el-radio-group>
				<el-radio-group
					v-if="CXttile === '下查结果'"
					v-model="CXcheckVal"
				>
					<el-radio
						:key="index"
						:label="it.orderType"
						v-for="(it, index) in upOrDownList"
						>{{ it.orderName }}({{ it.orderCount }})</el-radio
					>
				</el-radio-group>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="dialogCX = false" size="small"
						>取 消</el-button
					>
					<el-button @click="submitCX" size="small" type="primary"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<script>
import examineTop from '@/components/examineTop/index.vue';
import toolBtn from '@/components/public/toolBtn/toolBtn.vue';

import { mapState } from 'vuex';
import { unitPriceMethods } from '@/utils/util';
import { countMethodsUnitNumber } from '@/utils/count.js';
import { orderCopy } from '@/utils/takeMethods';
import {
	transformTimestamp,
	getObjValue,
	theUnitSet,
	batchhandle,
	quikecopyValue,
	oldstocklist,
	htmlToExcel,
} from '@/utils/pubulic.js';
import { pageoPtionProps } from '@/utils/printPagekey.js';

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

export default {
	components: {
		examineTop,
		toolBtn,
	},
	name: 'SaleDeliveryAddnotice',
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			radios: [],
			examineObj: {},
			salePrecisionNumber: [],
			isPrecision: [],
			isCount: [],
			isDisable: false,
			optionProps: JSON.parse(JSON.stringify(pageoPtionProps)),
			detailBtn: ['add', 'copy'],
			customeStocklist: [], // 客户仓库下拉数据
			CXcheckVal: '', // 上下查选中
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrdedetailIds: [], // 勾选的明细id集合
			OrderNoNames: [], // 选择的单据订单号集合
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			multipleSelection: [], // 明细列表选中
			dialogVisible: false, // 操作弹框显示
			tableInfo: [], //操作结果
			actionType: '', // 操作动作 新增还是修改还是编辑
			documentStatuslist: [], // 单据状态
			pickmtStatuslist: [], // 领料状态
			documentTypelist: [], // 单据类型
			matterCodelist: [], // 物料下拉数据
			specificationlist: [], // 规格型号（sku）下拉数据
			unitlist:
				this.$store.state && this.$store.state.storeData.allUnit
					? this.$store.state.storeData.allUnit
					: [], // 获取计量单位数据
			productDeptList: [], // 销售部门
			customerList1: [], // 客户下数据
			allPepolelist: [], // 根据人员
			dcurrencyList: [], // 结算币别的下拉数据
			settletypeList: [], // 结算方式下拉数据
			recconditionList: [], // 收款条件下拉数据
			rateTypeList: [], // 汇率类型
			warehouse: [], //仓库下拉数据
			CXttile: '',
			pagefromData: {
				id: 0, // 单据的id
				billNO: '', // 单据编号
				documentStatus: '', // 单据状态
				documentType: 'a', // 单据类型
				orderDate: transformTimestamp(new Date()), // 下单日期
				deliveryOrg: '', // 发货组织
				sellOrg: '', // 销售组织
				customers: '', // 客户
				sellDept: '', // 销售部门
				sellStaff: '', // 销售员
				merchandiser: '', // 跟单员
				logistics: '', // 物流/快递
				logisticsNo: '', // 物流单号
				linkMan: '', // 联系人
				linkPhone: '', // 联系电话
				linkAdress: '', // 客户地址
				settleOrg: '', // 结算组织
				settleCurrency: '', // 结算币别
				settleMode: '', // 结算方式
				collectionTerms: '', // 收款条件
				localcurrId: '', // 本位币
				exchangeTypeId: '', // 汇率类型
				exchangeRate: '', // 汇率
				details: [],
			},
			btnType: [], // 不需要显示的顶部按钮类型
			//明细数据
			addRow: {
				id: 0, // 主键
				seq: 0, // 序号
				parentOrderId: '', // 上游明细id
				parentOrderType: '', // 上游单据类型
				parentOrderNumber: '', // 上游单据销售数量
				parentOrderBillNo: '', // 销售订单号
				materialId: null, //物料id
				materialName: '', //物料名称
				specification: '', //规格型号
				salUnit: null, // 销售单位
				salesNumber: null, //销售数量
				stockOutNumber: 0, // 累计出库数量
				remainOutNumber: 0, // 剩余未出库数量
				taxPrice: 0, //含税单价
				taxRate: 0, //税率%
				stockId: '', //出货仓库
				stockPositionId: '', //出货仓位
				expectDate: '', // 期望交期
				isFree: '', //是否赠品
				price: 0, //单价
				allAmount: 0, //价税合计
				allAmountLc: 0, //价税合计(本位币)
				discountRate: 0, //折扣率%
				disCount: 0, //折扣额
				taxaMount: 0, //税额
				amount: 0, //金额
				amountLc: 0, //金额(本位币)
				salDate: '', //销售订单下单日期
				onlineOrderNo: '', //线上订单号
				barcode: '', // 条码
				remark: '', //备注
			},
			unitpriceAccuracy: null, //单价精度
			amountAccuracy: null, //金额精度
			selectRowIndexArr: [],
			selectRowIndex: '', // 当前 选择行
			// 批量填充
			batchfill: {
				romIndex: null,
				columnIndex: null,
				columnkey: null,
			},
			heightNum: 0,
		};
	},
	watch: {
		'pagefromData.documentStatus'(newvalue, oldvalue) {
			if (
				this.pagefromData.documentStatus === 'a' ||
				!this.pagefromData.documentStatus
			) {
				this.$topNavTagRename('新增发货通知单');
			} else {
				this.$topNavTagRename('编辑发货通知单');
			}
			if (
				this.pagefromData.documentStatus === 'a' ||
				this.pagefromData.documentStatus === 'd'
			) {
				this.btnType = [
					'add',
					'copy',
					'revoke',
					'audit',
					'de-approval',
					'delete',
					'push-down',
					'operation',
					// 'query',
					'up-check',
					'down-check',
					'refresh',
					's-p-t-g3',
					// 's-p-t-g4',
				]; // 不需要显示的顶部按钮类型
			} else {
				this.btnType = [
					'add',
					'print-aterial-list',
					'copy',
					'delet',
					'de-excute-finish',
					'de-excute-start',
					'close-case',
					'split-order',
					'finish',
					'export',
					'print-aterial-list',
					'print-brower',
					'delete',
					's-p-t-g5',
				]; // 不需要显示的顶部按钮类型
			}
		},
	},
	computed: {
		...mapState({
			orgId: (state) => (state && state.user ? state.user.orgId : null),
			userId: (state) => state.user.userInfo.staffId || null,
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),

			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,

			getPageObjValue: function () {
				// 根据key值显示对应的键名
				return function (arr, key) {
					return getObjValue(arr, key);
				};
			},

			isShow: function () {
				return this.isExmaineTop;
			},
			// 精度处理
			numAccuracy() {
				// 根据key值显示对应的键名
				return function (value, numdigit) {
					if (value) {
						if (numdigit) {
							return numdigit
								? unitPriceMethods(
										parseFloat(value).toFixed(numdigit)
								  )
								: unitPriceMethods(parseFloat(value));
						}
					} else {
						return 0;
					}
				};
			},
		}),
		publicidbyname: function () {
			// 根据key值显示对应的键名
			return function (arr, key) {
				return theUnitSet(arr, key);
			};
		},
	},
	created() {
		this.setApprovalFlowStatus();
	},
	mounted() {
		this.heightNum =
			document.documentElement.clientHeight - (40 + 30 + 16 + 16);
		this.pagefromData.details = [JSON.parse(JSON.stringify(this.addRow))];
		this.Init();
	},
	methods: {
		setExamine(res) {
			if (
				res.status === 200 &&
				res.data &&
				JSON.stringify(res.data) !== '{}'
			) {
				this.examineObj = res.data;
				//有审批流,但是自己不能审批则返回1,否则返回2,如果没有审批流或者报错为了不阻断流程返回3
				let isApprover = res.data.isApprover;
				this.isExmaineTop = isApprover ? 2 : 1;
				if (
					!res.data ||
					JSON.stringify(res.data) === '{}' ||
					this.pagefromData.documentStatus !== 'b'
				) {
					this.isExmaineTop = 3;
				}
				if (res.data.isDone) {
					this.pagefromData.documentStatus = 'c';
					this.isExmaineTop = 3;
				}
				// console.log(
				// 	this.baseInfoForm.documentStatus,
				// 	'=========this.baseInfoForm.documentStatus='
				// );
				// if (this.baseInfoForm.documentStatus !== 'b') {
				// 	this.isExmaineTop = 3;
				// }
				this.isexamineBtns = false;
			} else {
				this.isExmaineTop = 3;
				this.isexamineBtns = false;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('DeliveryNoticeOrder/GetInfo/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.getDcurrency(req.data.settleCurrency);
						this.setpageDate(req);
						this.pagefromData.documentStatus =
							req.data.documentStatus;
						if (
							this.pagefromData.documentStatus === 'a' ||
							this.pagefromData.documentStatus === 'd'
						) {
							this.isEdit = false;
						}
						this.setExamine(r);
					}
				});
			// this.saveIds = r.data.id;
			// this.baseInfoForm = purGetOrderId(this.baseInfoForm, r);
			this.$refs.multipleTable.clearSelection();
			this.multipleSelection = [];
			this.selectRowIndexArr = [];
		},
		handleSubmit(data) {
			this.isexamineBtns = true;
			this.$http
				.post(approvalFlowTrackingUpdate, data)
				.then((res) => {
					if (res.status === 200) {
						this.$message.success({
							message: '操作成功!',
							showClose: true,
						});
					}
					this.handleDetails(res);
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				})
				.finally(() => {
					// this.isexamineBtns = false;
				});
		},
		//顶部按钮点击
		handleBtns(vals) {
			if (vals.type === 'out') {
				this.$router.go(-1);
			} else {
				let data = {
					approvalDetailsId: this.examineObj.approvalDetailsId,
					approvalOrderType: this.examineObj.sendOrderType,
					orderId: this.examineObj.sendOrderId,
					orgId: this.pagefromData.settleOrg,
					deptId: this.pagefromData.sellDept,
					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.pagefromData.outSourcOrderNo === ''
			) {
				this.examineObj = {};
				return;
			}
			if (data.tracking && data.tracking.remark) {
				this.$message.error({
					message: `单据由-${data.tracking.remark}`,
					showClose: true,
					duration: 5000,
				});
			}

			if (
				data.documentStatus === 'a' ||
				data.documentStatus == 'd' ||
				this.$route.query.type === 'copy'
			) {
				this.examineObj = data.tracking;
				return;
			}
			let obj = {
				orderId: data.id,
				deptId: data.sellDept || 0,
				approvalOrderType: 5,
				orgId: data.settleOrg,
			};
			this.$http
				.post(approvalFlowTrackingGetby, obj)
				.then((res) => {
					if (res.status === 200) {
						this.setExamine(res);
						let details = res.data.details || [];
						let length = details.length;

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

		Init() {
			this.getAllcustomer();
			this.getWarehouse();
			this.getUnit();
			this.getOrgPepole();
			this.getStatus();
			this.getSettletype();
			this.getReccondition();
			this.getRateType();
		},
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 快粘贴
		pasteExcel(event, index, scope, key) {
			let rows = quikecopyValue(event);
			let recordAddIndex = index; // 记录行
			setTimeout(async () => {
				rows.forEach((it, idx) => {
					if (
						recordAddIndex + 1 <=
						this.pagefromData.details.length
					) {
						if (key === 'salesNumber') {
							this.pagefromData.details[recordAddIndex][key] = it;
						}
						recordAddIndex++;
					}
				});
			}, 10);
		},
		// 获取组织的所有人
		getOrgPepole() {
			var userlistall =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.userlistall
					: [];
			if (
				JSON.stringify(
					this.$store.state && this.$store.state.storeData
						? this.$store.state.storeData.userlistall
						: []
				) === '[]'
			) {
				this.$http.get('SysConfig/GetUserList').then((req) => {
					this.allPepolelist = req.data;
				});
			} else {
				this.allPepolelist = userlistall;
			}
		},
		// 获取路由传过来的值
		getRuterData() {
			if (
				this.$route.query.pushDownData &&
				this.$route.query.type === 'pushDown'
			) {
				let thedata = JSON.parse(
					decodeURIComponent(this.$route.query.pushDownData)
				);
				this.getDcurrency(thedata.settleCurrency);
				this.setpageDate({ data: thedata });
			}
		},
		//确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = '';
				if (this.CXcheckVal === 7) {
					// 销售订单
					pathName = 'SaleOrder';
				}
				if (this.CXcheckVal === 4) {
					// 销售出库单
					pathName = 'WarehouseSalesDeliveryExWarehouse';
				}
				let ary = [];
				ary = this.upOrDownList.filter((it) => {
					return it.orderType === this.CXcheckVal;
				});
				if (pathName) {
					this.$router.push({
						name: pathName,
						query: {
							detailsIds: JSON.stringify(
								ary.length > 0 ? ary[0].detailsIds : []
							),
							actionType:
								this.CXttile === '上查结果' ? 'up' : 'down',
							actionName: '销售发货通知单',
							OrderNoNames: JSON.stringify(
								ary.length > 0 ? ary[0].billNos : []
							),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// 下推确定
		sumitPushdown() {
			if (this.pushdownVal) {
				let pathName = '';
				let routerName = '';
				if (this.pushdownVal === 1) {
					// 销售出库单
					pathName = 'DeliveryNoticeOrder/PushDownSalOutStockOrder';
					routerName = 'SaleDeliveryAddexWarehouse';
				}
				this.$http
					.post(pathName, { ids: this.OrdedetailIds })
					.then((res) => {
						if (res.status === 200) {
							this.$router.push({
								name: routerName,
								query: {
									type: 'pushDown',
									pushDownData: JSON.stringify(res.data),
								},
							});
							console.log('下推', res);
						}
						this.dialogxt = false;
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		// 基本信息客户下拉监听
		customersChange(value) {
			// 获取客户根据客户自己id
			// this.$http.get('SysConfig/GetCustomerById/' + value).then(res => {
			this.$http
				.get('SysConfig/GetCustomerById', {
					cusId: value,
					orgId: this.pagefromData.sellOrg,
				})
				.then((res) => {
					if (res.status === 200) {
						this.saledeptorgChange(res.data.sellDept);
						this.pagefromData.sellDept = res.data.sellDept; // 销售部门
						this.pagefromData.sellStaff = res.data.sellPerson; // 销售员
						this.pagefromData.merchandiser = res.data.salesMan; // 跟单员
						this.pagefromData.linkMan = res.data.linkMan; // 联系人
						this.pagefromData.linkPhone = res.data.linkphone; // 联系电话
						this.pagefromData.linkAdress = res.data.address; // 客户地址
						this.pagefromData.collectionTerms =
							res.data.recconditionCode; //收款条件
						this.pagefromData.settleCurrency = res.data.settlecurr; //结算币别
					}
				});
			// 获取客户仓库
			if (this.pagefromData.details.length > 0) {
				this.pagefromData.details.forEach((it) => {
					it.customerStock = '';
				});
				this.$http
					.get(
						'SysConfig/GetWareouseByCompAndCusto/' +
							this.pagefromData.deliveryOrg,
						{ companyId: value }
					)
					.then((res) => {
						if (res.status === 200) {
							this.customeStocklist = res.data;
						}
					});
			}
		},
		// 获取结算币别
		getDcurrency(id) {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.dcurrency
					: [];
			var tagstr = JSON.stringify(
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.dcurrency
					: []
			);
			if (tagstr === '[]' || !tagstr) {
				this.$http.get('SysConfig/GetDcurrency').then((res) => {
					if (res.status === 200) {
						this.dcurrencyList = [];
						this.dcurrencyList =
							this.$store.state.storeData.dcurrency = res.data;
						if (id) {
							let ar = [];
							ar = res.data.filter((res) => {
								return res.id === id;
							});
							if (ar && ar.length > 0) {
								this.amountAccuracy = ar[0].amountAccuracy;
								this.unitpriceAccuracy =
									ar[0].unitpriceAccuracy;
							}
						}
					}
				});
			} else {
				this.dcurrencyList = [];
				this.dcurrencyList = infocustomerlist;
				if (id) {
					let ar = [];
					ar = this.dcurrencyList.filter((res) => {
						return res.id === id;
					});
					if (ar && ar.length > 0) {
						this.amountAccuracy = ar[0].amountAccuracy;
						this.unitpriceAccuracy = ar[0].unitpriceAccuracy;
					}
				}
			}
		},
		// 获取结算方式
		getSettletype() {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.settletype
					: [];
			var tagstr = JSON.stringify(
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.settletype
					: []
			);
			if (tagstr === '[]' || !tagstr) {
				this.$http.get('SysConfig/GetSettletype').then((res) => {
					if (res.status === 200) {
						this.settletypeList = [];
						this.settletypeList =
							this.$store.state.storeData.settletype = res.data;
					}
				});
			} else {
				this.settletypeList = infocustomerlist;
			}
		},
		// 获取收款条件
		getReccondition() {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.recondtion
					: [];
			var tagstr = JSON.stringify(
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.recondtion
					: []
			);
			if (tagstr === '[]' || !tagstr) {
				this.$http.get('SysConfig/GetReccondition').then((res) => {
					if (res.status === 200) {
						this.recconditionList = [];
						this.recconditionList =
							this.$store.state.storeData.recondtion = res.data;
					}
				});
			} else {
				this.recconditionList = infocustomerlist;
			}
		},
		// 获取汇率类型
		getRateType() {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.rateType
					: [];
			var tagstr = JSON.stringify(
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.rateType
					: []
			);
			if (tagstr === '[]' || !tagstr) {
				this.$http.get('SysConfig/GetRateType').then((res) => {
					if (res.status === 200) {
						this.rateTypeList = [];
						this.rateTypeList =
							this.$store.state.storeData.rateType = res.data;
					}
				});
			} else {
				this.rateTypeList = infocustomerlist;
			}
		},
		// 保存或者提交的时候，对数据个别字段例如 is211 seq 做数据整理，避免提交保存失败
		arrangeData(type) {
			if (this.pagefromData.details) {
				let newDetails = this.pagefromData.details.map((v, index) => {
					return { ...v, seq: index };
				});
				if (!type) {
					this.pagefromData.details = newDetails.filter((item) => {
						return item.salesNumber && item.salesNumber !== '0';
					});
				} else {
					this.pagefromData.details = newDetails;
				}
				// 清空明细选中
				this.$refs.multipleTable.clearSelection();
				this.selectRowIndexArr = [];
			}
		},
		// 初始化--编辑或者详情
		InItEditorCopy() {
			// 如果是复制，编辑，查看--过来的新增订单
			if (
				this.$route.query &&
				this.$route.query.type !== 'add' &&
				this.$route.query.productId
			) {
				this.getProductInfo(this.$route.query.productId);
			}
		},
		// 销售组织下拉改变是 （会影响销售部门的数据）
		saleorgChange(value, type) {
			if (type !== 'init' || !type) {
				this.pagefromData.customers = null;
				this.pagefromData.sellDept = null;
			}
			this.getProductdept(value, type);
		},
		// 销售部门下拉改变（会影响基础数据的销售员跟单员）
		saledeptorgChange(deptID, type) {
			if (type !== 'init' || !type) {
				this.pagefromData.sellStaff = null;
				this.pagefromData.merchandiser = null;
			}
		},
		numberPrecisionMethods(index, unit, S, P, C) {
			if (this.pagefromData.details[index][unit]) {
				let tempList = this.unitlist.filter(
					(it) => it.id === this.pagefromData.details[index][unit]
				);
				if (tempList && tempList.length > 0) {
					tempList[0].precision == 0
						? (this[P][index] = true)
						: (this[P][index] = false);
					tempList[0].precision == 0
						? (this[S][index] = 0)
						: (this[S][index] = tempList[0].precision);
				}
			}
			this[P][index] = this[P][index] ? this[P][index] : false;
			this[S][index] =
				this[S][index] || this[S][index] == 0 ? this[S][index] : 10;
			if (
				!this.pagefromData.details[index].materialNumber &&
				!this.$route.query.id
			) {
				this[P][index] = true;
			}
			if (!this[C][index]) {
				this[C][index] = 1;
			}
		},
		// 数量改变时
		numberChage(val, index, item, key) {
			// 判断条件 子单位
			this.numberPrecisionMethods(
				index,
				'unit',
				'salePrecisionNumber',
				'isPrecision',
				'isCount'
			);
			// 输入规则
			if (val) {
				if (val.toString().indexOf('.') !== -1) {
					let tempList = this.unitlist.filter(
						(it) => it.id === this.pagefromData.details[index].unit
					);
					if (tempList && tempList.length > 0) {
						tempList[0].roundoffType = 2;
					}
					let result = countMethodsUnitNumber(
						tempList,
						val,
						this.pagefromData.details[index][key],
						this.isCount[index],
						this.salePrecisionNumber[index]
					);
					this.pagefromData.details[index][key] = result.value * 1;
					this.isCount[index] = result.isDefault;
				}
				let numD = '';
				let count = '\\d';
				for (
					let ind = 0;
					ind < this.salePrecisionNumber[index];
					ind++
				) {
					numD = numD + count;
				}
				let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
				this.pagefromData.details[index][key] =
					this.pagefromData.details[index][key]
						.toString()
						.replace(/[^\d^\\.]+/g, '')
						.replace('.', '$#$')
						.replace(/\./g, '')
						.replace('$#$', '.')
						.replace(eval(reg), '$1$2.$3');
			}
			// 未入库数量 = 数量-合格入库数量
			this.pagefromData.details[index].noStockEligibleNumber =
				parseInt(item.number ? item.number : 0) -
				parseInt(item.stockEligibleNumber);
		},
		async setpageDate(res) {
			this.billNO = res.data.billNO;
			this.pagefromData = JSON.parse(JSON.stringify(res.data));
			this.pagefromData.localcurrId = res.data.localcurrId;
			this.pagefromData.documentStatus = res.data.documentStatus
				? res.data.documentStatus
				: 'a';
			this.pagefromData.orderDate = res.data.orderDate
				? res.data.orderDate
				: transformTimestamp(new Date());
			this.pagefromData.documentType = res.data.documentType
				? res.data.documentType
				: 'a';
			this.pagefromData.exchangeTypeId = parseInt(
				res.data.exchangeTypeId
			);
			this.actionType =
				this.pagefromData.documentStatus === 'a' ||
				this.pagefromData.documentStatus === 'd' ||
				!this.pagefromData.documentStatus
					? 'edit'
					: 'see';
			if (
				this.$route.query.type === 'pushDown' ||
				!this.pagefromData.documentStatus
			) {
				this.actionType = 'add';
			}
			this.documentStatus = res.data.documentStatus;
			this.pagefromData.sellOrg = res.data.sellOrg
				? parseInt(res.data.sellOrg)
				: '';
			// 详情里面根据组织id去获取明细的关联下拉数据
			this.saleorgChange(res.data.sellOrg, 'init');
			// 详情里面根据部门id去获取明细的关联下拉数据
			this.saledeptorgChange(res.data.sellDept, 'init');
			if (this.$route.query.type === 'pushDown') {
				await this.$http
					.get('SysConfig/GetUnitAllProperty')
					.then((r) => {
						if (r.status === 200) {
							this.unitlist = r.data;
						}
					});
			}
			if (res.data.details) {
				res.data.details.forEach((it, index) => {
					this.pagefromData.details[index].seq = index;
					if (this.$route.query.type === 'pushDown') {
						// 判断条件 子单位
						this.numberPrecisionMethods(
							index,
							'unit',
							'salePrecisionNumber',
							'isPrecision',
							'isCount'
						);
						let tempList = this.unitlist.filter(
							(it) =>
								it.id === this.pagefromData.details[index].unit
						);
						let result = countMethodsUnitNumber(
							tempList,
							this.pagefromData.details[index].salesNumber,
							this.pagefromData.details[index].salesNumber,
							this.isCount[index],
							this.salePrecisionNumber[index]
						);
						this.pagefromData.details[index].salesNumber =
							result.value;
						this.isCount[index] = result.isDefault;
					}
				});
			} else {
				this.pagefromData.details = [
					JSON.parse(JSON.stringify(this.addRow)),
				];
			}
		},
		// 获取销售出库单详情
		getProductInfo(prodctId) {
			this.$http
				.get('DeliveryNoticeOrder/GetInfo/' + prodctId)
				.then((res) => {
					if (res.status === 200) {
						this.getDcurrency(res.data.settleCurrency);
						this.setpageDate(res);
						this.setApprovalFlowTrackingGetby(res.data);
					}
				});
		},
		getUnit() {
			var unitlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.allUnit
					: [];
			if (
				JSON.stringify(
					this.$store.state && this.$store.state.storeData
						? this.$store.state.storeData.allUnit
						: []
				) === '[]'
			) {
				this.$http.get('SysConfig/GetUnitAllProperty').then((r) => {
					if (r.status === 200) {
						this.unitlist = this.$store.state.storeData.allUnit =
							r.data;
					}
				});
			} else {
				this.unitlist = unitlist;
			}
		},
		// 获取需要状态列表---[单据状态，领料状态，业务状态]
		getStatus() {
			var infoStatus =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.infoNoticeStatus
					: {};
			var tagstr = JSON.stringify(
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.infoNoticeStatus
					: {}
			);
			if (tagstr === '{}' || !tagstr) {
				this.$http.get('DeliveryNoticeOrder/GetStatus').then((r) => {
					if (r.status === 200) {
						this.documentStatuslist = r.data.documentStatus;
						this.documentTypelist = r.data.documentType;
						this.pagefromData.documentType = Object.keys(
							r.data.documentType
						)[0];
						this.$store.state.storeData.infoNoticeStatus = r.data;
					}
				});
			} else {
				this.documentStatuslist = infoStatus.documentStatus;
				this.documentTypelist = infoStatus.documentType;
				this.pagefromData.documentType = Object.keys(
					infoStatus.documentType
				)[0];
			}
		},
		// 物料/规格型号--下拉更新
		metterChange(val, index, type) {
			let metterInfo = {};
			if (type !== 'specification') {
				//物料
				metterInfo = this.matterCodelist.filter((res) => {
					return val === res.id;
				})[0];
			} else {
				//规格型号
				metterInfo = this.specificationlist.filter((res) => {
					return val === res.specifications;
				})[0];
			}
			if (type === 'specification') {
				// 规格型号改变
				this.matterCodeChange(metterInfo.number);
				this.pagefromData.details[index].materialId = metterInfo.id;
			}
			this.pagefromData.details[index].specification =
				metterInfo.specifications; // sku
			this.pagefromData.details[index].materialName = metterInfo.name; // 物料名称
			this.pagefromData.details[index].materialNumber = metterInfo.number;
			this.pagefromData.details[index].unit = metterInfo.baseUnitId; // 销售单位
			this.pagefromData.details[index].supplyorg = metterInfo.paezOrgName; // 供应组织
			this.pagefromData.details[index].is211 = metterInfo.is211; // 是否211
			this.pagefromData.details[index].supplyChain =
				metterInfo.supplyChain; // 供应链
			this.pagefromData.details[index].defaultSupplier =
				metterInfo.defaultSupplierName; // 默认供应商
			this.pagefromData.details[index].taxRate = metterInfo.taxRateNmae; // 税率
		},
		// 获取物料编码信息
		matterCodeChange(val) {
			if (val !== '') {
				setTimeout(() => {
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', {
							name: val,
							file: 'Number',
							orgId: this.pagefromData.sellOrg,
							isIncludeServerorCost: true,
						})
						.then((res) => {
							if (res.status === 200) {
								this.matterCodelist = res.data;
							}
						});
				}, 200);
			} else {
				this.matterCodelist = [];
			}
		},
		// 获取物料规格型号信息
		specificationChange(val) {
			if (val !== '') {
				setTimeout(() => {
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', {
							name: val,
							file: 'Specifications',
							orgId: this.pagefromData.sellOrg,
							isIncludeServerorCost: true,
						})
						.then((res) => {
							if (res.status === 200) {
								this.specificationlist = res.data;
							}
						});
				}, 200);
			} else {
				this.matterCodelist = [];
			}
		},
		//顶部按钮操作栏
		actionhandel(type) {
			// 提取明细id
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);

			let detailsIds = [];
			if (
				this.pagefromData.details &&
				this.pagefromData.details.length > 0
			) {
				detailsIds = [
					...new Set(
						this.multipleSelection
							.filter((item) => {
								if (item.id) {
									return item.id;
								}
							})
							.map((it) => {
								return it.id;
							})
					),
				];
			}
			// 取单据订单号
			let orderNoArry = [
				...new Set(
					this.multipleSelection.map((item) => {
						return item.billNO;
					})
				),
			];
			this.OrderNoNames = [];
			this.OrderNoNames = orderNoArry;
			this.OrdedetailIds = detailsIds; // 勾选的明细id集合击新增
			//点击保存
			if (type === 'save') {
				this.savePageData();
			}
			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 === 'submit') {
				this.submitPageData();
			}
			//点击撤销
			if (type === 'revoke') {
				this.toolarFn('DeliveryNoticeOrder/Revoke');
			}
			//点击审核
			if (type === 'audit') {
				this.toolarFn('DeliveryNoticeOrder/Check');
			}
			//点击反审核
			if (type === 'de-approval') {
				this.toolarFn('DeliveryNoticeOrder/NoCheck');
			}
			// 点击关闭
			if (type === 'close') {
				if (detailsIds.length > 0) {
					this.$http
						.post('DeliveryNoticeOrder/Close', { ids: detailsIds })
						.then((res) => {
							if (res.status === 200) {
								this.$message.success({
									message: '关闭成功',
									showClose: true,
								});
								this.getProductInfo(this.pagefromData.id);
							}
						});
				} else {
					this.$message.error({
						message: '请先选择要下推的明细行！',
						showClose: true,
					});
				}
			}
			// 点击反关闭
			if (type === 'de-close') {
				if (detailsIds.length > 0) {
					this.$http
						.post('DeliveryNoticeOrder/Reclose', {
							ids: detailsIds,
						})
						.then((res) => {
							if (res.status === 200) {
								this.$message.success({
									message: '反关闭成功',
									showClose: true,
								});
								this.getProductInfo(this.pagefromData.id);
							}
						});
				} else {
					this.$message.error({
						message: '请先选择要下推的明细行！',
						showClose: true,
					});
				}
			}
			// 点击下推
			if (type === 'push-down') {
				if (detailsIds.length > 0) {
					if (detailsIds.length <= 20) {
						if (this.pagefromData.documentStatus !== 'c') {
							this.$message.error({
								message:
									'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
								showClose: true,
							});
						} else {
							this.dialogxt = true;
						}
					} else {
						this.$message.warning({
							message: '最多一次性下推二十条明细',
							showClose: true,
						});
					}
				} else {
					this.$message.warning({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能下推',
						showClose: true,
					});
				}
			}
			// 点击查询--上查
			if (type === 'up-check') {
				if (detailsIds.length > 0) {
					this.$http
						.post('DeliveryNoticeOrder/GetUpNumber', {
							ids: detailsIds,
						})
						.then((res) => {
							if (res.status === 200) {
								this.upOrDownList = res.data;
								if (res.data.length > 0) {
									this.dialogCX =
										res.data && res.data.length > 0
											? true
											: false;
									this.CXttile = '上查结果';
									this.CXcheckVal =
										res.data && res.data.length === 1
											? res.data[0].orderType
											: null; //只有一个，就个默认值
								} else {
									this.$message.warning({
										message: '未查询到上下游关联数据！',
										showClose: true,
									});
								}
							}
						});
				} else {
					this.$message.error({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能上查',
						showClose: true,
					});
				}
			}
			// 点击查询--下查
			if (type === 'down-check') {
				if (detailsIds.length > 0) {
					this.$http
						.post('DeliveryNoticeOrder/GetDownNumber', {
							ids: detailsIds,
						})
						.then((res) => {
							if (res.status === 200) {
								this.upOrDownList = res.data;
								if (res.data.length > 0) {
									this.dialogCX =
										res.data && res.data.length > 0
											? true
											: false;
									this.CXttile = '下查结果';
									this.CXcheckVal =
										res.data && res.data.length === 1
											? res.data[0].orderType
											: null; //只有一个，就个默认值
								} else {
									this.$message.error({
										message: '未查询到上下游关联数据！',
										showClose: true,
									});
								}
							}
							console.log('下查', res, this.upOrDownList);
						});
				} else {
					this.$message.warning({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能下查',
						showClose: true,
					});
				}
			}
		},
		// 保存或者提交成功返回数据处理
		saveOrsumitData(res) {
			this.billNO = res.data.billNO;
			this.pagefromData.id = res.data.id;
			this.pagefromData.dataSources = res.data.dataSources;
			this.pagefromData.date = transformTimestamp(res.data.date);
		},
		// 精度处理
		theNumAccuracy(value, numdigit) {
			// 根据key值显示对应的键名
			if (value) {
				if (numdigit) {
					return numdigit
						? unitPriceMethods(parseFloat(value).toFixed(numdigit))
						: unitPriceMethods(parseFloat(value));
				}
			} else {
				return 0;
			}
		},
		setPagefromData(data) {
			let newdata = this.pagefromData;
			newdata.details.forEach((it, index) => {
				it.price = this.theNumAccuracy(
					it.taxPrice / (1 + it.taxRate / 100),
					this.unitpriceAccuracy
				); //单价
				it.allAmount = this.theNumAccuracy(
					parseFloat(
						parseFloat(it.salesNumber) ? it.salesNumber : 0
					) *
						it.taxPrice -
						it.disCount,
					this.amountAccuracy
				); //价税合计
				it.allAmountLc = this.theNumAccuracy(
					(parseFloat(it.salesNumber ? it.salesNumber : 0) *
						it.taxPrice -
						it.disCount) *
						this.pagefromData.exchangeRate,
					this.amountAccuracy
				); //价税合计（本位币）
				it.disCount = this.theNumAccuracy(
					(it.discountRate / 100) *
						it.taxPrice *
						parseFloat(it.salesNumber ? it.salesNumber : 0),
					this.amountAccuracy
				); //折扣额
				it.taxaMount = this.theNumAccuracy(
					((parseFloat(it.salesNumber ? it.salesNumber : 0) *
						it.taxPrice -
						it.disCount) *
						(it.taxRate / 100)) /
						(1 + it.taxRate / 100),
					this.amountAccuracy
				); //税额
				it.amount = this.theNumAccuracy(
					(parseFloat(it.salesNumber ? it.salesNumber : 0) *
						it.taxPrice -
						it.disCount) /
						(1 + it.taxRate / 100),
					this.amountAccuracy
				); //金额
				it.amountLc = this.theNumAccuracy(
					((parseFloat(it.salesNumber ? it.salesNumber : 0) *
						it.taxPrice -
						it.disCount) /
						(1 + it.taxRate / 100)) *
						this.pagefromData.exchangeRate,
					this.amountAccuracy
				);
				//金额(本位币)
			});
			return newdata;
		},
		// 保存---[不需要做必填校验]
		savePageData() {
			this.arrangeData();
			this.$http
				.post('DeliveryNoticeOrder/Save', this.setPagefromData())
				.then((res) => {
					if (res.status === 200) {
						// this.saveOrsumitData(res)
						this.pagefromData = JSON.parse(
							JSON.stringify(res.data)
						);
						this.$message.success({
							message: '保存成功',
							showClose: true,
						});
					}
				});
		},
		// 提交
		submitPageData() {
			this.arrangeData();
			this.$http
				.post('DeliveryNoticeOrder/Commit', this.setPagefromData())
				.then((res) => {
					if (res.status === 200) {
						// this.saveOrsumitData(res)
						this.pagefromData = JSON.parse(
							JSON.stringify(res.data)
						);
						this.setExamine({
							status: res.status,
							data: res.data.tracking,
						});
						this.$message.success({
							message: '提交成功',
							showClose: true,
						});
					}
				});
		},
		// 顶部操作方法-有公共的部分封装下
		toolarFn(path, detailsIds) {
			let formdata = detailsIds
				? {
						ids: [this.pagefromData.id],
						detailsIds: detailsIds,
				  }
				: { ids: [this.pagefromData.id] };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					if (res.data && !detailsIds) {
						res.data[0].isSuccess
							? this.$message.success({
									message: res.data[0].msg
										? res.data[0].msg
										: '成功',
									showClose: true,
							  })
							: this.$message.error({
									message: res.data[0].msg,
									showClose: true,
							  });
					} else {
						this.dialogVisible = true;
						this.tableInfo = res.data;
					}
					this.getProductInfo(this.pagefromData.id);
				}
			});
		},
		// 获取仓库
		getWarehouse() {
			this.$http
				.get('SysConfig/GetWarehouseByOrg/' + this.orgId)
				.then((r) => {
					if (r.status === 200) {
						this.warehouse =
							r.data && r.data.length > 0
								? oldstocklist(
										r.data.concat(
											oldstocklist(
												this.pagefromData.details
											).stockList
										),
										'retrieve'
								  )
								: oldstocklist(
										oldstocklist(this.pagefromData.details)
											.stockList,
										'retrieve'
								  );
					}
				});
		},
		// 星星--头部必填ico显示
		mustAfter(obj) {
			let arry = [6, 11];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 获取生产部门数据
		getProductdept(orgId) {
			if (orgId) {
				this.$http.post('SysConfig/GetDept/' + orgId).then((res) => {
					if (res.status === 200) {
						this.productDeptList = res.data;
					}
				});
			}
		},
		// 获取全部公司客户
		getAllcustomer() {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.customerlist
					: [];
			if (JSON.stringify(infocustomerlist) === '[]') {
				this.$http.get('SysConfig/GetCustomer').then((res) => {
					if (res.status === 200) {
						this.customerlist1 = res.data;
						this.$store.state.storeData.customerlist = res.data;
						this.InItEditorCopy();
						this.getRuterData();
					}
				});
			} else {
				this.customerlist1 = infocustomerlist;
				this.InItEditorCopy();
				this.getRuterData();
			}
		},
		// 插入的行
		getInsertInfo(data) {
			if (data.insertTopVal != 0) {
				for (let i = 0; i < data.insertTopVal; i++) {
					this.pagefromData.details.splice(
						this.selectRowIndex,
						0,
						JSON.parse(JSON.stringify(this.addRow))
					);
					this.selectRowIndex = parseInt(this.selectRowIndex) + 1;
				}
			}
			if (data.insertBottomVal != 0) {
				for (let i = 0; i < data.insertBottomVal; i++) {
					var num = this.selectRowIndex + 1;
					this.pagefromData.details.splice(
						num,
						0,
						JSON.parse(JSON.stringify(this.addRow))
					);
				}
			}
			this.arrangeData('明细');
		},
		// 向下复制行
		bottomCopyRow(data) {
			// 判断行数
			if (this.selectRowIndexArr.length == 1) {
				const tableArr = JSON.parse(
					JSON.stringify(
						this.pagefromData.details[this.selectRowIndex]
					)
				);
				tableArr.id = 0;
				var insertNum = this.selectRowIndex + 1;
				this.pagefromData.details.splice(insertNum, 0, tableArr);
				this.arrangeData('明细');
			} else {
				this.$message.error({
					message: '请勾选一条行,在操作',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			if (this.selectRowIndexArr.length <= 0) {
				this.$message.warning({
					message: '请选择要删除的行!',
					showClose: true,
				});
				return;
			}
			// 不能为空
			if (
				this.pagefromData.details.length > 1 &&
				this.selectRowIndexArr.length < this.pagefromData.details.length
			) {
				this.selectRowIndexArr.forEach((k) => {
					this.pagefromData.details.forEach((l, index) => {
						if (k === l.seq) {
							this.pagefromData.details.splice(index, 1);
						}
					});
				});
				this.arrangeData('明细');
			} else {
				this.$message.warning({
					message: '至少保留一行!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn(data) {
			let batcharry = [
				'salesNumber',
				'stockId',
				'deliveryDate',
				'onlineOrderNo',
				'barcode',
				'remark',
			];
			this.pagefromData = batchhandle(
				this.pagefromData,
				this.matterallCodelist,
				this.batchfill.romIndex,
				this.batchfill.columnkey,
				batcharry
			);
			for (
				let i = this.batchfill.romIndex + 1;
				i < this.pagefromData.details.length;
				i++
			) {
				// 重新判断数量精度
				if (this.batchfill.columnkey == 'salesNumber') {
					this.numberChage(
						this.pagefromData.details[i].salesNumber,
						i,
						this.pagefromData.details[i],
						'salesNumber'
					);
				}
			}
		},
		//注意这里是解构
		tableCellClassName({ row, column, rowIndex, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		getRowCol(row, column, cell, event) {
			this.batchfill.romIndex = row.index;
			this.batchfill.columnIndex = column.index;
			if (typeof cell === 'string') {
				this.batchfill.columnkey = cell;
			} else {
				this.batchfill.columnkey = column.property;
			}
			// 处理表格下拉框输入框显示隐藏
			this.pagefromData.details.forEach((it, index) => {
				Object.assign(it, {
					issalesNumbershow: false,
					isstockIdshow: false,
					isdeliveryDateshow: false,
					isonlineOrderNoshow: false,
					isbarcodeshow: false,
					isremarkshow: false,
				});
			});
			var showtagarry = [
				'issalesNumbershow',
				'isstockIdshow',
				'isdeliveryDateshow',
				'isonlineOrderNoshow',
				'isbarcodeshow',
				'isremarkshow',
			];
			var parentshowtagarry = [
				'salesNumber',
				'stockId',
				'deliveryDate',
				'onlineOrderNo',
				'barcode',
				'remark',
			];
			showtagarry.forEach((k, idx) => {
				if (column.property == parentshowtagarry[idx]) {
					this.pagefromData.details[row.index][k] = true;
					this.$nextTick((_) => {
						if (
							document.getElementById(column.property + row.index)
						) {
							document
								.getElementById(column.property + row.index)
								.focus();
						}
					});
				}
			});
		},
		// 明细选择行的数据处理
		selectdataSet(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (row) {
				this.selectRowIndex = row.seq;
			}
			if (selection && selection.length > 0) {
				this.selectRowIndex = selection[0].seq;
			}
			if (selection.length != 0) {
				this.selectRowIndexArr = selection.map((it) => {
					return it.seq;
				});
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 选择全部明细(全选)
		selectRowAll(selection) {
			this.selectdataSet(selection);
		},
		// 选择的行（单选）
		selectRow(selection, row) {
			this.selectdataSet(selection);
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderDetails.scss';
@import '@/assets/style/saleOrder/common.scss';

::v-deep(.div-col .el-input__inner) {
	padding: 0 30px 0 8px;
	width: 165px !important;
}

::v-deep(.date-input .el-input__inner) {
	padding-left: 30px !important;
}
</style>
