<!--仓库 -其他入库单 编辑 -->
<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 Iisshow"
										>
											<el-form-item label="单据编号">
												<el-input
													:maxlength="255"
													disabled
													placeholder="(保存时自动生成)"
													v-model.trim="
														pagefromData.billNo
													"
												></el-input>
												<!-- <div
                          :data-clipboard-text="pagefromData.billNo"
                          @click="saleOrderCopy"
                          class="copyBtn"
                        >
                          <i class="el-icon-document-copy" />
                        </div>-->
											</el-form-item>
										</div>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="单据类型"
										>
											<el-select
												disabled
												filterable
												v-model="
													pagefromData.billTypeId
												"
											>
												<el-option
													:key="key + index"
													:label="value"
													:value="key"
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in documentTypelist"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											class="item-bt-s item-date"
											label="盘点日期"
										>
											<el-date-picker
												:clearable="false"
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												:disabledDate="
													(data) => {
														return (
															data.getTime() >
															Date.now() - 8.64e6
														);
													}
												"
												format="YYYY-MM-DD"
												type="date"
												v-model="pagefromData.date"
												value-format="YYYY-MM-DD"
											></el-date-picker>
										</el-form-item>
										<el-form-item 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>
									</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
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												@change="orgChange"
												filterable
												placeholder="请选择组织"
												v-model="
													pagefromData.stockOrgId
												"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in orgIdArr"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											:required="true"
											class="item-bt-s"
											label="部门"
										>
											<el-cascader
												:disabled="
													!pagefromData.stockOrgId ||
													(pagefromData.documentStatus !==
														'a' &&
														pagefromData.documentStatus !==
															'd')
												"
												:options="productDeptList"
												:props="optionProps"
												:show-all-levels="false"
												@change="deptChange"
												ref="cascader"
												clearable
												placeholder="请选择部门"
												v-model="pagefromData.deptId"
											></el-cascader>
										</el-form-item>
										<el-form-item
											:required="true"
											label="盘点员"
										>
											<el-select
												:disabled="
													pagefromData.documentStatus !==
														'a' &&
													pagefromData.documentStatus !==
														'd'
												"
												filterable
												placeholder="请选择"
												v-model="pagefromData.stockerId"
											>
												<el-option
													:key="item.name"
													:label="item.name"
													:value="item.id"
													class="f-12"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													v-for="item in allPepolelist"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</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" prop="materialId" width="200">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:loading="loading"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											'materialId',
											scope.$index
										);
									}
								"
								@change="metterChange($event, scope.$index)"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'materialId'
									)
								"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.ismaterialIdshow"
								v-model="scope.row.materialId"
							>
								<el-option
									:key="item.idr"
									:label="item.number"
									:value="item.id"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in matterallCodelist[
										scope.$index
									]"
								></el-option>
							</el-select>
							<span v-else>{{ scope.row.materialNumber }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="规格型号(SKU)"
						prop="specification"
						width="280"
					/>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="150"
					></el-table-column>
					<el-table-column
						align="left"
						label="单位"
						prop="unitId"
						width="81"
					>
						<template #default="scope">
							<span>{{
								publicidbyname(unitlist, scope.row.unitId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="stockId" width="200">
						<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"
						label="盘点前数量"
						prop="beforeQty"
						width="120"
					>
						<template #default="scope">
							<span>{{ scope.row.beforeQty }}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="afterQty" width="120">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>盘点后数量
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'afterQty' + scope.$index"
								@blur="
									numberChage(
										scope.row.afterQty,
										scope.$index,
										scope.row,
										'afterQty'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'afterQty'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'afterQty'
									)
								"
								placeholder="0"
								v-if="scope.row.isafterQtyshow"
								v-model="scope.row.afterQty"
							></el-input>
							<span v-else>{{
								scope.row.afterQty ? scope.row.afterQty : 0
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" label="盈亏数量" width="120">
						<template #default="scope">
							<span>{{ scope.row.finalQty }}</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') ||
									!scope.row.stockId
								"
								@change="
									changecustomer(
										$event,
										scope.$index,
										'product'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'customerId'
									)
								"
								clearable
								filterable
								placeholder="请选择"
								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>{{
								publicidbyname(
									customerlist,
									scope.row.customerId
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						prop="customerStockId"
						width="150"
					>
						<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') ||
									!scope.row.customerId
								"
								@change="
									changecustomerStock(
										$event,
										scope.$index,
										'product'
									)
								"
								@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"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
									v-for="item in customeStockArrylist[
										scope.$index
									]"
								></el-option>
							</el-select>
							<span v-else>{{
								publicidbyname(
									customeStockArrylist[scope.$index],
									scope.row.customerStockId
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="note" width="280">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'note' + scope.$index"
								:maxlength="2000"
								@input="
									getRowCol(scope.row, scope.column, 'note')
								"
								v-if="scope.row.isnoteshow"
								v-model.trim="scope.row.note"
							></el-input>
							<span v-else>{{ scope.row.note }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
	</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,
} from '@/utils/pubulic.js';
import { pageoPtionProps } from '@/utils/printPagekey.js';
import { orderCopy, bottomAddRow } from '@/utils/takeMethods';
import { Decimal } from 'decimal.js';

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

export default {
	name: 'AddIncentorySheet',
	components: {
		examineTop,
		toolBtn,
	},
	data() {
		return {
			isexamineBtns: false,
			isExmaineTop: 3,
			radios: [],
			examineObj: {},
			salePrecisionNumber: [],
			isPrecision: [],
			isCount: [],
			isDisable: false,
			optionProps: JSON.parse(JSON.stringify(pageoPtionProps)),
			tableInfo: [], //操作结果
			documentStatuslist: [], // 单据状态
			documentTypelist: [], // 单据类型
			matterallCodelist: [[]], // 物料下拉数据
			specificationlist: [], // 规格型号（sku）下拉数据
			unitlist:
				this.$store.state && this.$store.state.storeData.allUnit
					? this.$store.state.storeData.allUnit
					: [], // 获取计量单位数据
			productDeptList: [], // 部门
			allPepolelist: [], // 部门人员
			warehouse: [], //仓库下拉数据
			warechildhouse: [], // 仓位下拉数据
			customeStockArrylist: [[]], // 所有的客户仓库下拉数据
			customeStocklist: [], // 客户仓库下拉数据
			customerlist: [],
			loading: false,
			detailBtn: ['allIn'],
			customerWarehouseTaglist: [], // 判断客户仓库是否必填 这个值有仓库带出默认是不必填
			newdetailsIds: {
				id: 0, // 明细的id
				seq: 0, // 序号
				materialId: null, //物料编码
				materialName: '', //物料名称
				specification: '', //规格型号
				unitId: null, // 单位
				stockId: null, // 仓库
				subStockId: null, // 仓位
				customerId: null, // 客户
				customerStockId: null, // 客户仓库
				beforeQty: 0, // 盘点前数量
				afterQty: null, // 盘点后数量
				note: '',
			}, // 重置明细信息
			btnType: [
				'copy',
				'save',
				'revoke',
				'audit',
				'delete',
				'push-down',
				'operation',
				'up-check',
				'down-check',
				// 'query',
				'refresh',
				's-p-t-g3',

				// 's-p-t-g4',
				'audit',
			],
			pagefromData: {
				id: 0, // 单据的id
				billNo: '', //单据编号
				date: transformTimestamp(new Date()), //下单日期
				documentStatus: 'a', // 单据状态
				billTypeId: '', // 单据类型
				stockOrgId: null, //组织
				deptId: '', // 部门
				stockerId: '', // 盘点员
				details: [],
			},
			//明细数据
			addRow: {},
			selectRowIndexArr: [],
			selectRowIndex: '', // 当前 选择行
			// 批量填充
			batchfill: {
				romIndex: null,
				columnIndex: null,
				columnkey: null,
			},
			heightNum: 0,
		};
	},
	watch: {
		orgId(value) {
			if (
				this.pagefromData.id === 0 ||
				this.pagefromData.id === null ||
				this.pagefromData.id === ''
			) {
				this.pagefromData.stockOrgId = value;
				this.orgChange(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 = [
					'copy',
					'save',
					'revoke',
					'delete',
					'push-down',
					'operation',
					'up-check',
					'down-check',
					// 'query',
					'refresh',
					's-p-t-g3',
					// 's-p-t-g4',
					// 'de-approval',
				]; // 不需要显示的顶部按钮类型
			} else {
				this.btnType = [
					'save',
					'copy',
					'delete',
					'close-case',
					'split-order',
					'push-down',
					'refresh',
					'operation',
					'up-check',
					'down-check',
					//'s-p-t-g4',
					// 'query',
					// 'de-approval',
				];
			}
		},
	},
	computed: {
		...mapState({
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			userId: (state) => state.user.userInfo.staffId || null,
			orgId: (state) =>
				state && state.org && state.org.orgId ? state.org.orgId : null,
			getApprovalResult: (state) =>
				state.examine.examineStatus.approvalResult,
			getPageObjValue: function () {
				// 根据key值显示对应的键名
				return function (arr, key) {
					return getObjValue(arr, key);
				};
			},
		}),
		isShow: function () {
			return this.isExmaineTop;
		},

		publicidbyname: function () {
			// 根据key值显示对应的键名
			return function (arr, key) {
				return theUnitSet(arr, key);
			};
		},
	},
	created() {
		this.heightNum =
			document.documentElement.clientHeight - (40 + 30 + 16 + 16);
		this.pagefromData.details = [
			JSON.parse(JSON.stringify(this.newdetailsIds)),
		];
		this.addRow = JSON.parse(JSON.stringify(this.newdetailsIds));
		this.Init();
		this.setApprovalFlowStatus();
	},
	mounted() {},
	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.isexamineBtns = false;
				this.isExmaineTop = 3;
			}
		},
		handleDetails(r) {
			this.$http
				.showLoading(false)
				.get('TrayCount/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,
					orgId: this.pagefromData.stockOrgId,
					deptId: this.pagefromData.deptId || 0,
					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.deptId || 0,
				approvalOrderType: 18,
				orgId: data.stockOrgId,
			};
			this.$http
				.post(approvalFlowTrackingGetby, obj)
				.then((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;
					}
				});
		},
		Init() {
			this.getUnit();
			this.getStatus();
			this.getOrgPeple();
			this.InItEditorCopy();
		},
		// 订单号 复制按钮
		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 == 'materialId') {
							this.matterCodeChange(it, 'number', recordAddIndex);
						}
						if (key === 'afterQty') {
							this.pagefromData.details[recordAddIndex][key] = it;
						}
						recordAddIndex++;
					}
				});
			}, 100);
		},
		// 保存或者提交的时候，对数据个别字段例如 is211 seq 做数据整理，避免提交保存失败
		arrangeData(type) {
			if (this.pagefromData.details) {
				let newDetails = this.pagefromData.details.map((v, index) => {
					return {
						...v,
						seq: index,
						afterQty: parseInt(v.afterQty ? v.afterQty : 0),
					};
				});
				this.pagefromData.details = newDetails;
				// 清空明细选中
				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.pagefromData.stockOrgId = this.orgId;
				this.customerWarehouseTaglist = [true];
				this.getWarehouse(this.orgId);
				this.getAllcustomer();
				this.getProductdept(this.orgId);
			}
		},
		// 获取全部公司客户
		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;
			}
		},
		changecustomerStock(id, index) {
			this.pagefromData.details[index].afterQty = 0;
			this.getrealityQty(this.pagefromData.details[index].stockId, index);
		},
		// 根据客户id集合获取客户仓库
		initgetcustomerstocklist(customerStockIds, total) {
			if (customerStockIds && customerStockIds.length > 0) {
				this.$http
					.post('SysConfig/GetCustomerStockList', {
						customerIds: customerStockIds,
						orgId: this.pagefromData.stockOrgId,
					})
					.then((res) => {
						if (res.status == 200) {
							if (total && total > 0) {
								for (let tag = 0; tag < total; tag++) {
									this.customeStockArrylist[tag] = res.data;
								}
							}
						}
					});
			}
		},
		// 改变客户的时候获取对应的客户仓库 ---1 到时候应该替换为公司id
		changecustomer(id, index, type) {
			if (type !== 'init') {
				this.pagefromData.details[index].customerStockId = '';
				this.pagefromData.details[index].afterQty = 0;
				this.getrealityQty(
					this.pagefromData.details[index].stockId,
					index
				);
			}
			if (id) {
				this.$http
					.post('SysConfig/GetCustomerStock', {
						customerId: this.pagefromData.details[index].customerId,
						orgId: this.pagefromData.stockOrgId,
						stockId: null,
					})
					.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'
									  );
						}
					});
			}
		},
		// 根据id获取组织人员
		getOrgPeple() {
			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.allPepolelist = req.data;
				});
			} else {
				this.allPepolelist = userlistall;
			}
		},
		// 生产组织下拉改变是 （会影响生产部门的数据）
		orgChange(value) {
			this.customerWarehouseTaglist = [true];
			this.pagefromData.deptId = null;
			this.pagefromData.stockerId = null;
			this.getProductdept(value);
			this.getAllcustomer();
			this.getWarehouse(value);
			// 组织改变是清空明细只留一条
			this.pagefromData.details = [
				JSON.parse(JSON.stringify(this.newdetailsIds)),
			];
		},
		deptChange(value) {
			if (value) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		numberPrecisionMethods(index, unit, S, P, C) {
			if (this.pagefromData.details[index][unit]) {
				let tempList = this.unitlist.filter(
					(it) => it.id === this.pagefromData.details[index][unit]
				);
				if (tempList && tempList.length > 0) {
					tempList[0].precision == 0
						? (this[P][index] = true)
						: (this[P][index] = false);
					tempList[0].precision == 0
						? (this[S][index] = 0)
						: (this[S][index] = tempList[0].precision);
				}
			}

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

			if (!this[C][index]) {
				this[C][index] = 1;
			}
		},
		// 数量改变时
		numberChage(val, index, item, key) {
			// 判断条件 子单位
			this.numberPrecisionMethods(
				index,
				'unitId',
				'salePrecisionNumber',
				'isPrecision',
				'isCount'
			);
			// 输入规则
			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]
					);
					this.pagefromData.details[index][key] = result.value * 1;
					this.isCount[index] = result.isDefault;
				} else {
					if (val.length > 8) {
						this.pagefromData.details[index][key] = val.substring(
							0,
							8
						);
					}
				}
				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]
						.toString()
						.replace(/[^\d^\\.]+/g, '')
						.replace('.', '$#$')
						.replace(/\./g, '')
						.replace('$#$', '.')
						.replace(eval(reg), '$1$2.$3');
			}
			//盈亏数量= 盘点后 -盘点前数量
			this.pagefromData.details[index].finalQty = new Decimal(
				this.pagefromData.details[index].afterQty
			).sub(new Decimal(this.pagefromData.details[index].beforeQty));
		},
		// 详情或者下推过来的数据处理
		setpageDate(res) {
			const names = [];
			const customerStockIds = [];
			this.pagefromData = JSON.parse(JSON.stringify(res.data));
			this.documentStatus = res.data.documentStatus;
			this.pagefromData.stockOrgId = res.data.stockOrgId;
			this.pagefromData.billTypeId = res.data.billTypeId + '';
			this.getAllcustomer();
			this.getWarehouse(res.data.stockOrgId, res.data.details);
			this.customeStockArrylist = [];
			this.matterallCodelist = [];
			if (res.data.details && res.data.details.length > 0) {
				res.data.details.forEach((it, index) => {
					this.pagefromData.details[index].seq = index;
					names.push(it.materialNumber);
					if (it.customerId) {
						customerStockIds.push(it.customerId);
					}
					this.changeWarehouse(
						this.pagefromData.details[index].stockId,
						index,
						'init'
					);
				});
				this.initMatterCode(names, res.data.details.length);
				this.initgetcustomerstocklist(
					customerStockIds,
					res.data.details.length
				);
			} else {
				this.customeStockArrylist.push([]);
				this.matterallCodelist.push([]);
				this.pagefromData.details = JSON.parse(
					JSON.stringify(this.newdetailsIds)
				);
			}
			// 详情里面根据组织id去获取明细的生产部门数据
			this.getProductdept(res.data.stockOrgId);
		},
		// 获取生产订单详情
		getProductInfo(prodctId) {
			this.$http.get('TrayCount/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() {
			this.$http.get('TrayCount/status/get').then((r) => {
				if (r.status === 200) {
					this.documentStatuslist = r.data.documentStatus;
					this.documentTypelist = r.data.trayCountBillType;
					this.pagefromData.billTypeId = Object.keys(
						r.data.trayCountBillType
					)[0];
				}
			});
		},
		// 物料/规格型号--下拉更新
		metterChange(val, index, type) {
			let metterInfo = {};
			if (type !== 'specification' && type !== 'number') {
				//物料
				metterInfo = this.matterallCodelist[index].filter((res) => {
					return val === res.id;
				})[0];
			} else {
				if (type === 'number') {
					//规格型号
					metterInfo = this.matterallCodelist[index].filter((res) => {
						return val === res.number;
					})[0];
				} else {
					//规格型号
					metterInfo = this.specificationalllist[index].filter(
						(res) => {
							return val === res.specifications;
						}
					)[0];
				}
			}
			if (type === 'specification') {
				// 规格型号改变
				this.matterCodeChange(metterInfo.number);
				this.pagefromData.details[index].materialId = metterInfo.id;
			}
			if (metterInfo) {
				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].is211 = metterInfo.is211;
				this.pagefromData.details[index].bomVersion =
					metterInfo.bomVersion;
				if (this.pagefromData.details[index].stockId) {
					this.getrealityQty(
						this.pagefromData.details[index].stockId,
						index
					);
				} else {
					this.pagefromData.details[index].stockId =
						metterInfo.stockId;
					this.getrealityQty(metterInfo.stockId, index);
				}
				this.pagefromData.details[index].afterQty = 0;
			}
		},
		// 初始化一次性获取物料信息的接口
		initMatterCode(names, total) {
			this.$http
				.post('SysConfig/GetMaterialLikeList', {
					names: names,
					file: 'Number',
					orgId: this.pagefromData.stockOrgId,
				})
				.then((res) => {
					if (res.status == 200) {
						if (total && total > 0) {
							for (let tag = 0; tag < total; tag++) {
								this.matterallCodelist[tag] = res.data;
							}
						}
					}
					console.log(this.matterallCodelist);
				});
		},
		// 获取物料编码信息
		matterCodeChange(val, type, index) {
			const _this = this;
			if (val !== '') {
				this.loading = true;
				this.loading = false;
				this.$http
					.showLoading(false)
					.post('SysConfig/GetMaterial', {
						name: val,
						file: 'Number',
						orgId: this.pagefromData.stockOrgId,
						includeCustomerStockInventory: false,
					})
					.then((res) => {
						if (res.status === 200) {
							if (type === 'init') {
								_this.matterallCodelist.push(
									res.data && res.data.length > 0
										? res.data
										: []
								);
							} else if (index || index === 0) {
								this.matterallCodelist[index] =
									res.data && res.data.length > 0
										? res.data
										: [];
								if (type === 'number') {
									this.metterChange(val, index, type);
								}
							}
						}
					});
			} else {
				this.matterallCodelist[index] = [];
			}
		},
		//顶部按钮操作栏
		actionhandel(type) {
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);

			// 点击新增
			if (type === 'add') {
				this.$router.push({
					path: '/warehouse/other/inventorySheetSet',
					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 === 'submit') {
				this.submitPageData();
			}
			//点击撤销
			if (type === 'revoke') {
				this.toolarFn('TrayCount/Revoke');
			}
			//点击审核
			if (type === 'audit') {
				this.toolarFn('TrayCount/check');
			}
			//点击反审核
			if (type === 'de-approval') {
				this.toolarFn('TrayCount/recheck');
			}
		},
		// 提交
		submitPageData() {
			this.pagefromData.details.forEach((it) => {
				it.afterQty = it.afterQty ? it.afterQty : 0;
				it.finalQty =
					(it.afterQty ? it.afterQty : 0) -
					(it.beforeQty ? it.beforeQty : 0);
			});
			this.$http
				.post('TrayCount/submit', this.pagefromData)
				.then((res) => {
					if (res.status === 200) {
						this.pagefromData = JSON.parse(
							JSON.stringify(res.data)
						);
						this.pagefromData.billTypeId = res.data.billTypeId + '';
						this.setExamine({
							status: res.status,
							data: res.data.tracking,
						});
						this.$message.success({
							message: '提交成功',
							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.tableInfo = res.data;
					}
					this.getProductInfo(this.pagefromData.id);
				}
			});
		},
		// 获取即时库存
		getrealityQty(value, index) {
			// 获取即时库存
			this.$http
				.post('Public/get/inventory', {
					orgId: this.pagefromData.stockOrgId,
					materialId: this.pagefromData.details[index].materialId,
					stockId: value,
					customerId: this.pagefromData.details[index].customerId,
					customerCode:
						this.pagefromData.details[index].customerStockId,
				})
				.then((res) => {
					this.pagefromData.details[index].beforeQty = res.data
						? res.data.surplusQty
						: 0;
					this.pagefromData.details[index].finalQty = new Decimal(
						this.pagefromData.details[index].afterQty
					).sub(
						new Decimal(this.pagefromData.details[index].beforeQty)
					);
				});
		},
		// 仓库选择修改-仓位信息更新
		changeWarehouse(value, index, type) {
			// 如果是详情带过来的数据 要根据仓库去查找下对于的仓位下拉数据,初始不要智控对应的仓位id
			if (type !== 'init') {
				this.pagefromData.details[index].customerId = '';
				this.pagefromData.details[index].customerStockId = '';
				this.pagefromData.details[index].afterQty = 0;
				this.getrealityQty(value, index);
			}
			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;
			}
		},
		// 获取仓库
		getWarehouse(id, res) {
			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 = [1, 5, 7];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 获取部门数据
		getProductdept(orgId) {
			if (orgId) {
				this.$http.post('SysConfig/GetDept/' + orgId).then((res) => {
					if (res.status === 200) {
						this.productDeptList = res.data;
					}
				});
			}
		},
		// 失焦处理
		selectBlur() {
			this.pagefromData.details.forEach((el) => {
				el.ismaterialIdshow = false;
				el.isstockIdshow = false;
				el.isafterQtyshow = false;
				el.iscustomerIdshow = false;
				el.iscustomerStockIdshow = false;
				el.isnoteshow = false;
			});
		},
		// 插入的行
		getInsertInfo() {
			this.pagefromData.details = bottomAddRow(
				this.pagefromData.details,
				JSON.parse(JSON.stringify(this.addRow))
			);
			this.matterallCodelist.splice(
				this.pagefromData.details.length,
				0,
				[]
			);
			this.customeStockArrylist.splice(
				this.pagefromData.details.length,
				0,
				[]
			);
			this.customerWarehouseTaglist.splice(
				this.pagefromData.details.length,
				0,
				true
			);
			// 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.matterallCodelist.splice(this.selectRowIndex, 0, [])
			//     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.matterallCodelist.splice(num, 0, [])
			//     this.customeStockArrylist.splice(num, 0, [])
			//     this.customerWarehouseTaglist.splice(num, 0, true)
			//   }
			// }
			this.selectBlur();
			this.$nextTick(() => {
				this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
					this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
			});
			this.arrangeData();
		},
		// 向下复制行
		bottomCopyRow(data) {
			// 判断行数
			if (this.selectRowIndexArr.length > 0) {
				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.matterallCodelist.splice(
						insertNum,
						0,
						JSON.parse(
							JSON.stringify(
								this.matterallCodelist[this.selectRowIndex]
							)
						)
					);
					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.selectBlur();
					this.arrangeData();
				} else {
					// 获取最后选择的行
					let lastIndex = -1;
					this.selectRowIndexArr.forEach((el) => {
						el > lastIndex ? (lastIndex = el) : false;
					});
					// 添加行
					this.selectRowIndexArr.forEach((el) => {
						lastIndex = lastIndex + 1;
						const tableArr = JSON.parse(
							JSON.stringify(this.pagefromData.details[el])
						);
						tableArr.id = 0;
						this.pagefromData.details.splice(
							lastIndex,
							0,
							tableArr
						);
						this.matterallCodelist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(this.matterallCodelist[el])
							)
						);
						this.customeStockArrylist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(
									this.customeStockArrylist[el]
										? this.customeStockArrylist[el]
										: []
								)
							)
						);
						this.customerWarehouseTaglist.splice(
							lastIndex,
							0,
							JSON.parse(
								JSON.stringify(
									this.customerWarehouseTaglist[el]
								)
							)
						);
					});
					this.selectBlur();
					this.arrangeData();
				}
			} else {
				this.$message.error({
					message: '请勾选一条行,在操作',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			if (this.selectRowIndexArr.length <= 0) {
				this.$message.error({
					message: '请选择要删除的行!',
					showClose: true,
				});
				return;
			}
			if (this.selectRowIndexArr.length <= 0) {
				this.$message.error({
					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.matterallCodelist.splice(index, 1);
							this.customeStockArrylist.splice(index, 1);
							this.customerWarehouseTaglist.splice(index, 1);
						}
					});
				});
				this.selectBlur();
				this.arrangeData('delet');
			} else {
				this.$message.error({
					message: '至少保留一行!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn(data) {
			let batcharry = [
				'materialId',
				'stockId',
				'afterQty',
				'customerId',
				'note',
			];
			this.pagefromData = batchhandle(
				this.pagefromData,
				this.matterallCodelist,
				this.batchfill.romIndex,
				this.batchfill.columnkey,
				batcharry
			);
			// 如果有客户仓库的处理
			if (
				this.batchfill.columnkey === 'customerId' ||
				this.batchfill.columnkey === 'stockId'
			) {
				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 = '';
							}
						}
					}
				});
			}
			if (this.batchfill.columnkey === 'stockId') {
				let materialIds = [];
				this.pagefromData.details.forEach((it, index) => {
					if (it.materialId) {
						materialIds.push(it.materialId);
					}
				});
				// 获取即时库存
				this.$http
					.post('Public/get/inventorylist', {
						orgId: this.pagefromData.stockOrgId,
						materialIds: materialIds,
						stockId:
							this.pagefromData.details[this.batchfill.romIndex]
								.stockId,
					})
					.then((res) => {
						if (res.status === 200) {
							this.pagefromData.details.forEach((item, index) => {
								if (!res.data || res.data.length === 0) {
									if (index > this.batchfill.romIndex) {
										item.realStock = 0;
									}
								} else {
									res.data.forEach((i) => {
										if (
											i.materialId === item.materialId &&
											index > this.batchfill.romIndex
										) {
											item.realStock =
												i && i.surplusQty
													? i.surplusQty
													: 0;
										}
									});
								}
							});
						}
					});
			}
		},
		//注意这里是解构
		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, {
					ismaterialIdshow: false,
					isstockIdshow: false,
					isafterQtyshow: false,
					iscustomerIdshow: false,
					iscustomerStockIdshow: false,
					isnoteshow: false,
				});
			});
			var showtagarry = [
				'ismaterialIdshow',
				'isstockIdshow',
				'isafterQtyshow',
				'iscustomerIdshow',
				'iscustomerStockIdshow',
				'isnoteshow',
			];
			var parentshowtagarry = [
				'materialId',
				'stockId',
				'afterQty',
				'customerId',
				'customerStockId',
				'note',
			];
			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 .el-input__inner) {
	padding: 0 16px 0 8px !important;
	width: 165px !important;
}
</style>
