<!--仓库 -组装拆卸单 编辑 -->
<template>
	<div
		:style="{ height: heightNum + 'px!important' }"
		class="sale-details-container order-mc-bg main-container"
	>
		<div class="sale-details-btn-group">
			<!-- 顶部按钮 -->
			<toolBtn
				:btnType="btnType"
				:isDisable="isDisable"
				@actionhandel="actionhandel"
			></toolBtn>
		</div>
		<!--基本信息 -->
		<div class="sale-details-tell-info">
			<img
				class="reviewIconImg"
				src="../../../assets/reviewed_ico.png"
				style="top: 19%; left: 130px"
				v-if="pagefromData.documentStatus === 'c'"
			/>
			<div class="tell-info-row-title">
				<h3>基本信息</h3>
				<div class="long-line-bx">
					<div class="long-line"></div>
				</div>
			</div>
			<div class="tell-info-table">
				<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
												: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 item-date"
										label="拆卸日期"
									>
										<el-date-picker
											:disabled="
												pagefromData.documentStatus !==
													'a' &&
												pagefromData.documentStatus !==
													'd'
											"
											:disabledDate="
												(data) => {
													return (
														data.getTime() >
														Date.now() - 8.64e6
													);
												}
											"
											class="item-date"
											format="YYYY-MM-DD"
											type="date"
											v-model="pagefromData.date"
											value-format="YYYY-MM-DD"
										>
										</el-date-picker>
									</el-form-item>
									<el-form-item
										:required="true"
										class="item-bt-s"
										label="单据类型"
									>
										<el-select
											disabled
											filterable
											v-model="pagefromData.billType"
										>
											<el-option
												: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 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"
											clearable
											ref="cascader"
											@change="deptChange"
											placeholder="请选择部门"
											v-model="pagefromData.deptId"
										></el-cascader>
									</el-form-item>
								</div>
							</el-col>
						</el-row>
					</el-form>
				</div>
			</div>
		</div>
		<!-- 成品明细 -->
		<div class="sale-details-tell-info" style="margin: 10px 0">
			<div class="tell-info-row-title">
				<h3>成品明细</h3>
				<div class="long-line-bx">
					<div class="long-line"></div>
				</div>
			</div>
			<!--展开BOM -->
			<div class="tell-container">
				<div
					@click="getMaterialBombyId"
					class="tell-info-copy-row"
					v-if="
						pagefromData.documentStatus === 'a' ||
						pagefromData.documentStatus === 'd'
					"
				>
					<span class="f-c">展开BOM</span>
				</div>
			</div>
			<!-- 成品明细-->
			<div class="tell-info-table">
				<el-table
					:cell-class-name="tableCellClassName"
					:data="pagefromData.product"
					:header-cell-class-name="mustAfter"
					@cell-click="topgetRowCol"
					@select="selectRow"
					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="190">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'materialIdp' + scope.$index"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											'product',
											scope.$index
										);
									}
								"
								@change="
									metterChange(
										$event,
										scope.$index,
										'product'
									)
								"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.ismaterialIdshowp"
								v-model="scope.row.materialId"
							>
								<el-option
									:key="item.id"
									:label="item.number"
									:value="item.id"
									v-for="item in matterCodelist"
									:style="{
										height: item.disable ? '0px' : 'auto',
									}"
								>
								</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="250"
					/>
					<el-table-column
						align="left"
						label="物料名称"
						prop="materialName"
						width="190"
					></el-table-column>
					<el-table-column
						align="left"
						label="单位"
						prop="unitId"
						width="108"
					>
						<template #default="scope">
							<span>{{
								publicidbyname(unitlist, scope.row.unitId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="qty" width="100">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>数量
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'qty' + scope.$index"
								:maxlength="8"
								@blur="
									numberChage(
										scope.row.qty,
										scope.$index,
										scope.row,
										'qty',
										'B'
									)
								"
								placeholder
								v-if="scope.row.isqtyshowp"
								v-model="scope.row.qty"
							></el-input>
							<span v-else>{{ scope.row.qty }}</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,
										'product'
									)
								"
								clearable
								filterable
								placeholder="请选择"
								v-if="scope.row.isstockIdshowp"
								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="stockerName"
						width="110"
					/>
					<el-table-column align="left" prop="customerId" width="220">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									!customerWarehouseTag ||
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd')
								"
								@change="
									changecustomer(
										$event,
										scope.$index,
										'product'
									)
								"
								clearable
								filterable
								placeholder="请选择"
								v-if="scope.row.iscustomerIdshowp"
								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="220"
					>
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>客户仓库
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									!customerWarehouseTag ||
									(pagefromData.documentStatus !== 'a' &&
										pagefromData.documentStatus !== 'd') ||
									!scope.row.customerId
								"
								clearable
								filterable
								placeholder="请选择"
								v-if="scope.row.iscustomerStockIdshowp"
								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 customeStocklist"
								></el-option>
							</el-select>
							<span v-else>{{
								publicidbyname(
									customeStocklist,
									scope.row.customerStockId
								)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="note" width="300">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>备注
						</template>
						<template #default="scope">
							<el-input
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'notep' + scope.$index"
								:maxlength="2000"
								@click="
									topgetRowCol(
										scope.row,
										scope.column,
										'note '
									)
								"
								v-if="scope.row.isnoteshowp"
								v-model="scope.row.note"
							></el-input>
							<span v-else>{{ scope.row.note }}</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>
		<!-- 子件明细 -->
		<div
			class="sale-details-tell-info"
			style="height: 420px; overflow-y: hidden"
		>
			<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 z_table">
				<el-table
					:cell-class-name="tableCellClassName"
					:data="pagefromData.product[0].details"
					:header-cell-class-name="mustAfter1"
					@cell-click="getRowCol"
					@select="selectRow"
					@select-all="selectRowAll"
					border
					height="336"
					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="190">
						<template #header>
							<span
								class="iconfont icon-bianji1 iconfont-mg"
							></span
							>物料编码
						</template>
						<template #default="scope">
							<el-select
								:disabled="
									pagefromData.documentStatus !== 'a' &&
									pagefromData.documentStatus !== 'd'
								"
								:id="'materialId' + scope.$index"
								:remote-method="
									(query) => {
										matterCodeChange(
											query,
											'detalis',
											scope.$index
										);
									}
								"
								@change="metterChange($event, scope.$index)"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'materialId'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'materialId'
									)
								"
								filterable
								placeholder="请输入关键词"
								remote
								reserve-keyword
								v-if="scope.row.ismaterialIdshow"
								v-model="scope.row.materialId"
							>
								<el-option
									:key="item.id"
									: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="170"
					></el-table-column>
					<el-table-column
						align="left"
						label="子单位"
						prop="unitId"
						width="108"
					>
						<template #default="scope">
							<span>{{
								publicidbyname(unitlist, scope.row.subUnitId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column align="left" prop="qtyChild" 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="'qtyChild' + scope.$index"
								:maxlength="8"
								@blur="
									numberChage(
										scope.row.qtyChild,
										scope.$index,
										scope.row,
										'qtyChild',
										'C'
									)
								"
								@paste="
									pasteExcel(
										$event,
										scope.$index,
										scope,
										'qtyChild'
									)
								"
								placeholder
								v-if="scope.row.isqtyChildshow"
								v-model="scope.row.qtyChild"
							></el-input>
							<span v-else>{{ scope.row.qtyChild }}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="单位"
						prop="unitId"
						width="108"
					>
						<template #default="scope">
							<span>{{
								publicidbyname(unitlist, scope.row.unitId)
							}}</span>
						</template>
					</el-table-column>
					<el-table-column
						align="left"
						label="数量(单位)"
						prop="qty"
						width="120"
					/>
					<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,
										'details'
									)
								"
								@click="
									getRowCol(
										scope.row,
										scope.column,
										'stockId'
									)
								"
								clearable
								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="220">
						<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,
										'details'
									)
								"
								@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="220"
					>
						<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
								"
								@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="300">
						<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 { mapState } from 'vuex';
import { countMethodsUnitNumber } from '@/utils/count.js';
import { orderCopy, bottomAddRow } from '@/utils/takeMethods';
import {
	transformTimestamp,
	getObjValue,
	theUnitSet,
	batchhandle,
	quikecopyValue,
	oldstocklist,
} from '@/utils/pubulic.js';
import { pageoPtionProps } from '@/utils/printPagekey.js';
export default {
	name: 'AddDisassembleOrderSet',
	components: {
		examineTop,
	},
	data() {
		return {
			isCountS: [],
			isPrecisionS: [],
			salePrecisionNumberS: [],
			isCountP: [],
			isPrecisionP: [],
			salePrecisionNumberP: [],
			isCount: [],
			isPrecision: [],
			salePrecisionNumber: [],
			isDisable: false,
			optionProps: JSON.parse(JSON.stringify(pageoPtionProps)),
			detailBtn: ['copy'],
			tableInfo: [], //操作结果
			documentStatuslist: [], // 单据状态
			documentTypelist: [], // 单据类型
			matterCodelist: [[]], // 物料下拉数据
			matterallCodelist: [[]], // 物料下拉数据
			unitlist:
				this.$store.state && this.$store.state.storeData.allUnit
					? this.$store.state.storeData.allUnit
					: [], // 获取计量单位数据
			productDeptList: [], // 部门
			customerlist: [], // 客户下拉数据
			customeStocklist: [], // 客户仓库下拉数据
			customeStockArrylist: [], // 所有客户仓库下拉数据
			warehouse: [], //仓库下拉数据
			warechildhouse: [], // 仓位下拉数据
			customerWarehouseTag: true,
			customerWarehouseTaglist: [],
			paegDetails: {
				id: 0, // 成品id
				seq: 0, // 序号
				materialId: null, //物料编码id
				materialName: '', //物料名称
				materialNumber: '',
				specification: '', //规格型号
				unitId: null, // 单位
				qty: 0, // 数量
				stockId: null, // 仓库
				subStockId: null, // 仓位
				stockerId: null, // 仓管员
				customerId: null, // 客戶id
				customerName: '', // 仓管员姓名
				customerStockId: null, // 客户仓库
				note: '', //备注
			}, //子物料明细信息
			pagefromData: {
				id: 0, // 单据的id
				billNo: '', // 单据编号
				billType: '', // 单据类型
				documentStatus: 'a', // 单据状态
				date: transformTimestamp(new Date()), //下单日期
				stockOrgId: null, //库存组织
				deptId: '', // 部门
				product: [
					//明细数据
					{
						id: 0, // 成品id
						seq: 0, // 序号
						materialId: null, //物料编码id
						materialName: '', //物料名称
						materialNumber: '',
						specification: '', //规格型号
						unitId: null, // 单位
						qty: 0, // 数量
						stockId: null, // 仓库
						subStockId: null, // 仓位
						stockerId: null, // 仓管员
						stockManger: '', // 仓管员姓名
						customerId: null, // 客戶id
						customerName: '', // 仓管员姓名
						note: '', //备注
						details: [], //子物料
					},
				],
			},
			pageAction:
				this.$route.query && this.$route.query.type
					? this.$route.query.type
					: '', // 判断到该页面的操作状态
			btnType: [
				'save',
				'revoke',
				'copy',
				's-p-t-g3',
				's-p-t-g4',
				'operation',
				'query',
				's-p-t-g5',
			], // 不需要显示的顶部按钮类型
			//明细数据
			addRow: {},
			selectRowIndexArr: [],
			selectRowIndex: '', // 当前 选择行
			// 批量填充
			batchfill: {
				romIndex: null,
				columnIndex: null,
				columnkey: null,
			},
			heightNum: 0,
		};
	},
	watch: {
		orgId(value) {
			if (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',
					'query',
					'refresh',
					's-p-t-g3',
					's-p-t-g4',
				]; // 不需要显示的顶部按钮类型
			} else {
				this.btnType = [
					'save',
					'copy',
					'delete',
					'close-case',
					'split-order',
					'push-down',
					'refresh',
					'operation',
					's-p-t-g4',
					'query',
				];
			}
		},
	},
	computed: {
		...mapState({
			orgId: (state) =>
				state && state.org && state.org.orgId ? state.org.orgId : null,
			orgIdArr: (state) => (state ? state.user.orgIdArr : null),
			getPageObjValue: function () {
				// 根据key值显示对应的键名
				return function (arr, key) {
					return getObjValue(arr, key);
				};
			},
		}),
		publicidbyname: function () {
			// 根据key值显示对应的键名
			return function (arr, key) {
				return theUnitSet(arr, key);
			};
		},
	},
	created() {
		this.heightNum =
			document.documentElement.clientHeight - (40 + 30 + 16 + 16);
		this.pagefromData.product[0] = JSON.parse(
			JSON.stringify(this.paegDetails)
		);
		this.pagefromData.product[0].details = [];
		this.pagefromData.product[0].details = [
			JSON.parse(JSON.stringify(this.paegDetails)),
		];
		this.addRow = JSON.parse(JSON.stringify(this.paegDetails));
		this.Init();
	},
	mounted() {},
	methods: {
		Init() {
			this.getUnit();
			this.getStatus();
			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.product[0].details.length
					) {
						if (key == 'materialId') {
							this.matterCodeChange(it, 'number', recordAddIndex);
						}
						if (key === 'qty') {
							this.pagefromData.product[0].details[
								recordAddIndex
							][key] = it;
						}
						recordAddIndex++;
					}
				});
			}, 100);
		},
		// 保存或者提交的时候，对数据个别字段例如 is211 seq 做数据整理，避免提交保存失败
		arrangeData(type) {
			if (this.pagefromData.product[0].details) {
				let newDetails = this.pagefromData.product[0].details.map(
					(v, index) => {
						return { ...v, seq: index };
					}
				);
				this.pagefromData.product[0].details = newDetails;
				// 清空明细选中
				this.$refs.multipleTable.clearSelection();
				this.selectRowIndexArr = [];
			}
		},
		// 根据客户id集合获取客户仓库
		initgetcustomerstocklist(customerStockIds, total, type) {
			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++) {
									if (type === 'initproduct') {
										this.customeStocklist = res.data;
									}
									if (type === 'initdetails') {
										this.customeStockArrylist[tag] =
											res.data;
									}
								}
							}
						}
					});
			}
		},
		deptChange(value) {
			if (value) {
				this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
			}
		},
		// 改变客户的时候获取对应的客户仓库 ---1 到时候应该替换为公司id
		changecustomer(id, index, type) {
			if (type !== 'init') {
				if (type === 'product') {
					this.pagefromData.product[index].customerStockId = '';
				}
				if (type === 'details') {
					this.pagefromData.product[0].details[
						index
					].customerStockId = '';
				}
				if (id) {
					this.$http
						.post('SysConfig/GetCustomerStock', {
							customerId:
								type === 'product'
									? this.pagefromData.product[0].customerId
									: this.pagefromData.product[0].details[
											index
									  ].customerId,
							orgId: this.pagefromData.stockOrgId,
							stockId: null,
						})
						.then((res) => {
							if (res.status === 200) {
								if (type === 'details') {
									this.customeStockArrylist[index] =
										res.data && res.data.length > 0
											? oldstocklist(
													res.data.concat(
														oldstocklist(
															this.pagefromData
																.product[0]
																.details
														).customerStockList
													),
													'retrieve'
											  )
											: oldstocklist(
													oldstocklist(
														this.pagefromData
															.product[0].details
													).customerStockList,
													'retrieve'
											  );
								} else {
									this.customeStocklist =
										res.data && res.data.length > 0
											? oldstocklist(
													res.data.concat(
														oldstocklist(
															this.pagefromData
																.product
														).customerStockList
													),
													'retrieve'
											  )
											: oldstocklist(
													oldstocklist(
														this.pagefromData
															.product
													).customerStockList,
													'retrieve'
											  );
								}
							}
						});
				}
			}
		},
		// 获取全部公司客户
		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;
			}
		},
		//根据物料Id 搜索 物料Bom信息
		getMaterialBombyId() {
			var theames = [];
			this.pagefromData.product[0].details = [];
			if (
				this.pagefromData.product[0].bomId &&
				this.pagefromData.product[0].materialId
			) {
				this.$http
					.get(
						'MaterialBom/GetBomDetailsByBomId/' +
							this.pagefromData.product[0].bomId +
							'/' +
							this.pagefromData.stockOrgId
					)
					.then((res) => {
						if (res.status === 200) {
							if (res.data.length > 0) {
								this.matterallCodelist = [];
								res.data.forEach((it, index) => {
									if (it.materialNumber) {
										theames.push(it.materialNumber);
										this.pagefromData.product[0].details.push(
											{
												id: 0, // 成品id
												seq: index + 1, // 序号
												materialId: it.materialId, //物料编码id
												materialName: it.materialName, //物料名称
												specification: it.specification, //规格型号
												materialNumber:
													it.materialNumber, //物料编码
												unitId: it.unitId, // 单位
												subUnitId: it.subUnitId, // 子单位
												qtyChild:
													(this.pagefromData
														.product[0].qty *
														it.numerator) /
													it.denominator, // 数量
												qty:
													(this.pagefromData
														.product[0].qty *
														it.numerator) /
													it.denominator /
													it.subUnitMultiple, // 数量
												subUnitMultiple:
													it.subUnitMultiple, //倍数
												numerator: it.numerator, //用料分子
												denominator: it.denominator, //用料分母
												stockId: null, // 仓库
												subStockId: null, // 仓位
												stockerId: null, // 仓管员
												stockManger: '', // 仓管员姓名
												customerId: null, // 客戶id
												customerName: '', // 仓管员姓名
												customerStockId: null, // 客户仓库
												note: '', //备注
											}
										);
										setTimeout((_) => {
											this.dataNumjd(index);
										}, 300);
									} else {
										this.pagefromData.product[0].details.push(
											{
												id: 0, // 成品id
												seq: index + 1, // 序号
												materialId: it.materialId, //物料编码id
												materialName: it.materialName, //物料名称
												specification: it.specification, //规格型号
												materialNumber:
													it.materialNumber, //物料编码
												unitId: it.unitId, // 单位
												subUnitId: it.subUnitId, // 子单位
												qtyChild:
													(this.pagefromData
														.product[0].qty *
														it.numerator) /
													it.denominator, // 数量
												qty:
													(this.pagefromData
														.product[0].qty *
														it.numerator) /
													it.denominator /
													it.subUnitMultiple, // 数量
												subUnitMultiple:
													it.subUnitMultiple, //倍数
												numerator: it.numerator, //用料分子
												denominator: it.denominator, //用料分母
												stockId: null, // 仓库
												subStockId: null, // 仓位
												stockerId: null, // 仓管员
												stockManger: '', // 仓管员姓名
												customerId: null, // 客戶id
												customerName: '', // 仓管员姓名
												customerStockId: null, // 客户仓库
												note: '', //备注
											}
										);
									}
									setTimeout((_) => {
										this.dataNumjd(index);
									}, 300);
								});
								this.$http
									.post('SysConfig/GetMaterialLikeList', {
										names: theames,
										file: 'Number',
										orgId: this.pagefromData.stockOrgId,
									})
									.then((res) => {
										if (res.status === 200) {
											theames.forEach((it, idx) => {
												this.matterallCodelist[idx] =
													res.data;
											});
											this.$forceUpdate();
										}
									});
							} else {
								this.matterallCodelist.push([]);
								this.pagefromData.product[0].details = [
									JSON.parse(
										JSON.stringify(this.paegDetails)
									),
								];
								this.$message.error({
									message: '没有相关子项明细',
									showClose: true,
								});
							}
						}
					});
			} else {
				this.$message.error({
					message: !this.pagefromData.product[0].materialId
						? '请先选择成品的物料信息再获取相关BOM信息'
						: !this.pagefromData.product[0].bomId
						? '该物料没有bom'
						: '',
					showClose: true,
				});
			}
		},
		// 初始化--编辑或者详情
		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.getProductdept(this.orgId);
				this.getAllcustomer(this.orgId);
			}
		},
		// 生产组织下拉改变是 （会影响生产部门的数据）
		orgChange(value) {
			this.customerWarehouseTaglist = [true];
			this.pagefromData.deptId = null;
			this.getProductdept(value);
			this.getWarehouse(value);
			this.pagefromData.stockOrgId = value;
			this.getAllcustomer();
			this.pagefromData.product[0] = JSON.parse(
				JSON.stringify(this.paegDetails)
			);
			this.pagefromData.product[0].details = [];
			this.pagefromData.product[0].details.push(
				JSON.parse(JSON.stringify(this.paegDetails))
			);
		},
		// BOM
		numberPrecisionMethods(index, unit, S, P, C, type) {
			if (type == 'B') {
				if (this.pagefromData.product[index][unit]) {
					let tempList = this.unitlist.filter(
						(it) => it.id === this.pagefromData.product[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.product[index].materialId &&
					!this.$route.query.id
				) {
					this[P][index] = true;
				}
				if (!this[C][index]) {
					this[C][index] = 1;
				}
			}
			if (type == 'C') {
				if (this.pagefromData.product[0].details[index][unit]) {
					let tempList = this.unitlist.filter(
						(it) =>
							it.id ===
							this.pagefromData.product[0].details[index][unit]
					);
					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.product[0].details[index].materialId &&
					!this.$route.query.id
				) {
					this[P][index] = true;
				}
				if (!this[C][index]) {
					this[C][index] = 1;
				}
			}
		},
		// 精度处理
		dataNumjd(index, value) {
			// 判断条件 单位
			this.numberPrecisionMethods(
				index,
				'unitId',
				'salePrecisionNumberP',
				'isPrecisionP',
				'isCountP',
				'C'
			);
			// 判断条件 子单位
			this.numberPrecisionMethods(
				index,
				'subUnitId',
				'salePrecisionNumberS',
				'isPrecisionS',
				'isCountS',
				'C'
			);
			const tempList = this.unitlist.filter(
				(it) =>
					it.id ===
					this.pagefromData.product[0].details[index].subUnitId
			);
			const tempListUnitId = this.unitlist.filter(
				(it) =>
					it.id === this.pagefromData.product[0].details[index].unitId
			);
			if (value !== 'init') {
				this.pagefromData.product[0].details[index].qty =
					this.pagefromData.product[0].details[index].qtyChild /
					(this.pagefromData.product[0].details[index].subUnitMultiple
						? this.pagefromData.product[0].details[index]
								.subUnitMultiple
						: 1);
			}
			let resultRealSoc = countMethodsUnitNumber(
				tempListUnitId,
				this.pagefromData.product[0].details[index].qty,
				this.pagefromData.product[0].details[index].qty,
				this.isCountP[index],
				this.salePrecisionNumberP[index],
				true
			);
			this.pagefromData.product[0].details[index].qty =
				resultRealSoc.value ? resultRealSoc.value * 1 : 0;
			let resultRealSoc1 = countMethodsUnitNumber(
				tempList,
				this.pagefromData.product[0].details[index].qtyChild,
				this.pagefromData.product[0].details[index].qtyChild,
				this.isCountS[index],
				this.salePrecisionNumberS[index],
				true
			);
			this.pagefromData.product[0].details[index].qtyChild =
				resultRealSoc1.value * 1;
		},
		// BOM 数量改变时
		numberChage(val, index, item, key, type) {
			if (type == 'B') {
				// 判断条件 子单位
				this.numberPrecisionMethods(
					index,
					'unitId',
					'salePrecisionNumber',
					'isPrecision',
					'isCount',
					'B'
				);
				// 输入规则
				if (val) {
					if (val.toString().indexOf('.') !== -1) {
						let tempList = JSON.parse(
							JSON.stringify(
								this.unitlist.filter(
									(it) =>
										it.id ===
										this.pagefromData.product[index].unitId
								)
							)
						);
						if (tempList && tempList.length > 0) {
							tempList[0].roundoffType = 2;
						}
						let result = countMethodsUnitNumber(
							tempList,
							val,
							this.pagefromData.product[index][key],
							this.isCount[index],
							this.salePrecisionNumber[index],
							true
						);
						this.pagefromData.product[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.product[index][key] =
						this.pagefromData.product[index][key]
							.toString()
							.replace(/[^\d^\\.]+/g, '')
							.replace('.', '$#$')
							.replace(/\./g, '')
							.replace('$#$', '.')
							.replace(eval(reg), '$1$2.$3');
				}
			}
			if (type == 'C') {
				// 判断条件 单位
				this.numberPrecisionMethods(
					index,
					'unitId',
					'salePrecisionNumberP',
					'isPrecisionP',
					'isCountP',
					'C'
				);
				// 判断条件 子单位
				this.numberPrecisionMethods(
					index,
					'subUnitId',
					'salePrecisionNumberS',
					'isPrecisionS',
					'isCountS',
					'C'
				);
				// 输入规则
				if (val) {
					if (val.toString().indexOf('.') !== -1) {
						let tempList = JSON.parse(
							JSON.stringify(
								this.unitlist.filter(
									(it) =>
										it.id ===
										this.pagefromData.product[0].details[
											index
										].subUnitId
								)
							)
						);
						if (tempList && tempList.length > 0) {
							tempList[0].roundoffType = 2;
						}
						let result = countMethodsUnitNumber(
							tempList,
							val,
							this.pagefromData.product[0].details[index][key],
							this.isCountS[index],
							this.salePrecisionNumberS[index],
							true
						);
						this.pagefromData.product[0].details[index][key] =
							result.value * 1;
						this.isCountS[index] = result.isDefault;
					}
					let numD = '';
					let count = '\\d';
					for (
						let ind = 0;
						ind < this.salePrecisionNumberS[index];
						ind++
					) {
						numD = numD + count;
					}
					let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
					this.pagefromData.product[0].details[index][key] =
						this.pagefromData.product[0].details[index][key]
							.toString()
							.replace(/[^\d^\\.]+/g, '')
							.replace('.', '$#$')
							.replace(/\./g, '')
							.replace('$#$', '.')
							.replace(eval(reg), '$1$2.$3');
					this.dataNumjd(index);
				}
			}
		},
		// 详情或者下推过来的数据处理
		setpageDate(res) {
			const names = [];
			const customerStockIds = [];
			this.pagefromData = JSON.parse(JSON.stringify(res.data));
			this.pagefromData.product = [res.data.product];
			this.pagefromData.billType = res.data.billType + '';
			this.documentStatus = res.data.documentStatus;
			this.pagefromData.stockOrgId = res.data.stockOrgId
				? parseInt(res.data.stockOrgId)
				: '';
			this.getWarehouse(
				this.pagefromData.stockOrgId,
				this.pagefromData.product[0]
			);
			this.getAllcustomer();
			this.customeStockArrylist = [];
			this.matterCodelist = [];
			this.matterallCodelist = [];
			if (
				this.pagefromData.product &&
				this.pagefromData.product.length > 0
			) {
				this.pagefromData.product.forEach((it, index) => {
					this.pagefromData.product[index].seq = index;
					names.push(it.materialNumber);
					if (it.customerId) {
						customerStockIds.push(it.customerId);
					}
					setTimeout(() => {
						this.changeWarehouse(
							this.pagefromData.product[index].stockId,
							index,
							'initproduct'
						);
					}, 500);
				});
				this.initMatterCode(
					names,
					this.pagefromData.product.length,
					'initproduct'
				);
				this.initgetcustomerstocklist(
					customerStockIds,
					this.pagefromData.product.length,
					'initproduct'
				);
			}
			if (
				this.pagefromData.product[0].details &&
				this.pagefromData.product[0].details.length > 0
			) {
				this.pagefromData.product[0].details.forEach((it, index) => {
					this.pagefromData.product[0].details[index].seq = index;
					names.push(it.materialNumber);
					if (it.customerId) {
						customerStockIds.push(it.customerId);
					}
					setTimeout(() => {
						this.changeWarehouse(
							this.pagefromData.product[0].details[index].stockId,
							index,
							'initdetails'
						);
					}, 500);
					this.dataNumjd(index, 'init');
				});
				this.initMatterCode(
					names,
					this.pagefromData.product[0].details.length,
					'initdetails'
				);
				this.initgetcustomerstocklist(
					customerStockIds,
					this.pagefromData.product[0].details.length,
					'initdetails'
				);
			}
			// 详情里面根据组织id去获取明细的生产部门数据
			this.getProductdept(res.data.stockOrgId);
		},
		// 获取盘点单详情
		getProductInfo(prodctId) {
			this.$http.get('Disassembly/get/' + prodctId).then((res) => {
				this.setpageDate(res);
			});
		},
		// 获取需要状态列表---[单据状态，领料状态，业务状态]
		getStatus() {
			this.$http.get('Disassembly/status/get').then((r) => {
				if (r.status === 200) {
					this.documentStatuslist = r.data.documentStatus;
					this.documentTypelist = r.data.disassemblyBillType;
					this.pagefromData.billType = Object.keys(
						r.data.disassemblyBillType
					)[0];
				}
			});
		},
		// 物料--下拉更新
		metterChange(val, index, type) {
			let metterInfo = {};
			//成品明细里面的物料相关明细
			metterInfo = this.matterCodelist.filter((res) => {
				return val === res.id;
			})[0];
			if (type === 'product') {
				this.pagefromData.product[index].materialName = metterInfo.name;
				this.pagefromData.product[index].specification =
					metterInfo.specifications;
				this.pagefromData.product[index].materialNumber =
					metterInfo.number;
				this.pagefromData.product[index].unitId = metterInfo.baseUnitId;
				this.pagefromData.product[index].bomId = metterInfo.bomId;
				this.pagefromData.product[index].bomVersion =
					metterInfo.bomVersion;
				this.pagefromData.product[index].qty = 0;
			} else {
				//子件明细里面的物料相关明细
				if (type !== 'number') {
					metterInfo = this.matterallCodelist[index].filter((res) => {
						return val === res.id;
					})[0];
				} else {
					metterInfo = this.matterallCodelist[index].filter((res) => {
						return val === res.number;
					})[0];
				}
				if (metterInfo) {
					this.pagefromData.product[0].details[index].materialId =
						metterInfo.id;
					this.pagefromData.product[0].details[index].materialName =
						metterInfo.name;
					this.pagefromData.product[0].details[index].materialNumber =
						metterInfo.number;
					this.pagefromData.product[0].details[index].specification =
						metterInfo.specifications;
					this.pagefromData.product[0].details[index].unitId =
						metterInfo.baseUnitId;
					this.pagefromData.product[0].details[index].bomId =
						metterInfo.bomId;
					this.pagefromData.product[0].details[index].bomVersion =
						metterInfo.bomVersion;
					this.pagefromData.product[0].details[index].subUnitId =
						metterInfo.subUnitId;
					this.pagefromData.product[0].details[
						index
					].subUnitMultiple = metterInfo.subUnitMultiple;
					this.pagefromData.product[0].details[index].qtyChild = 0; // 数量
					this.pagefromData.product[0].details[index].qty = 0; // 数量
				}
			}
		},
		// 初始化一次性获取物料信息的接口
		initMatterCode(names, total, type) {
			this.$http
				.post('SysConfig/GetMaterialLikeList', {
					names: names,
					file: 'Number',
					orgId: this.pagefromData.stockOrgId,
				})
				.then((res) => {
					if (res.status == 200) {
						if (type === 'initproduct' || type === 'product') {
							this.matterCodelist = res.data;
						}
						if (total && total > 0 && type === 'initdetails') {
							for (let tag = 0; tag < total; tag++) {
								this.matterallCodelist[tag] = res.data;
							}
						}
					}
				});
		},
		// 获取物料编码信息
		matterCodeChange(val, type, index) {
			const _this = this;
			if (val !== '') {
				this.$http
					.showLoading(false)
					.post('SysConfig/GetMaterial', {
						name: val,
						file: 'Number',
						orgId: this.pagefromData.stockOrgId,
					})
					.then((res) => {
						if (res.status === 200) {
							if (type === 'initdetails') {
								_this.matterallCodelist.push(
									res.data && res.data.length > 0
										? res.data
										: []
								);
							}
							if (type === 'initproduct' || type === 'product') {
								_this.matterCodelist = res.data;
							}
							if (type === 'detalis' || type === 'number') {
								this.matterallCodelist[index] =
									res.data && res.data.length > 0
										? res.data
										: [];
								if (type === 'number') {
									this.metterChange(val, index, type);
								}
							}
						}
					});
			} else {
				if (type === 'initproduct' || type === 'product') {
					this.matterCodelist = [];
				}
				if (type === 'detalis') {
					this.matterallCodelist[index] = [];
				}
			}
		},
		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;
			}
		},
		//顶部按钮操作栏
		actionhandel(type) {
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			// 点击新增
			if (type === 'add') {
				this.$router.push({
					path: '/warehouse/other/disassembleOrderSet',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			//点击提交
			if (type === 'submit') {
				this.submitPageData();
			}
			//点击撤销
			if (type === 'revoke') {
				this.toolarFn('Disassembly/revoke');
			}
			//点击审核
			if (type === 'audit') {
				this.toolarFn('Disassembly/check');
			}
			//点击反审核
			if (type === 'de-approval') {
				this.toolarFn('Disassembly/recheck');
			}
		},
		// 提交数据重构
		setpageData() {
			let data = {};
			data = JSON.parse(JSON.stringify(this.pagefromData));
			data.product = JSON.parse(
				JSON.stringify(
					this.pagefromData.product.constructor === Object
						? this.pagefromData.product
						: this.pagefromData.product[0]
				)
			);
			data.product.details = [];
			data.product.details = JSON.parse(
				JSON.stringify(
					this.pagefromData.product.constructor === Object
						? this.pagefromData.product.details
						: this.pagefromData.product[0].details
				)
			);
			return data;
		},
		// 提交
		submitPageData() {
			this.$http
				.post('Disassembly/submit', this.setpageData())
				.then((res) => {
					if (res.status === 200) {
						this.pagefromData = JSON.parse(
							JSON.stringify(res.data)
						);
						this.pagefromData.product = [];
						this.pagefromData.product = [
							JSON.parse(JSON.stringify(res.data.product)),
						];
						this.pagefromData.product[0].details = JSON.parse(
							JSON.stringify(res.data.product.details)
						);
						this.pagefromData.billType =
							JSON.parse(JSON.stringify(res.data.billType)) + '';
						this.pagefromData.product[0].details.forEach(
							(it, index) => {
								this.dataNumjd(index, 'init');
							}
						);
						this.$message.success({
							message: '提交成功',
							showClose: true,
						});
					}
				});
		},
		// 顶部操作方法-有公共的部分封装下
		toolarFn(path, details) {
			let formdata = details
				? {
						ids: [this.pagefromData.id],
						details: details,
				  }
				: { ids: [this.pagefromData.id] };
			this.$http.post(path, formdata).then((res) => {
				if (res.status === 200) {
					if (res.data && !details) {
						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);
				}
			});
		},
		// 仓库选择修改-仓位信息更新
		changeWarehouse(value, index, type) {
			// 如果是详情带过来的数据 要根据仓库去查找下对于的仓位下拉数据,初始不要智控对应的仓位id
			let arry = [];
			arry = this.warehouse.filter((it) => {
				return it.id === value;
			})[0];
			if (type === 'product') {
				this.pagefromData.product[index].subStockId = '';
				this.pagefromData.product[index].customerId = '';
				this.pagefromData.product[index].customerStockId = '';
				this.pagefromData.product[index].stockerName = arry.contacts;
				this.pagefromData.product[index].stockerId = arry.contactsId;
				this.customerWarehouseTag = arry.customerWarehouseTag;
			}
			if (type === 'details') {
				this.pagefromData.product[0].details[index].subStockId = '';
				this.pagefromData.product[0].details[index].customerId = '';
				this.pagefromData.product[0].details[index].customerStockId =
					'';
				this.pagefromData.product[0].details[index].stockerId = arry
					? arry.contactsId
					: null;
			}
			if (type === 'initproduct') {
				this.customerWarehouseTag = arry
					? arry.customerWarehouseTag
					: true;
			}
			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(stockOrgId, res) {
			if (stockOrgId) {
				this.$http
					.get('SysConfig/GetWarehouseByOrg/' + stockOrgId)
					.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'
									  );
							this.warehouse = oldstocklist(
								this.warehouse.concat(
									oldstocklist(res.details).stockList
								),
								'retrieve'
							);
							if (res) {
								this.customerWarehouseTag = r.data.filter(
									(it) => {
										return res.stockId === it.id;
									}
								);
								this.customerWarehouseTaglist = [];
								if (
									res &&
									res.details &&
									res.details.length > 0
								) {
									res.details.forEach((it, index) => {
										this.customerWarehouseTaglist.push(
											this.warehouse.filter((it) => {
												return it.stockId === it.id;
											}).length > 0
												? this.warehouse.filter(
														(it) => {
															return (
																it.stockId ===
																it.id
															);
														}
												  )[0].customerWarehouseTag
												: true
										);
									});
								}
							}
						}
					});
			}
		},
		// 获取子仓位
		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, 6];
			if (arry.indexOf(obj.columnIndex) !== -1) {
				return 'must';
			}
		},
		// 星星--头部必填ico显示
		mustAfter1(obj) {
			let arry = [1, 5, 8];
			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.product[0].details.forEach((el) => {
				el.ismaterialIdshowp = false;
				el.isqtyshowp = false;
				el.isstockIdshowp = false;
				el.iscustomerIdshowp = false;
				el.iscustomerStockIdshowp = false;
				el.isnoteshowp = false;
			});
		},
		// 插入的行
		getInsertInfo() {
			this.pagefromData.product[0].details = bottomAddRow(
				this.pagefromData.product[0].details,
				JSON.parse(JSON.stringify(this.addRow))
			);
			this.customeStockArrylist.splice(
				this.pagefromData.product[0].details.length,
				0,
				[]
			);
			this.matterallCodelist.splice(
				this.pagefromData.product[0].details.length,
				0,
				[]
			);
			this.customerWarehouseTaglist.splice(
				this.pagefromData.product[0].details.length,
				0,
				true
			);
			// if (data.insertTopVal != 0) {
			//   for (let i = 0; i < data.insertTopVal; i++) {
			//     this.pagefromData.product[0].details.splice(this.selectRowIndex, 0, JSON.parse(JSON.stringify(this.addRow)))
			//     this.customeStockArrylist.splice(this.selectRowIndex, 0, [])
			//     this.matterallCodelist.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.product[0].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.$nextTick(() => {
				this.$refs.multipleTable.$refs.bodyWrapper.scrollTop =
					this.$refs.multipleTable.$refs.bodyWrapper.scrollHeight;
			});
			this.selectBlur();
			this.arrangeData();
		},
		// 向下复制行
		bottomCopyRow(data) {
			// 判断行数
			if (this.selectRowIndexArr.length == 1) {
				const tableArr = JSON.parse(
					JSON.stringify(
						this.pagefromData.product[0].details[
							this.selectRowIndex
						]
					)
				);
				tableArr.id = 0;
				var insertNum = this.selectRowIndex + 1;
				this.pagefromData.product[0].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.arrangeData();
			} else {
				this.$message.error({
					message: '请勾选一条行,在操作',
					showClose: true,
				});
			}
		},
		// 删除行
		selectDeleteRow(data) {
			if (this.selectRowIndexArr.length <= 0) {
				this.$message.warning({
					message: '请选择要删除的行!',
					showClose: true,
				});
				return;
			}
			// 不能为空
			if (
				this.pagefromData.product[0].details.length > 1 &&
				this.selectRowIndexArr.length <
					this.pagefromData.product[0].details.length
			) {
				this.selectRowIndexArr.forEach((k) => {
					this.pagefromData.product[0].details.forEach((l, index) => {
						if (k === l.seq) {
							this.pagefromData.product[0].details.splice(
								index,
								1
							);
							this.matterallCodelist.splice(index, 1);
							this.customeStockArrylist.splice(index, 1);
							this.customerWarehouseTaglist.splice(index, 1);
						}
					});
				});
				this.arrangeData();
			} else {
				this.$message.warning({
					message: '至少保留一行!',
					showClose: true,
				});
			}
		},
		// 批量填充
		copyCellcolumn(data) {
			let batcharry = [
				'materialId',
				'qty',
				'qtyChild',
				'stockId',
				'customerId',
				'note',
			];
			this.pagefromData = batchhandle(
				this.pagefromData,
				this.matterallCodelist,
				this.batchfill.romIndex,
				this.batchfill.columnkey,
				batcharry,
				'组织'
			);
			for (
				let i = this.batchfill.romIndex + 1;
				i < this.pagefromData.product[0].details.length;
				i++
			) {
				if (this.batchfill.columnkey == 'materialId') {
					this.pagefromData.product[0].details[i].qty = 0;
					this.pagefromData.product[0].details[i].qtyChild = 0;
				}
				// 重新判断数量精度
				if (this.batchfill.columnkey == 'qtyChild') {
					this.numberChage(
						this.pagefromData.product[0].details[i].qtyChild,
						i,
						this.pagefromData.product[0].details[i],
						'qtyChild',
						'C'
					);
				}
			}
			// 如果有或者仓库的客户仓库的处理
			if (
				this.batchfill.columnkey === 'stockId' ||
				this.batchfill.columnkey === 'customerId'
			) {
				this.pagefromData.product[0].details.forEach((it, index) => {
					if (index > this.batchfill.romIndex) {
						if (this.batchfill.columnkey === 'stockId') {
							this.changeWarehouse(it.stockId, index, 'details');
						}
						if (this.batchfill.columnkey === 'customerId') {
							if (this.customerWarehouseTaglist[index]) {
								this.changecustomer(
									it.customerId,
									index,
									'details'
								);
							} else {
								this.pagefromData.product[0].details[
									index
								].customerId = '';
								this.pagefromData.product[0].details[
									index
								].customerStockId = '';
							}
						}
					}
				});
			}
		},
		//注意这里是解构
		tableCellClassName({ row, column, rowIndex, columnIndex }) {
			row.index = rowIndex;
			column.index = columnIndex;
		},
		topgetRowCol(row, column) {
			//输入处理 处理表格下拉框输入框显示隐藏
			this.pagefromData.product.forEach((it, index) => {
				Object.assign(it, {
					ismaterialIdshowp: false,
					isqtyshowp: false,
					isstockIdshowp: false,
					iscustomerIdshowp: false,
					iscustomerStockIdshowp: false,
					isnoteshowp: false,
				});
			});
			var showtagarry = [
				'ismaterialIdshowp',
				'isqtyshowp',
				'isstockIdshowp',
				'iscustomerIdshowp',
				'iscustomerStockIdshowp',
				'isnoteshowp',
			];
			var parentshowtagarry = [
				'materialId',
				'qty',
				'stockId',
				'customerId',
				'customerStockId',
				'note',
			];
			showtagarry.forEach((k, idx) => {
				if (column.property == parentshowtagarry[idx]) {
					this.pagefromData.product[0][k] = true;
					this.$nextTick((_) => {
						if (
							(column.property === 'qtyChild' ||
								column.property === 'note' ||
								column.property === 'qty') &&
							document.getElementById(
								(column.property == 'materialId'
									? 'materialIdp'
									: column.property == 'note'
									? 'notep'
									: column.property) + row.index
							)
						) {
							document
								.getElementById(
									(column.property == 'materialId'
										? 'materialIdp'
										: column.property == 'note'
										? 'notep'
										: column.property) + row.index
								)
								.focus();
						}
					});
				}
			});
		},
		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.product[0].details.forEach((it, index) => {
				Object.assign(it, {
					ismaterialIdshow: false,
					isqtyChildshow: false,
					isstockIdshow: false,
					iscustomerIdshow: false,
					iscustomerStockIdshow: false,
					isnoteshow: false,
				});
			});
			var showtagarry = [
				'ismaterialIdshow',
				'isqtyChildshow',
				'isstockIdshow',
				'iscustomerIdshow',
				'iscustomerStockIdshow',
				'isnoteshow',
			];
			var parentshowtagarry = [
				'materialId',
				'qtyChild',
				'stockId',
				'customerId',
				'customerStockId',
				'note',
			];
			showtagarry.forEach((k, idx) => {
				if (column.property == parentshowtagarry[idx]) {
					this.pagefromData.product[0].details[row.index][k] = true;
					this.$nextTick((_) => {
						if (
							(column.property === 'qtyChild' ||
								column.property === 'note' ||
								column.property === 'qty') &&
							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';

.item-bt-s {
	margin-bottom: 10px;
}

::v-deep(.item-date .el-input__inner) {
	padding: 0 16px 0 30px !important;
}
</style>
