<template>
	<view class="mainBox">
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" title="新增入库单" @clickLeft="back">
			<!-- @clickRight="handleScan"
      right-icon="scan"
    > -->
			<!--右菜单-->
			<template slot="float">
				<!-- <view class="nav-icon-caozuo rightNav" @click="getsure">
					<u-button type="success" size="small" class="u-reset-button" text="确定"></u-button>
				</view> -->
			</template>
		</uni-nav-bar>

		<u-form labelPosition="left" :model="formData" :rules="rules" ref="formRef" labelWidth="260" labelAlign="right" class="baseForm">
			<u-form-item label="物品类型" class="required-form" borderBottom prop="assetType">
				<view class="assetType_box" @click="openPicker">{{ assetTypeName ? assetTypeName : '请选择产品类型' }}</view>
			</u-form-item>
			<u-form-item label="入库场景" class="required-form" prop="bizType" borderBottom>
				<picker :disabled="!!(productList && productList.length)" @change="e => handlePicker(e, sceneState, 'bizType')" :value="pickerIndex" :range="sceneState" range-key="text">
					<u-input :value="sceneStateFilter(formData.bizType)" :disableColor="!!(productList && productList.length) ? '#F5F7FA' : '#fff'" placeholder="请选择" disabled type="select" />
				</picker>
				<u-icon slot="right" name="arrow-right"></u-icon>
			</u-form-item>
			<u-form-item label="来源单据" prop="documentSource" borderBottom>
				<u-input type="text" placeholder="请输入" v-model="formData.sourceBizNo" @click.native="goToRequisition" />
			</u-form-item>
			<u-form-item label="入库时间" prop="createUserName" borderBottom>
				<view class="assetType_box" @click="timeShow = true">{{ storageTime ? formatter(storageTime) : '请选择' }}</view>
			</u-form-item>
			<u-form-item label="入库登记人" prop="createUserName" borderBottom>
				<u-input disableColor="#ffffff" :value="formData.createUserName" placeholder="请选择" disabled type="text" />
			</u-form-item>
			<u-form-item label="送货人" prop="deliveryName" borderBottom>
				<u-input type="text" placeholder="请输入" v-model="formData.fromUser" />
			</u-form-item>
			<u-form-item label="送货人联系方式" prop="deliveryPhone" borderBottom>
				<u-input type="text" placeholder="请输入" v-model="formData.extInfo.deliveryPhone" />
			</u-form-item>
			<u-form-item label="备注" prop="remark" borderBottom>
				<u-input disableColor="#ffffff" :value="formData.remark" placeholder="请输入内容" type="text" />
			</u-form-item>
		</u-form>

		<uni-collapse ref="collapse" v-model="collapseOpen">
			<uni-collapse-item :typeOpen="1" title="" name="collapse1" :open="true" :key="detailOpen" :show-animation="true">
				<template v-slot:title>
					<view class="detail-box">
						<view data-v-41027c34="" class="uni-collapse-item__title-wrap">
							<view data-v-41027c34="" class="uni-collapse-item__title-box uni-collapse-item__title-box-base">
								<text data-v-41027c34="" class="tag tag-base"><text></text></text>
								<text data-v-41027c34="" class="uni-collapse-item__title-text"><text>入库明细</text></text>
							</view>
						</view>
						<!-- <u-button type="primary" size="small" text="扫码添加" @click.native.stop="selectType"></u-button> -->
						<u-button type="success" size="small" class="selectEnterType" text="手动添加" @click.native.stop="selectType"></u-button>
					</view>
				</template>

				<u-form
					labelPosition="left"
					:model="{ productList: productList }"
					ref="lisrFormRef"
					labelWidth="150"
					:rules="listRules"
					errorType="none"
					labelAlign="right"
					:labelStyle="{
						fontSize: '28rpx'
					}">
					<view class="listContent">
						<view class="listBox" v-for="(item, index) in productList" :key="index">
							<view class="listTit">
								<view class="name">{{ item.categoryCode }}</view>
								<view class="btn">
									<u-button v-if="item.isSave" type="primary" size="small" :hairline="true" text="编辑" @click="listEdit(index)"></u-button>
									<u-button v-else type="primary" size="small" :hairline="true" text="保存" @click="listSave(item, index)"></u-button>
									<u-button type="error" size="small" :hairline="true" text="删除" @click="getDelete(index)"></u-button>
								</view>
							</view>
							<view class="listCont" :class="{ save: item.isSave }">
								<view class="item w100">
									<u-form-item :label="`物品名称`">
										{{ item.categoryName }}
									</u-form-item>
								</view>
								<view class="item w100">
									<u-form-item label="包装规格" prop="packingSpecificationLabel">
										<u-tag style="margin-right: 5rpx" v-for="ite in item.packingSpecificationLabel" :text="ite"></u-tag>
									</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="批次号" :prop="`productList.${index}.batchNo`" required>
										<u--input :disabled="item.isSave" placeholder="请输入" border="surround" v-model="item.batchNo"></u--input>
									</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="数量" :prop="`productList.${index}.packingQuantity`" required>
										<u--input :disabled="item.isSave" placeholder="请输入" border="surround" v-model="item.packingQuantity" @change="computeNum(item, index, true)"></u--input>
									</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="包装单位" :prop="`productList.${index}.packingUnit`" required>
										<u--input :disabled="item.isSave" placeholder="请选择" border="surround" v-model="item.packingUnit" @click.native="showPackingUnitPicker(item, index)"></u--input>
									</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="仓库" :prop="`productList.${index}.warehouseId`" required>
										<u--input :disabled="item.isSave" placeholder="请选择" border="surround" v-model="item.warehouseName" @click.native="showWarehousePicker(index)"></u--input>
									</u-form-item>
								</view>
								<view class="item w100">
									<u-form-item label="供应商" :prop="`productList.${index}.supplierName`">
										<u--input :disabled="item.isSave" placeholder="请选择" border="surround" v-model="item.supplierName" @click.native="showSupplierPicker(item, index)"></u--input>
									</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="计量数量" prop="measureQuantity">{{ item.measureQuantity }}</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="计量单位" prop="measureUnit">{{ item.measureUnit }}</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="重量" prop="weight">{{ item.weight }}</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="重量单位" prop="weightUnit">{{ item.weightUnit }}</u-form-item>
								</view>
								<view class="item">
									<u-form-item label="是否拆包" prop="isUnpack">{{ item.isUnpack ? '是' : '否' }}</u-form-item>
								</view>
							</view>
							<view class="selectTime" v-if="item.outInDetailRecordRequestList.length > 0">
								<view class="timeBox">
									<u-button class="firstBtn" size="small" type="primary" text="选择时间类型" @click="timeTypeShow = true"></u-button>
									<u-button type="warning" size="small" :text="`批量设置${curDateTypeLabel[curDateType]}`" @click="typeTimeClick(index)"></u-button>
								</view>
							</view>
							<u-list @scrolltolower="scrolltolower" class="z_list" style="height: 100% !important">
								<view class="material rx-ss" v-for="(ite, idx) in item.outInDetailRecordRequestList" :key="idx">
									<!-- <view class="left rx-ss" @click="deletePacking(index, idx)">
										<uni-icons custom-prefix="iconfont" type="icon-shanchu" size="20" color="#fa3534"></uni-icons>
									</view> -->
									<view class="content_table">
										<view class="item">
											<view class="lable rx-cc">序号</view>
											<view class="content">{{ idx + 1 }}</view>
										</view>
										<view class="item">
											<view class="lable rx-cc">包装编码</view>
											<view class="content">{{ ite.packageNo }}</view>
										</view>
										<view class="item">
											<view class="lable rx-cc">包装数量({{ ite.packingUnit }})</view>
											<view class="content">{{ ite.packingQuantity }}</view>
										</view>
										<view class="item">
											<view class="lable rx-cc">计量数量({{ ite.measureUnit }})</view>
											<view class="content">{{ ite.measureQuantity }}</view>
										</view>
										<view class="item">
											<view class="lable rx-cc">物料代号</view>
											<view class="content input_box"><u--input clearable placeholder="请输入" border="surround" v-model="ite.materielDesignation"></u--input></view>
										</view>
										<view class="item">
											<view class="lable rx-cc">客户代号</view>
											<view class="content input_box"><u--input clearable placeholder="请输入" border="surround" v-model="ite.clientCode"></u--input></view>
										</view>
										<view class="item">
											<view class="lable rx-cc">刻码</view>
											<view class="content input_box"><u--input clearable placeholder="请输入" border="surround" v-model="ite.engrave"></u--input></view>
										</view>
										<view class="item">
											<view class="lable rx-cc">重量({{ ite.weightUnit }})</view>
											<view class="content input_box">
												<u--input clearable placeholder="请输入" border="surround" v-model="ite.weight" @change="weightInput($event, ite, index)"></u--input>
											</view>
										</view>
										<view class="item">
											<view class="lable rx-cc">质检状态</view>
											<view class="content" @click="statusClick(index, idx)">
												{{ qualityResults[ite.status] }}
											</view>
										</view>
										<view class="item">
											<view class="lable rx-cc">{{ curDateTypeLabel[curDateType] }}</view>
											<view class="content input_box">
												<u--input clearable placeholder="请选择" border="surround" v-model="ite[curDateType]" @click.native="typeTimeClick(index, idx)"></u--input>
											</view>
										</view>
									</view>
								</view>
							</u-list>
						</view>
					</view>
				</u-form>
			</uni-collapse-item>
		</uni-collapse>
		<view class="footBox">
			<view class="reg" @click="submit">
				<uni-icons custom-prefix="iconfont" size="20" color="#fff"></uni-icons>
				提交
			</view>
		</view>
		<!-- 选择物品类型 -->
		<ba-tree-picker ref="treePicker" :multiple="true" @select-change="confirm" title="选择物品类型" :localdata="goodsLists" valueKey="id" textKey="name" childrenKey="child" />
		<!-- 选择入库时间 -->
		<u-datetime-picker @confirm="timeConfirm" @cancel="timeCancel" :show="timeShow" v-model="storageTime" mode="datetime"></u-datetime-picker>
		<!-- 选择包装单位 -->
		<u-picker
			:show="packingUnitsShow"
			visibleItemCount="10"
			:columns="currentPackingSpecificationOption"
			keyName="conversionUnit"
			@confirm="selectPackingUnitInfo"
			@cancel="packingUnitsShow = false"
			title="选择包装单位"></u-picker>
		<!-- 选择供应商单位 -->
		<u-picker
			:show="suppliersShow"
			visibleItemCount="10"
			:columns="currentSupplierListOption"
			keyName="name"
			@confirm="selectSuppliersInfo"
			@cancel="suppliersShow = false"
			title="选择供应商"></u-picker>
		<!-- 选择仓库 -->
		<u-picker :show="warehouseShow" visibleItemCount="10" :columns="warehouseListOption" keyName="name" @confirm="selectWarehouseInfo" @cancel="warehouseShow = false" title="选择仓库"></u-picker>
		<!-- 选择时间类型 -->
		<u-picker :show="timeTypeShow" visibleItemCount="10" :columns="timeTypeOption" keyName="name" @confirm="selectTimeTypeInfo" @cancel="timeTypeShow = false" title="选择时间类型"></u-picker>
		<!-- 选择生产/采购日期 -->
		<u-datetime-picker @confirm="typeTimeConfirm" @cancel="typeTimeShow = false" :show="typeTimeShow" v-model="currentTypeTime" mode="datetime"></u-datetime-picker>
		<!-- 选择质检状态 -->
		<u-picker :show="statusShow" visibleItemCount="10" :columns="qualityResultsOption" keyName="label" @confirm="selectStautsInfo" @cancel="statusShow = false" title="选择质检状态"></u-picker>
	</view>
