<!-- 仓库--销售发货--销售发货单 -->
<template>
	<div class="main-container order-mc-bg">
		<prtMoled
			:printData="{
				tableData: multipleSelection,
				orderName: '发货通知单',
			}"
			:theadDate="theadDate"
			v-show="false"
		>
		</prtMoled>
		<div 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
												class="f-12"
												placeholder="请输入单据编号"
												v-model.trim="search.billNO"
											></el-input>
											<div
												:data-clipboard-text="
													search.billNO
												"
												@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
												placeholder="请选择"
												v-model="search.documentStatus"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													class="f-12"
													v-for="(
														value, key, index
													) in documentStatuslist"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item label="销售部门">
											<el-select
												clearable
												filterable
												placeholder="请选择部门"
												v-model="search.sellDeptId"
											>
												<el-option
													class="f_12"
													label="全部"
													value=""
												></el-option>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													v-for="item in productDeptList"
												></el-option>
											</el-select>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="客户"
										>
											<el-input
												class="f-12"
												placeholder="请输入客户名称"
												v-model="search.customers"
											></el-input>
											<div
												:data-clipboard-text="
													search.customers
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item
											class="Iisshow"
											label="产品"
										>
											<el-input
												class="f-12"
												placeholder="请输入物料名称/编码/SKU"
												v-model.trim="search.product"
											></el-input>
											<div
												:data-clipboard-text="
													search.product
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
									</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
												size="small"
												@click="resetSearch()"
												>重置</el-button
											>
											<el-button
												@click="searchData"
												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-input
												class="f-12"
												placeholder="请输入销售订单号"
												v-model.trim="search.salNo"
											></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="4">
										<el-form-item label="线上订单号">
											<el-input
												class="f-12"
												placeholder="请输入线上订单号"
												v-model.trim="
													search.onlineOrderNo
												"
											></el-input>
										</el-form-item>
									</el-col>
									<el-col :span="7">
										<el-form-item label="下单日期">
											<el-date-picker
												@change="time1Chang"
												class="f-12"
												end-placeholder="结束时间"
												start-placeholder="开始时间"
												type="daterange"
												v-model="Time1"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
									</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"
												@result="
													selfResult(
														$event,
														'customerSel1',
														'customerObj1',
														'tempObj1'
													)
												"
											></CustomCondition>
										</el-form-item>
									</el-col>
									<el-col :span="8">
										<el-form-item label="自定义条件2">
											<CustomCondition
												:getCustomerItem="statusForm"
												:key="compKey2"
												@result="
													selfResult(
														$event,
														'customerSel2',
														'customerObj2',
														'tempObj2'
													)
												"
											></CustomCondition>
										</el-form-item>
									</el-col>
									<el-col :span="8">
										<el-form-item label="自定义条件3">
											<CustomCondition
												:getCustomerItem="statusForm"
												:key="compKey3"
												@result="
													selfResult(
														$event,
														'customerSel3',
														'customerObj3',
														'tempObj3'
													)
												"
											></CustomCondition>
										</el-form-item>
									</el-col>
								</el-row>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<!-- 列表 -->
				<div class="sale-page-table-body">
					<el-table
						:data="tableData"
						:header-cell-class-name="headerRigthMethod"
						:header-cell-style="headerBg"
						:max-height="heightNum"
						@row-dblclick="openDetailsDB"
						@selection-change="handleSelectionChange"
						border
						class="table-box"
						element-loading-spinner="el-icon-loading"
						element-loading-text="加载中，请稍后..."
						ref="tableInfoRef"
						style="width: 100%; font-size: 12px"
						v-loading="isLoading"
					>
						<el-table-column
							align="center"
							fixed
							type="selection"
							width="40"
						/>
						<el-table-column
							align="left"
							fixed
							label="发货通知单号"
							prop="billNO"
							width="187"
						>
							<template #default="scope">
								<span
									@click="jump(scope.row)"
									style="color: #4178d5"
									>{{ scope.row.billNO }}</span
								>
							</template>
						</el-table-column>
						<el-table-column
							align="left"
							label="日期"
							prop="orderDate"
							width="83"
						/>
						<el-table-column
							align="center"
							label="单据状态"
							prop="documentStatus"
							width="72"
						/>
						<el-table-column
							align="center"
							label="关闭状态"
							prop="closeStatus"
							width="72"
						/>
						<el-table-column
							align="left"
							label="客户"
							prop="customers"
							width="172"
						/>
						<el-table-column
							align="left"
							label="销售部门"
							prop="sellDept"
							width="120"
						/>
						<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="materialName"
							width="150"
						/>
						<el-table-column
							align="center"
							label="销售单位"
							prop="unit"
							width="72"
						/>
						<el-table-column
							align="right"
							label="销售数量"
							prop="salesNumber"
							width="100"
						/>
						<el-table-column
							align="right"
							label="累计出库数量"
							prop="stockOutNumber"
							width="100"
						/>
						<el-table-column
							align="right"
							label="剩余未出数量"
							prop="remainOutNumber"
							width="100"
						/>
						<el-table-column
							align="left"
							label="出货仓库"
							prop="stock"
							width="120"
						/>
						<el-table-column
							align="left"
							label="销售订单号"
							prop="salOrderNo"
							width="187"
						/>
						<el-table-column
							align="left"
							label="线上/客户订单号"
							prop="onlineOrderNo"
							width="172"
						/>
						<el-table-column
							align="right"
							label="含税单价"
							prop="taxPrice"
							width="100"
						/>
						<el-table-column
							align="right"
							label="价税合计"
							prop="allAmount"
							width="100"
						/>
						<el-table-column
							align="right"
							label="价税合计 (本位币)"
							prop="allAmountLc"
							width="120"
						/>
						<el-table-column
							align="center"
							label="是否赠品"
							prop="isFree"
							width="72"
						/>
						<el-table-column
							align="left"
							label="发货组织"
							prop="deliveryOrg"
							width="172"
						/>
						<el-table-column
							align="left"
							label="备注"
							prop="remark"
							width="280"
						>
							<template #default="scope">
								<div
									:title="scope.row.remark"
									class="noteOrder"
									v-show="scope.row.showTooltip"
								>
									{{ scope.row.remark }}
								</div>
								<div
									class="noteOrder"
									v-show="!scope.row.showTooltip"
								>
									{{ scope.row.remark }}
								</div>
							</template>
						</el-table-column>
					</el-table>
				</div>
			</div>
			<!-- 底部 -->
			<div class="sale-page-footer">
				<div class="footer-left">
					<div>
						<span>销售数量:</span>
						<span class="sale-number-color">{{ salesNumber }}</span>
					</div>
					<div>
						<span>累计出库数量:</span>
						<span class="sale-number-color">{{
							stockOutNumber
						}}</span>
					</div>
					<div>
						<span>剩余未出数量:</span>
						<span class="sale-number-color">{{
							remainOutNumber
						}}</span>
					</div>
					<div>
						<span>价税合计 (本位币):</span>
						<span class="sale-number-color">{{ allAmountLc }}</span>
					</div>
				</div>
				<div class="footer-right">
					<el-pagination
						:currentPage="search.pageNo"
						:page-size="search.pageSize"
						:page-sizes="[50, 100, 150]"
						:total="orderTotal"
						@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;
								"
								>{{
									multipleSelection &&
									multipleSelection.length > 0
										? multipleSelection.length
										: 0
								}}</text
							>行
						</span>
					</el-pagination>
				</div>
				<div class="footer-pagination-total-page">
					<span
						>共{{ Math.ceil(orderTotal / search.pageSize) }}页</span
					>
				</div>
			</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 { mapState } from 'vuex';
