<template>
	<div class="main-container order-mc-bg">
		<PrintModel
			v-show="false"
			:printData="{
				tableData: multipleSelection,
				orderName: '分步式调出单',
			}"
			:theadDate="theadDate"
		></PrintModel>
		<div
			class="sale-container"
			:style="{ height: containerHeight + 'px!important' }"
		>
			<toolBtn @actionhandel="actionhandel" :btnType="btnType"></toolBtn>
			<div class="TopInfo" v-if="OrderNoNameslist.length > 0">
				关联查询：
				<strong>{{ OrderNoNameStr }}</strong>
				<strong>{{ OrderNoNameslist.length > 5 ? '等' : '' }}</strong>
				{{ $route.query.actionName ? $route.query.actionName : '' }}所选
				<strong>{{ OrderNoNameslist.length }}</strong
				>条明细行的 <strong>{{ CXaction }}</strong
				>结果
			</div>
			<div class="sale-page-body">
				<div class="sale-page-table-header" ref="getSaleTableHeader">
					<el-form :inline="true">
						<el-row class="form-row1">
							<el-col :span="20">
								<el-row :gutter="2">
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="分步式调出单号"
										>
											<el-input
												v-model.trim="orderNum"
												placeholder="请输入订单号"
												class="f_12"
												@keyup.enter="searchList"
												@input="
													searchCom(
														orderNum,
														'billNo',
														'ipt'
													)
												"
											></el-input>
											<div
												:data-clipboard-text="orderNum"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item label="单据状态">
											<el-select
												v-model="billStatus"
												filterable
												placeholder="选择状态"
												:clearable="true"
												@change="
													clearCom(
														billStatus,
														'documentStatus'
													)
												"
											>
												<el-option
													class="f_12"
													v-for="(
														value, key, index
													) in statusForm.documentStatus"
													@click="
														searchCom(
															billStatus,
															'documentStatus',
															'opt'
														)
													"
													:key="key + index"
													:label="value"
													:value="key"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="产品"
										>
											<el-input
												v-model.trim="product"
												placeholder="请输入物料名称/编码/SKU"
												@keyup.enter="searchList"
												class="f_12"
												@input="
													searchCom(
														product,
														'product',
														'ipt'
													)
												"
											></el-input>
											<div
												:data-clipboard-text="product"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item label="下单日期">
											<el-date-picker
												class="f_12 item-date"
												v-model="date"
												format="YYYY-MM-DD"
												value-format="YYYY-MM-DD"
												type="date"
												@change="
													searchCom(
														date,
														'date',
														'opt'
													)
												"
												placeholder="年/月/日"
											></el-date-picker>
										</el-form-item>
									</el-col>
									<el-col :span="8"></el-col>
								</el-row>
							</el-col>
							<el-col :span="4" class="form-row-lastcol">
								<el-row :gutter="2">
									<el-col :span="24">
										<el-form-item class="form-group1">
											<div
												class="alias-open"
												@click="openRow"
											>
												<span
													class="iconfont"
													:class="[
														isDown
															? 'icon-shuangjiantouzhankai-xia'
															: 'icon-shuangjiantoushouqi-shang',
													]"
												></span>
											</div>
											<el-button
												size="small"
												@click="resetSearch"
												>重置</el-button
											>
											<el-button
												type="primary"
												size="small"
												@click="searchList"
												>搜索</el-button
											>
										</el-form-item>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
						<el-row class="form-row2" v-show="rowShow">
							<el-col :span="21">
								<el-row :gutter="2">
									<el-col :span="5">
										<el-form-item label="调出库存组织">
											<el-select
												v-model="stockOrgId"
												:clearable="true"
												placeholder="请选择调出组织"
												@change="
													clearCom(
														stockOrgId,
														'stockOrgId'
													)
												"
											>
												<el-option
													class="f_12"
													v-for="item in statusForm.allocationOrg"
													@click="
														searchCom(
															item.id,
															'stockOrgId',
															'opt'
														)
													"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="5">
										<el-form-item label="调出仓库">
											<el-select
												v-model="srcStockId"
												:clearable="true"
												placeholder="请选择调出仓库"
												@change="
													clearCom(
														srcStockId,
														'srcStockId'
													)
												"
											>
												<el-option
													class="f_12"
													v-for="item in statusForm.callOutHouse"
													@click="
														searchCom(
															item.id,
															'srcStockId',
															'opt'
														)
													"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="5">
										<el-form-item label="调入库存组织">
											<el-select
												v-model="stockinOrgId"
												:clearable="true"
												placeholder="请选择调入组织"
												@change="
													clearCom(
														stockinOrgId,
														'stockinOrgId'
													)
												"
											>
												<el-option
													class="f_12"
													v-for="item in statusForm.allocationOrg"
													@click="
														searchCom(
															item.id,
															'stockinOrgId',
															'opt'
														)
													"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="5">
										<el-form-item label="调入仓库">
											<el-select
												v-model="destStockId"
												:clearable="true"
												placeholder="请选择调入仓库"
												@change="
													clearCom(
														destStockId,
														'destStockId'
													)
												"
											>
												<el-option
													class="f_12"
													v-for="item in statusForm.transferHouse"
													@click="
														searchCom(
															item.id,
															'destStockId',
															'opt'
														)
													"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="4"></el-col>
								</el-row>
								<el-row :gutter="2" class="form-row2-row2">
									<el-col :span="8" class="form-r2-r2-col">
										<el-form-item label="自定义条件1">
											<CustomCondition
												:getCustomerItem="statusForm"
												@result="
													resultCom(
														$event,
														'customerSel1',
														'customerObj1',
														'tempObj1'
													)
												"
												:key="compKey1"
												:reset="reset"
											></CustomCondition>
										</el-form-item>
									</el-col>
									<el-col :span="8">
										<el-form-item label="自定义条件2">
											<CustomCondition
												:getCustomerItem="statusForm"
												@result="
													resultCom(
														$event,
														'customerSel2',
														'customerObj2',
														'tempObj2'
													)
												"
												:key="compKey2"
												:reset="reset"
											></CustomCondition>
										</el-form-item>
									</el-col>
									<el-col :span="8">
										<el-form-item label="自定义条件3">
											<CustomCondition
												:getCustomerItem="statusForm"
												@result="
													resultCom(
														$event,
														'customerSel3',
														'customerObj3',
														'tempObj3'
													)
												"
												:key="compKey3"
												:reset="reset"
											></CustomCondition>
										</el-form-item>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div
					class="sale-page-table-body"
					:style="{ height: heightNum + 'px' }"
				>
					<el-table
						class="table-box"
						:data="tableData"
						border
						ref="tableInfoRef"
						style="width: 100%; font-size: 12px"
						:max-height="heightNum"
						:header-cell-style="headerBg"
						v-loading="tableLoading"
						@cell-click="openDetails"
						@row-dblclick="openDetailsDB"
						@selection-change="handleSelectionChange"
					>
						<el-table-column
							type="selection"
							align="center"
							width="40"
							fixed
						/>
						<el-table-column
							prop="salOrderBillNo"
							label="销售订单号"
							align="left"
							width="187"
							fixed
						/>
						<el-table-column
							prop="organizationOrderBillNo"
							label="组织间需求单号"
							align="left"
							width="172"
							fixed
						/>
						<el-table-column
							prop="billNo"
							label="分步式调出单号"
							align="left"
							width="172"
							fixed
						>
							<template #default="scope">
								<span style="color: #4178d5">{{
									scope.row.billNo
								}}</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="billType"
							label="业务类型"
							align="center"
							width="72"
						/>
						<el-table-column
							prop="date"
							label="下单日期"
							align="left"
							width="90"
						/>
						<el-table-column
							prop="documentStatus"
							label="单据状态"
							align="center"
							width="72"
						/>
						<el-table-column
							prop="stockOrg"
							label="调出库存组织"
							align="left"
							width="172"
						/>
						<el-table-column
							prop="stockinOrg"
							label="调入库存组织"
							align="left"
							width="172"
						/>
						<el-table-column
							prop="materialNumber"
							label="物料编码"
							align="left"
							width="150"
						/>
						<el-table-column
							prop="specification"
							label="规格型号(SKU)"
							align="left"
							width="280"
						/>
						<el-table-column
							prop="partName"
							label="物料名称"
							align="left"
							width="100"
						/>
						<el-table-column
							prop="unit"
							label="单位"
							align="center"
							width="81"
						/>
						<el-table-column
							prop="qty"
							label="调出数量"
							align="right"
							width="100"
						/>
						<el-table-column
							prop="stockReceiveQty"
							label="累计调入数量"
							align="right"
							width="100"
						/>
						<el-table-column
							prop="remainReceiveQty"
							label="剩余调入数量"
							align="right"
							width="100"
						/>
						<el-table-column
							prop="srcStock"
							label="调出仓库"
							align="left"
							width="120"
						/>
						<el-table-column
							prop="srcCustomer"
							label="调出客户"
							align="left"
							width="172"
						/>
						<el-table-column
							prop="srcCustomerStock"
							label="调出客户仓库"
							align="left"
							width="120"
						/>
						<el-table-column
							prop="destStock"
							label="调入仓库"
							align="left"
							width="120"
						/>
						<el-table-column
							prop="destCustomer"
							label="调入客户"
							align="left"
							width="120"
						/>
						<el-table-column
							prop="destCustomerStock"
							label="调入客户仓库"
							align="left"
							width="120"
						/>
						<el-table-column
							prop="deliveryDate"
							label="期望交期"
							align="left"
							width="90"
						/>
						<el-table-column
							prop="stockDept"
							label="部门"
							align="left"
							width="172"
						/>
						<el-table-column
							prop="remarks"
							label="备注"
							align="left"
							width="280"
						/>
					</el-table>
				</div>
			</div>
			<!-- 操作结果 -->
			<el-dialog title="操作结果" v-model="dialogVisible" width="40%">
				<div class="sale-page-table-body">
					<el-table
						class="table-box"
						:data="tableInfo"
						height="300"
						border
						:header-cell-class-name="headerRigthMethod"
						id="tableInfo-table"
					>
						<el-table-column prop="date" label="序号" width="50">
							<template #default="scope">
								<span>{{ scope.$index + 1 }}</span>
							</template>
						</el-table-column>
						<el-table-column
							prop="orderNo"
							label="分步式调出单"
							width="200"
						></el-table-column>
						<el-table-column prop="a" label="指令" 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 prop="msg" label="信息">
							<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.length }}条</span
						>
						<el-button
							size="small"
							@click="
								handelhtmlToExcel(
									'tableInfo-table',
									'操作结果'
								);
								dialogVisible = false;
							"
							>导 出</el-button
						>
						<el-button
							type="primary"
							size="small"
							@click="dialogVisible = false"
							>关 闭</el-button
						>
					</span>
				</template>
			</el-dialog>
			<!-- 选择下推单据 -->
			<el-dialog
				title="选择下推单据"
				v-model="dialogxt"
				width="20%"
				top="15%"
			>
				<el-radio-group v-model="pushdownVal">
					<el-radio
						v-for="item in pushDownList"
						:key="item.id"
						:value="item.id"
						:label="item.id"
						>{{ item.value }}</el-radio
					>
				</el-radio-group>
				<template #footer>
					<span class="dialog-footer">
						<el-button size="small" @click="dialogxt = false"
							>取 消</el-button
						>
						<el-button
							type="primary"
							size="small"
							@click="sumitPushdown(pushdownVal)"
							>确 定</el-button
						>
					</span>
				</template>
			</el-dialog>
			<!-- 选择上下查单据 -->
			<el-dialog
				:title="CXttile"
				v-model="dialogCX"
				width="20%"
				top="15%"
			>
				<div class="sale-page-table-body">
					<el-radio-group
						v-model="CXcheckVal"
						v-if="CXttile === '上查结果'"
					>
						<el-radio
							:label="it.orderType"
							v-for="(it, index) in upOrDownList"
							:key="index"
							>{{ it.orderName }}({{ it.orderCount }})</el-radio
						>
					</el-radio-group>
					<el-radio-group
						v-model="CXcheckVal"
						v-if="CXttile === '下查结果'"
					>
						<el-radio
							:label="it.orderType"
							v-for="(it, index) in upOrDownList"
							:key="index"
							>{{ it.orderName }}({{ it.orderCount }})</el-radio
						>
					</el-radio-group>
				</div>
				<template #footer>
					<span class="dialog-footer">
						<el-button size="small" @click="dialogCX = false"
							>取 消</el-button
						>
						<el-button type="primary" size="small" @click="submitCX"
							>确 定</el-button
						>
					</span>
				</template>
			</el-dialog>
			<div class="sale-page-footer">
				<div class="footer-left">
					<div>
						<span>调出数量:</span>
						<span class="sale-number-color">{{
							pagingSaleNumber
						}}</span>
					</div>
				</div>
				<div class="footer-right">
					<el-pagination
						:page-sizes="pagingList"
						:page-size="pageSize"
						layout="slot,sizes, total,prev,pager, next,jumper"
						:total="totalItemNumber"
						popper-class="每页显示"
						:pager-count="5"
						@size-change="handleSizeChange"
						@current-change="handleCurrentChange"
					>
						<span class="total-select-item">
							共选中
							<text
								style="
									text-align: center;
									color: #4178d5;
									padding: 0 1px;
								"
								>{{ selectItem }}</text
							>行
						</span>
					</el-pagination>
				</div>
				<div class="footer-pagination-total-page">
					<span>共{{ totalPageNumber }}页</span>
				</div>
			</div>
		</div>
	</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import { toRaw } from '@vue/reactivity';