</template>

<script>
	// import ScanCode from '@/components/ScanCode.vue'
	import {
		getTreeByGroup,
		contactQueryByCategoryIdsAPI,
		getCode,
		getCategoryPackageDisposition,
		getWarehouseList,
		getAssetNum,
		storage,
		qualityInspectionTwo,
		submitTwo
	} from '@/api/warehouseManagement'
	import { getByCode } from '@/api/pda/common'
	import dayjs from 'dayjs'
	import { sceneState } from '../common'
	import { post, postJ, get, getJ } from '@/utils/api.js'
	import WarehouseChoose from '@/components/WarehouseChoose'
	import { warehousingType, inputStatus, emergencyState, warehousingMaterialListTable, getDictName, materialType } from '../enum.js'
	import baTreePicker from '@/components/ba-tree-picker/ba-tree-picker.vue'
	// import addDetails from '@/components/addDetails'
	import UploadFileNew from '@/components/UploadFileNew'
	// import { getRuleNo } from '@/utils/utils.js'
	import { tableHeader } from '../common'
	// import dictMixins from '@/mixins/dictMixins.js'
	export default {
		components: {
			WarehouseChoose,
			baTreePicker,
			UploadFileNew
		},
		// mixins: [dictMixins],
		data() {
			return {
				goodsLists: [], // 物品类型
				assetTypeName: '', // 物品类型名称
				timeShow: false,
				packingSpecificationOption: [], // 包装规格
				currentPackingSpecificationOption: [], // 当前包装规格
				currentSupplierListOption: [], // 当前供货商
				warehouseListOption: [], // 仓库列表
				currentTypeTime: Number(new Date()), // 当前时间类型的时间
				storageTime: '', // 入库时间
				currentProductIndex: null, // 当前产品索引
				currentPackingIndex: null, // 当前包装索引
				packingUnitsShow: false,
				typeTimeShow: false,
				suppliersShow: false,
				warehouseShow: false,
				timeTypeShow: false,
				statusShow: false,
				dictCodeList: [], // 字典列表
				curDateType: 'purchaseDate',
				qualityResultsOption: [
					[
						{
							label: '合格',
							value: 1
						},
						{
							label: '不合格',
							value: 2
						}
					]
				], // 质检状态 0未检 1已检
				qualityResults: {
					1: '合格',
					2: '不合格'
				}, // 质检结果 1合格 2不合格
				curDateTypeLabel: {
					purchaseDate: '采购日期',
					productionDate: '生产日期'
				},
				timeTypeOption: [
					[
						{
							name: '采购日期',
							prop: 'purchaseDate'
						},
						{
							name: '生产日期',
							prop: 'productionDate'
						}
					]
				], // 时间类型
				collapseOpen: 'collapse1',
				emergencyState,
				warehousingType,
				materialType,
				sceneState,
				inputStatus,
				getDictName,
				detailOpen: false,
				codeOpen: false,
				deptList: [], //部门
				supplierList: [], //供应商
				formData: {
					type: 1, // 入库
					bizType: '1', // 入库场景
					storageTime: '', // 入库时间
					extInfo: {}, // 扩展信息
					sourceBizNo: '', // 来源单据编号
					fromUser: '', // 送货人
					remark: '' // 备注
				},
				statusList: [
					{
						id: 1,
						name: '紧急'
					},
					{
						id: 2,
						name: '中等'
					},
					{
						id: 1,
						name: '普通'
					}
				], //紧急状态
				pickerIndex: 0,
				productList: [],
				userList: [],
				rules: {
					assetType: {
						type: 'number',
						required: true,
						message: '请选择入库产品类型',
						trigger: ['blur', 'change']
					},
					bizType: {
						type: 'number',
						required: true,
						message: '请选择入库场景',
						trigger: ['blur', 'change']
					}
					// contentImage: {
					//   type: 'array',
					//   required: true,
					//   message: '请上传附件',
					//   trigger: ['blur', 'change']
					// }
				},
				settingIndex: 0
			}
		},
		onShow() {
			// const _this = this
			// uni.$off('scancode') // 每次进来先 移除全局自定义事件监听器
			// uni.$on('scancode', function (data) {
			//   uni.navigateBack({
			//     delta: 1
			//   })
			//   _this.qrContent = data.code.trim()
			//   _this.handleScan()
			// })
			this.collapseOpen = 'collapse1'
		},
		beforeDestroy() {
			uni.$off('setSelectList')
			uni.$off('requisitionSelect')
		},
		async onLoad(options) {
			await this.getListItems() // 物品类型
			await this.getwarehouseList() // 仓库列表
			await this.requireDictCode() // 字典列表
			// this.requestDict('物品类型')
			// this.getDept()
			// this.getSupplier()
			const userInfo = uni.getStorageSync('userInfo')
			this.formData.createUserName = userInfo.name
			this.storageTime = Number(new Date())
			this.formData.storageTime = this.formatter(this.storageTime)
			// this.formData.registerId = userInfo.id
			uni.$on('setSelectList', async data => {
				if (data?.length) {
					this.formData.sourceBizNo = ''
					// 获取批次号
					const batchNo = await getCode('lot_number_code')
					// 获取供应商
					const supplierList = await contactQueryByCategoryIdsAPI({
						categoryIds: data.map(item => item.id)
					})
					// 获取包装规格
					let packingSpecification = await getCategoryPackageDisposition({
						categoryIds: data.map(item => item.id)
					})
					this.packingSpecificationOption = data.map(item => {
						return packingSpecification.filter(ite => item.id == ite.categoryId).sort((a, b) => a.sort - b.sort)
					})
					let productList = data.map((item, index) => {
						// 显示规格
						let packingSpecificationLabel = this.packingSpecificationOption[index]
							.map(item => {
								if (item.sort > 0) {
									return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`
								}
							})
							.filter(item => !!item)
						return {
							index: this.productList.length - 1 > -1 ? this.productList[this.productList.length - 1].index + index + 1 : this.productList.length + index,
							categoryId: item.id, // 物品id
							categoryName: item.name, // 物品名称
							categoryCode: item.code, // 物品编码
							categoryModel: item.modelType, // 物品型号
							specification: item.specification, // 规格
							brandNum: item.brandNum, // 牌号
							batchNo: batchNo, // 批次号
							supplierListOptions: supplierList[item.id], // 供应商列表
							supplierId: '', // 供应商id
							supplierName: '', // 供应商名称
							approvalNumber: item.approvalNumber, // 批准文号
							packingSpecification: item.packingSpecification, // 包装规格
							packingSpecificationOption: this.packingSpecificationOption[index], // 包装规格选项
							packingSpecificationLabel: packingSpecificationLabel, // 包装规格显示
							minPackingQuantity: '', // 最小包装单元数量
							packingQuantity: '', // 包装数量
							packingUnit: '', // 包装单位
							measureQuantity: 0, // 计量数量
							measureUnit: item.measuringUnit, // 计量单位
							netWeight: item.netWeight > -1 ? item.netWeight : 0, // 净重
							weight: 0, // 重量
							weightUnit: item.weightUnit, // 重量单位
							totalMoney: '', // 总价
							price: item.price, // 单价
							purpose: '', // 用途
							isUnpack: item.isUnpack, // 是否允许拆包
							outInDetailRecordRequestList: []
						}
					})

					this.productList = this.productList.concat(productList)
					console.log(this.productList, '------------------this.productList----111-----')
					setTimeout(() => {
						this.detailOpen = !this.detailOpen
						this.$refs.collapse && this.$refs.collapse.resize()
					}, 0)
				}
			})
			uni.$on('requisitionSelect', async (data, query) => {
				console.log(data)
				console.log(query)

				this.formData.sourceBizNo = query.sourceBizNo
				this.formData.bizType = query.bizType
				this.formData.extInfo.assetType = query.assetType.split(',')
				let filterArray = this.formData.extInfo.assetType.map(item => {
					return this.goodsLists.find(ite => ite.id == item).name
				})
				this.assetTypeName = Array.from(new Set(filterArray)).join('/')
				const batchNo = await getCode('lot_number_code')
				// 获取包装规格
				let packingSpecification = await getCategoryPackageDisposition({
					categoryIds: data.map(item => item.categoryId)
				})
				this.packingSpecificationOption = data.map(item => {
					return packingSpecification.filter(ite => item.categoryId == ite.categoryId).sort((a, b) => a.sort - b.sort)
				})
				this.productList = data.map((productItem, productIndex) => {
					// 显示规格
					let packingSpecificationLabel = this.packingSpecificationOption[productIndex]
						.map(item => {
							if (item.sort > 0) {
								return `${item.packageCell}${item.packageUnit}/${item.conversionUnit}`
							}
						})
						.filter(item => !!item)
					return {
						...productItem,
						index: this.productList.length + productIndex,
						isSave: productItem.outInDetailRecordRequestList?.length > 0 ? true : false,
						batchNo: batchNo, // 批次号
						warehouseIds: [productItem.warehouseId], // 仓库Id
						warehouseNames: [productItem.warehouseName], // 仓库名称
						packingSpecificationOption: this.packingSpecificationOption[productIndex], // 包装规格选项
						packingSpecificationLabel: packingSpecificationLabel, // 包装规格显示
						outInDetailRecordRequestList:
							productItem.outInDetailRecordRequestList?.length > 0
								? productItem.outInDetailRecordRequestList.map((packingItem, packingIndex) => {
										return {
											...packingItem,
											index: this.productList.length + productIndex + '-' + packingIndex, // 包装索引
											batchNo: batchNo, // 批次号
											parentIndex: this.productList.length + productIndex, // 物品索引
											categoryName: productItem.categoryName,
											categoryCode: productItem.categoryCode,
											materialDetailList: packingItem.materialDetailList.map((materialItem, materialIndex) => {
												return {
													...materialItem,
													index: this.productList.length + productIndex + '-' + packingIndex + '——' + materialIndex, // 包装索引
													parentIndex: this.productList.length + productIndex + '-' + packingIndex, // 物品索引
													batchNo: batchNo, // 批次号
													categoryName: productItem.categoryName,
													categoryCode: productItem.categoryCode
												}
											})
										}
								  })
								: []
					}
				})
				setTimeout(() => {
					this.detailOpen = !this.detailOpen
					this.$refs.collapse && this.$refs.collapse.resize()
				}, 0)
			})
			// 明细信息填写
			uni.$on('batchNumBack', productList => {
				if (productList?.length) {
					this.productList = productList
				}
			})
		},
		mounted() {
			// this.getAddDetails();
		},
		computed: {
			tableHeader() {
				return tableHeader(this.formData.assetType)
			},
			materialCodeReqList() {
				return this.productList.map(i => i.warehouseLedgerDetails || []).flat()
			},
			isMaterial() {
				return this.formData.assetType == 3
			},
			warehousingName() {
				return []
				this.productList = []
				return this.getDictValue('物品类型', this.formData.assetType)
			},
			listRules() {
				return this.productList.reduce((cur, pre, index) => {
					return {
						...cur,
						[`productList.${index}.batchNo`]: {
							type: 'string',
							required: true,
							trigger: ['blur', 'change']
						},
						[`productList.${index}.packingQuantity`]: {
							type: 'number',
							required: true,
							trigger: ['blur', 'change']
						},
						[`productList.${index}.packingUnit`]: {
							type: 'string',
							required: true,
							trigger: ['blur', 'change']
						},
						[`productList.${index}.warehouseId`]: {
							type: 'string',
							required: true,
							trigger: ['blur', 'change']
						}
					}
				}, {})
			}
		},
		methods: {
			goToRequisition() {
				uni.navigateTo({
					url: '/pages/warehouse/components/requisitionList?type=' + 1
				})
			},
			// 入库
			submit() {
				if (this.productList.length <= 0) {
					uni.showToast({
						icon: 'none',
						title: '请添加产品！'
					})
					return
				}
				let boolen = this.productList.every(item => item.isSave)
				if (!boolen) {
					uni.showToast({
						icon: 'none',
						title: '请先保存所有产品信息！'
					})
					return
				}
				uni.showLoading({
					title: '保存中...'
				})
				this.formData.outInDetailList = this.productList
				let obj = uni.$u.deepClone(this.formData)
				// 处理物品类型assetType
				obj.extInfo.assetType = obj.extInfo.assetType.join(',')
				// 处理仓库id
				let warehouseId = []
				let warehouseName = []
				let warehouseIds = this.productList.map(item => item.warehouseIds).flat()
				let warehouseNames = this.productList.map(item => item.warehouseNames).flat()
				warehouseIds.forEach((item, index) => {
					if (!warehouseId.includes(item)) {
						warehouseId.push(item)
						warehouseName.push(warehouseNames[index])
					}
				})
				obj.warehouseIds = warehouseId
				obj.warehouseNames = warehouseName
				// 是否需要审核(0审核 1跳过审核)
				if (obj.bizType == '12') {
					obj.isSkip = 1
				} else {
					obj.isSkip = 0
				}
				// obj.isSkip = 1;
				console.log(obj)
				storage(obj)
					.then(async res => {
						console.log('入库成功', res)
						if (res.code == 0) {
							try {
								// 委外入库（非采购）
								if (obj.bizType == '12') {
									await qualityInspectionTwo({
										outInId: res.data[0]
									})
								} else {
									await submitTwo({ outInId: res.data[0] })
								}
								uni.hideLoading()
								uni.showToast({
									icon: 'none',
									title: '入库成功',
									duration: 1500
								})
								setTimeout(() => {
									uni.navigateBack({
										delta: 1
									})
								}, 1500)
							} catch (error) {
								uni.hideLoading()
								console.log('提交流程失败', error)
							}
						}
					})
					.catch(err => {
						console.log('入库失败', err)
						uni.hideLoading()
						uni.showToast({
							icon: 'none',
							title: '入库失败',
							duration: 2000
						})
					})
			},
			// 重量限制
			weightInput(value, row, productIndex) {
				const newValue = value.replace(/[^\d.]/g, '') // 保留数字和小数点
				const decimalCount = (newValue.match(/\./g) || []).length // 计算小数点的个数
				if (row.weight < 0) {
					row.weight = 0
				} else if (row.weight > 9999) {
					row.weight = 9999
				} else {
					if (decimalCount > 1) {
						// 如果小数点个数大于1，移除多余的小数点
						const lastIndex = newValue.lastIndexOf('.')
						row.weight = newValue.slice(0, lastIndex) + newValue.slice(lastIndex + 1)
					} else if (decimalCount === 1) {
						// 如果小数点个数等于1，允许小数点的输入
						row.weight = newValue
					} else {
						row.weight = newValue === '' ? 0 : parseFloat(newValue) // 如果输入为空，则设为0
					}
				}
				this.packingWeightCahnge(productIndex)
			},
			// 包装重量修改
			packingWeightCahnge(productIndex) {
				// 修改物品重量
				let totalWeight = this.productList[productIndex].outInDetailRecordRequestList.reduce((accumulator, currentValue) => {
					return Number(accumulator) + Number(currentValue.weight)
				}, 0)
				this.$set(this.productList[productIndex], 'weight', totalWeight)
			},
			scrolltolower() {
				console.log('滑动了~~~')
			},
			typeTimeClick(index, idx) {
				console.log('index-----', index)
				console.log('idx----', idx)
				this.currentProductIndex = index
				this.currentPackingIndex = idx > -1 ? idx : -1
				this.typeTimeShow = true
			},
			statusClick(index, idx) {
				this.currentProductIndex = index
				this.currentPackingIndex = idx > -1 ? idx : -1
				this.statusShow = true
			},
			selectStautsInfo(e) {
				this.productList[this.currentProductIndex].outInDetailRecordRequestList[this.currentPackingIndex].status = e.value[0]?.value
				this.statusShow = false
			},
			typeTimeConfirm() {
				this.typeTimeShow = false
				this.$nextTick(() => {
					console.log(this.currentPackingIndex)
					if (this.currentPackingIndex > -1) {
						// 单独
						this.productList[this.currentProductIndex].outInDetailRecordRequestList[this.currentPackingIndex][this.curDateType] = this.formatter(this.currentTypeTime)
					} else {
						// 批量
						this.productList[this.currentProductIndex].outInDetailRecordRequestList = this.productList[this.currentProductIndex].outInDetailRecordRequestList.map(item => {
							console.log(this.currentTypeTime)
							console.log(this.formatter(this.currentTypeTime))
							return {
								...item,
								[this.curDateType]: this.formatter(this.currentTypeTime)
							}
						})
					}
				})
			},
			// 物品保存验证表单（单独）
			validateFormIndividually(index) {
				return new Promise(async resolve => {
					console.log('index----------------', index)
					let fileds = [`productList.${index}.batchNo`, `productList.${index}.packingQuantity`, `productList.${index}.packingUnit`, `productList.${index}.warehouseId`]
					Promise.all(
						fileds.map(
							item =>
								new Promise(async (res, rej) => {
									this.$refs.lisrFormRef.validateField(item, err => {
										console.log('err--', err)
										if (err?.length) {
											rej(err)
										} else {
											res(true)
										}
									})
								})
						)
					)
						.then(() => {
							resolve()
						})
						.catch(err => {
							uni.showToast({
								icon: 'none',
								title: '请填入必填项！'
							})
						})
				})
			},
			// 产品编辑
			listEdit(index) {
				this.currentProductIndex = index
				this.productList[index].isSave = false
				this.productList[index].outInDetailRecordRequestList = []
			},
			listSave(row, index) {
				console.log('index------', index)
				this.validateFormIndividually(index).then(async () => {
					console.log('通过了！！！')
					// 判断包装单位和计量单位是否为不拆物料层规格
					let packingBoolen = !!this.getDict(row.packingUnit).dictValue
					let measureBoolen = !!this.getDict(row.measureUnit).dictValue
					let packingNum = 0
					// 处理包装单位为KG类的情况
					if (packingBoolen) {
						let filterArr = row.packingSpecificationOption.filter(item => {
							return item.packageUnit == row.packingUnit && item.packageUnit != item.conversionUnit
						})
						packingNum = Math.ceil(row.packingQuantity / filterArr[0].packageCell)
					}
					// 处理包装单位不为KG类,计量单位为KG类的情况
					let measureNum = row.packingQuantity
					if (measureBoolen) {
						let splitIndex = row.packingSpecificationOption.findIndex(item => item.conversionUnit == row.packingUnit && item.packageUnit != item.conversionUnit)
						for (; splitIndex > 1; splitIndex--) {
							measureNum = measureNum * row.packingSpecificationOption[splitIndex].packageCell
						}
					}
					// 获取包装编码列表
					const { data } = await getAssetNum([
						{
							assetCode: row.categoryCode + row.index,
							batchNum: row.batchNo,
							num: packingBoolen ? packingNum : row.isUnpack ? (measureBoolen ? measureNum : row.measureQuantity) : row.packingQuantity
						}
					])
					this.generateWrappers(row, index, data)
					this.$set(this.productList[index], 'isSave', true)
				})
			},
			// 获取当前时间函数
			getNowDate() {
				let date = new Date(),
					obj = {
						year: date.getFullYear(), //获取完整的年份(4位)
						month: date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
						strDate: date.getDate(), // 获取当前日(1-31)
						hour: date.getHours(), //获取当前小时(0 ~ 23)
						minute: date.getMinutes(), //获取当前分钟(0 ~ 59)
						second: date.getSeconds() //获取当前秒数(0 ~ 59)
					}
				Object.keys(obj).forEach(key => {
					if (obj[key] < 10) obj[key] = `0${obj[key]}`
				})
				return obj
			},
			// 生成包装
			generateWrappers(row, productIndex, packingCodeList) {
				console.log('是否拆包----', row.isUnpack)
				console.log('包装规格----', row.packingSpecificationOption)
				console.log('计量单位----', row.measureUnit)
				console.log('包装数量----', row.packingQuantity)
				console.log('包装编码----', packingCodeList)
				let obj = this.getNowDate()
				let productionDate = ''
				let purchaseDate = ''
				if (this.formData.bizType == '1') {
					// 生产入库
					productionDate = `${obj.year}-${obj.month}-${obj.strDate} ${obj.hour}:${obj.minute}:${obj.second}`
					this.curDateType = 'productionDate'
				} else if (this.formData.bizType == '2') {
					// 采购入库
					purchaseDate = `${obj.year}-${obj.month}-${obj.strDate} ${obj.hour}:${obj.minute}:${obj.second}`
					this.curDateType = 'purchaseDate'
				}
				// 判断包装单位和计量单位是否为不拆物料层规格
				let packingBoolen = !!this.getDict(row.packingUnit).dictValue
				let measureBoolen = !!this.getDict(row.measureUnit).dictValue
				let num = row.packingQuantity
				let filterArr = []
				// 处理包装单位为KG类的情况
				if (packingBoolen) {
					filterArr = row.packingSpecificationOption.filter(item => {
						return item.packageUnit == row.packingUnit && item.packageUnit != item.conversionUnit
					})
					num = Math.ceil(row.packingQuantity / filterArr[0].packageCell)
				} else {
					if (row.isUnpack) {
						if (measureBoolen) {
							// 处理包装单位不为KG类,计量单位为KG类的情况
							let splitIndex = row.packingSpecificationOption.findIndex(item => item.conversionUnit == row.packingUnit && item.packageUnit != item.conversionUnit)
							for (; splitIndex > 1; splitIndex--) {
								// num = this.$math.format(num * row.packingSpecificationOption[splitIndex].packageCell, 14)
								num = num * row.packingSpecificationOption[splitIndex].packageCell
							}
						} else {
							console.log(row.packingSpecificationOption)
							let splitIndex = row.packingSpecificationOption.findIndex(item => item.conversionUnit == row.packingUnit && item.packageUnit != item.conversionUnit)
							console.log(splitIndex)
							for (; splitIndex > 0; splitIndex--) {
								console.log(splitIndex)
								// num = this.$math.format(num * row.packingSpecificationOption[splitIndex].packageCell, 14)
								num = num * row.packingSpecificationOption[splitIndex].packageCell
							}
						}
					} else {
						num = row.packingQuantity
					}
				}
				for (let index = 0; index < num; index++) {
					let measureQuantity = 1
					// 处理包装单位为KG类,计算每桶KG值
					if (packingBoolen) {
						// console.log(this.$math.format(filterArr[0].packageCell * (index + 1), 14))
						console.log(filterArr[0].packageCell * (index + 1))
						console.log(row.packingQuantity)
						// measureQuantity =
						// 	Number(row.packingQuantity) > this.$math.format(filterArr[0].packageCell * (index + 1), 14)
						// 		? filterArr[0].packageCell
						// 		: Number(row.packingQuantity) - this.$math.format(filterArr[0].packageCell * index, 14)
						measureQuantity = Number(row.packingQuantity) > filterArr[0].packageCell * (index + 1) ? filterArr[0].packageCell : Number(row.packingQuantity) - filterArr[0].packageCell * index
					} else {
						if (!row.isUnpack) {
							if (measureBoolen) {
								// 处理包装单位不为KG类,计量单位为KG类的情况
								let splitIndex = row.packingSpecificationOption.findIndex(item => item.conversionUnit == row.packingUnit && item.packageUnit != item.conversionUnit)
								for (; splitIndex > 0; splitIndex--) {
									// measureQuantity = this.$math.format(measureQuantity * row.packingSpecificationOption[splitIndex].packageCell, 14)
									measureQuantity = measureQuantity * row.packingSpecificationOption[splitIndex].packageCell
								}
							} else {
								let splitIndex = row.packingSpecificationOption.findIndex(item => item.conversionUnit == row.packingUnit && item.packageUnit != item.conversionUnit)
								for (; splitIndex > 0; splitIndex--) {
									console.log(splitIndex)
									// measureQuantity = this.$math.format(measureQuantity * row.packingSpecificationOption[splitIndex].packageCell, 14)
									measureQuantity = measureQuantity * row.packingSpecificationOption[splitIndex].packageCell
								}
							}
						}
					}
					let item = {
						index: row.index + '-' + index, // 包装索引
						warehouseId: row.warehouseIds[0], // 仓库id
						warehouseName: row.warehouseNames[0], // 仓库名称
						categoryName: row.categoryName, // 产品名称
						categoryCode: row.categoryCode, // 产品编码
						categoryModel: row.categoryModel, // 物品型号
						specification: row.specification, // 规格
						brandNum: row.brandNum, // 牌号
						parentIndex: row.index, // 产品索引
						batchNo: row.batchNo, // 批次号
						packageNo: packingCodeList[index].onlyCode, // 包装编码
						packingQuantity: 1, // 包装数量
						packingUnit: row.isUnpack
							? packingBoolen
								? filterArr[0].conversionUnit
								: measureBoolen
								? row.packingSpecificationOption[1].conversionUnit
								: row.measureUnit
							: packingBoolen
							? filterArr[0].conversionUnit
							: row.packingUnit,
						measureQuantity: row.isUnpack ? (packingBoolen ? measureQuantity : measureBoolen ? row.packingSpecificationOption[1].packageCell : measureQuantity) : measureQuantity, // 计量数量
						measureUnit: row.isUnpack ? (measureBoolen ? row.packingSpecificationOption[1].packageUnit : row.measureUnit) : row.measureUnit, // 计量单位
						weight: 0, // 重量
						packingSpecificationOption: row.packingSpecificationOption, // 包装规格
						weightUnit: row.weightUnit, // 重量单位
						netWeight: row.netWeight, // 净重
						barcodes: '', // 发货条码
						clientCode: '', // 客户代号
						materielDesignation: '', // 物料代号
						engrave: '', // 刻码
						isUnpack: row.isUnpack, // 是否允许拆包
						productionDate: productionDate, // 生产日期
						purchaseDate: purchaseDate, // 采购时间
						result: 1, // 结果(1合格 2不合格)
						status: 1 // 状态(0=未质检 1已质检)
					}
					let outBoolen = !!this.getDict(item.measureUnit).dictValue
					console.log('this.dictCodeList-------', this.dictCodeList)
					console.log('item.measureUnit-------', item)
					console.log('!!this.getDict(item.measureUnit).dictValue--------', this.getDict(item.measureUnit))
					if (outBoolen) {
						// 计量单位为KG类，直接替换
						item.weight = item.measureQuantity
					} else {
						// 计量单位为不为KG类，重新统计计算
						let inBoolen = !!this.getDict(item.packingSpecificationOption[0].packageUnit).dictValue
						let startIndex = item.packingSpecificationOption.findIndex(ite => {
							return item.measureUnit == ite.packingUnit && ite.packingUnit != ite.conversionUnit
						})
						console.log(startIndex)
						let endIndex = item.packingSpecificationOption.findIndex(ite => item.packingUnit == ite.conversionUnit)
						console.log(endIndex)
						let total = item.packingQuantity
						for (; startIndex < endIndex; endIndex--) {
							// total = this.$math.format(item.packingSpecificationOption[endIndex].packageCell * total, 14)
							total = item.packingSpecificationOption[endIndex].packageCell * total
						}
						if (inBoolen) {
							// 第二层为KG类
							item.weight = total
						} else {
							// 第二层不为KG类
							// item.weight = this.$math.format(total * item.netWeight, 14)
							item.weight = total * item.netWeight
						}
					}
					row.outInDetailRecordRequestList.push(item)
				}

				// // 单独点击保存并插入对应位置(包装)
				// if (productIndex == 0) {
				// 	this.packingList.splice(productIndex, 0, ...packingList)
				// } else {
				// 	let packingIndex = this.packingList.findLastIndex(item => item.parentIndex == this.productList[productIndex - 1].index)
				// 	this.packingList.splice(packingIndex + 1, 0, ...packingList)
				// }
			},
			async requireDictCode() {
				// 不拆物料层规格列表
				const res = await getByCode('material_layer')
				this.dictCodeList = res.map(item => {
					const arr = Object.entries(item)
					return {
						dictCode: arr[0][0],
						dictValue: arr[0][1]
					}
				})
			},
			getDict(dictCode) {
				// 不拆物料层规格列表
				if (this.dictCodeList.length > 0) {
					return this.dictCodeList.find(item => item.dictCode == dictCode) || {}
				} else {
					return {}
				}
			},
			async computeNum(row, index, isClear) {
				console.log(row)
				console.log(row.packingQuantity)
				console.log(row.packingUnit)
				// 清空仓库(包装数量输入)
				if (isClear) {
					// this.$set(this.productList[index], 'warehouseId', '')
					// this.$set(this.productList[index], 'warehouseName', '')
					if (row.packingQuantity < 1) {
						this.$set(this.productList[index], 'packingQuantity', 1)
					} else if (row.packingQuantity > 9999) {
						this.$set(this.productList[index], 'packingQuantity', 9999)
					} else {
						this.$set(this.productList[index], 'packingQuantity', row.packingQuantity.replace(/[^\d\.{2,}]/g, ''))
					}
				}
				if (row.packingQuantity && row.packingUnit) {
					let startIndex = row.packingSpecificationOption.findIndex(ite => {
						return row.measuringUnit == ite.packingUnit && ite.packingUnit != ite.conversionUnit
					})
					console.log(startIndex)
					let endIndex = row.packingSpecificationOption.findIndex(ite => row.packingUnit == ite.conversionUnit)
					console.log(endIndex)
					let total = row.packingQuantity
					for (; startIndex < endIndex; endIndex--) {
						total = row.packingSpecificationOption[endIndex].packageCell * total
					}
					row.measureQuantity = total
					// 判断包装单位和计量单位是否为不拆物料层规格
					console.log(this.getDict(row.packingUnit))
					let packingBoolen = !!this.getDict(row.packingUnit).dictValue
					let measureBoolen = !!this.getDict(row.measureUnit).dictValue
					if (packingBoolen || measureBoolen) {
						row.weight = total
					} else {
						row.weight = total * row.netWeight
					}
				}
			},
			//获取仓库
			async getwarehouseList() {
				let res = await getWarehouseList()
				this.warehouseListOption = [res.data]
			},
			showWarehousePicker(index) {
				this.currentProductIndex = index
				this.warehouseShow = true
			},
			showPackingUnitPicker(data, index) {
				this.currentProductIndex = index
				this.currentPackingSpecificationOption = [data.packingSpecificationOption]
				this.packingUnitsShow = true
			},
			showSupplierPicker(data, index) {
				this.currentProductIndex = index
				this.currentSupplierListOption = [data.supplierListOptions]
				this.suppliersShow = true
			},
			selectPackingUnitInfo(e) {
				this.productList[this.currentProductIndex].packingUnit = e.value[0]?.conversionUnit
				this.computeNum(this.productList[this.currentProductIndex], this.currentProductIndex)
				this.packingUnitsShow = false
			},
			selectSuppliersInfo(e) {
				this.productList[this.currentProductIndex].supplierName = e.value[0]?.name
				this.productList[this.currentProductIndex].supplierId = e.value[0]?.id
				this.suppliersShow = false
			},
			selectWarehouseInfo(e) {
				this.productList[this.currentProductIndex].warehouseName = e.value[0]?.name
				this.productList[this.currentProductIndex].warehouseId = e.value[0]?.id
				this.productList[this.currentProductIndex].warehouseNames = [e.value[0]?.name]
				this.productList[this.currentProductIndex].warehouseIds = [e.value[0]?.id]
				this.warehouseShow = false
			},
			selectTimeTypeInfo(e) {
				this.curDateType = e.value[0]?.prop
				this.timeTypeShow = false
			},
			sceneStateFilter(bizType) {
				if (bizType) {
					return this.sceneState.filter(item => item.value == bizType)[0].text
				}
			},
			formatter(dataTime) {
				return dayjs(dataTime).format('YYYY-MM-DD HH:mm:ss')
			},
			timeConfirm() {
				this.timeShow = false
				this.$nextTick(() => {
					console.log(this.storageTime)
					console.log(this.formatter(this.storageTime))
					this.formData.storageTime = this.formatter(this.storageTime)
					console.log(this.formData)
				})
			},
			timeCancel() {
				this.timeShow = false
			},
			openPicker() {
				this.$refs.treePicker._show()
			},
			// 获取物品列表
			async getListItems() {
				this.goodsLists = await getTreeByGroup({ type: 2 })
			},
			confirm(data, name, allList) {
				console.log('name-------', name)
				this.assetTypeName = name
				this.formData.extInfo.assetType = allList.map(item => item.id)
			},
			handleScan() {
				if (this.formData.bizType !== '' && this.formData.bizType != 5) {
					uni.showModal({
						title: '提示',
						content: '仅退还入库支持扫码,是否清除已选明细并切换至退还入库?',
						success: async res => {
							if (res.confirm) {
								this.productList = []
								this.formData.bizType = 5
								this.getData()
							}
						}
					})
					return
				}
				this.getData()
			},
			// goScan () {
			//   uni.navigateTo({
			//     url: '/pages/ScanCode/ScanCode'
			//   })
			// },
			// 根据条码请求设备数据 @_@
			getData() {
				let par = {
					barType: this.qrContent.split('@_@')[1] || 0,
					qrContent: this.qrContent
				}
				// uni.showLoading({
				// 	title: '加载中',
				// 	mask: true
				// })
				// postJ(this.apiUrl + '/scan/getAssetInfo', par)
				// 	.then(res => {
				// 		let data = res.data
				// 		console.log(data, 'qrContent')
				// 		if (data.assetType === undefined) {
				// 			uni.showToast({
				// 				title: '请扫码物品码',
				// 				icon: 'none'
				// 			})
				// 			return
				// 		} else if (data.source == 2) {
				// 			uni.showModal({
				// 				title: '提示',
				// 				content: '当前物品已在库',
				// 				success: async res => {}
				// 			})

				// 			return
				// 		} else if (this.warehousingName && this.formData.assetType != data.assetType) {
				// 			uni.showToast({
				// 				title: `当前物品不属于${this.warehousingName}分类`,
				// 				icon: 'none'
				// 			})
				// 			return
				// 		}

				// 		this.setScanMaterial(data)
				// 	})
				// 	.finally(() => {
				// 		uni.hideLoading()
				// 	})
			},
			async setScanMaterial(data) {
				this.formData.assetType = data.assetType
				this.formData.bizType = 5

				const curMap = {
					assetId: 'id',
					assetCode: 'informationCode', //编码
					assetName: 'informationName', //名称
					materialId: 'id',
					materialName: 'informationName',
					batchNo: '', //批次号
					unit: 'measuringUnit', //单位
					minPackUnit: 'packingUnit' //最小包装单位
				}
				let obj = {}

				for (const key in curMap) {
					obj[key] = (curMap[key] && data.information[curMap[key]]) || ''
				}

				let detailObj = uni.$u.deepClone(obj)

				detailObj.onlyCode = data.assetCode

				obj = {
					...data.information,
					...obj,
					...{
						cargoSpaceCode: '', //货位编码
						cargoSpaceId: '', //货位id
						shelfId: '', //货架id
						shelfCode: '', //货架名称
						areaId: '', //库区id
						areaName: '', //库区名称
						warehouseId: '', //仓库id
						warehouseName: '', //仓库名称
						measurementUnit: '',
						bizStatus: 1,
						contentImage: []
					}
				}
				let warehouseLedgerDetails = [detailObj]

				this.productList.push(obj)

				this.$set(this.productList[this.productList.length - 1], 'warehouseLedgerDetails', warehouseLedgerDetails)
				this.$set(this.productList[this.productList.length - 1], 'selfWarehouseLedgerDetails', uni.$u.deepClone(warehouseLedgerDetails))

				this.handleBatchSetting(obj, this.productList.length - 1, true)
			},
			calcSum(a, b, c, row) {
				if ((Number.isNaN(+a) && a !== '') || (Number.isNaN(+b) && b !== '') || (Number.isNaN(+c) && c !== '')) {
					return ''
				}

				return a * b * c + { yuan: '元', wanyuan: '万元' }[row.univalenceUnit]
			},
			handleBatchSetting(item, index, isScan = false) {
				this.settingIndex = index
				uni.setStorageSync('inputData', item)
				uni.setStorageSync('productList', this.productList || [])

				uni.navigateTo({
					url: '/pages/warehouse/enterHouse/batchNumEdit?bizType=' + this.formData.bizType + '&assetType=' + this.formData.assetType + '&index=' + index + '&isScan=' + isScan
				})
			},
			chooseFile(file) {
				console.log(file)
				this.$refs.lFile.upload({
					//替换为你的上传接口地址
					url: this.apiUrl + '/data/doc/add',
					// 服务端接收附件的key
					name: 'file',
					//根据你接口需求自定义 (优先不传content-type,安卓端无法收到参数再传)
					header: {
						Authorization: 'bearer eyJhbGciO',
						uid: '27682',
						client: 'app'
					}

					// 限制选择附件的大小上限，默认10M
					// maxSize: 20,

					// 若需要在body单独添加附件名或附件大小如下方式传入组件：
					// addName: '后端要的附件名称字段key,此处请勿写name的同值如(file)，会覆盖name',
					// addSize: '后端要的附件大小字段key'

					// body参数直接写key,value,如：
					// date: '2020-1-1',
					// key2: 'value2',
				})
			},
			// 抬头下拉信息保存
			handlePicker(e, list, idKey, nameKey) {
				console.log('e?.detail--------------', e)
				if (idKey) {
					this.formData[idKey] = list[e?.detail.value]?.value
				}
				if (nameKey) {
					this.formData[nameKey] = list[e?.detail.value]?.text
				}
				this.$nextTick(() => {
					if (idKey === 'assetType' || idKey === 'bizType') {
						this.$refs.formRef.validateField(idKey)
					}
					console.log('this.formData.bizType---', this.formData.bizType)
				})
			},
			// 抬头下拉信息保存
			handleDictPicker(e, list, idKey, nameKey) {
				if (idKey) {
					this.formData[idKey] = list[e?.detail.value]?.dictCode
				}
				if (nameKey) {
					this.formData[nameKey] = list[e?.detail.value]?.dictValue
				}
				this.$nextTick(() => {
					if (idKey === 'assetType' || idKey === 'bizType') {
						this.$refs.formRef.validateField(idKey)
					}
				})
			},
			// 明细下拉信息保存
			handleListPicker(e, list, item, idKey, nameKey) {
				if (idKey) {
					item[idKey] = list[e.detail.value].id
				}
				if (nameKey) {
					item[nameKey] = list[e.detail.value].name
				}
			},
			//获取仓库信息
			handleWarehouseChoose(item) {
				this.$refs.warehouseChooseRef.openDefault(item, res => {
					Object.assign(item, res)
				})
			},
			//状态
			getstatus(e) {
				this.formData.houseType = this.statusList[e.detail.value].name
			},
			//上传附件
			getUpFlie(res) {
				console.log(res)
				let arr = []
				res.forEach(item => {
					let obj = {
						accessUrl: item.accessUrl,
						docId: item.docId,
						name: item.name,
						size: item.size,
						url: item.url,
						type: 1
					}
					// obj.type.id = item.type.id;
					// obj.type.value = item.type.name;
					arr.push(obj)
				})
				this.formData.attaments = arr
			},
			//选择入库类别跳转
			selectType() {
				if (!this.formData.extInfo.assetType) {
					uni.showToast({
						title: '请选择物品类型',
						icon: 'none'
					})
					return
				}
				if (!this.formData.bizType) {
					uni.showToast({
						title: '请选择入库场景',
						icon: 'none'
					})
					return
				}
				uni.navigateTo({
					url: '/pages/warehouse/enterHouse/selectEnterType?assetType=' + this.formData.extInfo.assetType
				})
			},
			//删除
			getDelete(index) {
				uni.showModal({
					title: '提示',
					content: '是否删除当前物品',
					success: res => {
						if (res.confirm) {
							this.productList.splice(index, 1)
						}
					}
				})
			},
			deletePacking(index, idx) {
				uni.showModal({
					title: '提示',
					content: '是否删除当前包装',
					success: res => {
						if (res.confirm) {
							this.productList[index].outInDetailRecordRequestList.splice(idx, 1)
							this.productList[index].packingQuantity = this.productList[index].packingQuantity - 1
						}
					}
				})
			},
			// 入库操作
			// listEdit(row) {
			// 	this.$set(row, 'isSave', false)
			// },
			// listSave(row, index) {
			// 	const fileds = [`productList.${index}.cargoSpaceCode`, `productList.${index}.batchNum`]

			// 	if (this.formData.bizType != 5) {
			// 		fileds.push(...[`productList.${index}.outInNum`, `productList.${index}.measurementUnit`])
			// 	} else if (this.productList.some(i => !i.selfWarehouseLedgerDetails?.length)) {
			// 		uni.showToast({
			// 			title: '请选择资产编号！',
			// 			icon: 'none'
			// 		})
			// 		return
			// 	}
			// 	Promise.all(
			// 		fileds.map(
			// 			item =>
			// 				new Promise(async (resolve, rej) => {
			// 					this.$refs.lisrFormRef.validateField(item, err => {
			// 						if (err?.length) {
			// 							rej(err)
			// 						} else {
			// 							resolve()
			// 						}
			// 					})
			// 				})
			// 		)
			// 	)
			// 		.then(res => {
			// 			this.$set(row, 'isSave', true)
			// 			if (this.formData.bizType != 5) {
			// 				this.createMaterialCode(row)
			// 			} else {
			// 				// 退还
			// 				this.createMaterialCodeReturn(row)
			// 			}
			// 		})
			// 		.catch(err => {
			// 			uni.showToast({
			// 				icon: 'error',
			// 				title: '请填入必填项！'
			// 			})
			// 		})
			// },
			//入库明细删除
			listDel(row, index) {
				this.productList.splice(index, 1)
			},
			// 入库明细生成条码信息
			async createMaterialCode(row) {
				return
				// 添加相同物品重新更新明细 原料编码
				const list = this.productList.filter(i => i.assetCode === row.assetCode && i.batchNum === row.batchNum && i.isSave)

				const num = list.reduce((num, pre) => {
					num += row.isUnpack ? pre.outInNum * pre.measurementUnit : pre.outInNum
					return num
				}, 0)

				const res = await postJ(this.apiUrl + '/outInWarehouse/getAssetNum', {
					batchNum: row.batchNum,
					assetCode: row.assetCode,
					num
				})
				if (res?.success) {
					list.forEach(item => {
						if (item.warehouseLedgerDetails?.length) {
							item.warehouseLedgerDetails.forEach(i => {
								i.onlyCode = res.data.shift().onlyCode
							})
						} else {
							this.$set(
								item,
								'warehouseLedgerDetails',
								Array.from(new Array(item.isUnpack ? item.outInNum * item.measurementUnit : +item.outInNum), (val, idx) => {
									return {
										...item,
										onlyCode: res.data.shift().onlyCode,
										bizStatus: 1,
										contentImage: []
									}
								})
							)
						}
					})
				}

				// 添加相同物品，重复批次号 重新更新明细 包装编码
				const batchList = this.productList.filter(i => i.batchNum === row.batchNum && i.isSave)
				if (batchList.length) {
					const num = batchList.reduce((num, pre) => {
						num += +pre.outInNum
						return num
					}, 0)
					const res1 = await postJ(this.apiUrl + '/outInWarehouse/getAssetNum', {
						batchNum: row.batchNum,
						num
					})
					if (res1?.success) {
						batchList.forEach(item => {
							let num = res1.data.shift()?.num
							let measurementUnit = item.measurementUnit

							if (item.warehouseLedgerDetails?.length) {
								item.warehouseLedgerDetails.forEach((i, index) => {
									this.$set(i, 'num', num)
									if (!item.isUnpack) {
										if (index < item.warehouseLedgerDetails.length - 1) {
											num = res1.data.shift()?.num
										}
									} else {
										// 拆包的包装编码一致
										measurementUnit--
										if (measurementUnit === 0 && index < item.warehouseLedgerDetails.length - 1) {
											measurementUnit = item.measurementUnit
											num = res1.data.shift()?.num
										}
									}
								})
							}
						})
					}
				}
			},
			// 入库明细生成条码信息 退还
			async createMaterialCodeReturn(row) {
				return
				// 添加相同物品重新更新明细 原料编码
				const list = this.productList.filter(i => i.batchNum === row.batchNum && i.isSave)
				// 退还
				const res = await postJ(this.apiUrl + '/outInWarehouse/getAssetNum', {
					batchNum: row.batchNum,
					num: list.reduce((num, pre) => {
						num += pre.selfWarehouseLedgerDetails.length
						return num
					}, 0)
				})
				if (res?.success) {
					list.forEach(item => {
						const num = res.data.shift().num
						if (item.warehouseLedgerDetails?.length) {
							item.warehouseLedgerDetails.forEach(i => {
								i.num = num

								if (!item.isUnpack) {
									// 拆包的包装编码一致
									num = res.data.shift()?.num
								}
							})
						} else {
							this.$set(
								item,
								'warehouseLedgerDetails',
								item.selfWarehouseLedgerDetails.map((val, idx) => {
									let obj = {
										...val,
										bizStatus: 1,
										batchNum: item.batchNum,
										cargoSpaceCode: item.cargoSpaceCode, //货位编码
										cargoSpaceId: item.cargoSpaceId, //货位id
										shelfId: item.shelfId, //货架id
										shelfCode: item.shelfCode, //货架名称
										areaId: item.areaId, //库区id
										areaName: item.areaName, //库区名称
										warehouseId: item.warehouseId, //仓库id
										warehouseName: item.warehouseName, //仓库名称
										num
									}
									if (!item.isUnpack) {
										// 拆包的包装编码一致
										num = res.data.shift()?.num
									}
									return obj
								})
							)
						}
					})
				}
			},
			//确定提交
			getsure() {
				return
				this.$refs.formRef.validate().then(res => {
					if (!this.productList?.length) {
						uni.showToast({
							icon: 'error',
							title: '请添加明细！'
						})
						return
					} else if (this.productList.some(item => !item.warehouseLedgerDetails?.length)) {
						uni.showToast({
							icon: 'error',
							title: '请完善明细信息！'
						})
						return
					}

					const params = {
						outInWarehouse: { ...this.formData, bizStatus: 1 },
						warehouseLedgerInfos: this.productList
					}
					postJ(this.apiUrl + '/outInWarehouse/add', params).then(res => {
						if (res?.success) {
							uni.showToast({
								icon: 'success',
								title: '保存成功'
							})
							setTimeout(() => {
								uni.navigateBack({
									delta: 1
								})
							}, 1500)
						}
					})
				})
			},
			// 部门确认
			deptConfirm(data, name) {
				this.formData.deptName = name
				this.formData.deptCode = data[0]
			},
			// 部门确认
			verifyDeptConfirm(data, name) {
				this.formData.verifyDeptCode = data[0]
				this.formData.verifyDeptName = name
				this.formData.verifyId = ''
				this.formData.verifyName = ''

				this.getUser(data[0])
			},
			// 获取部门
			getDept() {
				return
				get(this.apiUrl + '/main/org/dept/effectiveTree').then(res => {
					if (res?.success) {
						this.deptList = res.data
					}
				})
			},
			// 获取供应商
			getSupplier() {
				// post(this.apiUrl + `/main/supplier/list?page=1&size=999`, {
				// 	page: 1,
				// 	size: 999
				// }).then(res => {
				// 	if (res?.success) {
				// 		this.supplierList = res.data.items
				// 	}
				// })
			},

			// 获取人员
			getUser(deptCode) {
				// post(this.apiUrl + '/main/user/list', {
				// 	deptCode,
				// 	page: 1,
				// 	size: 9999
				// }).then(res => {
				// 	if (res?.success) {
				// 		this.userList = res.data.items.map(item => {
				// 			item.name = item.trueName
				// 			item.id = item.userId
				// 			return item
				// 		})
				// 	}
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	.mainBox {
		padding-bottom: 120rpx;

		/deep/.required-form .u-form-item__body__left__content__label::before {
			content: '*';
			color: red;
		}
	}
	.required-form-text {
		/deep/ .u-form-item__body__right {
			overflow: hidden;
			.u-form-item__body__right__content {
				width: 100%;
				display: inline-block !important;
				width: 100%;
			}
		}
	}
	.picList {
		display: flex;
		align-items: center;
		justify-items: flex-start;
		flex-wrap: wrap;
	}
	/deep/.baseForm {
		.u-form-item__body {
			padding: 0px !important;
		}
		.assetType_box {
			padding: 12rpx 18rpx;
			width: 100%;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
		}
	}
	/deep/.picList .u-image {
		margin-right: 10rpx;
		margin-bottom: 10rpx;
	}

	/deep/.cLine .u-line:nth-child(1) {
		border-bottom: none !important;
	}

	.detail-box {
		position: relative;
		display: flex;
		justify-content: space-between;
		align-items: center;

		/deep/uni-button {
			margin: 0 !important;
			width: 180rpx;
		}
		.selectEnterType {
			margin-left: 10rpx !important;
		}
	}

	.footBox {
		position: fixed;
		left: 0px;
		bottom: 0px;
		height: 100rpx;
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;

		view {
			width: 100%;
			height: 100%;
			text-align: center;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
		}

		.reg {
			background: $u-success-dark;
		}

		.add {
			background: $uni-color-primary;
		}

		.uni-icons {
			margin-right: 8rpx !important;
		}
	}

	.listBox {
		padding: 20rpx 10rpx;
		border-bottom: 1px #f2f2f2 solid;
		position: relative;
		&.code {
			.label {
				width: 120rpx !important;
			}
		}
		.listTit {
			width: 100%;
			display: flex;
			justify-content: space-between;
			align-items: center;
			/deep/uni-button {
				margin-right: 20rpx;
				width: 100rpx;

				&.assets {
					width: 180rpx;
				}
			}
			.name {
				width: 50%;
				margin-left: 10px;
				overflow: hidden;
				white-space: nowrap;
				-o-text-overflow: ellipsis;
				text-overflow: ellipsis;
				font-size: 30rpx;
			}

			.btn {
				display: flex;
				justify-content: flex-end;
			}

			.weight {
				width: 30%;
				font-size: 30rpx;
				margin-left: auto;
				margin-right: 60rpx;
				position: relative;
				display: flex;

				input {
					margin-right: 10rpx;
					border: 1px solid black;
					width: 40%;
					height: 20rpx;
				}
			}

			.weight::after {
				position: absolute;
				right: -30rpx;
				top: 50%;
				content: '';
				background: #eee;
				width: 1px;
				height: 28rpx;
				margin-top: -14rpx;
			}
		}
		.z_list {
			max-height: 500rpx;
			.material {
				margin-top: 10rpx;

				.left {
					width: 40rpx;
				}

				.zdy_check {
					width: 30rpx;
					height: 30rpx;
					border: 2rpx solid #c8c9cc;
					border-radius: 4rpx;
				}

				.check_active {
					background: $theme-color;
					border: 2rpx solid $theme-color;

					/deep/ .u-icon__icon {
						color: #fff !important;
					}
				}

				.content_table {
					width: 670rpx;
					border: 2rpx solid $border-color;

					.item {
						display: flex;
						border-bottom: 2rpx solid $border-color;

						.lable {
							width: 200rpx;
							text-align: center;
							background-color: #f7f9fa;
							font-size: 26rpx;
							border-right: 2rpx solid $border-color;
							flex-shrink: 0;
						}

						.ww80 {
							width: 80rpx;
						}

						.content {
							width: 500rpx;
							min-height: 64rpx;
							font-size: 28rpx;
							line-height: 28rpx;
							font-style: normal;
							font-weight: 400;
							padding: 18rpx 8rpx;
							box-sizing: border-box;
							word-wrap: break-word;
							flex-grow: 1 !important;
						}
						.input_box {
							padding: 0 !important;
						}

						.content_num {
							display: flex;
							align-items: center;
							padding: 0 4rpx;

							/deep/ .uni-input-input {
								width: 200rpx;
								border: 2rpx solid #f0f8f2;
								background: #f0f8f2;
								color: $theme-color;
							}

							.unit {
								padding: 0 4rpx;
								font-size: 24rpx;
								color: #404446;
							}
						}

						.ww400 {
							/deep/ .uni-input-input {
								width: 400rpx;
							}
						}

						.pd4 {
							padding: 4rpx 8rpx;
						}

						&:last-child {
							border-bottom: none;
						}
					}

					.ww55 {
						width: 55%;
					}

					.ww45 {
						width: 45%;
					}

					.ww50 {
						width: 50%;
					}

					.ww30 {
						width: 30%;
					}

					.ww70 {
						width: 70%;
					}

					.ww80 {
						width: 80%;
					}

					.ww20 {
						width: 20%;
					}

					.check {
						width: 30rpx;
						height: 30rpx;
					}

					.tag_box {
						padding: 2rpx 10rpx;
						margin-right: 12rpx;
						background: #e6a23c;
						font-size: 22rpx;
						color: #fff;
						border-radius: 4rpx;
					}
				}
			}
		}
		.more {
			position: absolute;
			bottom: 26rpx;
			right: 30rpx;
			font-size: 28rpx;
			color: #666;
		}
	}

	.listCont {
		display: flex;
		align-items: center;
		flex-wrap: wrap;
		margin-top: 20rpx;
		margin-left: 10rpx;

		&.save {
			.u-input {
				border: none;
			}
		}
		.u-input {
			border: 1px solid rgb(229, 229, 229);
			height: 15rpx !important;
		}

		.item {
			width: 47%;
			font-size: 28rpx;
			margin-bottom: 10rpx;
			margin-right: 3%;
			// line-height: 45rpx;
			// overflow: hidden;
			// white-space: nowrap;
			// text-overflow: ellipsis;
			// -o-text-overflow: ellipsis;
			// color: #000;
			// display: flex;
			/deep/.u-form-item__body {
				padding: 0 !important;
			}
			/deep/.u-input__content__field-wrapper__field,
			/deep/.u-form-item {
				font-size: 28rpx !important;
			}

			text.label {
				width: 120rpx;
				display: inline-block;
				text-align: right;
				margin-right: 20rpx;
				margin-bottom: 20rpx;
			}
			/deep/.uni-date__x-input {
				height: 40rpx;
				font-size: 28rpx;
			}

			/deep/.uni-date {
				width: 48%;
				display: inline-block;
				.uni-icons {
					display: none !important;
				}
				.uni-date-x {
					padding: 0 !important;
				}
			}
		}

		.item text {
			color: #666;
		}
	}
	.selectTime {
		display: flex;
		justify-content: flex-end;
		margin-bottom: 10rpx;
		.timeBox {
			display: flex;
			width: 500rpx;
			.firstBtn {
				margin-right: 10rpx;
			}
		}
	}
	.listBox:last-child {
		border: none !important;
	}

	.textBox {
		border: 1px #f2f2f2 solid;
		height: 160px;
		display: block;
		width: auto !important;
	}

	.saveBtn {
		width: 50%;
		margin: 40rpx auto;
	}
	.top-css {
		border-bottom: 1px solid rgb(207, 204, 204);
	}
</style>
