<!-- 委外退料订单 -->
<template>
	<div class="main-container order-mc-bg">
		<div class="sale-container">
			<!-- 打印摸版组件-->
			<prtMoled
				:printData="{
					tableData: multipleSelection,
					orderName: '委外退料单',
				}"
				:theadDate="theadDate"
				v-show="false"
			>
			</prtMoled>
			<!-- 顶部按钮组 -->
			<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.outSourcReturnNo
												"
											></el-input>
											<div
												:data-clipboard-text="
													search.outSourcReturnNo
												"
												@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
											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-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-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" class="form-row2-row2">
									<el-col :span="8" class="form-r2-r2-col">
										<el-form-item label="自定义条件1">
											<CustomCondition
												:getCustomerItem="
													statusForm ? 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 ? 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 ? 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 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="salBillNo"
							width="187"
						></el-table-column>
						<el-table-column
							align="left"
							fixed
							label="委外订单号"
							prop="outSourcOrderNO"
							width="172"
						></el-table-column>
						<el-table-column
							align="left"
							fixed
							label="委外退料单号"
							prop="outSourcReturnNo"
							width="172"
						>
							<template #default="scope">
								<span
									@click="jump(scope.row)"
									style="color: #4178d5"
									>{{ scope.row.outSourcReturnNo }}</span
								>
							</template>
						</el-table-column>
						<el-table-column
							align="left"
							label="下单日期"
							prop="date"
							width="83"
						>
							<template #default="scope">
								<span>{{
									scope.row.date
										? transformTime(scope.row.date)
										: ''
								}}</span>
							</template>
						</el-table-column>
						<el-table-column
							align="center"
							label="单据状态"
							prop="documentStatus"
							width="72"
						/>
						<el-table-column
							align="left"
							label="组织"
							prop="suborg"
							width="172"
						/>
						<el-table-column
							align="left"
							label="供应商"
							prop="supplier"
							width="172"
						/>
						<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="100"
						/>
						<el-table-column
							align="center"
							label="子单位"
							prop="subUnit"
							width="81"
						/>
						<el-table-column
							align="center"
							label="单位"
							prop="unit"
							width="81"
						/>
						<el-table-column
							align="right"
							label="实退数量"
							prop="realNumber"
							width="100"
						/>
						<el-table-column
							align="left"
							label="仓库"
							prop="stock"
							width="120"
						/>
						<!-- <el-table-column prop="stockLoc" label="仓位" align="left" width="160" /> -->
						<el-table-column
							align="center"
							label="退料类型"
							prop="returnType"
							width="83"
						/>
						<el-table-column
							align="left"
							label="退料原因"
							prop="reason"
							width="250"
						/>
						<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">{{ realNumber }}</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
								}}</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="dialogCX" width="20%">
			<div class="sale-page-table-body">
				<el-radio-group 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 {
	resultComMethods,
	customChangeMethods,
	transformTimestamp,
	exporthandel,
	htmlToExcel,
	newprintPreview,
	dateData,
} from '@/utils/pubulic.js';
import { outSourcRetrunOrderPrint } from '@/utils/printPagekey.js';
import { orderCopy } from '@/utils/takeMethods';
import CustomCondition from '@/components/public/CustomCondition.vue';
export default {
	name: 'OutSourcRetrunOrder',
	components: {
		CustomCondition,
	},
	data() {
		return {
			theadDate: JSON.parse(JSON.stringify(outSourcRetrunOrderPrint)), // 打印要的字段表
			statusForm: {
				customCondition: [],
			}, // 自定义条件 订单类型 单据状态 供应组织 是否211 是否赠品 关闭状态
			//条件
			reset: false,
			customerSel1: '',
			customerSel2: '',
			customerSel3: '',
			tempObj1: null,
			tempObj2: null,
			tempObj3: null,
			compKey1: 0,
			compKey2: 0,
			compKey3: 0,
			CXcheckVal: null, // 查询选择
			dialogCX: false, // 选择查询弹框显示
			upOrDownList: [], // 上查下查弹窗可选数据
			OrdedetailIds: [], // 勾选的明细id集合
			OrderNoNames: [], // 选择的单据订单号集合
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号str
			CXaction: '', // 判断是上查还是下查
			actionType: '', //判断点击的顶部那个按钮
			tableInfo: [], //操作结果
			isLoading: false, //表格加载数据
			documentStatuslist: [], // 单据状态
			pickmtStatuslist: [], // 邻料状态
			produceBusinessStatuslist: [], // 业务状态
			multipleSelection: [],
			ids: [],
			btnType: [
				'exDetails',
				's-p-t-g1',
				'push-down',
				'close',
				'de-close',
				'split-order',
				'finish',
				'close-case',
				'de-excute-start',
				'de-excute-finish',
				'print-aterial-list',
				'down-check',
			], // 不需要显示的顶部按钮类型
			productDeptList: [], // 生产部门
			Time1: [],
			Time2: [],
			dialogVisible: false, // 操作弹框显示
			dialogxt: false, // 选择下推单据弹框显示
			// 搜索条件
			search: {
				orgId: '', // 组织id
				outSourcReturnNo: '', // 退料单号
				suborgId: '', //委外组织
				documentStatus: '', //单据状态
				product: '', //产品 物料名称/编码/SKU
				orderBeginDate: '', // 下单开始日期
				orderEndDate: '', //下单结束日期
				realNumber: '', //实退数量
				pageNo: 1, // 页码
				pageSize: 50, // 页数
				detailsIds: [], // 明细ids集合
			},
			realNumber: 0, //实退数量
			tableData: [],
			selectItem: 0,
			rowShow: false,
			heightNum: 0,
			windowHeight: 0,
			orderTotal: 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;
		this.getProductdept();
		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.Init();
			}
		},
		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;
		},
	},
	methods: {
		keyupFn(e) {
			if (e.keyCode === 13) {
				// enter见搜索
				this.searchData();
			}
		},
		// 初始化
		Init() {
			this.getcheckInfo();
			this.getoutSourcRetrunOrder();
			this.getStatus();
			this.getselfData();
		},
		resetSearch() {
			// 搜索条件
			this.reset = true;
			(this.search = {
				orgId: this.orgId, // 组织id
				outSourcReturnNo: '', // 退料单号
				suborgId: '', //委外组织
				documentStatus: '', //单据状态
				product: '', //产品 物料名称/编码/SKU
				orderBeginDate: '', // 下单开始日期
				orderEndDate: '', //下单结束日期
				realNumber: '', //实退数量
				pageNo: 1, // 页码
				pageSize: 50, // 页数
				detailsIds: [], // 明细ids集合
			}),
				(this.Time1 = []);
			this.customerSel1 = '';
			this.customerSel2 = '';
			this.customerSel3 = '';
			setTimeout(() => {
				this.reset = false;
			}, 200);
			this.getoutSourcRetrunOrder();
		},
		resultCom(result, fieldSale, fieldObj, tempObj) {
			// 自定义条件赋值
			let returnResult = resultComMethods(
				result,
				this[fieldSale],
				result.outResult,
				this[tempObj],
				this.search
			);
			this[fieldSale] = returnResult.fieldSale;
			this[fieldObj] = returnResult.fieldObj;
			this[tempObj] = returnResult.tempObj;
			this.search = returnResult.search;
		},
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 双击计入
		openDetailsDB(row, column) {
			let typeStr1 =
				row.documentStatus === '重新审核' ||
				row.documentStatus === '创建'
					? 'edit'
					: 'see';
			this.$router.push({
				path: '/Outsourc/outsourcMange/outSourcReturnSet',
				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 === 3) {
					// 委外订单
					pathName = 'OutsourcOrder';
				}
				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: 'up',
							actionName: '委外退料',
							OrderNoNames: JSON.stringify(
								ary.length > 0 ? ary[0].billNos : []
							),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// 自定义的数据源
		getselfData() {
			// 获取自定义条件数据
			this.$http.get('Dictionary/outSourcReturn').then((req) => {
				// 下拉字段集合
				var newList = [];
				req.data.forEach((element) => {
					newList.push(element);
				});
				this.statusForm.customCondition = newList;
			});
		},
		// 自定义监听数据处理
		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.documentStatusKey === 'a' ||
				item.documentStatusKey === 'd' ||
				item.documentStatus === '重新审核' ||
				item.documentStatus === '创建'
					? 'edit'
					: 'see';
			this.$router.push({
				name: 'AddOutSourcRetrunOrder',
				query: { type: typeStr, productId: item.id },
			});
		},
		// 获取需要状态列表---[单据状态，邻料状态，业务状态]
		getStatus() {
			this.$http.get('OutSourcOrder/GetStatus').then((r) => {
				if (r.status === 200) {
					this.documentStatuslist = r.data.documentStatus;
					this.pickmtStatuslist = r.data.pickmtStatus;
					this.produceBusinessStatuslist =
						r.data.produceBusinessStatus;
				}
			});
		},
		// 获取部门数据
		getProductdept() {
			this.$http.post('SysConfig/GetDept/' + this.orgId).then((res) => {
				if (res.status === 200) {
					this.productDeptList = res.data;
				}
			});
		},
		// 获取委外订单数据
		getoutSourcRetrunOrder() {
			this.isLoading = true;
			this.$http
				.post('OutSourcReturn/OutSourcReturnQuery', this.search)
				.then((res) => {
					if (res.status === 200) {
						this.isLoading = false;
						this.tableData = res.data.list;
						this.orderTotal = res.data.total;
						this.realNumber = res.data.realNumber;
					}
				});
		},
		// 顶部公共按钮操作
		actionhandel(type) {
			this.actionType = type;
			// 点击新增
			if (type === 'add') {
				this.$router.push({
					name: 'EditOutSourcRetrunOrder',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			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.outSourcReturnNo;
						})
					),
				];
				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 === 'copy') {
					if (nweArysize !== 1 && nweArysize > 0) {
						this.$message.error({
							message: '只能克隆单号相同的委外订单',
							showClose: true,
						});
					} else {
						this.$router.push({
							name: 'OutsourcingOrderAdd',
							query: {
								type: 'copy',
								productId: this.multipleSelection[0].id,
							},
						});
					}
				}
				// 点击提交
				if (type === 'submit') {
					this.toolarFn('OutSourcReturn/CommitList', newArry);
				}
				// 点击撤销
				if (type === 'revoke') {
					this.toolarFn('OutSourcReturn/Revoke', newArry);
				}
				// 点击审核
				if (type === 'audit') {
					this.toolarFn('OutSourcReturn/Check', newArry);
				}
				// 点击反审核
				if (type === 'de-approval') {
					this.toolarFn('OutSourcReturn/NoCheck', newArry);
				}
				// 点击删除
				if (type === 'delet') {
					this.toolarFn('OutSourcReturn/Delete', newArry);
				}
				// 点击查询上查
				if (type === 'up-check') {
					if (detailsIds.length > 0) {
						this.$http
							.post('OutSourcReturn/Upper', { ids: detailsIds })
							.then((res) => {
								if (res.status === 200) {
									this.upOrDownList = res.data;
									this.dialogCX =
										res.data && res.data.length > 0
											? true
											: false;
									this.CXcheckVal =
										res.data && res.data.length === 1
											? res.data[0].orderType
											: null; //只有一个，就个默认值
								}
							});
					} else {
						this.$message.warning({
							message:
								'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能上查',
							showClose: true,
						});
					}
				}
				// 打印预览
				if (type === 'print-brower') {
					if (
						this.multipleSelection.filter((it) => {
							return (
								it.documentStatus !== '已审核' ||
								it.supplier !==
									this.multipleSelection[0].supplier
							);
						}).length > 0
					) {
						this.$message.error({
							message: '仅可打印已审核且供应商相同的单据',
							showClose: true,
						});
					} else {
						this.multipleSelection = this.multipleSelection.sort(
							dateData('date', 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'
						? 'OutSourcReturn/Export'
						: 'OutSourcReturn/ExportAll',
					this.search
				);
			}
			// 点击刷新
			if (type === 'refresh') {
				this.getoutSourcRetrunOrder();
			}
		},
		// 顶部操作方法-公共部分封装下
		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.getoutSourcRetrunOrder();
				}
			});
		},
		// 下单日期改变
		time1Chang(value) {
			if (value && value.length > 0) {
				this.search.orderBeginDate = value[0];
				this.search.orderEndDate = value[1];
			} else {
				this.search.orderBeginDate = '';
				this.search.orderEndDate = '';
			}
		},
		// 期望日期改变
		time2Chang(value) {
			if (value && value.length > 0) {
				this.search.expectBeginDate = value[0];
				this.search.expectEndDate = value[1];
			} else {
				this.search.expectBeginDate = '';
				this.search.expectEndDate = '';
			}
		},
		// 搜索事件
		searchData() {
			this.search.pageNo = 1;
			this.getoutSourcRetrunOrder();
		},
		//控制表头颜色
		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();
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderList.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
