<template>
	<div class="main-container order-mc-bg">
		<PrintModel
			:printData="{
				tableData: multipleSelection,
				orderName: '直接调拨单',
			}"
			:theadDate="theadDate"
			v-show="false"
		></PrintModel>
		<div
			:style="{ height: containerHeight + 'px!important' }"
			class="sale-container"
		>
			<toolBtn :btnType="btnType" @actionhandel="actionhandel"></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
												@input="
													searchCom(
														orderNum,
														'billNo',
														'ipt'
													)
												"
												@keyup.enter="searchList"
												class="f_12"
												placeholder="请输入单号"
												v-model.trim="orderNum"
											></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
												:clearable="true"
												@change="
													clearCom(
														billStatus,
														'documentStatus'
													)
												"
												filterable
												placeholder="选择状态"
												v-model="billStatus"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													@click="
														searchCom(
															billStatus,
															'documentStatus',
															'opt'
														)
													"
													class="f_12"
													v-for="(
														value, key, index
													) in statusForm.documentStatus"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="产品"
										>
											<el-input
												@input="
													searchCom(
														product,
														'product',
														'ipt'
													)
												"
												@keyup.enter="searchList"
												class="f_12"
												placeholder="请输入产品名称"
												v-model.trim="product"
											></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
												@change="
													searchCom(
														date,
														'date',
														'opt'
													)
												"
												class="f_12 item-date"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
												type="date"
												v-model="date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
									</el-col>
									<el-col :span="4"></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
												@click="openRow"
												class="alias-open"
											>
												<span
													:class="[
														isDown
															? 'icon-shuangjiantouzhankai-xia'
															: 'icon-shuangjiantoushouqi-shang',
													]"
													class="iconfont"
												></span>
											</div>
											<el-button
												@click="resetSearch"
												size="small"
												>重置</el-button
											>
											<el-button
												@click="searchList"
												size="small"
												type="primary"
												>搜索</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="4">
                    <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.native="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="4">
										<el-form-item label="调入仓库">
											<el-select
												:clearable="true"
												@change="
													clearCom(
														destStockId,
														'destStockId'
													)
												"
												placeholder="选择仓库"
												v-model="destStockId"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													@click="
														searchCom(
															item.id,
															'destStockId',
															'opt'
														)
													"
													class="f_12"
													v-for="item in statusForm.transferHouse"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item label="调出仓库">
											<el-select
												:clearable="true"
												@change="
													clearCom(
														srcStockId,
														'srcStockId'
													)
												"
												placeholder="选择仓库"
												v-model="srcStockId"
											>
												<el-option
													:key="item.id"
													:label="item.name"
													:value="item.id"
													@click="
														searchCom(
															item.id,
															'srcStockId',
															'opt'
														)
													"
													class="f_12"
													v-for="item in statusForm.callOutHouse"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="16"></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"
												:key="compKey1"
												:reset="reset"
												@result="
													resultCom(
														$event,
														'customerSel1',
														'customerObj1',
														'tempObj1'
													)
												"
											></CustomCondition>
										</el-form-item>
									</el-col>
									<el-col :span="8">
										<el-form-item label="自定义条件2">
											<CustomCondition
												:getCustomerItem="statusForm"
												:key="compKey2"
												:reset="reset"
												@result="
													resultCom(
														$event,
														'customerSel2',
														'customerObj2',
														'tempObj2'
													)
												"
											></CustomCondition>
										</el-form-item>
									</el-col>
									<el-col :span="8">
										<el-form-item label="自定义条件3">
											<CustomCondition
												:getCustomerItem="statusForm"
												:key="compKey3"
												:reset="reset"
												@result="
													resultCom(
														$event,
														'customerSel3',
														'customerObj3',
														'tempObj3'
													)
												"
											></CustomCondition>
										</el-form-item>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div
					:style="{ height: heightNum + 'px' }"
					class="sale-page-table-body"
				>
					<el-table
						:data="tableData"
						:header-cell-style="headerBg"
						:max-height="heightNum"
						@cell-click="openDetails"
						@row-dblclick="openDetailsDB"
						@selection-change="handleSelectionChange"
						border
						class="table-box"
						ref="tableInfoRef"
						style="width: 100%; font-size: 12px"
						v-loading="tableLoading"
					>
						<el-table-column
							align="center"
							fixed
							type="selection"
							width="40"
						/>
						<el-table-column
							align="left"
							fixed
							label="销售订单号"
							prop="salOrderBillNo"
							width="187"
						/>
						<el-table-column
							align="left"
							fixed
							label="直接调拨单"
							prop="billNo"
							width="172"
						>
							<template #default="scope">
								<span style="color: #4178d5">{{
									scope.row.billNo
								}}</span>
							</template>
						</el-table-column>
						<el-table-column
							align="left"
							label="下单日期"
							prop="date"
							width="83"
						/>
						<el-table-column
							align="center"
							label="单据状态"
							prop="documentStatus"
							width="72"
						/>
						<el-table-column
							align="left"
							label="物料编码"
							prop="materialNumber"
							width="150"
						/>
						<el-table-column
							align="left"
							label="规格型号(SKU)"
							prop="specification"
							width="280"
						/>
						<el-table-column
							align="left"
							label="物料名称"
							prop="partName"
							width="100"
						/>
						<el-table-column
							align="center"
							label="单位"
							prop="unit"
							width="81"
						/>
						<el-table-column
							align="right"
							label="调拨数量"
							prop="qty"
							width="100"
						/>
						<el-table-column
							align="left"
							label="调出仓库"
							prop="srcStock"
							width="120"
						/>
						<el-table-column
							align="left"
							label="调出客户"
							prop="srcCustomer"
							width="172"
						/>
						<el-table-column
							align="left"
							label="调出客户仓库"
							prop="srcCustomerStock"
							width="120"
						/>
						<el-table-column
							align="left"
							label="调入仓库"
							prop="destStock"
							width="120"
						/>
						<el-table-column
							align="left"
							label="调入客户"
							prop="destCustomer"
							width="172"
						/>
						<el-table-column
							align="left"
							label="调入客户仓库"
							prop="destCustomerStock"
							width="120"
						/>
						<el-table-column
							align="left"
							label="备注"
							prop="remarks"
							width="280"
						/>
					</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.length }}条</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>
			<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-size="pageSize"
						:page-sizes="pagingList"
						:pager-count="5"
						:total="totalItemNumber"
						@current-change="handleCurrentChange"
						@size-change="handleSizeChange"
						layout="slot,sizes, total,prev,pager, next,jumper"
						popper-class="每页显示"
					>
						<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 { directPrint } from '@/utils/printPagekey.js';
