<template>
	<div
		class="create-purchase-container order-mc-bg main-container"
		:style="{ height: heightNum + 'px!important' }"
	>
		<!-- 顶部按钮组 -->
		<toolBtn
			@actionhandel="actionhandel"
			:btnType="btnType"
			:isDisable="isDisable"
		></toolBtn>
		<div class="create-purchase-base-info">
			<img
				src="../../../assets/reviewed_ico.png"
				class="reviewIconImg-pur"
				v-if="baseInfoForm.documentStatus === 'c'"
			/>
			<el-tabs
				style="margin-bottom: 8px; margin-top: 16px"
				type="border-card"
			>
				<el-tab-pane label="基本信息">
					<div class="base-info-form-box">
						<el-form :model="baseInfoForm" label-width="80px">
							<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
													v-model.trim="
														baseInfoForm.billNo
													"
													placeholder="(保存时自动生成)"
													:disabled="isEdit"
													:maxlength="50"
													@input="
														saleRexgu(
															baseInfoForm.billNo,
															'billNo'
														);
														purchaseCom(
															baseInfoForm.billNo,
															'billNo'
														);
													"
												></el-input>
												<div
													:data-clipboard-text="
														baseInfoForm.billNo
													"
													@click="saleOrderCopy"
													class="copyBtn"
												>
													<i
														class="el-icon-document-copy"
													/>
												</div>
											</el-form-item>
										</div>
										<el-form-item
											label="销售订单号"
											class="item-bt-s Iisshow"
										>
											<el-input
												v-model.trim="
													baseInfoForm.saleOrderNo
												"
												:disabled="
													isEdit || isPushDownOrg
												"
												placeholder="请输入"
												:maxlength="50"
												@input="
													saleRexgu(
														baseInfoForm.saleOrderNo,
														'saleOrderNo'
													);
													purchaseCom(
														baseInfoForm.saleOrderNo,
														'saleOrderNo'
													);
												"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.saleOrderNo
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											label="下单组织"
											class="item-bt-s"
											:required="true"
										>
											<el-select
												v-model="
													baseInfoForm.demandOrgId
												"
												class="click-cell-ipt-issue"
												:disabled="
													isEdit || isPushDownOrg
												"
												placeholder="请选择"
												@change="clearCom()"
											>
												<el-option
													style="font-size: 12px"
													@click="
														purchaseCom(
															item.id,
															'demandOrgId'
														)
													"
													v-for="item in statusForm.demandOrgs"
													:key="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="接单组织"
											class="item-bt-s"
											:required="true"
										>
											<el-select
												v-model="
													baseInfoForm.receptOrgId
												"
												class="click-cell-ipt-issue"
												:disabled="isEdit"
												placeholder="请选择"
											>
												<el-option
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															item.id,
															'receptOrgId'
														)
													"
													v-for="item in statusForm.receptOrgs"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="下单日期"
											class="item-bt-s item-date"
										>
											<el-date-picker
												:disabled="isEdit"
												v-model="baseInfoForm.orderDate"
												@change="
													purchaseCom(
														baseInfoForm.orderDate,
														'orderDate'
													)
												"
												type="date"
												value-format="YYYY-MM-DD"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
											></el-date-picker>
										</el-form-item>
										<!-- :disabledDate="pickerOptions" -->
										<el-form-item
											label="期望交期"
											class="item-bt-s item-date"
											:required="true"
										>
											<el-date-picker
												:disabled="isEdit"
												v-model="
													baseInfoForm.hopeFinishDate
												"
												@change="
													purchaseCom(
														baseInfoForm.hopeFinishDate,
														'hopeFinishDate'
													)
												"
												type="date"
												value-format="YYYY-MM-DD"
												format="YYYY-MM-DD"
												placeholder="年/月/日"
											></el-date-picker>
										</el-form-item>
										<el-form-item
											label="客户"
											class="item-bt-s"
										>
											<el-select
												class="f_12"
												v-model="
													baseInfoForm.customerId
												"
												:disabled="
													isEdit ||
													isPushDownOrg ||
													isOutCusHouse
												"
												filterable
												remote
												reserve-keyword
												placeholder="请输入关键词"
												@change="
													customerChange(
														baseInfoForm.customerId,
														'customerId'
													)
												"
											>
												<el-option
													v-for="item in statusForm.custList"
													@click="
														purchaseCom(
															item.id,
															'customerId'
														)
													"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="客户仓库"
											class="item-bt-s"
										>
											<el-select
												v-model="
													baseInfoForm.customerStockId
												"
												class="click-cell-ipt-issue"
												:disabled="
													isEdit || isOutCusHouse
												"
												placeholder=" "
											>
												<el-option
													style="font-size: 12px"
													@click="
														purchaseCom(
															baseInfoForm.customerStockId,
															'customerStockId',
															null,
															null,
															item.disabled
														)
													"
													v-for="item in statusForm.subStocks"
													:key="item.id"
													:label="item.name"
													:value="item.id"
													:disabled="item.disabled"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="销售员"
											class="item-bt-s"
										>
											<el-select
												v-model="
													baseInfoForm.salespersonId
												"
												class="click-cell-ipt-issue"
												:disabled="
													isEdit || isPushDownOrg
												"
												placeholder="请选择"
												:clearable="true"
											>
												<el-option
													style="font-size: 12px"
													@click="
														purchaseCom(
															item.id,
															'salespersonId'
														)
													"
													v-for="item in statusForm.salePerson"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="跟单员"
											class="item-bt-s"
										>
											<el-select
												v-model="
													baseInfoForm.merchandiserId
												"
												class="click-cell-ipt-issue"
												:disabled="
													isEdit || isPushDownOrg
												"
												placeholder="请选择"
												:clearable="true"
											>
												<el-option
													style="font-size: 12px"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													@click="
														purchaseCom(
															item.id,
															'merchandiserId'
														)
													"
													v-for="item in statusForm.qcPerson"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											label="单据状态"
											class="item-bt-s"
										>
											<el-select
												v-model="
													baseInfoForm.documentStatus
												"
												:disabled="true"
												placeholder="请选择"
												:clearable="true"
											>
												<el-option
													style="font-size: 12px"
													v-for="(
														value, key, index
													) in statusForm.bills"
													:key="key + index"
													:label="value"
													:value="key"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="物料编码"
											class="item-bt-s"
											:required="true"
										>
											<el-select
												v-model="
													baseInfoForm.materialId
												"
												:disabled="
													isEdit || isPushDownOrg
												"
												filterable
												remote
												reserve-keyword
												placeholder="请输入关键词"
												:remote-method="
													matterCodeChange
												"
											>
												<el-option
													v-for="item in statusForm.matterCodelist"
													@click="
														matterSkuCom(
															item.id,
															item.number,
															'materialId'
														)
													"
													:key="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:label="item.number"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="规格型号(SKU)"
											class="item-bt-s"
											:required="true"
										>
											<el-select
												v-model="baseInfoForm.skuId"
												:disabled="
													isEdit || isPushDownOrg
												"
												filterable
												remote
												reserve-keyword
												placeholder="请输入关键词"
												:remote-method="skuCodeChange"
											>
												<el-option
													v-for="item in statusForm.specificationsList"
													@click="
														matterSkuCom(
															item.id,
															item.specifications,
															'skuId'
														)
													"
													:key="item.id"
													:style="{
														height: item.disable
															? '0px'
															: 'auto',
													}"
													:label="item.specifications"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="物料名称"
											class="item-bt-s Iisshow"
										>
											<el-input
												v-model.trim="
													baseInfoForm.materialName
												"
												placeholder=" "
												:disabled="true"
												:maxlength="255"
											></el-input>
											<div
												:data-clipboard-text="
													baseInfoForm.materialName
												"
												@click="saleOrderCopy"
												class="copyBtn"
											>
												<i
													class="el-icon-document-copy"
												/>
											</div>
										</el-form-item>
										<el-form-item
											label="销售单位"
											class="item-bt-s"
										>
											<el-select
												v-model="baseInfoForm.unitId"
												class="click-cell-ipt-issue"
												placeholder="请选择"
												:disabled="true"
											>
												<el-option
													style="font-size: 12px"
													@click="
														purchaseCom(
															baseInfoForm.unitId,
															'unitId'
														)
													"
													v-for="item in statusForm.units"
													:key="item.id"
													:label="item.name"
													:value="item.id"
												></el-option>
											</el-select>
										</el-form-item>
										<el-form-item
											label="下单数量"
											class="item-bt-s"
											:required="true"
										>
											<el-input
												v-model="baseInfoForm.orderQty"
												:disabled="isEdit"
												placeholder="请输入"
												:maxlength="19"
												@input="
													saleNum(
														baseInfoForm.orderQty,
														'orderQty',
														isPrecision
													);
													purchaseCom(
														baseInfoForm.orderQty,
														'orderQty'
													);
												"
												@blur="
													returnRemove0(
														baseInfoForm.orderQty,
														'orderQty'
													)
												"
											></el-input>
										</el-form-item>
										<el-form-item
											label="已交数量"
											class="item-bt-s"
										>
											<el-input
												v-model="
													baseInfoForm.deliveredQty
												"
												:disabled="true"
												placeholder=" "
												:maxlength="255"
											></el-input>
										</el-form-item>
										<el-form-item
											label="未交数量"
											class="item-bt-s"
										>
											<el-input
												v-model="
													baseInfoForm.undeliveredQty
												"
												:disabled="true"
												placeholder=" "
												:maxlength="255"
											></el-input>
										</el-form-item>
										<el-form-item
											label="已收数量"
											class="item-bt-s"
										>
											<el-input
												v-model="
													baseInfoForm.transferQty
												"
												:disabled="true"
												placeholder=" "
												:maxlength="255"
											></el-input>
										</el-form-item>
										<el-form-item
											label="未收数量"
											class="item-bt-s"
										>
											<el-input
												v-model="
													baseInfoForm.untransferQty
												"
												:disabled="true"
												placeholder=" "
												:maxlength="255"
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													label="关闭状态"
													class="item-bt-s"
													:maxlength="50"
												>
													<el-select
														v-model="
															baseInfoForm.isClosed
														"
														placeholder=" "
														:disabled="true"
													>
														<el-option
															style="
																font-size: 12px;
															"
															v-for="(
																value,
																key,
																index
															) in statusForm.cloStatus"
															:key="key + index"
															:label="value"
															:value="key"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													label="数据来源"
													class="item-bt-s"
												>
													<el-select
														v-model="
															baseInfoForm.createType
														"
														:disabled="true"
														placeholder=" "
													>
														<el-option
															style="
																font-size: 12px;
															"
															v-for="(
																value,
																key,
																index
															) in statusForm.createTypes"
															:key="key + index"
															:label="value"
															:value="key"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													label="仓库"
													class="item-bt-s"
													:required="true"
												>
													<el-select
														v-model="
															baseInfoForm.stockId
														"
														class="click-cell-ipt-issue"
														@change="selectChange"
														:disabled="isEdit"
														placeholder=" "
													>
														<el-option
															style="
																font-size: 12px;
															"
															:style="{
																height: item.disable
																	? '0px'
																	: 'auto',
															}"
															@click="
																purchaseCom(
																	baseInfoForm.stockId,
																	'stockId',
																	null,
																	null,
																	item.disabled,
																	item.customerWarehouseTag
																)
															"
															v-for="item in statusForm.stocks"
															:key="item.id"
															:label="item.name"
															:value="item.id"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													label="销售部门"
													class="item-bt-s"
												>
													<el-cascader
														class="click-cell-ipt-c"
														ref="cascader"
														@change="
															purchaseCom(
																baseInfoForm.saleDeptId,
																'saleDeptId',
																'ipt',
																'type'
															)
														"
														style="font-size: 12px"
														v-model="
															baseInfoForm.saleDeptId
														"
														:disabled="
															isEdit ||
															isPushDownOrg
														"
														placeholder="请选择部门"
														:options="
															statusForm.saleDept
														"
														:props="optionProps"
														:show-all-levels="false"
														clearable
													></el-cascader>
												</el-form-item>
												<el-form-item
													label="是否211"
													class="item-bt-s"
												>
													<el-select
														v-model="
															baseInfoForm.is211
														"
														placeholder=" "
														:disabled="true"
													>
														<el-option
															style="
																font-size: 12px;
															"
															@click="
																purchaseCom(
																	baseInfoForm.is211,
																	'is211'
																)
															"
															v-for="item in is211s"
															:key="item.id"
															:label="item.name"
															:value="item.id"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													label="供应链"
													class="item-bt-s"
												>
													<el-select
														v-model="
															baseInfoForm.supplyChain
														"
														placeholder=" "
														:disabled="true"
													>
														<el-option
															style="
																font-size: 12px;
															"
															@click="
																purchaseCom(
																	baseInfoForm.supplyChain,
																	'supplyChain'
																)
															"
															v-for="(
																value,
																key,
																index
															) in statusForm.supplyChains"
															:key="index"
															:label="value"
															:value="key"
														></el-option>
													</el-select>
												</el-form-item>
												<el-form-item
													label="备注"
													class="item-bt-s address-textarea"
												>
													<el-input
														v-model="
															baseInfoForm.description
														"
														placeholder=" "
														:disabled="isEdit"
														@input="
															purchaseCom(
																baseInfoForm.description,
																'description'
															)
														"
														type="textarea"
														maxlength="50"
														resize="none"
														:autosize="{
															minRows: 3,
															maxRows: 3,
														}"
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="12"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
				<el-tab-pane label="操作记录">
					<div class="base-info-form-box">
						<el-form :model="baseInfoForm" label-width="80px">
							<el-row :gutter="10">
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											label="创建人"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.creatorName
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
										<el-form-item
											label="创建时间"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.createDate
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col col-2">
										<el-form-item
											label="最后修改人"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.modifierName
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
										<el-form-item
											label="最后修改时间"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.modifyDate
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
										<el-form-item
											label="提交时间"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.submitDate
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-row :gutter="0">
											<el-col :span="24">
												<el-form-item
													label="审核人"
													class="item-bt-s"
													:maxlength="50"
												>
													<el-input
														v-model.trim="
															baseInfoForm.approverName
														"
														:disabled="true"
														maxlength="50"
													></el-input>
												</el-form-item>
												<el-form-item
													label="审核时间"
													class="item-bt-s"
												>
													<el-input
														v-model.trim="
															baseInfoForm.approveDate
														"
														:disabled="true"
														placeholder
													></el-input>
												</el-form-item>
											</el-col>
										</el-row>
									</div>
								</el-col>
								<el-col :span="4">
									<div class="div-col">
										<el-form-item
											label="关闭人"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.closerName
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
										<el-form-item
											label="关闭时间"
											class="item-bt-s"
										>
											<el-input
												v-model.trim="
													baseInfoForm.closeDate
												"
												:disabled="true"
												placeholder
											></el-input>
										</el-form-item>
									</div>
								</el-col>
								<el-col :span="4"></el-col>
							</el-row>
						</el-form>
					</div>
				</el-tab-pane>
			</el-tabs>
		</div>
		<!-- 选择 下推单据 -->
		<el-dialog
			title="选择下推单据"
			v-model="dialogxt"
			width="20%"
			top="15%"
		>
			<el-radio-group v-model="pushdownVal">
				<el-radio
					v-for="item in pushDownList"
					:key="item.id"
					:value="item.id"
					:label="item.id"
					>{{ item.value }}</el-radio
				>
			</el-radio-group>
			<template #footer>
				<span class="dialog-footer">
					<el-button size="small" @click="dialogxt = false"
						>取 消</el-button
					>
					<el-button
						type="primary"
						size="small"
						@click="sumitPushdown(pushdownVal)"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
		<!-- 选择 上下查单据 -->
		<el-dialog :title="CXttile" v-model="dialogCX" width="20%" top="15%">
			<div class="sale-page-table-body">
				<el-radio-group
					v-model="CXcheckVal"
					v-if="CXttile === '上查结果'"
				>
					<el-radio
						:label="it.orderType"
						v-for="(it, index) in upOrDownList"
						:key="index"
						>{{ it.orderName }}({{ it.orderCount }})</el-radio
					>
				</el-radio-group>
				<el-radio-group
					v-model="CXcheckVal"
					v-if="CXttile === '下查结果'"
				>
					<el-radio
						:label="it.orderType"
						v-for="(it, index) in upOrDownList"
						:key="index"
						>{{ it.orderName }}({{ it.orderCount }})</el-radio
					>
				</el-radio-group>
			</div>
			<template #footer>
				<span class="dialog-footer">
					<el-button size="small" @click="dialogCX = false"
						>取 消</el-button
					>
					<el-button type="primary" size="small" @click="submitCX"
						>确 定</el-button
					>
				</span>
			</template>
		</el-dialog>
	</div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import { unitPriceMethods } from '@/utils/util';
