<!-- 生产入库新增编辑查看-->
<template>
	<div>
		<transition name="bounce">
			<examineTop
				v-if="isExmaineTop === 2"
				:radios="radios"
				@handleBtns="handleBtns"
				@handleOpen="handleOpen"
				:isexamineBtns="isexamineBtns"
			/>
			<!-- 	:isexamineBtns="isexamineBtns" -->
		</transition>
	</div>

	<div
		:style="{ height: heightNum + 'px!important' }"
		class="sale-details-container order-mc-bg main-container"
	>
		<div class="sale-details-btn-group">
			<!-- 顶部按钮 -->
			<template v-if="isExmaineTop !== 2">
				<toolBtn
					:btnType="btnType"
					:isDisable="isDisable"
					@actionhandel="actionhandel"
					:isExmaineTop="isShow"
				></toolBtn>
			</template>
		</div>
		<div class="sale-details-base-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				v-if="pagefromData.documentStatus === 'c'"
			/>
			<el-tabs style="margin-bottom: 8px" type="border-card">
				<!-- 基本信息 -->
				<el-tab-pane label="基本信息">
					<div class="base-info-form-box">
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<div class="order-number-bx item-bt-s">
											<el-form-item
												class="Iisshow"
												label="生产入库单号"
											>
												<el-input
													disabled
													placeholder="(保存时自动生成)"
													v-model.trim="
														produceInStockNo
													"
												></el-input>
												<div
													:data-clipboard-text="
														produceInStockNo
													"
													@click="saleOrderCopy"
													class="copyBtn"
												>
													<i
														class="el-icon-document-copy"
													/>
												</div>
											</el-form-item>
										</div>
										<el-form-item
											class="item-bt-s"
											label="单据状态"
										>
											<el-select
												:disabled="true"
												placeholder="请选择单据状态"
												v-model="
													pagefromData.documentStatus
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in documentStatuslist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="生产入库单类型"
										>
											<el-select
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												clearable
												placeholder="请选择"
												v-model="
													pagefromData.documentType
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													class="f-12"
													v-for="(
														value, key, index
													) in inStockDocumentTypelist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s item-date"
											label="下单日期"
										>
											<el-date-picker
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												format="YYYY-MM-DD"
												type="date"
												v-model="pagefromData.date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="组织"
										>
											<el-select
												@change="orgChange"
												disabled
												filterable
												placeholder="请选择组织"
												v-model="pagefromData.prdorgId"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													v-for="item in orgIdArr"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<!-- 操作记录 -->
				<el-tab-pane :disabled="!pagefromData.id" label="操作记录">
					<div
						:style="{ height: '185px!important' }"
						class="base-info-form-box"
					>
						<el-form
							:model="pagefromData"
							label-width="80px"
							ref="form"
						>
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											class="item-bt-s"
											label="创建人"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													pagefromData.createName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											class="item-bt-s"
											label="创建日期"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													pagefromData.createDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="最后修改人"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													pagefromData.modifyName
												"
											></el-input>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="最后修改时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													pagefromData.modifyDate
												"
											></el-input>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="提交时间"
										>
											<el-input
												:disabled="true"
												placeholder
												v-model.trim="
													pagefromData.commitDate
												"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													:maxlength="50"
													class="item-bt-s"
													label="审核人"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model.trim="
															pagefromData.checkName
														"
													></el-input>
												</el-form-item>
												<el-form-item
													class="item-bt-s"
													label="审核时间"
												>
													<el-input
														:disabled="true"
														placeholder
														v-model.trim="
															pagefromData.checkDate
														"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<!-- 明细信息 -->
		<div class="sale-details-tell-info">
			<div class="tell-info-row-title">
				<h3>明细信息</h3>
				<div class="long-line-bx">
					<div class="long-line"></div>
				</div>
			</div>
			<!-- 明细工具栏 -->
			<div class="tell-info-button-group">
				<DetailsOperation
					:detailBtn="detailBtn"
					:deviationSelectArr="selectRowIndexArr"
					:isEdit="
						pagefromData.documentStatus !== 'a' &&
						pagefromData.documentStatus !== 'd'
					"
					@copyCellcolumn="copyCellcolumn"
					@copyRow="bottomCopyRow"
					@deleteRow="selectDeleteRow"
					@insertObj="getInsertInfo"
				></DetailsOperation>
			</div>
			<!-- 表格信息-->
			<div class="tell-info-table">
				<el-table
					:cell-class-name="tableCellClassName"
					:data="pagefromData.details"
					:header-cell-class-name="mustAfter"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectRowAll"
					border
					max-height="400"
					ref="multipleTable"
					style="width: 100%; font-size: 12px"
				>
					<el-table-column
						align="center"
						fixed
						type="selection"
						width="40"
					/>
					<el-table-column
						align="left"
						label="销售订单号"
						prop="salBillNo"
						width="187"
					></el-table-column>
					<el-table-column
						align="left"
						label="生产订单号"
						prop="moBillNo"
						width="172"
					></el-table-column>
					<el-table-column
						align="left"
						label="物料编码"
						prop="materialNumber"
						width="180"
					></el-table-column>
					<el-table-column
						align="left"
						label="规格型号(SKU)"
						prop="specification"
						width="280"
					></el-table-column>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="150"
					></el-table-column>
					<el-table-column
						align="center"
						label="单位"
						prop="unitId"
						width="72"
					>
						<template #default="scope">
							<span>{{
								publicidbyname(unitlist, scope.row.unitId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="workShopId" width="150">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>生产部门
						</template>
						<template
							@click="
								getRowCol(scope.row, scope.column, 'workShopId')
							"
							#default="scope"
						>
							<el-cascader
								:disabled="
									(pagefromData.prdorgId === 0 ||
										pagefromData.prdorgId === '' ||
										pagefromData.prdorgId === null) &&
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:options="productDeptList"
								:props="optionProps"
								:show-all-levels="false"
								clearable
								placeholder="请选择部门"
								v-if="scope.row.isworkShopIdshow"
								v-model="scope.row.workShopId"
							></el-cascader>
							<span v-else>{{
								scope.row.workShopId
									? publicidbyname(
											productDeptList,
											scope.row.workShopId
									  )
									: null
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="right"
						label="应收数量"
						prop="mustNumber"
						width="120"
					/>
					<el-table-column
						align="right"
						prop="realNumber"
						width="130"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>实收数量
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'realNumber' + scope.$index"
								@blur="
									numberChage(
										scope.row.realNumber,
										scope.$index,
										scope.row,
										'realNumber'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'realNumber'
									)
								"
								maxlength="11"
								placeholder
								v-if="scope.row.isrealNumbershow"
								v-model="scope.row.realNumber"
							></el-input>
							<span v-else>{{ scope.row.realNumber }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="仓库"
						prop="stockId"
						width="155"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>仓库
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								@change="changeWarehouse($event, scope.$index)"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'stockId'
									)
								"
								filterable
								placeholder="请选择"
								v-if="scope.row.isstockIdshow"
								v-model="scope.row.stockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in warehouse"
								></el-option>
							</el-select>
							<span v-else>{{
								publicidbyname(warehouse, scope.row.stockId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="customerId" width="172">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									!customerWarehouseTaglist[scope.$index] ||
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd')
								"
								@change="
									changecustomer(
										$event,
										scope.$index,
										'product'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerId'
									)
								"
								class="f_12"
								clearable
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.iscustomerIdshow"
								v-model="scope.row.customerId"
							>
								<el-option
									:key="item.id"
									:label="item.name"
									:value="item.id"
									v-for="item in customerlist"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
								></el-option>
							</el-select>
							<span v-else>{{
								scope.row.customerId
									? publicidbyname(
											customerlist,
											scope.row.customerId
									  )
									: null
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="客户仓库"
						prop="customerStockId"
						width="150"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户仓库
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									!customerWarehouseTaglist[scope.$index] ||
									!scope.row.customerId ||
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd')
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerStockId'
									)
								"
								clearable
								filterable
								placeholder="请选择"
								v-if="scope.row.iscustomerStockIdshow"
								v-model="scope.row.customerStockId"
							>
								<el-option
									:disabled="item.disabled"
									:key="item.id"
									:label="item.name"
									:value="item.id"
									v-for="item in customeStockArrylist[
										scope.$index
									]"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
								></el-option>
							</el-select>
							<span v-else>{{
								scope.row.customerStockId
									? publicidbyname(
											customeStockArrylist[scope.$index],
											scope.row.customerStockId
									  )
									: null
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="remark" width="225">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'remark' + scope.$index"
								:maxlength="2000"
								@input="
									getRowCol(scope.row, scope.column, 'remark')
								"
								v-if="scope.row.isremarkshow"
								v-model="scope.row.remark"
							></el-input>
							<span v-else>{{ scope.row.remark }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<!-- 操作结果 -->
		<el-dialog title="操作结果" v-model="dialogVisible" width="40%">
			<div class="sale-page-table-body">
				<el-table
					:data="tableInfo"
					:header-cell-class-name="headerRigthMethod"
					border
					class="table-box"
					height="300"
					id="tableInfo-table"
				>
					<el-table-column label="序号" prop="date" width="50">
						<template #default="scope">
							<span>{{ scope.$index + 1 }}</span>
						</template>
					</el-table-column>
					<el-table-column
						label="订单号"
						prop="orderNo"
						width="200"
					></el-table-column>
					<el-table-column label="指令" prop="a" width="110">
						<template #default>
							<span>{{
								actionType === 'submit'
									? '提交'
									: actionType === 'revoke'
									? '撤销'
									: actionType === 'audit'
									? '审核'
									: actionType === 'de-approval'
									? '反审'
									: actionType === 'delet'
									? '删除'
									: actionType === 'finish'
									? '完工'
									: actionType === 'close-case'
									? '结案'
									: actionType === 'de-excute-start'
									? '反执行至开工'
									: actionType === 'de-approval'
									? ' 结案'
									: actionType === 'delet'
									? '删除'
									: actionType === 'finish'
									? '完工'
									: actionType === 'close-case'
									? '反审'
									: actionType === 'de-excute-finish'
									? '反执行至完工'
									: ''
							}}</span>
						</template>
					</el-table-column>
					<el-table-column label="结果" width="80">
						<template #default="scope">
							<span :style="{ 'txt-Red': scope.row.isSuccess }">{{
								scope.row.isSuccess ? '成功' : '失败'
							}}</span>
						</template>
					</el-table-column>
					<el-table-column label="信息" prop="msg">
						<template #default="scope">
							<span class="txt-Red">{{ scope.row.msg }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<span
						class="f-12 ext-black-light"
						style="margin-right: 25px"
						>共{{
							tableInfo && tableInfo.length > 0
								? tableInfo.length
								: 0
						}}条</span
					>
					<el-button
						@click="
							handelhtmlToExcel('tableInfo-table', '操作结果');
							dialogVisible = false;
						"
						size="small"
						>导 出</el-button
					>
					<el-button
						@click="dialogVisible = false"
						size="small"
						type="primary"
						>关 闭</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择上下查单据 -->
		<el-dialog title="上查结果" top="15%" v-model="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 examineTop from '@/components/examineTop/index.vue';
import toolBtn from '@/components/public/toolBtn/toolBtn.vue';

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

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

export default {
	name: 'AddProductWarehouOrder',
	components: {
		examineTop,
		toolBtn,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			examineObj: {},
			radios: [],
			salePrecisionNumber: [],
			isPrecision: [],
			isCount: [],
			isDisable: false,
			savetag: 0,
			optionProps: JSON.parse(JSON.stringify(pageoPtionProps)),
			customerlist: [], // 客户下拉数据
			customeStockArrylist: [], // 所有客户仓库下拉数据
			CXcheckVal: '', // 上下查选中
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			multipleSelection: [], // 明细列表选中
			tableInfo: [], //操作结果
			dialogVisible: false, // 操作弹框显示
			dialogxt: false, // 选择下推单据弹框显示
			actionType: '', // 操作动作 新增还是修改还是编辑
			documentStatuslist: [], // 单据状态下拉数据
			inStockDocumentTypelist: [], // 生产入库类型
			matterCodelist: [], // 物料下拉数据
			specificationlist: [], // 规格型号（sku）下拉数据
			unitlist:
				this.$store.state && this.$store.state.storeData.allUnit
					? this.$store.state.storeData.allUnit
					: [], // 获取计量单位数据
			productDeptList: [], // 生产部门
			warehouse: [], //仓库下拉数据
			warechildhouse: [], // 仓位下拉数据
			customerWarehouseTaglist: [], // 判断客户仓库是否必填 这个值有仓库带出默认是不必填
			loading: false,
			saleOrderNumlist: [], // 销售订单号下拉数据
			productOrderNumlist: [], // 生产订单号下拉数据
			produceInStockNo: '', // 生产入库订单号
			documentStatus: '', // 单据状态
			detailBtn: ['add', 'copy', 'delet'], // 明细操作
			pagefromData: {
				id: 0,
				date: transformTimestamp(new Date()), //下单日期
				documentType: '', // 生产退料单类型
				documentStatus: '',
				prdorgId: null, //生产组织
				details: [],
			},
			pageAction:
				this.$route.query && this.$route.query.type
					? this.$route.query.type
					: '', // 判断到该页面的操作状态
			btnType: [], // 不需要显示的顶部按钮类型
			queryId: 0,
			addRow: {
				id: 0,
				seq: '', //序号
				salBillNo: '', //销售订单号
				moBillNo: '', // 生产订单号
				materialId: '', //物料编码
				subUnitId: '', //子单位
				unitId: '', //单位
				workShopId: '', //生产部门
				mustNumber: '', //应收数量
				realNumber: '', //实收数量
				stockId: '', //仓库
				stockLocId: '', //仓位
				remark: '', //备注
			},
			selectRowIndex: 0,
			// 批量填充
			batchfill: {
				romIndex: null,
				columnIndex: null,
				columnkey: null,
			},
			heightNum: 0,
			selectRowIndexArr: [],
		};
	},
	created() {
		this.setApprovalFlowStatus();
	},
	watch: {
		orgId(value) {
			this.orgId = value;
		},
		'pagefromData.documentStatus'(newvalue, oldvalue) {
			if (
				this.pagefromData.documentStatus === 'a' ||
				!this.pagefromData.documentStatus
			) {
				this.$topNavTagRename('新增生产入库单');
			} else {
				this.$topNavTagRename('编辑生产入库单');
			}
			if (
				this.pagefromData.documentStatus === 'a' ||
				this.pagefromData.documentStatus === 'd'
			) {
				this.btnType = [
					'add',
					'copy',
					'revoke',
					'audit',
					'de-approval',
					'delete',
					'push-down',
					'operation',
					'up-check',
					'down-check',
					// 'query',
					'refresh',
					's-p-t-g3',
					'operation',
					// 's-p-t-g4',
				]; // 不需要显示的顶部按钮类型
			} else {
				this.btnType = [
					'add',
					'copy',
					'delete',
					'push-down',
					'operation',
					'refresh',
					'operation',
					'down-check',
				];
			}
		},
	},
	computed: {
		...mapState({
			orgId: (state) =>
				state && state.org && state.org.orgId ? state.org.orgId : null,
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			userId: (state) => state.user.userInfo.staffId || null,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
			isShow: function () {
				return this.isExmaineTop;
			},
			getPageObjValue: function () {
				return function (arr, key) {
					return getObjValue(arr, key);
				};
			},
		}),
		publicidbyname: function () {
			// 根据key值显示对应的键名
			return function (arr, key) {
				return theUnitSet(arr, key);
			};
		},
	},
	mounted() {
		this.heightNum =
			document.documentElement.clientHeight - (40 + 30 + 16 + 16);
		this.queryId = this.$route.query.id;
		this.actionType = this.$route.query.type;
		this.pagefromData.details = [this.addRow];
		this.Init();
	},
	methods: {
		setExamine(res) {
			if (
				res.status === 200 &&
				res.data &&
				JSON.stringify(res.data) !== '{}'
			) {
				this.examineObj = res.data;
				//有审批流,但是自己不能审批则返回1,否则返回2,如果没有审批流或者报错为了不阻断流程返回3
				let isApprover = res.data.isApprover;
				this.isExmaineTop = isApprover ? 2 : 1;
				if (
					!res.data ||
					JSON.stringify(res.data) === '{}' ||
					this.pagefromData.documentStatus !== 'b'
				) {
					this.isExmaineTop = 3;
				}
				if (res.data.isDone) {
					this.pagefromData.documentStatus = 'c';
					this.isExmaineTop = 3;
				}
				this.isexamineBtns = false;
			} else {
				this.isExmaineTop = 3;
				this.isexamineBtns = false;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('ProduceInStock/Get/' + r.data.sendOrderId)
				.then((req) => {
					if (req.status == 200) {
						this.setpageDate(req);
						this.pagefromData.documentStatus =
							req.data.documentStatus;
						if (
							this.pagefromData.documentStatus === 'a' ||
							this.pagefromData.documentStatus === 'd'
						) {
							this.isEdit = false;
						}
						this.setExamine(r);
					}
				});
			// this.saveIds = r.data.id;
			// this.baseInfoForm = purGetOrderId(this.baseInfoForm, r);
			// this.$refs.multipleTable.clearSelection();
			// this.multipleSelection = [];
			// this.selectRowIndexArr = [];
		},
		handleSubmit(data) {
			this.isexamineBtns = true;
			this.$http
				.post(approvalFlowTrackingUpdate, data)
				.then((res) => {
					if (res.status === 200) {
						this.$message.success({
							message: '操作成功!',
							showClose: true,
						});
					}
					this.handleDetails(res);
				})
				.catch((err) => {
					if (err) {
						this.isExmaineTop = 3;
					}
				})
				.finally(() => {
					// this.isexamineBtns = false;
				});
		},
		//顶部按钮点击
		handleBtns(vals) {
			if (vals.type === 'out') {
				this.$router.go(-1);
			} else {
				let data = {
					approvalDetailsId: this.examineObj.approvalDetailsId,
					approvalOrderType: this.examineObj.sendOrderType,
					orderId: this.examineObj.sendOrderId,
					deptId: this.pagefromData.details[0].workShopId || 0,
					orgId: this.pagefromData.prdorgId,
					details: {
						trackId: this.examineObj.id,
						approverId: this.userId,
						approvalMethod: this.examineObj.currentApprovalMethod,
						approvalResult: vals.approvalResult,
						wayId: this.examineObj.currentWayId,
						remark: vals.remark,
						// upperId
					},
				};
				this.handleSubmit(data);
			}
		},
		//跳转到追踪页面
		handleOpen() {
			this.$router.push({
				path: '/examine/mange/examineFollow',
				query: { id: this.examineObj.id },
			});
		},
		//获取处理意见状态
		setApprovalFlowStatus() {
			this.radios = this.getApprovalResult;
		},

		//审批流-详情
		setApprovalFlowTrackingGetby(data) {
			if (
				this.$route.query.type === 'copy' &&
				this.pagefromData.outSourcOrderNo === ''
			) {
				this.examineObj = {};
				return;
			}
			if (data.tracking && data.tracking.remark) {
				this.$message.error({
					message: `单据由-${data.tracking.remark}`,
					showClose: true,
					duration: 5000,
				});
			}
			if (
				data.documentStatus === 'a' ||
				data.documentStatus == 'd' ||
				this.$route.query.type === 'copy'
			) {
				this.examineObj = data.tracking;
				return;
			}
			let obj = {
				orderId: data.id,
				deptId: data.details[0].workShopId || 0,
				approvalOrderType: 17,
				orgId: data.prdorgId,
			};
			this.$http
				.post(approvalFlowTrackingGetby, obj)
				.then((res) => {
					this.setExamine(res);
					if (res.status === 200) {
						this.setExamine(res);
						let details = res.data.details || [];
						let length = details.length;

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

		Init() {
			this.getUnit();
			this.getStatus();
			this.getAllcustomer();
			this.InItEditorCopy();
			// 主要是判断下推用
			this.getRuterData();
		},
		// 操作弹框导出
		handelhtmlToExcel(domid, title) {
			htmlToExcel(domid, title);
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 快粘贴
		pasteExcel(event, index, scope, key) {
			let rows = quikecopyValue(event);
			let recordAddIndex = index; // 记录行
			setTimeout(async () => {
				rows.forEach((it, idx) => {
					if (
						recordAddIndex + 1 <=
						this.pagefromData.details.length
					) {
						if (key === 'realNumber') {
							this.pagefromData.details[
								recordAddIndex
							].realNumber = it;
						}
						recordAddIndex++;
					}
				});
			}, 10);
		},
		// 获取客户仓库数据
		getCoustomerChild(value, index) {
			this.$http
				.post('SysConfig/GetCustomerStock', {
					customerId: value
						? value
						: this.pagefromData.details[index].customerId,
					orgId: this.pagefromData.prdorgId,
					stockId: this.pagefromData.details[index].stockId,
				})
				.then((res) => {
					if (res.status === 200) {
						this.customeStockArrylist[index] =
							res.data && res.data.length > 0
								? oldstocklist(
										res.data.concat(
											oldstocklist(
												this.pagefromData.details
											).customerStockList
										),
										'retrieve'
								  )
								: oldstocklist(
										oldstocklist(this.pagefromData.details)
											.customerStockList,
										'retrieve'
								  );
					}
				});
		},
		// 改变客户的时候获取对应的客户仓库 ---1 到时候应该替换为公司id
		changecustomer(id, index, type) {
			if (type !== 'init' && id) {
				if (type === 'product') {
					this.pagefromData.details[index].customerStockId = '';
				}
			}
			if (id) {
				this.getCoustomerChild(id, index);
			}
		},
		// 获取全部公司客户
		getAllcustomer() {
			var infocustomerlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.customerlist
					: [];
			if (JSON.stringify(infocustomerlist) === '[]') {
				this.$http.get('SysConfig/GetCustomer').then((res) => {
					if (res.status === 200) {
						this.customerlist =
							this.$store.state.storeData.customerlist = res.data;
					}
				});
			} else {
				this.customerlist = infocustomerlist;
			}
		},
		// 获取路由传过来的值
		getRuterData() {
			if (this.$route.query.type === 'pushDown') {
				let ids = JSON.parse(decodeURIComponent(this.$route.query.ids));
				this.$http
					.post('ProduceOrder/PushDownInStock', { ids: ids })
					.then((res) => {
						if (res.status === 200) {
							this.setpageDate({
								data: res.data,
							});
						}
					});
			}
		},
		//确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = '';
				if (this.CXcheckVal === 1) {
					// 生产订单
					pathName = 'ProductOrder';
				}
				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,
				});
			}
		},
		// 保存或者提交的时候，对数据个别字段例如 is211 seq 做数据整理，避免提交保存失败
		arrangeData(type) {
			if (this.pagefromData.details) {
				if (type) {
					this.savetag = 0;
					this.pagefromData.details.forEach((it, index) => {
						if (!it.realNumber || it.realNumber == 0) {
							this.savetag++;
						}
						it.seq = index;
					});
					if (this.savetag !== this.pagefromData.details.length) {
						let arr = [];
						arr = this.pagefromData.details.filter((it) => {
							return it.realNumber !== '' && it.realNumber > 0;
						});
						this.pagefromData.details = arr;
					}
				}
				// 清空明细选中
				this.$refs.multipleTable.clearSelection();
				this.selectRowIndexArr = [];
			}
		},
		// 初始化--编辑或者详情
		InItEditorCopy() {
			// 如果是复制，编辑，查看--过来的新增订单
			if (
				this.$route.query &&
				this.$route.query.type !== 'add' &&
				this.$route.query.productId
			) {
				this.getProductInfo(this.$route.query.productId);
			} else {
				this.customerWarehouseTaglist = [true];
				this.getProductdept(this.orgId);
				this.getWarehouse(this.orgId);
			}
		},
		// 生产组织下拉改变是 （会影响生产部门的数据）
		orgChange(value) {
			this.customerWarehouseTaglist = [true];
			this.getWarehouse(value);
			this.getProductdept(value);
			if (
				this.pagefromData.details &&
				this.pagefromData.details.length > 0
			) {
				this.pagefromData.details.forEach((res, index) => {
					this.pagefromData.details[index].workShopId = null;
				});
			}
		},
		numberPrecisionMethods(index) {
			if (this.pagefromData.details[index].unitId) {
				let tempList = this.unitlist.filter(
					(it) => it.id === this.pagefromData.details[index].unitId
				);
				if (tempList && tempList.length > 0) {
					tempList[0].precision == 0
						? (this.isPrecision[index] = true)
						: (this.isPrecision[index] = false);
					tempList[0].precision == 0
						? (this.salePrecisionNumber[index] = 0)
						: (this.salePrecisionNumber[index] =
								tempList[0].precision);
				}
			}

			this.isPrecision[index] = this.isPrecision[index]
				? this.isPrecision[index]
				: false;
			this.salePrecisionNumber[index] =
				this.salePrecisionNumber[index] ||
				this.salePrecisionNumber[index] == 0
					? this.salePrecisionNumber[index]
					: 10;
			if (
				!this.pagefromData.details[index].materialNumber &&
				!this.$route.query.id
			) {
				this.isPrecision[index] = true;
			}

			if (!this.isCount[index]) {
				this.isCount[index] = 1;
			}
		},
		// 数量改变时
		numberChage(val, index, item, key) {
			// 判断条件 单位
			this.numberPrecisionMethods(index);
			// 输入规则
			if (val) {
				if (val.toString().indexOf('.') !== -1) {
					let tempList = JSON.parse(
						JSON.stringify(
							this.unitlist.filter(
								(it) =>
									it.id ===
									this.pagefromData.details[index].unitId
							)
						)
					);
					if (tempList && tempList.length > 0) {
						tempList[0].roundoffType = 2;
					}
					let result = countMethodsUnitNumber(
						tempList,
						val,
						this.pagefromData.details[index][key],
						this.isCount[index],
						this.salePrecisionNumber[index],
						true
					);
					this.pagefromData.details[index][key] = result.value * 1;
					this.isCount[index] = result.isDefault;
				}
				let numD = '';
				let count = '\\d';
				for (
					let ind = 0;
					ind < this.salePrecisionNumber[index];
					ind++
				) {
					numD = numD + count;
				}
				let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
				this.pagefromData.details[index][key] =
					this.pagefromData.details[index][key] *
					(1)
						.toString()
						.replace(/[^\d^\\.]+/g, '')
						.replace('.', '$#$')
						.replace(/\./g, '')
						.replace('$#$', '.')
						.replace(eval(reg), '$1$2.$3');
				this.pagefromData.details[index][key] =
					this.pagefromData.details[index][key] * 1;
			}
			// 未入库数量 = 数量-合格入库数量
			this.pagefromData.details[index].noStockEligibleNumber =
				parseInt(item.number ? item.number : 0) -
				parseInt(item.stockEligibleNumber);
		},
		// 必填校验
		checkData() {
			let checkTag = false;
			if (!this.pagefromData.date || this.pagefromData.prdorgId) {
				this.$message.error({
					message: '请完善基本信息的必填项，再操作',
					showClose: true,
				});
				return;
			}
			if (!this.pagefromData.details) {
				this.$message.error({
					message: '请添加至少一条明细信息，再操作',
					showClose: true,
				});
				return;
			} else {
				let arytag = this.pagefromData.details.filter((it) => {
					return (
						!it.salOrderNo ||
						!it.materialId ||
						!it.number ||
						!it.status ||
						!it.planStartDate ||
						!it.planFinishDate ||
						!it.bomId
					);
				});
				if (arytag.length > 0) {
					checkTag = true;
				}
			}
		},
		// 详情或者下推过来的数据处理
		async setpageDate(res) {
			if (res) {
				this.pagefromData = JSON.parse(JSON.stringify(res.data));
				this.pagefromData.date =
					res && res.data && res.data.date
						? res.data.date
						: transformTimestamp(new Date()); //下单日期
				this.produceInStockNo = res.data.produceInStockNo; // 入库单号
				this.actionType =
					this.pagefromData.documentStatus === 'a' ||
					this.pagefromData.documentStatus === 'b' ||
					this.pagefromData.documentStatus === 'd'
						? 'edit'
						: 'see';
				this.documentStatus = res.data.documentStatus;
				this.pagefromData.prdorgId = parseInt(res.data.prdorgId); //组织
				this.getWarehouse(res.data.prdorgId, res.data.details);
				this.customeStockArrylist = [];
				if (res.data.details && res.data.details.length > 0) {
					this.pagefromData.details.forEach((it, index) => {
						Object.assign(it, {
							isworkShopIdshow: false,
							isrealNumbershow: false,
							isstockIdshow: false,
							iscustomerIdshow: false,
							iscustomerStockIdshow: false,
							isremarkshow: false,
						});
						this.pagefromData.details[index].unitId = it.unitId
							? parseInt(it.unitId)
							: '';
						this.pagefromData.details[index].subUnitId =
							it.subUnitId;
						this.pagefromData.details[index].workShopId =
							it.workShopId ? parseInt(it.workShopId) : '';
						this.changecustomer(it.customerId, index, 'init');
						this.matterCodeChange(it.materialNumber);
						this.changeWarehouse(
							this.pagefromData.details[index].stockId,
							index,
							'init'
						);
						if (this.$route.query.type === 'pushDown') {
							this.numberPrecisionMethods(index);
							if (
								this.pagefromData.details[index].realNumber
									.toString()
									.indexOf('.') !== -1
							) {
								let tempList = this.unitlist.filter(
									(it) =>
										it.id ===
										this.pagefromData.details[index].unitId
								);
								tempList[0].precision == 0
									? (this.isPrecision[index] = true)
									: (this.isPrecision[index] = false);
								tempList[0].precision == 0
									? (this.salePrecisionNumber[index] = 0)
									: (this.salePrecisionNumber[index] =
											tempList[0].precision);
								let result = countMethodsUnitNumber(
									tempList,
									this.pagefromData.details[index].realNumber,
									this.pagefromData.details[index].realNumber,
									this.isCount[index],
									this.salePrecisionNumber[index],
									true
								);
								this.pagefromData.details[index].realNumber =
									result.value;
								let resultM = countMethodsUnitNumber(
									tempList,
									this.pagefromData.details[index].mustNumber,
									this.pagefromData.details[index].mustNumber,
									this.isCount[index],
									this.salePrecisionNumber[index],
									true
								);
								this.pagefromData.details[index].mustNumber =
									resultM.value;
								// mustNumber
								this.isCount[index] = result.isDefault;
							}
						}
					});
				} else {
					this.customeStockArrylist.push([]);
					this.pagefromData.details = [this.addRow];
				}
				// 详情里面根据组织id去获取明细的生产部门数据
				this.getProductdept(res.data.prdorgId);
			}
		},
		// 获取生产订单详情
		getProductInfo(prodctId) {
			this.$http.get('ProduceInStock/Get/' + prodctId).then((res) => {
				// if (res.data.tracking && res.data.tracking.remark) {
				// 	this.$message.error({
				// 		message: `单据由-${res.data.tracking.remark}`,
				// 		showClose: true,
				// 		duration: 5000,
				// 	});
				// }
				this.setpageDate(res);

				this.setApprovalFlowTrackingGetby(res.data);
			});
		},
		getUnit() {
			var unitlist =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.allUnit
					: [];
			if (
				JSON.stringify(
					this.$store.state && this.$store.state.storeData
						? this.$store.state.storeData.allUnit
						: []
				) === '[]'
			) {
				this.$http.get('SysConfig/GetUnitAllProperty').then((r) => {
					if (r.status === 200) {
						this.unitlist = this.$store.state.storeData.allUnit =
							r.data;
					}
				});
			} else {
				this.unitlist = unitlist;
			}
		},
		// 获取需要状态列表---[单据状态，退料状态]
		getStatus() {
			var infoStatus =
				this.$store.state && this.$store.state.storeData
					? this.$store.state.storeData.infoStatus
					: {};
			if (
				JSON.stringify(
					this.$store.state && this.$store.state.storeData
						? this.$store.state.storeData.infoStatus
						: {}
				) === '{}'
			) {
				this.$http.get('ProduceOrder/GetStatus').then((r) => {
					if (r.status === 200) {
						this.documentStatuslist = r.data.documentStatus;
						this.inStockDocumentTypelist =
							r.data.inStockDocumentType;
						this.pagefromData.documentType = Object.keys(
							r.data.inStockDocumentType
						)[1];
						this.$store.state.storeData.infoStatus = r.data;
					}
				});
			} else {
				this.documentStatuslist = infoStatus.documentStatus;
				this.inStockDocumentTypelist = infoStatus.inStockDocumentType;
				this.pagefromData.documentType = Object.keys(
					infoStatus.inStockDocumentType
				)[1];
			}
		},
		// 物料下拉更新
		metterChange(val, index, type) {
			let metterInfo = {};
			if (type !== 'specification') {
				//物料
				metterInfo = this.matterCodelist.filter((res) => {
					return val === res.id;
				})[0];
			} else {
				//规格型号
				metterInfo = this.specificationlist.filter((res) => {
					return val === res.specifications;
				})[0];
			}
			if (type === 'specification') {
				// 规格型号改变
				this.matterCodeChange(metterInfo.number);
				this.pagefromData.details[index].materialId = metterInfo.id;
			}
			this.pagefromData.details[index].materialName = metterInfo.name;
			this.pagefromData.details[index].materialNumber = metterInfo.number;
			this.pagefromData.details[index].specification =
				metterInfo.specifications;
			this.pagefromData.details[index].unitId = metterInfo.baseUnitId;
			this.pagefromData.details[index].bomId = metterInfo.bomId;
			this.pagefromData.details[index].bomVersion = metterInfo.bomVersion;
		},
		// 获取物料编码信息
		matterCodeChange(val) {
			if (val !== '') {
				this.loading = true;
				setTimeout(() => {
					this.loading = false;
					this.$http
						.post('SysConfig/GetMaterial', {
							name: val,
							file: 'Number',
							orgId: this.orgId,
						})
						.then((res) => {
							if (res.status === 200) {
								this.matterCodelist = res.data;
							}
						});
				}, 200);
			} else {
				this.matterCodelist = [];
			}
		},
		// 获取物料规格型号信息
		specificationChange(val) {
			if (val !== '') {
				this.loading = true;
				setTimeout(() => {
					this.loading = false;
					this.$http
						.showLoading(false)
						.post('SysConfig/GetMaterial', {
							name: val,
							file: 'Specifications',
							orgId: this.orgId,
						})
						.then((res) => {
							if (res.status === 200) {
								this.specificationlist = res.data;
							}
						});
				}, 200);
			} else {
				this.specificationlist = [];
			}
		},
		//顶部按钮操作栏
		actionhandel(type) {
			// 提取明细id

			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);

			let detailsIds = [];
			if (
				this.pagefromData.details &&
				this.pagefromData.details.length > 0
			) {
				detailsIds = [
					...new Set(
						this.multipleSelection
							.filter((item) => {
								if (item.id) {
									return item.id;
								}
							})
							.map((it) => {
								return it.id;
							})
					),
				];
			}
			// 点击新增
			if (type === 'add') {
				this.$router.push({
					name: 'AddProudtReturnOrder',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			if (type == 'exDetails') {
				if (
					!this.examineObj ||
					JSON.stringify(this.examineObj) === '{}'
				) {
					this.$message.error('该单据不存在审批流!');
					return false;
				}
				this.$router.push({
					path: '/examine/mange/examineFollow',
					query: { id: this.examineObj.id },
				});
			}
			//点击保存
			if (type === 'save') {
				this.savePageData();
			}
			//点击提交
			if (type === 'submit') {
				this.submitPageData();
			}
			//点击撤销
			if (type === 'revoke') {
				this.toolarFn('ProduceInStock/Revoke');
			}
			//点击审核
			if (type === 'audit') {
				this.toolarFn('ProduceInStock/Check');
			}
			//点击反审核
			if (type === 'de-approval') {
				this.toolarFn('ProduceInStock/NoCheck');
			}
			//点击查询 --上查
			if (type === 'up-check') {
				if (detailsIds.length > 0) {
					this.$http
						.post('ProduceInStock/Upper', { ids: detailsIds })
						.then((res) => {
							if (res.status === 200) {
								this.upOrDownList = res.data;
								this.dialogCX =
									res.data && res.data.length > 0
										? true
										: false;
								this.CXttile = '上查结果';
								this.CXcheckVal =
									res.data && res.data.length === 1
										? res.data[0].orderType
										: null; //只有一个，就个默认值
							}
						});
				} else {
					this.$message.warning({
						message:
							'请先勾选明细,并确认勾选的信息是否有保存提交,只有有效明细信息才能上查',
						showClose: true,
					});
				}
			}
		},
		// 保存或者提交成功返回数据处理
		saveOrsumitData(res) {
			this.pagefromData = JSON.parse(JSON.stringify(res.data));
			this.produceInStockNo = res.data.produceInStockNo;
			this.pagefromData.id = res.data.id;
			this.pagefromData.date = transformTimestamp(res.data.date);
		},
		// 保存---[不需要做必填校验]
		savePageData() {
			this.arrangeData('save');
			if (
				this.pagefromData.details.length > 0 &&
				this.pagefromData.details[0].realNumber &&
				this.pagefromData.details[0].realNumber != 0
			) {
				this.$http
					.post('ProduceInStock/Save', this.pagefromData)
					.then((res) => {
						if (res.status === 200) {
							// this.saveOrsumitData(res)
							this.pagefromData = JSON.parse(
								JSON.stringify(res.data)
							);
							this.produceInStockNo = res.data.produceInStockNo;
							this.$message.success({
								message: '保存成功',
								showClose: true,
							});
						}
					});
				if (this.savetag > 0) {
					this.$message.warning({
						message: '已自动过滤数量为0的明细数据',
						showClose: true,
					});
				}
			} else {
				if (this.savetag === this.pagefromData.details.length) {
					this.$message.warning({
						message:
							'不能提交所有明细信息的数量为0或者空，请重新填写',
						showClose: true,
					});
				} else if (this.savetag > 0) {
					this.$message.warning({
						message: '已自动过滤数量为0的明细数据',
						showClose: true,
					});
				}
			}
		},
		// 提交
		submitPageData() {
			this.arrangeData('submit');
			if (
				this.pagefromData.details.length > 0 &&
				this.pagefromData.details[0].realNumber &&
				this.pagefromData.details[0].realNumber != 0
			) {
				this.$http
					.post('ProduceInStock/Commit', this.pagefromData)
					.then((res) => {
						if (res.status === 200) {
							// this.saveOrsumitData(res)
							this.pagefromData = JSON.parse(
								JSON.stringify(res.data)
							);
							this.setExamine({
								status: res.status,
								data: res.data.tracking,
							});
							this.produceInStockNo = res.data.produceInStockNo;
							this.$message.success({
								message: '提交成功',
								showClose: true,
							});
						}
					});
			} else {
				this.$message.warning({
					message: '已自动过滤明细里面数量为0的的数据',
					showClose: true,
				});
			}
		},
		// 顶部操作方法-有公共的部分封装下
		toolarFn(path, detailsIds) {
			let formdata = detailsIds
				? {
						ids: [this.pagefromData.id],
						detailsIds: detailsIds,
				  }
				: { ids: [this.pagefromData.id] };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					if (res.data && !detailsIds) {
						res.data[0].isSuccess
							? this.$message.success({
									message: res.data[0].msg
										? res.data[0].msg
										: '成功',
									showClose: true,
							  })
							: this.$message.error({
									message: res.data[0].msg,
									showClose: true,
							  });
					} else {
						this.dialogVisible = true;
						this.tableInfo = res.data;
					}
					this.getProductInfo(this.pagefromData.id);
				}
			});
		},
		// 仓库选择修改-仓位信息更新
		changeWarehouse(value, index, type) {
			// 如果是详情带过来的数据 要根据仓库去查找下对于的仓位下拉数据,初始不要智控对应的仓位id
			let wit = this.warehouse.filter((it) => {
				return it.id === value;
			});
			if (type !== 'init') {
				this.pagefromData.details[index].stockLocId = '';
				this.pagefromData.details[index].customerId = '';
				this.pagefromData.details[index].customerStockId = '';
				this.pagefromData.details[index].customerWarehouseTag =
					this.warehouse && wit && wit.length > 0
						? wit[0].customerWarehouseTag
						: false;
			}
			if (this.warehouse.length > 0) {
				this.customerWarehouseTaglist[index] = this.warehouse.filter(
					(it) => {
						return value === it.id;
					}
				)
					? this.warehouse.filter((it) => {
							return value === it.id;
					  })[0].customerWarehouseTag
					: false;
			}

			// this.getWarechildhouse(value)
		},
		// 获取仓库
		getWarehouse(id, res) {
			if (id) {
				this.$http
					.get('SysConfig/GetWarehouseByOrg/' + id)
					.then((r) => {
						if (r.status === 200) {
							this.warehouse =
								r.data && r.data.length > 0
									? oldstocklist(
											r.data.concat(
												oldstocklist(res).stockList
											),
											'retrieve'
									  )
									: oldstocklist(
											oldstocklist(res).stockList,
											'retrieve'
									  );
							if (res) {
								this.customerWarehouseTaglist = [];
								res.forEach((item, index) => {
									this.customerWarehouseTaglist.push(
										this.warehouse.filter((it) => {
											return item.stockId === it.id;
										}).length > 0
											? this.warehouse.filter((it) => {
													return (
														item.stockId === it.id
													);
											  })[0].customerWarehouseTag
											: false
									);
								});
							}
						}
					});
			}
		},
		// 获取子仓位
		getWarechildhouse(id) {
			if (id) {
				this.$http
					.get('SysConfig/GetChildWarehouse/' + id)
					.then((r) => {
						if (r.status === 200) {
							this.warechildhouse = r.data;
						}
					});
			}
		},
		// 星星--头部必填ico显示
		mustAfter(obj) {
			let arry = [9, 10];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 销售订单号下拉数据
		getsaleNumlist() {},
		// 获取生产部门数据
		getProductdept(orgId) {
			this.$http.post('SysConfig/GetDept/' + orgId).then((res) => {
				if (res.status === 200) {
					this.productDeptList = res.data;
				}
			});
		},
		// 插入的行
		getInsertInfo(data) {
			if (data.insertTopVal != 0) {
				for (let i = 0; i < data.insertTopVal; i++) {
					this.pagefromData.details.splice(
						this.selectRowIndex,
						0,
						JSON.parse(JSON.stringify(this.addRow))
					);
					this.customeStockArrylist.splice(
						this.selectRowIndex,
						0,
						[]
					);
					this.customerWarehouseTaglist.splice(num, 0, true);
					this.selectRowIndex = parseInt(this.selectRowIndex) + 1;
				}
			}
			if (data.insertBottomVal != 0) {
				for (let i = 0; i < data.insertBottomVal; i++) {
					var num = this.selectRowIndex + 1;
					this.pagefromData.details.splice(
						num,
						0,
						JSON.parse(JSON.stringify(this.addRow))
					);
					this.customeStockArrylist.splice(num, 0, []);
					this.customerWarehouseTaglist.splice(num, 0, true);
				}
			}
			this.arrangeData('明细');
			this.$refs.multipleTable.clearSelection();
		},
		// 向下复制行
		bottomCopyRow(data) {
			// 判断行数
			if (this.selectRowIndexArr.length == 1) {
				const tableArr = JSON.parse(
					JSON.stringify(
						this.pagefromData.details[this.selectRowIndex]
					)
				);
				tableArr.id = 0;
				var insertNum = this.selectRowIndex + 1;
				this.pagefromData.details.splice(insertNum, 0, tableArr);
				this.customeStockArrylist.splice(
					insertNum,
					0,
					JSON.parse(
						JSON.stringify(
							this.customeStockArrylist[this.selectRowIndex]
								? this.customeStockArrylist[this.selectRowIndex]
								: []
						)
					)
				);
				this.customerWarehouseTaglist.splice(
					insertNum,
					0,
					JSON.parse(
						JSON.stringify(
							this.customerWarehouseTaglist[this.selectRowIndex]
						)
					)
				);
				this.arrangeData('明细');
				this.$refs.multipleTable.clearSelection();
			} else {
				this.$message.error({
					message: '请勾选一条行,在操作',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			if (this.selectRowIndexArr.length <= 0) {
				this.$message.warning({
					message: '请选择要删除的行!',
					showClose: true,
				});
				return;
			}
			// 不能为空
			if (
				this.pagefromData.details.length > 1 &&
				this.selectRowIndexArr.length < this.pagefromData.details.length
			) {
				this.selectRowIndexArr.forEach((k) => {
					this.pagefromData.details.forEach((l, index) => {
						if (k === l.seq) {
							this.pagefromData.details.splice(index, 1);
							this.customeStockArrylist.splice(index, 1);
							this.customerWarehouseTaglist.splice(index, 1);
						}
					});
				});
				this.arrangeData('明细');
				this.$refs.multipleTable.clearSelection();
			} else {
				this.$message.warning({
					message: '至少保留一行!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn(data) {
			let batcharry = [
				'workShopId',
				'realNumber',
				'stockId',
				'customerId',
				'remark',
			];
			this.pagefromData = batchhandle(
				this.pagefromData,
				[],
				this.batchfill.romIndex,
				this.batchfill.columnkey,
				batcharry
			);
			for (
				let i = this.batchfill.romIndex + 1;
				i < this.pagefromData.details.length;
				i++
			) {
				// 重新判断数量精度
				if (this.batchfill.columnkey == 'realNumber') {
					this.numberChage(
						this.pagefromData.details[i].realNumber,
						i,
						this.pagefromData.details[i],
						'realNumber',
						this.isPrecision
					);
				}
			}
			// 如果有或者仓库的客户仓库的处理
			if (
				this.batchfill.columnkey === 'stockId' ||
				this.batchfill.columnkey === 'customerId'
			) {
				this.pagefromData.details.forEach((it, index) => {
					if (index > this.batchfill.romIndex) {
						if (this.batchfill.columnkey === 'stockId') {
							this.changeWarehouse(it.stockId, index);
						}
						if (this.batchfill.columnkey === 'customerId') {
							if (this.customerWarehouseTaglist[index]) {
								this.changecustomer(
									it.customerId,
									index,
									'product'
								);
							} else {
								this.pagefromData.details[index].customerId =
									'';
								this.pagefromData.details[
									index
								].customerStockId = '';
							}
						}
					}
				});
			}
		},
		//注意这里是解构
		tableCellClassName({ row, column, rowIndex, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		getRowCol(row, column, cell, event) {
			this.batchfill.romIndex = row.index;
			this.batchfill.columnIndex = column.index;
			if (typeof cell === 'string') {
				this.batchfill.columnkey = cell;
			} else {
				this.batchfill.columnkey = column.property;
			}
			// 处理表格下拉框输入框显示隐藏
			this.pagefromData.details.forEach((it, index) => {
				Object.assign(it, {
					isworkShopIdshow: false,
					isrealNumbershow: false,
					isstockIdshow: false,
					iscustomerIdshow: false,
					iscustomerStockIdshow: false,
					isremarkshow: false,
				});
			});
			var showtagarry = [
				'isworkShopIdshow',
				'isrealNumbershow',
				'isstockIdshow',
				'iscustomerIdshow',
				'iscustomerStockIdshow',
				'isremarkshow',
			];
			var parentshowtagarry = [
				'workShopId',
				'realNumber',
				'stockId',
				'customerId',
				'customerStockId',
				'remark',
			];
			showtagarry.forEach((k, idx) => {
				if (column.property == parentshowtagarry[idx]) {
					this.pagefromData.details[row.index][k] = true;
					this.$nextTick((_) => {
						if (
							document.getElementById(column.property + row.index)
						) {
							document
								.getElementById(column.property + row.index)
								.focus();
						}
					});
				}
			});
		},
		// 明细选择行的数据处理
		selectdataSet(selection, row) {
			this.multipleSelection = [];
			this.multipleSelection = selection;
			if (row) {
				this.selectRowIndex = row.seq;
			}
			if (selection && selection.length > 0) {
				this.selectRowIndex = selection[0].seq;
			}
			if (selection.length != 0) {
				this.selectRowIndexArr = selection.map((it) => {
					return it.seq;
				});
			} else {
				this.selectRowIndexArr = [];
			}
		},
		// 选择全部明细(全选)
		selectRowAll(selection) {
			this.selectdataSet(selection);
		},
		// 选择的行（单选）
		selectRow(selection, row) {
			this.selectdataSet(selection);
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/saleOrder/saleOrderCommon.scss';
@import '@/assets/style/saleOrder/orderDetails.scss';
@import '@/assets/style/saleOrder/common.scss';

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