import {
	exporthandel,
	htmlToExcel,
	resultComMethods,
	customChangeMethods,
	dateData,
	printPreview,
} from '@/utils/pubulic.js';
import { orderCopy } from '@/utils/takeMethods';
import { issuePrint } from '@/utils/printPagekey.js';
import CustomCondition from '@/components/public/CustomCondition.vue';
export default {
	name: 'WarehouseAllocationkissue',
	components: {
		CustomCondition,
	},
	data() {
		return {
			theadDate: JSON.parse(JSON.stringify(issuePrint)), // 打印要的字段表
			containerHeight: '', // body容器高度
			tableLoading: false, // 加载
			pagingSaleNumber: '', // 调出数量
			pagingList: [50, 100, 150], // 底部分页
			pageSize: 50,
			pageNo: 1,
			totalItemNumber: 0,
			totalPageNumber: 0,
			selectItem: 0,
			statusForm: {
				// 自定义条件
				customCondition: [], // 自定义
				allocationOrg: [], // 组织
				transferHouse: [], // 调入仓库
				callOutHouse: [], // 调出仓库
				documentStatus: {}, // 单据状态
			},
			orderNum: '', // 分步式调出单号
			billStatus: '', // 单据状态
			product: '', // 产品
			date: '', // 下单日期
			stockinOrgId: '', // 调入库存组织
			destStockId: '', // 调入仓库
			stockOrgId: '', // 调出库存组织
			srcStockId: '', // 调出仓库
			customerSel1: '', // 条件
			customerSel2: '',
			customerSel3: '',
			customerObj1: null,
			customerObj2: null,
			customerObj3: null,
			tempObj1: null,
			tempObj2: null,
			tempObj3: null,
			compKey1: 0,
			compKey2: 0,
			compKey3: 0,
			search: {
				// 列表请求参数
				pageNo: 1,
				pageSize: 50,
				orgId:
					this.$store.state &&
					this.$store.state.org &&
					this.$store.state.org.orgId === ''
						? this.orgIdArr[0].id
						: this.$store.state.org.orgId,
				detailsIds: [],
			},
			selectIndex: [], // 选择的条目
			tableData: [], // 表格数据
			rowShow: false, // 展开行
			heightNum: 0, // 搜索高度
			windowHeight: 0, // 屏幕高度
			isDown: true, // 按钮切换
			multipleSelection: [],
			btnType: [
				'exDetails',
				'save',
				'split-order',
				'print-aterial-list',
				'finish',
				'close-case',
				'de-excute-start',
				'de-excute-finish',
				'de-close',
				'close',
			], // 禁用按钮
			dialogVisible: false, // 操作弹框显示
			tableInfo: [], // 操作结果
			actionType: '', // 操作类型
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrdedetailIds: [], // 勾选的明细id集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			OrderNoNames: [], // 选择的单据订单号集合
			pushDownList: [], // 下推集合
			reset: false,
		};
	},
	methods: {
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 自定义条件赋值
		resultCom(result, fieldSale, fieldObj, tempObj) {
			let returnResult = resultComMethods(
				result,
				this[fieldSale],
				toRaw(result.outResult),
				this[tempObj],
				this.search
			);
			this[fieldSale] = returnResult.fieldSale;
			this[fieldObj] = returnResult.fieldObj;
			this[tempObj] = returnResult.tempObj;
			this.search = returnResult.search;
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		actionhandel(type) {
			// 顶部公共按钮操作
			this.actionType = type;
			if (type === 'add') {
				this.$router.push({
					path: '/warehouse/allocation/activeIssue',
					query: { type: 'add', id: '' },
				});
			}
			if (this.multipleSelection && this.multipleSelection.length > 0) {
				let nweArysize = 0;
				let newArry = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.orderId;
						})
					),
				];
				let detailsIds = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.id;
						})
					),
				];
				this.OrdedetailIds = [];
				this.OrdedetailIds = detailsIds;
				let orderNoArry = [
					// 取单据订单号
					...new Set(
						this.multipleSelection.map((item) => {
							return item.billNo;
						})
					),
				];
				this.OrderNoNames = [];
				this.OrderNoNames = orderNoArry;
				nweArysize = new Set(
					this.multipleSelection.map((item) => {
						return item.billNo;
					})
				).size;
				if (type === 'copy') {
					console.log('nweArysize', nweArysize);
					// 点击复制
					if (nweArysize !== 1 && nweArysize > 0) {
						this.$message.error({
							message: '只能克隆单号相同的订单',
							showClose: true,
						});
					} else {
						this.$router.push({
							path: '/warehouse/allocation/activeIssue',
							query: {
								type: 'copy',
								id: this.multipleSelection[0].orderId,
								detailsIds: detailsIds,
								sjtag: Math.random() * 36,
							},
						});
					}
				}
				if (type === 'submit') {
					// 点击提交
					this.toolarFn('StktransferOut/CommitList', newArry);
				}
				if (type === 'revoke') {
					// 点击撤销
					this.toolarFn('StktransferOut/Revoke', newArry);
				}
				if (type === 'audit') {
					// 点击审核
					this.toolarFn('StktransferOut/Check', newArry);
				}
				if (type === 'de-approval') {
					// 点击反审核
					this.toolarFn('StktransferOut/NoCheck', newArry);
				}
				if (type === 'delet') {
					// 点击删除
					this.toolarFn('StktransferOut/Delete', newArry);
				}
				if (type === 'push-down') {
					// 点击下推
					if (detailsIds.length <= 20) {
						if (
							this.multipleSelection.filter((it) => {
								return it.documentStatus !== '已审核';
							}).length > 0
						) {
							this.$message.error({
								message:
									'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
								showClose: true,
							});
						} else {
							this.$http
								.showLoading(false)
								.get('StktransferOut/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.warning({
							message: '最多一次性下推二十条明细',
							showClose: true,
						});
					}
				}
				if (type === 'up-check') {
					// 点击查询--上查
					this.$http
						.post('StktransferOut/GetUpNumber', { ids: detailsIds })
						.then((res) => {
							if (res.status === 200) {
								if (res.data.length === 0 || res.data === []) {
									this.$message.warning({
										message: '没有可上查的单据!',
										showClose: true,
									});
								} else {
									this.upOrDownList = res.data;
									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; //只有一个，就个默认值
								}
							}
						});
				}
				if (type === 'down-check') {
					// 点击查询--下查
					this.$http
						.post('StktransferOut/GetDownNumber', {
							ids: detailsIds,
						})
						.then((res) => {
							if (res.status === 200) {
								if (res.data.length === 0 || res.data === []) {
									this.$message.warning({
										message: '没有可下查的单据!',
										showClose: true,
									});
								} else {
									this.upOrDownList = res.data;
									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; //只有一个，就个默认值
								}
							}
						});
				}
				// 打印
				if (type === 'print-brower') {
					if (
						this.multipleSelection.filter((it) => {
							return it.documentStatus !== '已审核';
						}).length > 0
					) {
						this.$message.error({
							message: '仅可打印已审核的单据',
							showClose: true,
						});
					} else {
						this.multipleSelection = this.multipleSelection.sort(
							dateData('date', false)
						);
						setTimeout(() => {
							printPreview(1, '分步式调出单');
						}, 200);
					}
				}
			} else {
				//按列表字段导出,点击全部导出
				if (
					type !== 'add' &&
					type !== 'refresh' &&
					type !== 'list-export' &&
					type !== 'all-export'
				) {
					this.$message.error({
						message: '请先勾选',
						showClose: true,
					});
				}
			}
			if (type === 'list-export' || type === 'all-export') {
				exporthandel(
					type === 'list-export'
						? 'StktransferOut/Export'
						: 'StktransferOut/ExportAll',
					this.search
				);
			}
			if (type === 'refresh') {
				// 点击刷新
				this.getList(this.search);
			}
		},
		sumitPushdown(id) {
			// 下推确定
			this.CXcheckVal = id;
			if (id) {
				let pathName = '';
				let routerName = '';
				if (this.CXcheckVal === '21') {
					// "分步式调入单"
					pathName = 'StktransferOut/PushDownPurchaseOrder';
					routerName = 'ActiveEntryOrder';
				}
				this.$http
					.post(pathName, { ids: this.OrdedetailIds })
					.then((res) => {
						if (res.status === 200) {
							this.dialogxt = false;
							this.$router.push({
								name: routerName,
								query: {
									type: 'pushDown',
									pushDownData: JSON.stringify(res.data),
									sjtag: Math.random() * 36,
								},
							});
						}
						this.dialogxt = false;
					});
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		getcheckInfo() {
			// 上下查数据
			if (this.$route.query) {
				this.search.detailsIds = this.$route.query.detailsIds
					? JSON.parse(
							decodeURIComponent(this.$route.query.detailsIds)
					  )
					: [];
				this.CXaction =
					this.$route.query.actionType === 'up' ? '上查' : '下查';
				let ordNostr = '';
				this.OrderNoNameslist = this.$route.query.OrderNoNames
					? JSON.parse(
							decodeURIComponent(this.$route.query.OrderNoNames)
					  )
					: [];
				if (this.OrderNoNameslist) {
					this.OrderNoNameslist.forEach((it, index) => {
						if (index < 5) {
							ordNostr = ordNostr + it + ',';
						}
					});
				}
				this.OrderNoNameStr = ordNostr;
			}
		},
		submitCX() {
			// 确定上下查
			if (this.CXcheckVal) {
				let pathName = '';
				if (this.CXcheckVal === 10) {
					// "组织间需求单"
					pathName = 'OrgNeeds';
				}
				if (this.CXcheckVal === 21) {
					// "分步式调入单"
					pathName = 'WarehouseAllocationEntryorder';
				}
				let ary = [];
				ary = this.upOrDownList.filter((it) => {
					return it.orderType === this.CXcheckVal;
				});
				if (pathName) {
					this.dialogCX = false;
					this.$router.push({
						name: pathName,
						query: {
							detailsIds: JSON.stringify(
								ary.length > 0 ? ary[0].detailsIds : []
							),
							actionType:
								this.CXttile === '上查结果' ? 'up' : 'down',
							actionName: '分步式调出单',
							OrderNoNames: JSON.stringify(
								ary.length > 0 ? ary[0].billNos : []
							),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		toolarFn(path, newArry, detailsIds, type) {
			// 顶部操作方法
			let formdata = detailsIds ? { ids: detailsIds } : { ids: newArry };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					this.dialogVisible = true;
					this.tableInfo = res.data;
					this.getList(this.search);
				}
			});
		},
		headerBg({ columnIndex }) {
			// 表头居右
			if (columnIndex === 17 || columnIndex === 18) {
				return `text-align:right!important;`;
			}
		},
		headerRigthMethod({ row, column, rowIndex, columnIndex }) {
			return 'headerRight';
		},
		handleSelectionChange(val) {
			// 表格选中条目发生改变
			this.selectItem = val.length;
			this.multipleSelection = val;
		},
		handleSizeChange(val) {
			// 每页条数
			this.pageSize = val;
			this.search.pageSize = val;
			this.totalPageNumber = Math.ceil(
				this.totalItemNumber / this.search.pageSize
			);
			this.getList(this.search);
		},
		handleCurrentChange(val) {
			// 分页当前页切换
			this.pageNo = val;
			this.search.pageNo = val;
			this.getList(this.search);
		},
		openRow() {
			// 搜索切换高度
			this.isDown = !this.isDown;
			this.rowShow = !this.rowShow;
			if (this.rowShow) {
				this.heightNum = this.heightNum - 80;
			} else {
				this.heightNum = this.heightNum + 80;
			}
		},
		openDetails(row, column) {
			// 打开详情页
			if (column.property == 'billNo') {
				this.$router.push({
					path: '/warehouse/allocation/activeIssue',
					query: {
						type: 'details',
						id: row.orderId,
						status: row.documentStatus,
					},
				});
			}
		},
		openDetailsDB(row, column) {
			this.$router.push({
				path: '/warehouse/allocation/activeIssue',
				query: {
					type: 'details',
					id: row.orderId,
					status: row.documentStatus,
				},
			});
		},
		getList(query) {
			// 列表请求
			this.tableLoading = true;
			this.$http.post('StktransferOut/GetList/', query).then((req) => {
				if (req.status == 200) {
					this.tableLoading = false;
					this.tableData = req.data.list;
					this.totalItemNumber = req.data.total;
					this.totalPageNumber = Math.ceil(
						this.totalItemNumber / this.search.pageSize
					);
					this.pagingSaleNumber = req.data.qty;
					if (
						this.multipleSelection.length &&
						this.multipleSelection.length > 0
					) {
						let detailsIds = [
							...new Set(
								this.multipleSelection.map((item) => {
									return item.id;
								})
							),
						];
						this.tableData.forEach((el, ind) => {
							if (detailsIds.indexOf(el.id) !== -1) {
								this.$refs.tableInfoRef.toggleRowSelection(
									this.tableData[ind],
									true
								);
							}
						});
					}
				}
			});
		},
		searchList() {
			// 搜索
			this.getList(this.search);
		},
		searchCom(val, key, type) {
			// 搜索公共方法
			if (type == 'ipt') {
				if (val) {
					this.search[key] = val;
				} else {
					delete this.search[key];
					// this.searchList()
				}
			} else {
				this.search[key] = val;
			}
			if (type == 'opt') {
				if (key === 'stockOrgId') {
					this.srcStockId = '';
					delete this.search.srcStockId;
				}
				if (key === 'stockinOrgId') {
					this.destStockId = '';
					delete this.search.destStockId;
				}
				// this.searchList()
			}
		},
		clearCom(val, key) {
			// 删除的公共方法
			if (!val) {
				if (key === 'stockOrgId') {
					this.srcStockId = '';
					delete this.search.srcStockId;
				}
				if (key === 'stockinOrgId') {
					this.destStockId = '';
					delete this.search.destStockId;
				}
				delete this.search[key];
				// this.searchList()
			}
		},
		Init() {
			let vuexKey = ['dicStktrOut'];
			let setVuexData = ['setDicStktrOut'];
			let requestQueryUrl = ['Dictionary/stktransferout'];
			let resDataQuery = ['customCondition'];

			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]]));
						});
					}
				} else {
					this.$http.get(requestQueryUrl[ind]).then((r) => {
						if (r.status === 200) {
							if (typeof resDataQuery[ind] == 'string') {
								this.statusForm[resDataQuery[ind]] = r.data;
							} else {
								resDataQuery[ind].forEach((ele, index) => {
									this.statusForm[resDataQuery[ind][index]] =
										r.data;
								});
							}
							this[setVuexData[ind]](
								this.statusForm[resDataQuery[ind]]
							);
						}
					});
				}
			});

			// 枚举 - 调拨类型、订单状态、调出类型
			if (
				this.stktranStatus &&
				JSON.stringify(this.stktranStatus) !== '{}'
			) {
				this.statusForm.documentStatus = JSON.parse(
					JSON.stringify(this.stktranStatus.documentStatus)
				);
			} else {
				this.$http
					.showLoading(false)
					.get('StktransferOut/GetStatus')
					.then((req) => {
						if (req.status == 200) {
							this.setStktranStatus(req.data);
							this.statusForm.documentStatus =
								req.data.documentStatus; // 订单状态
						}
					});
			}

			this.windowHeight = document.documentElement.clientHeight; // 计算表格高度和底部位置
			if (this.$route.query.detailsIds) {
				this.heightNum = this.windowHeight - 301; // 计算表格高度
			} else {
				this.heightNum = this.windowHeight - 258; // 计算表格高度
			}
			this.containerHeight = this.windowHeight - 102; // 计算容器的高度
			this.getList(this.search);
		},
		getStatusType() {
			// 获取状态和类型
			this.statusForm.allocationOrg = this.orgIdArr; // 调拨组织
		},
		resetSearch() {
			// 重置
			let arr = [
				'orderNum',
				'billStatus',
				'product',
				'date',
				'stockOrgId',
				'srcStockId',
				'stockinOrgId',
				'destStockId',
			];
			for (let index = 0; index < arr.length; index++) {
				this[arr[index]] = '';
			}
			this.reset = true;
			this.search = {
				pageNo: this.pageNo,
				pageSize: this.pageSize,
				orgId:
					this.$store.state && this.$store.state.org
						? this.$store.state.org.orgId
						: null,
			};
			this.search.detailsIds = [];
			this.search.extention = {};
			this.customerSel1 = '';
			this.customerSel2 = '';
			this.customerSel3 = '';
			if (this.$route.query.detailsIds) {
				this.search.detailsIds = JSON.parse(
					decodeURIComponent(this.$route.query.detailsIds)
				);
			}
			setTimeout(() => {
				this.reset = false;
			}, 200);
			this.searchList();
		},
		...mapActions({
			setStktranStatus: 'storeData/setStktranStatus',
			setDicStktrOut: 'storeData/setDicStktrOut',
		}),
		addListIssue(event) {
			if (event.keyCode === 13) {
				this.searchList();
			}
		},
	},
	computed: {
		...mapState({
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			getorgId: (state) =>
				state && state.org && state.org.orgId ? state.org.orgId : null,
			stktranStatus: (state) => state.storeData.stktranStatus,
			dicStktrOut: (state) => state.storeData.dicStktrOut,
		}),
		orgIdChange() {
			// 监听ID
			return this.$store.state && this.$store.state.org
				? this.$store.state.org.orgId
				: null;
		},
	},
	created: function () {
		this.getcheckInfo();
		this.Init();
		this.getStatusType();
	},
	activated() {
		document.addEventListener('keyup', this.addListIssue, false);
	},
	deactivated() {
		document.removeEventListener('keyup', this.addListIssue, false);
	},
	watch: {
		orgIdChange: function () {
			// 监听组织
			this.search.orgId =
				this.$store.state && this.$store.state.org
					? this.$store.state.org.orgId
					: null;
			//   this.getList(this.search)
			this.resetSearch();
		},
		stockinOrgId: function () {
			// 监听调入组织 获取调入仓库
			if (this.stockinOrgId) {
				this.$http
					.get('SysConfig/GetWarehouseByOrg/' + this.stockinOrgId)
					.then((req) => {
						if (req.status == 200) {
							this.statusForm.transferHouse = req.data;
						}
					});
			}
		},
		stockOrgId: function () {
			// 监听调出组织 获取调出仓库
			if (this.stockOrgId) {
				this.$http
					.get('SysConfig/GetWarehouseByOrg/' + this.stockOrgId)
					.then((req) => {
						if (req.status == 200) {
							this.statusForm.callOutHouse = req.data;
						}
					});
			}
		},
		customerSel1: function () {
			let returnR = customChangeMethods(
				this.customerSel1,
				this.customerSel2,
				this.customerSel3,
				'x',
				this.compKey1
			);
			this.customerSel1 = returnR.selfVal;
			this.customerSel2 = returnR.otherO;
			this.customerSel3 = returnR.otherT;
			this.compKey1 = returnR.keyRsf;
		},
		customerSel2: function () {
			let returnR = customChangeMethods(
				this.customerSel2,
				this.customerSel1,
				this.customerSel3,
				'y',
				this.compKey2
			);
			this.customerSel2 = returnR.selfVal;
			this.customerSel1 = returnR.otherO;
			this.customerSel3 = returnR.otherT;
			this.compKey2 = returnR.keyRsf;
		},
		customerSel3: function () {
			let returnR = customChangeMethods(
				this.customerSel3,
				this.customerSel1,
				this.customerSel2,
				'z',
				this.compKey3
			);
			this.customerSel3 = returnR.selfVal;
			this.customerSel1 = returnR.otherO;
			this.customerSel2 = returnR.otherT;
			this.compKey3 = returnR.keyRsf;
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderList.scss';
@import '@/assets/style/saleOrder/common.scss';
::v-deep(.item-date .el-input__inner) {
	padding: 0 16px 0 30px !important;
}
</style>