import examineTop from '@/components/examineTop/index.vue';

import {
	orderCopy,
	ndCopyClearData,
	watchCustomerChange,
	ndSaveSubBackData,
	getNowTimeGlobal,
	changeDownOrgClearData,
	ndIptDownOrgChangeClearData,
	ndSearchOrder,
	ndSurePushDown,
	ndSearchMaterSku,
} from '@/utils/takeMethods';
import { countMethodsUnitNumber } from '@/utils/count.js';
import { ElMessageBox, ElMessage } from 'element-plus';
import {
	getStatusType,
	removeChildren,
	splitJointList,
} from '@/utils/pubulic.js';
import { getStaffListApiUser } from '@/utils/api.js';
import {
	needsBtnAdd,
	needsBtnEdit,
	ndDefaultTableInfo,
	ndCustomSearch,
	is211s,
	optionProps,
	ndPushDownList,
} from '@/utils/variable.js';
export default {
	inject: ['reload'],
	name: 'CreateOrgNeeds',
	components: {
		examineTop,
	},
	data() {
		return {
			materialSearch: false,
			salePrecisionNumber: 10,
			isPrecision: false,
			unitData: [],
			isCount: '',
			isDisable: false,
			isOrder: true,
			isEdit: true, // 状态为:创建、重新审核可编辑，其它类型不可编辑
			statusForm: JSON.parse(JSON.stringify(ndCustomSearch)),
			optionProps: JSON.parse(JSON.stringify(optionProps)),
			baseInfoForm: JSON.parse(JSON.stringify(ndDefaultTableInfo)),
			btnType: JSON.parse(JSON.stringify(needsBtnAdd)),
			heightNum: 0, // 容器的高度                            // 输入数字
			is211s: JSON.parse(JSON.stringify(is211s)),
			isOutCusHouse: true,
			saveIds: '',
			isPushDown: false,
			isPushDownOrg: false,
			dialogVisible: false, // 操作弹框显示
			tableInfo: [], // 操作结果
			actionType: '', // 操作类型
			pushdownVal: null, // 下推选择
			dialogxt: false, // 选择下推单据弹框显示
			OrdedetailIds: [], // 勾选的明细id集合
			dialogCX: false, // 上下查弹框控制
			upOrDownList: [], // 上查下查弹窗可选数据
			OrderNoNameslist: [], // 上查下查的订单号
			OrderNoNameStr: '', // 上查下查的订单号
			CXaction: '', // 判断是上查还是下查
			CXttile: '', // 查询弹框的名称
			CXcheckVal: '', // 选择的查询radio
			OrderNoNames: [], // 选择的单据订单号集合
			pushDownList: JSON.parse(JSON.stringify(ndPushDownList)),
		};
	},
	computed: {
		...mapState({
			orgId: (state) => state.user.orgId,
			orgIdArr: (state) => state.user.orgIdArr,
			unitAll: (state) => state.storeData.allUnit,
			customer: (state) => state.storeData.customer,
			listGetStatus: (state) => state.storeData.listGetStatus,
			getAllUserList: (state) => state.storeData.getAllUserList,
		}),
	},
	methods: {
		...mapActions({
			setAllUnit: 'storeData/setAllUnit',
			setCustomer: 'storeData/setCustomer',
			setListGetStatus: 'storeData/setListGetStatus',
			setGetAllUserList: 'storeData/setGetAllUserList',
		}),
		Init() {
			// 初始化
			let vuexKey = ['unitAll', 'customer'];
			let setVuexData = ['setAllUnit', 'setCustomer'];
			let requestQueryUrl = [
				'SysConfig/GetUnitAllProperty',
				'SysConfig/GetCustomer',
			];
			let resDataQuery = ['units', 'custList'];

			vuexKey.forEach((ele, ind) => {
				if (this[vuexKey[ind]] && this[vuexKey[ind]].length > 0) {
					if (typeof resDataQuery[ind] == 'string') {
						this.statusForm[resDataQuery[ind]] = JSON.parse(
							JSON.stringify(this[vuexKey[ind]])
						);
					} else {
						resDataQuery[ind].forEach((ele, index) => {
							this.statusForm[resDataQuery[ind][index]] =
								JSON.parse(JSON.stringify(this[vuexKey[ind]]));
						});
					}
					if (vuexKey[ind] == 'unitAll') {
						this.unitData = this.statusForm[resDataQuery[ind]];
					}
				} else {
					this.$http.get(requestQueryUrl[ind]).then((r) => {
						if (r.status === 200) {
							if (typeof resDataQuery[ind] == 'string') {
								this.statusForm[resDataQuery[ind]] = r.data;
							} else {
								resDataQuery[ind].forEach((ele, index) => {
									this.statusForm[resDataQuery[ind][index]] =
										r.data;
								});
							}
							this[setVuexData[ind]](
								this.statusForm[resDataQuery[ind]]
							);
							// 单位
							if (vuexKey[ind] == 'unitAll') {
								this.unitData =
									this.statusForm[resDataQuery[ind]];
							}
						}
					});
				}
			});
			if (
				this.listGetStatus &&
				JSON.stringify(this.listGetStatus) !== '{}'
			) {
				this.statusForm.bills = JSON.parse(
					JSON.stringify(this.listGetStatus.documentStatus)
				);
				this.statusForm.cloStatus = JSON.parse(
					JSON.stringify(this.listGetStatus.closeStatus)
				);
				this.statusForm.supplyChains = JSON.parse(
					JSON.stringify(this.listGetStatus.supplyChainType)
				);
				this.statusForm.createTypes = JSON.parse(
					JSON.stringify(this.listGetStatus.dataSourceType)
				);
			} else {
				this.$http.get('SysConfig/GetStatus').then((req) => {
					if (req.status == 200) {
						this.setListGetStatus(req.data);
						this.statusForm.bills = req.data.documentStatus; // 单据状态
						this.statusForm.cloStatus = req.data.closeStatus; // 关闭状态
						this.statusForm.supplyChains = req.data.supplyChainType; // 供应链
						this.statusForm.createTypes = req.data.dataSourceType; // 数据来源
					}
				});
			}

			// 获取人员接口
			if (this.getAllUserList && this.getAllUserList.length > 0) {
				this.statusForm.qcPerson = this.getAllUserList;
				this.statusForm.salePerson = this.getAllUserList;
			} else {
				getStaffListApiUser().then((r) => {
					r.status == 200 ? this.setGetAllUserList(r.data) : false;
					r.status == 200
						? (this.statusForm.qcPerson = r.data)
						: (this.statusForm.qcPerson = []);
					r.status == 200
						? (this.statusForm.salePerson = r.data)
						: (this.statusForm.salePerson = []);
				});
			}

			this.baseInfoForm.documentStatus = '';
			var windowHeight = document.documentElement.clientHeight;
			this.heightNum = windowHeight - 102;
			this.baseInfoForm.orderDate = this.getNowTime();
			this.statusForm.demandOrgs = this.orgIdArr; // 下单组织
			this.statusForm.receptOrgs = this.orgIdArr; // 接单组织
			// 手工录入 或 系统生成
			if (
				this.$route.query.type === 'add' ||
				this.$route.query.type === 'copy' ||
				this.$route.query.type === 'pushDown'
			) {
				this.baseInfoForm.createType = '1';
				this.isPushDown = false;
			} else {
				this.baseInfoForm.createType = '2';
				this.isPushDown = true;
			}
			if (
				this.$route.query.type === 'add' ||
				this.$route.query.type === 'copy'
			) {
				this.isEdit = false;
				this.baseInfoForm.documentStatus = 'a';
				this.baseInfoForm.isClosed = 'a';
				this.baseInfoForm.billNo = '';
				this.baseInfoForm.demandOrgId = this.$store.state.org.orgId;
				if (this.$route.query.type === 'copy') {
					this.getPurChaseDetails();
				}
			}
			if (
				this.$route.query.type == 'pushDown' &&
				this.$route.query.pushDownData
			) {
				// 下推进入
				this.isEdit = false;
				this.getPurChaseDetails(
					JSON.parse(
						decodeURIComponent(this.$route.query.pushDownData)
					)
				);
			}
			if (this.$route.query.type == 'details' && this.$route.query.id) {
				// 通过点击详情进入
				this.getPurChaseDetails();
			}
		},
		saleRexgu(val, key) {
			if (key === 'billNo') {
				if (val) {
					this.baseInfoForm.billNo = val
						.toString()
						.replace(/[^A-Za-z0-9\\-]/g, '');
				}
			}
			if (key === 'saleOrderNo') {
				if (val) {
					this.baseInfoForm.saleOrderNo = val
						.toString()
						.replace(/[^A-Za-z0-9\\-]/g, '');
				}
			}
		},
		async matterSkuCom(id, val, key, isInner) {
			if (key === 'materialId') {
				this.statusForm.matterCodelist.forEach((el) => {
					if (id === el.id) {
						this.baseInfoForm = ndSearchMaterSku(
							this.baseInfoForm,
							el
						);
					}
				});
			}
			if (key === 'skuId') {
				this.statusForm.specificationsList.forEach((el) => {
					if (id === el.id) {
						this.baseInfoForm = ndSearchMaterSku(
							this.baseInfoForm,
							el
						);
					}
				});
			}
			if (this.baseInfoForm.unitId && !isInner) {
				let tempList = this.unitData.filter(
					(it) => it.id === this.baseInfoForm.unitId
				);
				tempList[0].precision == 0
					? (this.isPrecision = true)
					: (this.isPrecision = false);
				tempList[0].precision == 0
					? (this.salePrecisionNumber = 0)
					: (this.salePrecisionNumber = tempList[0].precision);
			}
		},
		// 下推确定
		sumitPushdown(id) {
			this.CXcheckVal = id;
			if (id) {
				let result = ndSurePushDown(this.CXcheckVal);
				let pathName = result.pathName;
				let routerName = result.routerName;
				if (this.CXcheckVal === 4) {
					if (this.OrdedetailIds.length === 1) {
						this.$http
							.post(pathName + this.OrdedetailIds)
							.then((res) => {
								if (res.status === 200) {
									this.dialogxt = false;
									this.$router.push({
										name: routerName,
										query: {
											type: 'pushDown',
											pushDownData: JSON.stringify(
												res.data
											),
											sjtag: Math.random() * 36,
										},
									});
								} else {
									this.dialogxt = false;
								}
							});
					} else {
						this.$message.error({
							message: '组织间需求单不允许多条合并下推!',
							showClose: true,
						});
					}
				} else {
					this.$http
						.post(pathName, { ids: this.OrdedetailIds })
						.then((res) => {
							if (res.status === 200) {
								this.dialogxt = false;
								this.$router.push({
									name: routerName,
									query: {
										type: 'pushDown',
										pushDownData: JSON.stringify(res.data),
										typeId: 1,
										sjtag: Math.random() * 36,
									},
								});
							} else {
								this.dialogxt = false;
							}
						});
				}
			} else {
				this.$message.error({
					message: '请先选中在确认',
					showClose: true,
				});
			}
		},
		// 确定上下查
		submitCX() {
			if (this.CXcheckVal) {
				let pathName = ndSearchOrder(this.CXcheckVal);
				let ary = [];
				ary = this.upOrDownList.filter((it) => {
					return it.orderType === this.CXcheckVal;
				});
				if (pathName) {
					this.dialogCX = false;
					this.$router.push({
						name: pathName,
						query: {
							detailsIds: JSON.stringify(
								ary.length > 0 ? ary[0].detailsIds : []
							),
							actionType:
								this.CXttile === '上查结果' ? 'up' : 'down',
							actionName: '组织间需求单',
							OrderNoNames: JSON.stringify(ary[0].billNos),
						},
					});
					this.dialogCX = false;
				}
			} else {
				this.$message.error({
					message: '请先选择在确认',
					showClose: true,
				});
			}
		},
		// 输入框公共方法
		purchaseCom(value, key, ipt, type, disable, isOpen) {
			if (!disable) {
				if (type) {
					this.$refs.cascader.togglePopperVisible(); // 选择之后将下拉框界面收起
				}
				this.baseInfoForm[key] = value;
				if (key === 'demandOrgId') {
					this.$http
						.showLoading(false)
						.post(
							'SysConfig/GetDept/' + this.baseInfoForm.demandOrgId
						)
						.then((r) => {
							if (r.status == 200) {
								this.statusForm.saleDept = removeChildren(
									r.data
								);
							}
						});
					this.baseInfoForm.stockId = '';
					this.statusForm.stocks = [];
					this.$http
						.showLoading(false)
						.get(
							'SysConfig/GetWarehouse/' +
								this.baseInfoForm.demandOrgId
						)
						.then((r) => {
							if (r.status == 200) {
								this.statusForm.stocks = r.data;
							}
						});

					let result = ndIptDownOrgChangeClearData(
						this.baseInfoForm,
						this.statusForm
					);
					this.baseInfoForm = result.baseInfoForm;
					this.statusForm = result.statusForm;

					this.$http
						.showLoading(false)
						.get('SysConfig/GetCustomer')
						.then((r) => {
							if (r.status === 200) {
								this.statusForm.custList = r.data;
							}
						});
				}
				if (key === 'stockId') {
					let rowObject = this.statusForm.stocks.filter(
						(it) => it.id === value
					);
					this.isOutCusHouse =
						rowObject.length > 0
							? !rowObject[0].customerWarehouseTag
							: true;
				}
				if (key === 'demandOrgId') {
					if (
						this.baseInfoForm.receptOrgId ===
						this.baseInfoForm.demandOrgId
					) {
						this.baseInfoForm.demandOrgId = null;
						this.$message.error({
							message: '下单组织不能与接单组织相同！',
							showClose: true,
						});
					}
				}
				if (key === 'receptOrgId') {
					if (
						this.baseInfoForm.receptOrgId ===
						this.baseInfoForm.demandOrgId
					) {
						this.baseInfoForm.receptOrgId = null;
						this.$message.error({
							message: '接单组织不能与下单组织相同！',
							showClose: true,
						});
					}
				}
				if (key === 'orderQty') {
					if (this.baseInfoForm.parentOrderId) {
						if (
							this.baseInfoForm.maxNumber ||
							this.baseInfoForm.maxNumber == 0
						) {
							if (
								Number(this.baseInfoForm.orderQty) >
								Number(this.baseInfoForm.maxNumber)
							) {
								this.baseInfoForm.orderQty =
									this.baseInfoForm.maxNumber;
							}
						}
					}
					if (this.baseInfoForm.unitId) {
						let tempList = this.unitData.filter(
							(it) => it.id === this.baseInfoForm.unitId
						);
						tempList[0].precision == 0
							? (this.isPrecision = true)
							: (this.isPrecision = false);
						tempList[0].precision == 0
							? (this.salePrecisionNumber = 0)
							: (this.salePrecisionNumber =
									tempList[0].precision);
					}
					if (!this.isCount) {
						this.isCount = 1;
					}
					if (value.indexOf('.') !== -1) {
						this.isCountComMethods('orderQty');
					} else {
						this.isCount = 2;
					}
				}
				if (key === 'hopeFinishDate') {
					let comparD = this.compareDate(
						this.baseInfoForm.orderDate,
						value
					);
					if (comparD == false) {
						this.$message.error({
							message: '期望交期不能小于下单日期,请重新选择',
							showClose: true,
						});
						this.baseInfoForm.hopeFinishDate = '';
					}
				}
			}
		},
		// 删除公共
		clearCom() {
			this.$http.get('SysConfig/GetCustomer').then((r) => {
				if (r.status === 200) {
					this.statusForm.custList = r.data;
				}
			});
			let result = changeDownOrgClearData(
				this.baseInfoForm,
				this.statusForm
			);
			this.baseInfoForm = result.baseInfoForm;
			this.statusForm = result.statusForm;
			this.statusForm.custList = [];
		},
		// 获取当前时间
		getNowTime() {
			return getNowTimeGlobal();
		},
		// 顶部公共按钮操作
		actionhandel(type) {
			let ids = [];
			let detailsIds = [];
			this.isDisable = true;
			setTimeout(() => {
				this.isDisable = false;
			}, 2000);
			if (this.$route.query.id) {
				ids = [this.$route.query.id];
			}
			if (this.saveIds != '') {
				ids = [this.saveIds];
			}
			if (this.baseInfoForm.id && this.baseInfoForm.id != 0) {
				detailsIds = [this.baseInfoForm.id];
				this.OrdedetailIds = [];
				this.OrdedetailIds = detailsIds;
			}
			if (type === 'add' || type === 'copy') {
				// 点击新增
				this.$router.push({
					path: '/purchase/demand/createOrgNeeds',
					query: { type: 'add', id: '', sjtag: Math.random() * 36 },
				});
			}
			if (type === 'save' || type === 'submit') {
				// 点击提交
				this.saveSubmitCom(type);
			}
			if (type === 'revoke') {
				// 撤销
				this.revokePageData(ids);
			}
			if (type === 'audit') {
				// 审核
				this.auditPageData(ids);
			}
			if (type === 'de-approval') {
				// 反审核
				this.deApprovalPageDate(ids);
			}
			if (type === 'delet') {
				// 删除
				this.deleteOrder(ids);
			}
			if (type === 'close') {
				// 点击关闭
				this.close(ids);
			}
			if (type === 'de-close') {
				// 点击反关闭
				this.reClose(ids);
			}
			if (type === 'push-down') {
				// 点击下推
				if (this.baseInfoForm.documentStatus !== 'c') {
					this.$message.error({
						message:
							'单据状态错误，只能选择单据状态为已审核单据，请重新选择！',
						showClose: true,
					});
				} else {
					this.dialogxt = true;
				}
			}
			if (type === 'up-check' || type === 'down-check') {
				let pathName =
					type === 'up-check'
						? 'Organization/upper'
						: 'Organization/lower';
				this.$http.post(pathName, { ids: detailsIds }).then((res) => {
					if (res.status === 200) {
						if (res.data.length === 0 || res.data === []) {
							this.$message.warning({
								message:
									type === 'up-check'
										? '没有可上查的单据!'
										: '没有可下查的单据!',
								showClose: true,
							});
						} else {
							this.upOrDownList = res.data;
							this.dialogCX =
								res.data && res.data.length > 0 ? true : false;
							this.CXttile =
								type === 'up-check' ? '上查结果' : '下查结果';
							this.CXcheckVal =
								res.data && res.data.length === 1
									? res.data[0].orderType
									: null; //只有一个，就个默认值
						}
					}
				});
			}
		},
		// 点击删除 -- 关闭当前页签 -- 返回列表
		deleteOrder(ids) {
			if (
				this.baseInfoForm.documentStatus === 'b' ||
				this.baseInfoForm.documentStatus === 'c'
			) {
				this.$message.warning({
					message: '不能删除已审核或审核中的单据!',
					showClose: true,
				});
			} else {
				if (!isNaN(ids[0])) {
					this.$http
						.post('Organization/delete', { ids: ids })
						.then((res) => {
							if (res.status === 200) {
								if (r.data[0].isSuccess == false) {
									this.$message.error({
										message: r.data[0].msg,
										showClose: true,
									});
								} else {
									this.$store.state.topNavTag.tags.splice(
										this.$store.state.topNavTag.tags.findIndex(
											(item) =>
												item.path === this.$route.path
										),
										1
									);
									this.$router.push(
										this.$store.state.topNavTag.tags[
											this.$store.state.topNavTag.tags
												.length - 1
										].path
									);
								}
							}
						});
				} else {
					this.$message.warning({
						message: '不能删除此单据!',
						showClose: true,
					});
				}
			}
		},
		reClose(ids) {
			if (this.baseInfoForm.documentStatus == 'c') {
				ElMessageBox.confirm('你确认要反关闭此单据', '操作确认', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					type: 'Success',
				})
					.then(() => {
						this.$http
							.post('Organization/reclose', { ids: ids })
							.then((r) => {
								if (r.status == 200) {
									if (r.data[0].isSuccess == true) {
										ElMessage({
											type: 'success',
											message: '反关闭成功',
											showClose: true,
										});
										this.baseInfoForm.isClosed = 'a';
									} else {
										ElMessage({
											type: 'error',
											message: r.data[0].msg,
											showClose: true,
										});
									}
								}
							});
					})
					.catch(() => {
						ElMessage({
							type: 'info',
							message: '取消反关闭',
							showClose: true,
						});
					});
			} else {
				this.$message.error({
					message: '只能反关闭已审核的单据',
					showClose: true,
				});
			}
		},
		close(ids) {
			if (this.baseInfoForm.documentStatus == 'c') {
				ElMessageBox.confirm('你确认要关闭此单据', '操作确认', {
					confirmButtonText: '确认',
					cancelButtonText: '取消',
					type: 'Success',
				})
					.then(() => {
						this.$http
							.post('Organization/close', { ids: ids })
							.then((r) => {
								if (r.status == 200) {
									if (r.data[0].isSuccess === true) {
										ElMessage({
											type: 'success',
											message: '关闭成功',
											showClose: true,
										});
										this.baseInfoForm.isClosed = 'b';
										this.$http
											.get(
												'Organization/get/' +
													this.baseInfoForm.id
											)
											.then((req) => {
												if (req.status == 200) {
													this.baseInfoForm =
														ndSaveSubBackData(
															this.baseInfoForm,
															req
														);
												}
											});
									} else {
										ElMessage({
											type: 'error',
											message: r.data[0].msg,
											showClose: true,
										});
									}
								}
							});
					})
					.catch(() => {
						ElMessage({
							type: 'info',
							message: '取消关闭',
							showClose: true,
						});
					});
			} else {
				this.$message.error({
					message: '只能关闭已审核的单据',
					showClose: true,
				});
			}
		},
		// 反审核
		deApprovalPageDate(ids) {
			if (this.baseInfoForm.documentStatus == 'c') {
				this.$http
					.post('Organization/recheck', { ids: ids })
					.then((r) => {
						if (r.status == 200) {
							r.data.forEach((element) => {
								if (element.isSuccess === false) {
									this.$message.error({
										message: element.msg,
										showClose: true,
									});
								} else {
									this.$message.success({
										message: '反审成功!',
										showClose: true,
									});
									this.baseInfoForm.documentStatus = 'd';
									this.isEdit = false;
									this.$http
										.get(
											'Organization/get/' +
												this.baseInfoForm.id
										)
										.then((req) => {
											if (req.status == 200) {
												this.baseInfoForm =
													ndSaveSubBackData(
														this.baseInfoForm,
														req
													);
											}
										});
								}
							});
						}
					});
			} else {
				this.$message.error({
					message: '只能反审核处于已审核的单据!',
					showClose: true,
				});
			}
		},
		// 审核
		auditPageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http
					.post('Organization/check', { ids: ids })
					.then((r) => {
						if (r.status == 200) {
							if (r.data[0].isSuccess) {
								this.$message.success({
									message: '审核成功!',
									showClose: true,
								});
								this.baseInfoForm.documentStatus = 'c';
								this.isEdit = true;
								this.$http
									.get(
										'Organization/get/' +
											this.baseInfoForm.id
									)
									.then((req) => {
										if (req.status == 200) {
											this.baseInfoForm =
												ndSaveSubBackData(
													this.baseInfoForm,
													req
												);
										}
									});
							} else {
								this.$message.error({
									message: r.data[0].msg,
									showClose: true,
								});
							}
						}
					});
			} else {
				this.$message.error({
					message: '只能审核处于审核中的单据!',
					showClose: true,
				});
			}
		},
		// 撤消
		revokePageData(ids) {
			if (this.baseInfoForm.documentStatus == 'b') {
				this.$http
					.post('Organization/revoke', { ids: ids })
					.then((r) => {
						if (r.status == 200) {
							this.$message.success({
								message: '撤消成功!',
								showClose: true,
							});
							this.baseInfoForm.documentStatus = 'a';
							this.isEdit = false;
							if (this.baseInfoForm.parentOrderId) {
								this.isPushDownOrg = true;
							}
						}
					});
			} else {
				this.$message.error({
					message: '只能撤销审核中的单据!',
					showClose: true,
				});
			}
		},
		// 处理保存、提交返回数据
		saveOrSubmitData(r) {
			if (r) {
				this.$http.get('Organization/get/' + r.data.id).then((req) => {
					if (req.status == 200) {
						this.baseInfoForm = ndSaveSubBackData(
							this.baseInfoForm,
							req,
							'inner'
						);
					}
				});
				this.baseInfoForm.billNo = r.data.billNo;
				this.baseInfoForm.id = r.data.id;
				this.saveIds = r.data.id;
			}
		},
		// 保存提交共公方法
		saveSubmitCom(type) {
			if (
				this.baseInfoForm.documentStatus == 'a' ||
				this.baseInfoForm.documentStatus == 'd'
			) {
				let pathName =
					type === 'save'
						? 'Organization/save'
						: 'Organization/submit';
				this.$http.post(pathName, this.baseInfoForm).then((req) => {
					if (req.status === 200) {
						this.saveOrSubmitData(req);
						this.$message.success({
							message:
								type === 'save' ? '保存成功!' : '提交成功!',
							showClose: true,
						});
						type === 'submit'
							? (this.baseInfoForm.documentStatus = 'b')
							: false;
						type === 'submit'
							? (this.isEdit = true)
							: (this.isEdit = false);
					}
				});
			} else {
				this.$message.error({
					message: '只能保存或提交创建或重新审核的单据!',
					showClose: true,
				});
			}
		},
		async getPurChaseDetails(res) {
			if (res) {
				this.isPushDownOrg = res.isPushDown;
				this.isEdit = false;
				for (const key in res) {
					if (
						res[key] !== null &&
						res[key] !== undefined &&
						key !== 'supplyChain'
					) {
						for (const baseKey in this.baseInfoForm) {
							if (key === baseKey) {
								this.baseInfoForm[baseKey] = res[key];
							}
						}
					}
				}
				this.baseInfoForm.maxNumber = res.maxNumber;
				this.baseInfoForm.customerStockList = res.customerStockList;
				this.baseInfoForm.stockList = res.stockList;
				this.baseInfoForm.isPushDown = res.isPushDown;
				await this.matterCodeChange(this.baseInfoForm.materialNumber);
				await this.matterSkuCom(
					this.baseInfoForm.materialId,
					this.baseInfoForm.materialNumber,
					'materialId'
				);
				this.baseInfoForm.skuId = this.baseInfoForm.materialId;
				this.baseInfoForm.documentStatus = 'a';
				if (this.baseInfoForm.isClosed == 0) {
					this.baseInfoForm.isClosed = 'a';
				} else if (this.baseInfoForm.isClosed == 1) {
					this.baseInfoForm.isClosed = 'b';
				}
				this.baseInfoForm.supplyChain = 0 + '';
				if (
					this.baseInfoForm.stockId === 0 ||
					this.baseInfoForm.stockId === null ||
					this.baseInfoForm.stockId === undefined
				) {
					this.baseInfoForm.stockId = '';
				}
				this.baseInfoForm.customerId = Number(
					this.baseInfoForm.customerId
				);
				this.baseInfoForm.customerId =
					this.baseInfoForm.customerId == 0
						? null
						: this.baseInfoForm.customerId;
				let rowObject = this.statusForm.stocks.filter(
					(it) => it.id === this.baseInfoForm.stockId
				);
				this.isOutCusHouse =
					rowObject.length > 0
						? !rowObject[0].customerWarehouseTag
						: true;
				if (
					this.baseInfoForm.parentOrderId &&
					Number(this.baseInfoForm.orderQty) >
						Number(this.baseInfoForm.maxNumber)
				) {
					this.baseInfoForm.orderQty = this.baseInfoForm.maxNumber;
				}
				this.isCount = 1;
				this.isCountComMethods('orderQty');
				this.isCountComMethods('maxNumber');
				this.isCount = 2;
			} else {
				this.$http
					.get('Organization/get/' + this.$route.query.id)
					.then(async (req) => {
						if (req.status == 200) {
							this.isPushDownOrg = req.data.isPushDown;
							Object.assign(this.baseInfoForm, req.data);
							this.baseInfoForm.documentStatus =
								this.baseInfoForm.documentStatus + '';
							this.baseInfoForm.createType =
								this.baseInfoForm.createType + '';
							await this.matterCodeChange(
								this.baseInfoForm.materialNumber
							);
							await this.matterSkuCom(
								this.baseInfoForm.materialId,
								this.baseInfoForm.materialNumber,
								'materialId',
								true
							);
							this.baseInfoForm.skuId =
								this.baseInfoForm.materialId;
							this.baseInfoForm.maxNumber = req.data.maxNumber;
							this.baseInfoForm.isPushDown = req.isPushDown;
							if (this.baseInfoForm.isClosed == 0) {
								this.baseInfoForm.isClosed = 'a';
							} else if (this.baseInfoForm.isClosed == 1) {
								this.baseInfoForm.isClosed = 'b';
							}
							if (
								this.baseInfoForm.documentStatus === 'a' ||
								this.baseInfoForm.documentStatus === 'd'
							) {
								this.isEdit = false;
							} else {
								this.isEdit = true;
							}
							if (this.baseInfoForm.billNo) {
								this.isOrder = false;
							}
							let rowObject = this.statusForm.stocks.filter(
								(it) => it.id === this.baseInfoForm.stockId
							);
							if (rowObject.length > 0) {
								this.isOutCusHouse =
									rowObject.length > 0
										? !rowObject[0].customerWarehouseTag
										: true;
							}
							if (this.baseInfoForm.parentOrderType === 10) {
								this.isPushDownOrg = true;
							}
							if (this.$route.query.type === 'copy') {
								this.isCountComMethods('orderQty');
								this.isEdit = false;
								this.isPushDownOrg = false;
								this.baseInfoForm = ndCopyClearData(
									this.baseInfoForm
								);
							}
							if (
								!this.baseInfoForm.stockId ||
								this.baseInfoForm.stockId === 0
							) {
								this.baseInfoForm.stockId = '';
							}
							if (
								this.baseInfoForm.parentOrderId &&
								Number(this.baseInfoForm.orderQty) >
									Number(this.baseInfoForm.maxNumber)
							) {
								this.baseInfoForm.orderQty =
									this.baseInfoForm.maxNumber;
							}
						}
					});
			}
		},
		// 订单号 复制按钮
		saleOrderCopy() {
			orderCopy();
		},
		// 统一数量精度处理
		isCountComMethods(key) {
			let tempList = this.unitData.filter(
				(it) => it.id === this.baseInfoForm.unitId
			);
			tempList[0].precision == 0
				? (this.isPrecision = true)
				: (this.isPrecision = false);
			tempList[0].precision == 0
				? (this.salePrecisionNumber = 0)
				: (this.salePrecisionNumber = tempList[0].precision);
			let result = countMethodsUnitNumber(
				tempList,
				this.baseInfoForm[key],
				this.baseInfoForm[key],
				this.isCount,
				this.salePrecisionNumber,
				true
			);
			this.baseInfoForm[key] = result.value;
			this.isCount = result.isDefault;
		},
		// 匹配物料sku的方法
		async backMaterSkuMethods(val, key, id) {
			return this.$http
				.showLoading(false)
				.post('SysConfig/GetMaterial', {
					name: val,
					file: key,
					orgId: id,
				})
				.then((res) => {
					if (res.status === 200) {
						this.rowArr = res.data;
						return res.data;
					} else {
						return [];
					}
				});
		},
		// 获取物料编码信息
		async matterCodeChange(val) {
			if (val && this.baseInfoForm.demandOrgId) {
				this.statusForm.matterCodelist = await this.backMaterSkuMethods(
					val,
					'Number',
					this.baseInfoForm.demandOrgId
				);
				this.statusForm.specificationsList =
					this.statusForm.matterCodelist;
			} else {
				this.statusForm.matterCodelist = [];
			}
		},
		// 获取型号SKU信息
		async skuCodeChange(val) {
			if (val && this.baseInfoForm.demandOrgId) {
				this.statusForm.specificationsList =
					await this.backMaterSkuMethods(
						val,
						'Specifications',
						this.baseInfoForm.demandOrgId
					);
				this.statusForm.matterCodelist =
					this.statusForm.specificationsList;
			} else {
				this.statusForm.specificationsList = [];
			}
		},
		// 日期大小对比
		compareDate(logintime, logouttime) {
			var arys1 = new Array();
			var arys2 = new Array();
			if (logintime != null && logouttime != null) {
				arys1 = logintime.split('-');
				var logindate = new Date(
					arys1[0],
					parseInt(arys1[1] - 1),
					arys1[2]
				);
				arys2 = logouttime.split('-');
				var logoutdate = new Date(
					arys2[0],
					parseInt(arys2[1] - 1),
					arys2[2]
				);
				if (logindate > logoutdate) {
					return false;
				} else {
					return true;
				}
			}
		},
		// 去0
		returnRemove0(val, key) {
			if (val) {
				let value = unitPriceMethods(val);
				this.baseInfoForm[key] = value;
			}
		},
		selectChange() {
			this.baseInfoForm.customerStockId = '';
			this.baseInfoForm.customerId = '';
		},
		customerChange(val, key) {
			this.baseInfoForm.customerStockId = '';
		},
		//  输入整数
		saleNum(val, key, isPrecision) {
			isPrecision = isPrecision ? isPrecision : false;
			this.salePrecisionNumber = this.salePrecisionNumber
				? this.salePrecisionNumber
				: 10;
			if (!this.baseInfoForm.materialId && !this.$route.query.id) {
				isPrecision = true;
			}
			if (val) {
				if (isPrecision) {
					if (val.toString().indexOf('.') !== -1) {
						this.baseInfoForm[key] = Number(val).toFixed(0);
					}
					this.baseInfoForm[key] = this.baseInfoForm[key]
						.toString()
						.replace(/\D/g, '');
				} else {
					let numD = '';
					let count = '\\d';
					for (let ind = 0; ind < this.salePrecisionNumber; ind++) {
						numD = numD + count;
					}
					let reg = '/^(-)*(\\d+)\\.(' + numD + ').*$/';
					this.baseInfoForm[key] = this.baseInfoForm[key]
						.toString()
						.replace(/[^\d^\\.]+/g, '')
						.replace('.', '$#$')
						.replace(/\./g, '')
						.replace('$#$', '.')
						.replace(eval(reg), '$1$2.$3');
				}
			}
		},
	},
	created: function () {
		this.Init();
	},
	watch: {
		'baseInfoForm.demandOrgId': function () {
			if (this.baseInfoForm.demandOrgId) {
				this.$http
					.post('SysConfig/GetDept/' + this.baseInfoForm.demandOrgId)
					.then((r) => {
						if (r.status == 200) {
							this.statusForm.saleDept = removeChildren(r.data);
						}
					});
				this.statusForm.stocks = [];
				this.$http
					.get(
						'SysConfig/GetWarehouseByOrg/' +
							this.baseInfoForm.demandOrgId
					)
					.then((r) => {
						if (r.status == 200) {
							this.statusForm.stocks = r.data;
							this.statusForm.stocks = splitJointList(
								this.baseInfoForm,
								this.statusForm.stocks,
								'stockList',
								true
							);
						}
					});
			}
		},
		'baseInfoForm.customerId': function () {
			let [isInner, query] = [false, {}];
			let result = watchCustomerChange(this.baseInfoForm);
			isInner = result.isInner;
			query = result.query;
			if (isInner) {
				this.$http
					.post('SysConfig/GetCustomerStock', query)
					.then((r) => {
						if (r.status == 200) {
							this.statusForm.subStocks = r.data;
							this.statusForm.subStocks = splitJointList(
								this.baseInfoForm,
								this.statusForm.subStocks,
								'customerStockList',
								true
							);
						}
					});
			}
		},
		'baseInfoForm.documentStatus'() {
			if (
				this.baseInfoForm.documentStatus === 'a' ||
				this.baseInfoForm.documentStatus === 'd'
			) {
				this.$topNavTagRename('新增组织间需求单');
				this.btnType = needsBtnAdd;
			} else {
				this.$topNavTagRename('编辑组织间需求单');
				this.btnType = needsBtnEdit;
			}
		},
	},
};
</script>
<style lang="scss" scoped>
@import '@/assets/style/purchase/purchaseCommon.scss';
@import '@/assets/style/purchase/createOrgNeeds.scss';
@import '@/assets/style/saleOrder/common.scss';
</style>