import { orderCopy } from '@/utils/takeMethods';
import CustomCondition from '@/components/public/CustomCondition.vue';
export default {
	name: 'WarehouseAllocationDirect',
	components: {
		CustomCondition,
	},
	data() {
		return {
			theadDate: JSON.parse(JSON.stringify(directPrint)), // 打印要的字段表
			containerHeight: '', // body容器高度
			tableLoading: false, // 加载
			pagingSaleNumber: '', // 调出数量
			pagingList: [50, 100, 150], // 底部分页
			pageSize: 50,
			selectPageNum: 1,
			totalItemNumber: 0,
			totalPageNumber: 0,
			selectItem: 0,
			statusForm: {
				// 自定义条件
				customCondition: [], // 自定义
				allocationOrg: [], // 组织
				transferHouse: [], // 调入仓库
				callOutHouse: [], // 调出仓库
				documentStatus: {}, // 单据状态
			},
			orderNum: '', // 分步式调出单号
			billStatus: '', // 单据状态
			product: '', // 产品
			customers: '', // 客户
			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',
				'query',
				'close',
				'de-close',
				'push-down',
				'split-order',
				'print-aterial-list',
				'finish',
				'close-case',
				'de-excute-start',
				'de-excute-finish',
			], // 禁用按钮
			dialogVisible: false, // 操作弹框显示
			tableInfo: [], // 操作结果
			actionType: '', // 操作类型
			OrdedetailIds: [], // 勾选的明细id集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			OrderNoNames: [], // 选择的单据订单号集合
			reset: false,
		};
	},
	methods: {
		// 获取仓库
		getWarehouseByOrg() {
			this.$http
				.get('SysConfig/GetWarehouseByOrg/' + this.orgIdChange)
				.then((req) => {
					if (req.status == 200) {
						this.statusForm.transferHouse = req.data;
						this.statusForm.callOutHouse = req.data;
					}
				});
		},
		// 操作弹框导出
		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/activeDirect',
					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.orderNum;
						})
					),
				];
				this.OrderNoNames = [];
				this.OrderNoNames = orderNoArry;
				nweArysize = new Set(
					this.multipleSelection.map((item) => {
						return item.orderId;
					})
				).size;
				if (type === 'copy') {
					// 点击复制
					if (nweArysize !== 1 && nweArysize > 0) {
						this.$message.error({
							message: '只能克隆单号相同的单据',
							showClose: true,
						});
					} else {
						this.$router.push({
							path: '/warehouse/allocation/activeDirect',
							query: {
								type: 'copy',
								id: this.multipleSelection[0].orderId,
								detailsIds: detailsIds,
								sjtag: Math.random() * 36,
							},
						});
					}
				}
				if (type === 'submit') {
					// 点击提交
					this.toolarFn('Stkdirecttransfers/CommitList', newArry);
				}
				if (type === 'revoke') {
					// 点击撤销
					this.toolarFn('Stkdirecttransfers/Revoke', newArry);
				}
				if (type === 'audit') {
					// 点击审核
					this.toolarFn('Stkdirecttransfers/Check', newArry);
				}
				if (type === 'de-approval') {
					// 点击反审核
					this.toolarFn('Stkdirecttransfers/NoCheck', newArry);
				}
				if (type === 'delet') {
					// 点击删除
					this.toolarFn('Stkdirecttransfers/Delete', newArry);
				}
				// 打印
				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'
						? 'Stkdirecttransfers/Export'
						: 'Stkdirecttransfers/ExportAll',
					this.search
				);
			}
			if (type === 'refresh') {
				// 点击刷新
				this.getList(this.search);
			}
		},
		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;
			}
		},
		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/activeDirect',
					query: {
						type: 'details',
						id: row.orderId,
						status: row.documentStatus,
					},
				});
			}
		},
		openDetailsDB(row, column) {
			this.$router.push({
				path: '/warehouse/allocation/activeDirect',
				query: {
					type: 'details',
					id: row.orderId,
					status: row.documentStatus,
				},
			});
		},
		getList(query) {
			// 列表请求
			this.tableLoading = true;
			this.$http.post('Stkdirecttransfers/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.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') {
				// this.searchList()
			}
		},
		clearCom(val, key) {
			// 删除的公共方法
			if (!val) {
				delete this.search[key];
				// this.searchList()
			}
		},
		Init() {
			let vuexKey = ['dicStkdirFers'];
			let setVuexData = ['setDicStkdirFers'];
			let requestQueryUrl = ['Dictionary/stkdirecttransfers'];
			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.stkdirecttrStatus &&
				JSON.stringify(this.stkdirecttrStatus) !== '{}'
			) {
				this.statusForm.documentStatus = JSON.parse(
					JSON.stringify(this.stkdirecttrStatus.documentStatus)
				);
			} else {
				this.$http
					.showLoading(false)
					.get('Stkdirecttransfers/GetStatus')
					.then((req) => {
						if (req.status == 200) {
							this.setStkdirecttrStatus(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',
				'stockinOrgId',
				'destStockId',
				'srcStockId',
			];
			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({
			setStkdirecttrStatus: 'storeData/setStkdirecttrStatus',
			setDicStkdirFers: 'storeData/setDicStkdirFers',
		}),
		addListDirect(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,
			stkdirecttrStatus: (state) => state.storeData.stkdirecttrStatus,
			dicStkdirFers: (state) => state.storeData.dicStkdirFers,
		}),
		orgIdChange() {
			// 监听ID
			return this.$store.state && this.$store.state.org
				? this.$store.state.org.orgId
				: null;
		},
	},
	created: function () {
		this.getcheckInfo();
		this.Init();
		this.getStatusType();
		this.getWarehouseByOrg();
	},
	activated() {
		document.addEventListener('keyup', this.addListDirect, false);
	},
	deactivated() {
		document.removeEventListener('keyup', this.addListDirect, false);
	},
	watch: {
		orgIdChange: function () {
			// 监听组织
			this.search.orgId =
				this.$store.state && this.$store.state.org
					? this.$store.state.org.orgId
					: null;
			// this.getList(this.search)
			// if (!this.search.orgId) {
			// 	return;
			// }
			this.resetSearch();
			this.getWarehouseByOrg();
		},
		stockinOrgId: function () {
			// 监听调入组织 获取调入仓库
			if (this.stockinOrgId) {
				this.$http
					.get('SysConfig/GetWarehouseByOrg/' + this.stockinOrgId)
					.then((req) => {
						if (req.status == 200) {
							this.statusForm.transferHouse = req.data;
							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>