import {
	transformTimestamp,
	exporthandel,
	htmlToExcel,
	dateData,
	newprintPreview,
} from '@/utils/pubulic.js';
import { orderCopy } from '@/utils/takeMethods';
import { toRaw } from 'vue';
import { noticePrint } from '@/utils/printPagekey.js';
import CustomCondition from '@/components/public/CustomCondition.vue';
export default {
	name: 'WarehouseSalesDeliveryNorice',
	components: {
		CustomCondition,
	},
	data() {
		return {
			theadDate: JSON.parse(JSON.stringify(noticePrint)), // 打印要的字段表
			// 自定义条件 订单类型 单据状态 供应组织 是否211 是否赠品 关闭状态
			statusForm: {
				customCondition: [],
				orders: [],
				bills: [],
				supplys: [],
				is211: [],
				isFree: [],
				cloStatus: [],
				warehouse: [],
				childWarehouse: [],
				orgAllPerson: [],
				reccondition: [],
				settleType: [],
				dcurrency: [],
			},
			//条件
			customerSel1: '',
			customerSel2: '',
			customerSel3: '',
			customerObj1: null,
			customerObj2: null,
			customerObj3: null,
			tempObj1: null,
			tempObj2: null,
			tempObj3: null,
			compKey1: 0,
			compKey2: 0,
			compKey3: 0,
			CXcheckVal: '', // 上下查选中
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			OrdedetailIds: [], // 勾选的明细id集合
			OrderNoNames: [], // 选择的单据订单号集合
			CXttile: '', // 查询弹框的名称
			multipleSelection: [], // 列表选中
			pushdownVal: null, // 下推选择
			actionType: '', //判断点击的顶部那个按钮
			tableInfo: [], //操作结果
			isLoading: false, //表格加载数据
			documentStatuslist: [], // 单据状态
			btnType: [
				'exDetails',
				's-p-t-g1',
				'print-aterial-list',
				'save',
				'copy',
				'de-excute-finish',
				'de-excute-start',
				'close-case',
				'split-order',
				'finish',
			], // 不需要显示的顶部按钮类型
			productDeptList: [], // 部门
			Time1: [],
			dialogVisible: false, // 操作弹框显示
			dialogxt: false, // 选择下推单据弹框显示
			search: {
				orgId: '', // 组织id
				detailsIds: [], // 明细列表ID 上下查 使用
				billNO: '', // 订单编号
				documentStatus: '', //单据状态
				sellDeptId: '', //生产部门
				customers: '', // 客户
				product: '', //产品 物料名称/编码/SKU
				pickmtStatus: '', //领料状态
				salNo: '', // 销售订单号
				orderBeginDate: '', // 下单开始日期
				orderEndDate: '', //下单结束日期
				pageNo: 1, // 页码
				pageSize: 50, // 页数
			},
			salesNumber: 0, //销售数量
			allAmountLc: 0, //价税合计(本位币)
			orderTotal: 0, // 未入库数量统计
			remainOutNumber: 0, //剩余未出数量
			stockOutNumber: 0, // 累计出库数量
			tableData: [],
			selectItem: 0,
			rowShow: false,
			heightNum: 0,
			windowHeight: 0,
			isDown: true,
		};
	},
	computed: {
		...mapState({
			orgId: (state) =>
				state && state.org && state.org.orgId ? state.org.orgId : null,
		}),
		transformTime: function () {
			return function (value) {
				return transformTimestamp(value);
			};
		},
	},
	created() {
		this.windowHeight = document.documentElement.clientHeight;
		this.heightNum =
			this.windowHeight - (40 + 30 + 54 + 34 + 34 + 34 + 16 + 16);
		this.search.orgId = this.orgId;
		// 键盘监听事件
		document.addEventListener('keyup', (e) => {
			if (e.keyCode === 13) {
				// enter见搜索
				this.searchData();
			}
		});
		this.Init();
	},
	activated() {
		// 键盘监听事件
		document.addEventListener('keyup', this.keyupFn, false);
	},
	deactivated() {
		document.removeEventListener('keyup', this.keyupFn, false);
	},
	watch: {
		orgId(val) {
			if (val) {
				// 监听组织切换 ，数据初始化
				this.search.orgId = val;
				this.search.pageNo = 1;
				this.getProductdept();
				this.getselfData();
				this.getnotice();
			}
		},
		customerSel1(val, oldVal) {
			this.setselfChangeValue(
				'customerSel1',
				'customerSel2',
				'customerSel13',
				'z',
				'customerSel1',
				'compKey3'
			);
		},
		customerSel2(val, oldVal) {
			this.setselfChangeValue(
				'customerSel2',
				'customerSel1',
				'customerSel13',
				'y',
				'customerSel2',
				'compKey2'
			);
		},
		customerSel3(val, oldVal) {
			this.setselfChangeValue(
				'customerSel3',
				'customerSel1',
				'customerSel12',
				'z',
				'customerSel2',
				'compKey3'
			);
		},
	},
	methods: {
		keyupFn(e) {
			if (e.keyCode === 13) {
				// enter见搜索
				this.searchData();
			}
		},
		// 初始化
		Init() {
			this.search.orgId = this.orgId;
			this.getcheckInfo();
			this.getProductdept();
			this.getnotice();
			this.getStatus();
			this.getselfData();
		},
		resetSearch() {
			this.search = {
				orgId: this.orgId, // 组织id
				detailsIds: [], // 明细列表ID 上下查 使用
				billNO: '', // 订单编号
				documentStatus: '', //单据状态
				sellDeptId: '', //生产部门
				customers: '', // 客户
				product: '', //产品 物料名称/编码/SKU
				pickmtStatus: '', //领料状态
				salNo: '', // 销售订单号
				orderBeginDate: '', // 下单开始日期
				orderEndDate: '', //下单结束日期
				pageNo: 1, // 页码
				pageSize: 50, // 页数
			};
			this.getnotice();
		},
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 双击计入
		openDetailsDB(row, column) {
			let typeStr1 =
				row.documentStatus === '重新审核' ||
				row.documentStatus === '创建'
					? 'edit'
					: 'see';
			this.$router.push({
				path: '/warehouse/salesDelivery/noticeSet',
				query: { type: typeStr1, productId: row.id },
			});
		},
		// 上下查数据
		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 === 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,
				});
			}
		},
		// 用料清单-跳转到生产用料清单设置页面
		// 自定义的数据源
		getselfData() {
			// 获取自定义条件数据
			this.$http.get('Dictionary/deliverynotice').then((req) => {
				var newList = [];
				toRaw(req.data).forEach((element) => {
					newList.push(element);
				});
				this.statusForm.customCondition = toRaw(newList);
			});
			// 获取所需要的状态
			this.$http.get('SalOrder/GetEnum').then((req) => {
				// 单据类型
				for (const key in req.data.salOrderType) {
					this.statusForm.orders.push({
						id: key,
						name: req.data.salOrderType[key],
					});
				}
				// 单据状态
				for (const key in req.data.documentStatus) {
					this.statusForm.bills.push({
						id: key,
						name: req.data.documentStatus[key],
					});
				}
				// 关闭状态
				for (const key in req.data.closeStatus) {
					this.statusForm.cloStatus.push({
						id: key,
						name: req.data.closeStatus[key],
					});
				}
				// 供应链
				for (const key in req.data.supplyChainType) {
					this.statusForm.supplys.push({
						id: key,
						name: req.data.supplyChainType[key],
					});
				}
				// 是否211
				for (const key in req.data.is211Type) {
					this.statusForm.is211.push({
						id: key,
						name: req.data.is211Type[key],
					});
				}
				// 是否赠品
				for (const key in req.data.isFreeType) {
					this.statusForm.isFree.push({
						id: key,
						name: req.data.isFreeType[key],
					});
				}
			});
			// 获取仓库
			this.$http
				.get('SysConfig/GetWarehouseByOrg/' + this.orgId)
				.then((req) => {
					this.statusForm.warehouse = req.data;
				});
			// 获取子仓库
			this.$http.get('SysConfig/GetChildWarehouse').then((req) => {
				this.statusForm.childWarehouse = req.data;
			});
			// 获取组织下所有人员
			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.statusForm.orgAllPerson = req.data;
				});
			} else {
				this.statusForm.orgAllPerson = userlistall;
			}
			// 收款条件
			this.$http.get('SysConfig/GetReccondition').then((req) => {
				this.statusForm.reccondition = toRaw(req.data);
			});
			// 结算方式
			this.$http.get('SysConfig/GetSettletype').then((req) => {
				this.statusForm.settleType = toRaw(req.data);
			});
			// 结算币别
			this.$http.get('SysConfig/GetDcurrency').then((req) => {
				this.statusForm.dcurrency = toRaw(req.data);
			});
			// 供应链
			// 结算组织
		},
		// 自定义监听数据处理
		setselfChangeValue(
			customerSel1,
			customerSel2,
			customerSel3,
			key,
			compKey
		) {
			if (this[customerSel1] == undefined) {
				this[customerSel1] = key;
			}
			if (this[customerSel1] == key) {
				return;
			}
			if (
				this[customerSel1] == this[customerSel2] ||
				this[customerSel1] == this[customerSel3]
			) {
				this[customerSel1] = key;
				this[compKey] += 1;
				this.$message.error({
					message: '不能重复选择!',
					showClose: true,
				});
			}
		},
		// 自定义选择赋值结果
		selfResult(result, fieldSale, fieldObj, tempObj) {
			this[fieldSale] = result.currVal;
			this[fieldObj] = result.outResult;

			if (JSON.stringify(this[fieldObj]) != '{}') {
				this[tempObj] = JSON.parse(JSON.stringify(this[fieldObj]));
				for (const key in this[fieldObj]) {
					this.search[key] = this[fieldObj][key];
				}
			} else {
				for (const key in this[tempObj]) {
					delete this.search[`${key}`];
				}
				this[tempObj] = null;
			}

			if (this[fieldSale] == undefined || this[fieldSale] == '') {
				for (const key in this[tempObj]) {
					delete this.search[`${key}`];
				}
				this[tempObj] = null;
			}
		},
		// 搜索切换高度
		openRow() {
			this.isDown = !this.isDown;
			this.rowShow = !this.rowShow;
			if (this.rowShow) {
				this.heightNum = this.heightNum - 80;
			} else {
				this.heightNum = this.heightNum + 80;
			}
		},
		// 点击生产订单查看或者是编辑
		jump(item) {
			// 只有创建和重新审核的单据才能做修改，其余都是查看
			let typeStr =
				item.documentStatus === '重新审核' ||
				item.documentStatus === '创建'
					? 'edit'
					: 'see';
			if (typeStr === 'edit') {
				this.$router.push({
					path: '/warehouse/salesDelivery/noticeSet',
					meta: { title: '编辑发货通知单' },
					query: { type: typeStr, productId: item.id },
				});
			} else {
				this.$router.push({
					path: '/warehouse/salesDelivery/noticeSet',
					query: { type: typeStr, productId: item.id },
				});
			}
		},
		// 获取需要状态列表---[单据状态，领料状态，业务状态]
		getStatus() {
			this.$http.get('DeliveryNoticeOrder/GetStatus').then((r) => {
				if (r.status === 200) {
					this.documentStatuslist = r.data.documentStatus;
				}
			});
		},
		// 获取部门数据
		getProductdept() {
			this.$http.post('SysConfig/GetDept/' + this.orgId).then((res) => {
				if (res.status === 200) {
					this.productDeptList = res.data;
				}
			});
		},
		// 获取生产订单数据
		getnotice() {
			this.isLoading = true;
			this.$http
				.post('DeliveryNoticeOrder/GetList', this.search)
				.then((res) => {
					if (res.status === 200) {
						this.isLoading = false;
						this.tableData = res.data.list;
						this.orderTotal = res.data.total;
						this.salesNumber = res.data.salesNumber;
						this.allAmountLc = res.data.allAmountLc;
						this.stockOutNumber = res.data.stockOutNumber;
						this.remainOutNumber = res.data.remainOutNumber;
					}
				});
		},
		// 顶部公共按钮操作
		actionhandel(type) {
			this.actionType = type;
			if (this.multipleSelection && this.multipleSelection.length > 0) {
				let nweArysize = 0;
				// 单据id集合 （有去重）
				let newArry = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.id;
						})
					),
				];
				// 取单据订单号
				let orderNoArry = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.billNO;
						})
					),
				];
				this.OrderNoNames = [];
				this.OrderNoNames = orderNoArry;
				// 明细id集合 （有去重）
				let detailsIds = [
					...new Set(
						this.multipleSelection.map((item) => {
							return item.detailId;
						})
					),
				];
				this.OrdedetailIds = [];
				this.OrdedetailIds = detailsIds;
				// 单据id 集合的size
				nweArysize = new Set(
					this.multipleSelection.map((item) => {
						return item.id;
					})
				).size;
				// 点击提交
				if (type === 'submit') {
					this.toolarFn('DeliveryNoticeOrder/CommitList', newArry);
				}
				// 点击撤销
				if (type === 'revoke') {
					this.toolarFn('DeliveryNoticeOrder/Revoke', newArry);
				}
				// 点击审核
				if (type === 'audit') {
					this.toolarFn('DeliveryNoticeOrder/Check', newArry);
				}
				// 点击反审核
				if (type === 'de-approval') {
					this.toolarFn('DeliveryNoticeOrder/NoCheck', newArry);
				}
				// 点击删除
				if (type === 'delet') {
					this.toolarFn('DeliveryNoticeOrder/Delete', newArry);
				}
				// 点击下推
				if (type === 'push-down') {
					if (
						this.multipleSelection.filter((it) => {
							return it.documentStatus !== '已审核';
						}).length > 0
					) {
						this.$message.error({
							message:
								'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
							showClose: true,
						});
					} else {
						this.dialogxt = true;
					}
				}
				// 点击查询--上查
				if (type === 'up-check') {
					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.error({
										message:
											'没有可上查的条件,请确认是否下推过',
										showClose: true,
									});
								}
							}
							console.log('上查', res, this.upOrDownList);
						});
				}
				// 点击查询--下查
				if (type === 'down-check') {
					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,
									});
								}
							}
						});
				}
				// 点击关闭
				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.getnotice();
								}
							});
					} 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.getnotice();
								}
							});
					} else {
						this.$message.error({
							message: '请先选择要下推的明细行！',
							showClose: true,
						});
					}
				}
				// 打印
				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('orderDate', false)
						);
						setTimeout(() => {
							newprintPreview('发货通知单');
						}, 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'
						? 'DeliveryNoticeOrder/Export'
						: 'DeliveryNoticeOrder/ExportAll',
					this.search
				);
			}
			// 点击刷新
			if (type === 'refresh') {
				this.search.pageNo = 1;
				this.getnotice();
			}
		},
		// 顶部操作方法-公共部分封装下
		toolarFn(path, newArry, detailsIds) {
			let formdata = detailsIds
				? {
						ids: newArry,
						detailsIds: detailsIds,
				  }
				: { ids: newArry };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					this.dialogVisible = true;
					this.tableInfo = res.data;
					this.search.pageNo = 1;
					this.getnotice();
				}
			});
		},
		// 下单日期改变
		time1Chang(value) {
			if (value && value.length > 0) {
				this.search.orderBeginDate = value[0];
				this.search.orderEndDate = value[1];
			} else {
				this.search.orderBeginDate = '';
				this.search.orderEndDate = '';
			}
		},
		// 搜索事件
		searchData() {
			this.search.pageNo = 1;
			this.getnotice();
		},
		//控制表头颜色
		headerBg({ row, column, rowIndex, columnIndex }) {
			if (columnIndex === 17 || columnIndex === 18) {
				return `text-align:right!important;`;
			}
		},
		headerRigthMethod({ row, column, rowIndex, columnIndex }) {
			return 'headerRight';
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
		handleSizeChange(val) {
			this.search.pageNo = 1;
			this.search.pageSize = val;
			this.Init();
		},
		handleCurrentChange(val) {
			this.search.pageNo = val;
			this.Init();
		},
		unitPriceMethods(value) {
			if (typeof value == 'number') {
				var valNum4 = value.toFixed(4);
				var valStr4 = valNum4.toString();
				if (valStr4.charAt(valStr4.length - 1) == 0) {
					var valStr3 = valStr4.slice(0, valStr4.length - 1);
					if (valStr3.charAt(valStr3.length - 1) == 0) {
						var valStr2 = valStr3.slice(0, valStr3.length - 1);
						return valStr2;
					} else {
						return valStr3;
					}
				} else {
					return valStr4;
				}
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderList.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
