<template>
	<BasicContainer :option="option">
		<!-- 主体内容 -->
		<view class="main">
			<!-- 顶部 -->
			<view class="main_top">
				<input type="text" v-model="details.searchText" placeholder="请输入库位码" class="main_top_search" />
				<view class="button" @click="submitSearch">搜索</view>
			</view>

			<!-- 库位信息 -->
			<view class="main_info">
				<view class="main_info_row">
					<view class="main_info_item">
						<text>合同号:</text>
						<text>{{ article.allocationCode }}</text>
					</view>
				</view>
				<view class="main_info_row">
					<view class="main_info_item">
						<text>合同类型:</text>
						<text>
							{{
					    stock.isInventory == 1 ? '库存品' :
					    zero.isZero == 1 ? '零担' :
					    article.contract
					  }}
						</text>
					</view>
				</view>
				<view class="main_info_row">
					<view class="main_info_item">
						<text>总数:</text>
						<text>{{ article.allNum  }}</text>
					</view>
					<view class="main_info_item">
						<text>已盘数:</text>
						<text>{{article.finishNum}}</text>
					</view>
					<view class="main_info_item">
						<text>库位未盘数:</text>
						<text>{{article.allNum - article.finishNum}}</text>
					</view>
				</view>
			</view>


			<!-- tabBar选项卡 -->
			<view class="tabBar">
				<view class="tabBar-item">{{stock.isInventory==1?'库存品':zero.isZero == 1 ? '零担' :"定制品"}}</view>
			</view>

			<!-- 控件 -->
			<view class="control">
				<view class="button" @click="showControl = true" v-show="!showControl">批量操作</view>
				<view class="button" @click="grounding" v-show="!showControl">添加物料</view>
				<template v-if="showControl">
					<view class="button" @click="handleInvertSelection">反选</view>

					<view class="controlList">
						<view class="button" @click="handleBatchDel">
							批量删除
						</view>
						<view class="button" @click="handleBatchUp">
							批量上架
						</view>
						<view class="button" @click="handleBatchState">
							状态修改
						</view>
					</view>
				</template>
			</view>

			<!-- 列表 -->
			<scroll-view class="scvmabx" @scrolltolower="reachBottomInitPage" scroll-y="true" @touchmove.stop>
				<!-- 按库位盘点 -->
				<template v-if="renderList.length !== 0">
					<view class="list" v-for="(item, index) in renderList" :key="item"
						:class="`list ${details.activeColor[item.questStatus]}`">
						<!-- 复选框 -->
						<view class="leftIcon">
							<template v-if="item.questStatus !== 3">
								<image class="checkImage" @click="details.checkList[index] = !details.checkList[index]"
									:src="details.checkList[index]?'/pagesHome/static/check.png':'/pagesHome/static/nocheck.png'">
								</image>
							</template>
						</view>

						<!-- 定制品 -->
						<template v-if="stock.isInventory !== 1 && zero.isZero !== 1">
							<!-- 						<view class="table_article">
								<view class="table_head">
									<view class="">包条码</view>
									<view class="">合同号</view>
									<view class="">库位</view>
									<view class="">状态</view>
									<view class="">操作</view>
								</view>

								<view class="table_body">
									<view>{{item.orderPackageCode}}</view>
									<view>{{item.orderCode}}</view>
									<view>{{item.allocation}}</view>
									<view>{{item.currentStatus==1?'在库':'1'}}</view>
									<view class="">
										<view class="button" @click="handleState(item)">处理</view>
										<view class="button" @click="upDataItem(item)">上架</view>
									</view>
								</view>
							</view> -->
							<view class="rightMsg">
								<view class="tpbx" v-if="item.questStatus !== 3">
									<view style="flex: none;">
										操作:
									</view>
									<view style="display: flex; justify-content: space-around;">
										<text class="button" @click="handleState(item)">处理</text>
										<text class="button" @click="upDataItem(item)">上架</text>
									</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>包条码：{{item.orderPackageCode}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>合同号：{{item.orderCode}}</view>
								</view>

								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>库位：{{item.allocation}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>状态：{{item.currentStatus==1?'在库':'1'}}</view>
								</view>
							</view>
						</template>

						<!-- 零担 -->
						<template v-else-if="zero.isZero === 1">
							<view class="rightMsg">
								<view class="tpbx" v-if="item.questStatus !== 3">
									<view style="flex: none;">
										操作:
									</view>
									<view style="display: flex; justify-content: space-around;">
										<text class="button" @click="handleState(item)">处理</text>
										<text class="button" @click="upDataItem(item)">上架</text>
									</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>合同号：{{item.orderCode}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>运单号：{{item.waybillNub}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>数量：{{item.quantity}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>库位：{{item.allocation}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>状态：'在库</view>
								</view>
							</view>
						</template>

						<!-- 库存品 -->
						<template v-else>
							<view class="rightMsg">
								<view class="tpbx" v-if="item.questStatus !== 3">
									<view style="flex: none;">
										操作:
									</view>
									<view style="display: flex; justify-content: space-around;">
										<text class="button" @click="handleState(item)">处理</text>
										<text class="button" @click="upDataItem(item)">上架</text>
									</view>
								</view>

								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>合同号：{{item.orderCode}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>库位：{{item.allocation}}</view>
								</view>
								<view class="tpbx" v-if='stock.isInventory==1'>
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>物料编码：{{item.materialCode}}</view>
								</view>
								<view class="tpbx" v-if='stock.isInventory==1'>
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>物料名称：{{item.materialName}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>数量：{{item.quantity}}</view>
								</view>
								<view class="tpbx">
									<image src="/pagesHome/static/kuweiicon.png"></image>
									<view>状态：{{item.currentStatus==1?"在库":''}}</view>
								</view>
							</view>
						</template>
					</view>
				</template>
			</scroll-view>

			<!-- 提交 -->
			<button @click="submitCheck" class="submitButton" type="primary">提交盘点</button>
		</view>
		<saomiao2></saomiao2>
		<tiplist ref="tiplists"></tiplist>
		<view class="popUp" @click="details.showUpData = false" v-if="details.showUpData">
			<view class="container" @click.stop>
				<view style="text-align: center;" class="">
					上架
				</view>
				<view class="up" style="height: 100px;">
					<input style="padding: 10px; border: 1px solid #000;" type="text" v-model="details.scancode"
						placeholder="扫描或输入库位码" id="">
				</view>
				<view style="display: flex; align-items: center;" class="">
					<button style="flex:  1;" @click.stop="details.showUpData = false" class="button">取消</button>
					<button style="flex: 1;" @click.stop="upDataForm" class="button">上架</button>
				</view>
			</view>
		</view>
	</BasicContainer>
</template>

<script setup lang="ts">
	import {
		onShow,
		onLoad,
		onHide,
	} from '@dcloudio/uni-app'
	import { ref, reactive, toRefs, watch } from "vue";

	import {
		getWarehouseTaskAllocationDetailByStrip,
		getallocationDetailByZeroWaList,
		getallocationDetailByStockList,
		pcontractQuestDetailList,
		getWarehouseUpdateQuestDetail,
		postqueryupdateQuestDetailAllocation,
		getWarehouseDeleteQuestDetail,
		getWarehouseSaveNewQuestDetail
	} from '@/api/user.js';
	import utils from '@/utils/utils.js';

	const option = reactive({
		// 页面标题
		title: '按合同号盘点',
		isEnd: false,
		haveData: true,
		async pullDownRefreshInitPage() {
			console.log('下拉刷新')
			// // 页面信息清空
			// article.articleList = []
			// return initPage()
		},
		async reachBottomInitPage() {
			console.log('触底加载')

			return true
		}
	})

	const details = reactive({
		// 选项卡页码
		tabBarCode: 3,
		// 是否显示控件
		showControl: false,
		// 搜索框的值
		searchText: '',
		// 扫描后的值
		scancode: '',
		// 是否为扫描
		isScan: false,
		// 渲染的列表
		renderList: [],
		checkList: [],
		allocationId: '',
		questId: '',
		showUpData: false,
		isUpScan: false,
		// 是否为批量操作
		isBatch: false,
		// 单一上架的数据
		upItme: {},
		// 状态样式
		activeColor: [
			'normal',
			'green',
			'',
			'red'
		],
		marketName: [],
		goodsType: ''
	})
	const infos = ref({})//路由传入进来的参数
	// 定制品
	const article = reactive({
		// 定制品列表
		articleList: [],
		// 定制品复选框列表
		articleCheckList: [],
		articlePage: {
			current: 1,
			size: 10,
		},
		total: 0,
		// 库位号
		allocationCode: '',
		// 总数
		allNum: '',
		// 已盘点
		finishNum: '',
		// 合同类型
		contract: '',
		isInventory: 0,
	})

	// 零担
	const zero = reactive({
		// 零担列表
		zeroList: [],
		// 零担复选框列表
		zeroCheckList: [],
		zeroPage: {
			current: 1,
			size: 10,
		},
		// 总数
		total: 0,
		// 库位号
		allocationCode: '',
		// 总数
		allNum: '',
		// 已盘点
		finishNum: '',
		// 合同类型
		contract: '',
		isZero: 0
	})

	// 库存品
	const stock = reactive({
		// 库存品列表
		stockList: [],
		// 库存品复选框列表
		stockCheckList: [],
		stockPage: {
			current: 1,
			size: 10,
		},
		total: 0,
		// 库位号
		allocationCode: '',
		// 总数
		allNum: '',
		// 已盘点
		finishNum: '',
		// 合同类型
		contract: '',
		renderList: '',
		isInventory: null
	})

	const {
		showControl,
		tabBarCode,
		renderList,
	} = toRefs(details)

	const tiplists = ref(null)

	// 页面初始化执行回调
	onLoad((info) => {
		infos.value = info
		details.marketName = JSON.parse(info.marketName)
		console.log(info, 'infos==========');
		Tjinfo()//初始化请求数据
	})

	// 开启监听扫描
	onShow(() => {
		uni.$on('scancodedate', function (code) {
			if (code) {
				details.scancode = code
				console.log(code);
				scandata()
			}
		})
	})

	// 关闭扫描监听
	onHide(() => {
		uni.$off('scancodedate')
	})

	// 添加防抖函数
	let antiShake : any = null
	// 触底加载
	function reachBottomInitPage() {
		// 数据请求完毕, 不再请求
		// if (option.isEnd) {
		// 	return uni.showToast({
		// 		icon: 'success',
		// 		title: '数据已加载完毕'
		// 	})
		// }
		// if (antiShake) {
		// 	uni.hideLoading()
		// 	// 清空定时器
		// 	clearTimeout(antiShake)
		// 	return antiShake = null
		// }
		// // 显示Loading, 并阻止点击屏幕
		// uni.showLoading({
		// 	title: '正在加载',
		// 	mask: true
		// })
		// antiShake = setTimeout(async () => {
		// 	// 触底请求
		// 	console.log('触底')
		// 	// 定制品
		// 	if (tabBarCode.value === 1) { Tjinfo() }
		// 	// 零担
		// 	if (tabBarCode.value === 2) { Tjinfo() }
		// 	// 库存品
		// 	if (tabBarCode.value === 3) { Tjinfo() }

		// 	// 关闭Loading效果
		// 	uni.hideLoading()
		// 	// 清空定时器
		// 	antiShake = null
		// }, 1000)
	}

	// 请求页面数据
	async function initPage() {
		// 请求定制品数据
		if (tabBarCode.value === 1) return initArticle()
		// 请求零担数据
		if (tabBarCode.value === 2) return initZero()
		// 请求库存品数据
		if (tabBarCode.value === 3) return initStock()
	}

	// 公共判断
	function Tjinfo() {
		const FormData = {
			warehouseId: infos.value.warehouseId,
			taskId: infos.value.taskId,
			orderCode: infos.value.orderCode,
			isInventory: infos.value.isInventory
		}

		console.log('infos :>> ', infos);
		if (infos.value.isInventory === '1') {
			FormData.orderCode = infos.value.martialCode
		}


		pcontractQuestDetailList(FormData).then(res => {
			console.log(res);
			// 库存品
			if (res.data.isInventory == 1) {
				stock.isInventory = res.data.isInventory
				stock.contract = '库存品'
				stock.allocationCode = res.data.packagelistVOList
				details.renderList = res.data.packagelistVOList
				stock.allNum = res.data.total//总数
				console.log(stock.allocationCode, '列表');
				stock.finishNum = res.data.unTotal//已盘数
				stock.renderList = res.data.packagelistVOList
				stock.isInventory = res.data.isInventory
			} else if (res.data.isZero === 1) {
				zero.isZero = 1
			}
			// 默认定制品
			article.contract = '定制品'
			article.allocationCode = res.data.orderCode
			article.allNum = res.data.total//总数
			article.finishNum = res.data.unTotal//已盘数
			details.renderList = res.data.packagelistVOList
			details.checkList = details.renderList.map(() => false)
			if (stock.isInventory === 1) details.goodsType = '库存品'
			else if (zero.isZero === 1) details.goodsType = '零担'
			else details.goodsType = '定制品'
		})
	}


	/**
	 * 请求定制品数据
	 */


	async function initArticle() {
		// Tjinfo()
	}

	/**
	 * 请求零担数据
	 */
	async function initZero() {
		// Tjinfo()
	}

	/**
	 * 请求库存品数据
	 */
	async function initStock() {
		// Tjinfo()	
	}

	// 扫描后执行的回调
	async function scandata() {
		if (details.goodsType !== '定制品') return
		details.scancode
		const flag = details.renderList.find(val => val.orderPackageCode === details.scancode)
		console.log('flag :>> ', flag);
		// 当包件存在
		if (flag) {
			const questDetailList = [{
				id: flag.questDetailId,
				// 在库数
				stockNum: flag.quantity,
				// 丢失
				lossNum: 0,
				// 配送
				deliveNum: 0,
				// 破损
				wornNum: 0,
				// 不可修复
				noRepairNum: 0,
				// 未入库
				noReceivedNum: 0,
			}]
			const res = await getWarehouseUpdateQuestDetail({ questDetailList, questId: infos.value.taskId })
			const { code, msg } = res
			console.log('res :>> ', res);
			if (code === 200) {
				Tjinfo()
				utils.ttsspke(msg)
			}
		} else {
			grounding()
		}
	}

	// 改变选项卡激活状态
	function handleTabBarCode(code : number) {
		showControl.value = false
		tabBarCode.value = code
		console.log(code);
		initPage()
	}

	/**
	 * 提交搜索请求
	 */
	function submitSearch() {
		uni.showToast({
			title: '功能还在开发中',
			icon: 'none'
		})
	}

	/**
	 * 提交盘点
	 */
	function submitCheck() {
		uni.navigateBack()
	}

	/**
	 * 复选框反选
	 */
	function handleInvertSelection() {
		details.checkList = details.checkList.map(val => !val)
	}

	/**
	 * 批量删除
	 */
	function handleBatchDel() {
		let checkList = details.checkList
		if (!checkList.some(val => val)) {
			return uni.showToast({
				icon: 'none',
				title: '最少选择一条数据'
			})
		}
		const questDetailList = []
		details.renderList.forEach((val, index) => { if (checkList[index]) questDetailList.push({ id: val.id }) })
		tiplists.value.setdetails({
			title: '确认批量删除',
			isshow: true,
			tipstate: 2,
			list: [],
			confirmTxt: '确认删除',
			isonecheck: true,
			success: (deta) => {
				// const res = getWarehouseUpdateQuestDetail({ ids })
				// console.log('res :>> ', res);
				try {
					getWarehouseDeleteQuestDetail({ questDetailList, questId: infos.value.taskId }).then(res => {
						initPage()
						utils.ttsspke(res.msg)
					})
				} catch (e) {
					//TODO handle the exception
				} finally {
					tiplists.value.setdetails({ isshow: false })
				}
			},
			cancel: () => {
				tiplists.value.setdetails({ isshow: false })
			},
			close: () => {
				tiplists.value.setdetails({ isshow: false })
			}
		})
	}


	/**
	 * 批量上架
	 */
	function handleBatchUp() {
		details.isUpScan = true
		details.showUpData = true
		details.isBatch = true
	}

	/**
	 * 单个上架
	 */
	function upDataItem(item) {
		// 开启上架扫描
		details.isUpScan = true
		details.showUpData = true
		details.isBatch = false
		details.upItme = item
	}

	/**
	 * 提交上架
	 */
	async function upDataForm() {
		try {
			if (!details.scancode) return uni.showToast({
				title: '请输入或扫描库位码',
				icon: 'none'
			})
			let arr : any = []
			// 批量操作
			if (details.isBatch) {
				// arr = details.renderList.filter((v, i) => )
				// 定制品
				arr = details.renderList.filter((v, i) => details.checkList[i])

			} else {
				arr = [details.upItme]
			}
			if (arr.length === 0) {
				uni.showToast({
					title: '最少选择一条数据',
					icon: 'none'
				})
				utils.ttsspke('最少选择一条数据')
				return
			}
			const questDetailList = arr.map(val => { return { id: val.questDetailId } })
			const res = await postqueryupdateQuestDetailAllocation({ allocationId: details.scancode, questId: infos.value.taskId, questDetailList })
			if (res.code === 200) {
				Tjinfo()
			}
			utils.ttsspke(res.msg)
		} catch (err) {
			console.log('err :>> ', err);
			//TODO handle the exception
		} finally {
			// 关闭弹窗
			details.showUpData = false
			details.isBatch = false
		}
	}

	/**
	 * 修改单个状态
	 */
	function handleState(item) {
		try {
			const checkSectionList = [
				{
					title: '丢失',
					isCheck: false,
					value: 0,
					disabled: true
				},
				{
					title: '配送',
					isCheck: false,
					value: 0,
					disabled: true
				},
				{
					title: '破损',
					isCheck: false,
					value: 0,
					disabled: true
				},
				{
					title: '不可修复',
					isCheck: false,
					value: 0,
					disabled: true
				},
				{
					title: '未入库',
					isCheck: false,
					value: 0,
					disabled: true
				}
			]
			// 定制品
			if (stock.isInventory !== 1 && zero.isZero !== 1) {
				tiplists.value.setdetails({
					title: '修改状态',
					isshow: true,
					tipstate: 6,
					list: [{ title: '在库', value: item.quantity }],
					checkSectionList,
					checklist: [],
					inputtext: '',
					confirmTxt: '确认选择',
					isonecheck: true,
					success: async (deta) => {
						const { checklist, checkSectionList } = deta
						if (checklist.length == 0) {
							uni.showToast({
								title: '请选择修改的状态',
								icon: 'none'
							})
							return
						}
						if (checkSectionList[checklist[0]].value === 0) {
							return uni.showToast({
								title: '请输入修改的数量',
								icon: 'none'
							})
						}
						const questDetailList = [{
							id: item.questDetailId,
							// 在库数
							stockNum: item.quantity,
							// 丢失
							lossNum: checkSectionList[0].value,
							// 配送
							deliveNum: checkSectionList[1].value,
							// 破损
							wornNum: checkSectionList[2].value,
							// 不可修复
							noRepairNum: checkSectionList[3].value,
							// 未入库
							noReceivedNum: checkSectionList[4].value,
						}]
						const res = await getWarehouseUpdateQuestDetail({ questDetailList, questId: details.questId })
						const { code } = res
						if (code === 200) Tjinfo()
						tiplists.value.setdetails({ isshow: false })
					},
					cancel: () => {
						tiplists.value.setdetails({ isshow: false })
					},
					close: () => {
						tiplists.value.setdetails({ isshow: false })
					}
				})
				// 零担和库存品
			} else {
				tiplists.value.setdetails({
					title: '修改状态',
					isshow: true,
					tipstate: 6,
					list: [{ title: '在库', value: item.quantity }],
					checkSectionList,
					checklist: [],
					inputtext: '',
					confirmTxt: '确认选择',
					isonecheck: false,
					success: async (deta) => {
						const { checklist, checkSectionList } = deta
						if (checklist.length == 0) {
							uni.showToast({
								title: '请选择修改的状态',
								icon: 'none'
							})
							return
						}
						if (checkSectionList[checklist[0]].value === 0) {
							return uni.showToast({
								title: '请输入修改的数量',
								icon: 'none'
							})
						}
						const questDetailList = [{
							id: item.questDetailId,
							// 在库数
							stockNum: item.quantity,
							// 丢失
							lossNum: checkSectionList[0].value,
							// 配送
							deliveNum: checkSectionList[1].value,
							// 破损
							wornNum: checkSectionList[2].value,
							// 不可修复
							noRepairNum: checkSectionList[3].value,
							// 未入库
							noReceivedNum: checkSectionList[4].value,
						}]
						const res = await getWarehouseUpdateQuestDetail({ questDetailList, questId: infos.value.taskId })
						const { code } = res
						if (code === 200) initPage()
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						utils.ttsspke(res.msg)
						tiplists.value.setdetails({ isshow: false })
					},
					cancel: () => {
						tiplists.value.setdetails({ isshow: false })
					},
					close: () => {
						tiplists.value.setdetails({ isshow: false })
					}
				})
			}
		} catch (e) {
			//TODO handle the exception
		} finally { }
	}

	/**
	 * 批量修改状态
	 */
	function handleBatchState() {
		if (!details.checkList.some(val => val)) {
			return uni.showToast({
				icon: 'none',
				title: '最少选择一条数据'
			})
		}
		const questDetailList = []
		details.renderList.forEach((val, index) => {
			if (details.checkList[index]) {
				questDetailList.push({
					id: val.questDetailId,
					// 在库数
					stockNum: val.quantity,
					// 丢失
					lossNum: 0,
					// 配送
					deliveNum: 0,
					// 破损
					wornNum: 0,
					// 不可修复
					noRepairNum: 0,
					// 未入库
					noReceivedNum: 0,
				})
			}
		})
		tiplists.value.setdetails({
			title: '确定批量修改',
			isshow: true,
			tipstate: 2,
			list: [],
			confirmTxt: '确认修改',
			isonecheck: true,
			success: (deta) => {
				// const res = getWarehouseUpdateQuestDetail({ ids })
				// console.log('res :>> ', res);
				try {
					getWarehouseUpdateQuestDetail({ questDetailList, questId: infos.value.taskId }).then(res => {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						});
						utils.ttsspke(res.msg)
						Tjinfo()
					})
				} catch (e) {
					//TODO handle the exception
				} finally {
					tiplists.value.setdetails({ isshow: false })
				}
			},
			cancel: () => {
				tiplists.value.setdetails({ isshow: false })
			},
			close: () => {
				tiplists.value.setdetails({ isshow: false })
			}
		})
	}

	/**
	 * 新增物料
	 */
	function grounding() {
		const marketName = Array.from(details.marketName)
		console.log('marketName :>> ', marketName);
		let goodsType = details.goodsType

		tiplists.value.setdetails({
			title: '新增',
			isshow: true,
			tipstate: 5,
			upform: {
				article: {
					// 合同号
					contractNumber: '',
					// 包条码
					orderPackageCode: details.scancode
				},
				stock: {}
			},
			marketName,
			// goodsType: '库存品',
			goodsType,
			confirmTxt: '确认新增',
			isonecheck: true,
			success: async (deta) => {
				let submitData : any = {}

				if (goodsType === '定制品') submitData = articleAdd(deta)
				if (goodsType === '零担') {
					uni.showToast({
						title: '功能还在开发中'
					})
					tiplists.value.setdetails({ isshow: false })
					return submitData = zeroAdd(deta)
				}
				if (goodsType === '库存品') submitData = stockAdd(deta)

				const res = await getWarehouseSaveNewQuestDetail(submitData)
				console.log('res :>> ', res);
				const { code } = res
				if (code === 200) {
					Tjinfo()
					uni.showToast({
						title: '操作成功',
						icon: 'success'
					})
				}
				tiplists.value.setdetails({ isshow: false })
			},
			cancel: () => {
				tiplists.value.setdetails({ isshow: false })
			},
			close: () => {
				tiplists.value.setdetails({ isshow: false })
			}
		})
	}

	// 定制品添加
	function articleAdd(deta) {
		const { upform: { article: { contractNumber, orderPackageCode } } } = deta
		if (!contractNumber) return uni.showToast({
			title: '请输入合同号',
			icon: 'none'
		})

		if (!orderPackageCode) return uni.showToast({
			title: '请输入或扫描包条码',
			icon: 'none'
		})

		const submitData = {
			questDetail: {
				ordePackageCode: orderPackageCode,
				orderCode: contractNumber,
				stockNum: 1,
			},
			orderCode: article.allocationCode,
			questTarget: 1,
			questType: 3,
			questId: infos.value.taskId,
		}
		return submitData
	}

	// 零担添加
	function zeroAdd(deta) { }

	// 库存品添加
	function stockAdd(deta) {
		console.log('deta :>> ', deta);
		const { upform: { stock: { orderCode, stockNum, marketName, incomingBatch } } } = deta
		// if (!contractNumber) return uni.showToast({
		// 	title: '请输入合同号',
		// 	icon: 'none'
		// })

		// if (!orderPackageCode) return uni.showToast({
		// 	title: '请输入或扫描包条码',
		// 	icon: 'none'
		// })
		console.log('data :>> ', deta);
		const submitData = {
			questDetail: {
				orderCode: orderCode,
				stockNum: stockNum,
				marketName,
				incomingBatch
			},
			orderCode: article.allocationCode,
			questTarget: 3,
			questType: 3,
			questId: infos.value.taskId,
		}

		return submitData
	}

	// watch([articleList, zeroList, stockList, tabBarCode], () => {
	// 	// 定制品
	// 	if (tabBarCode.value === 1) {
	// 		return renderList.value = articleList.value
	// 	}
	// 	// 零担
	// 	if (tabBarCode.value === 2) {
	// 		return renderList.value = zeroList.value
	// 	}
	// 	// // 库存品
	// 	if (tabBarCode.value === 3) {
	// 		return renderList.value = stockList.value
	// 	}
	// })
</script>

<style lang="scss" scoped>
	$buttonColor: #d3832a;

	// 本页按钮样式
	.button {
		font-size: 28upx;
		padding: 10upx 20upx;
		border: 1upx solid $buttonColor;
		background-color: #fff;
		color: #d3832a;
		border-radius: 5upx;
	}

	.main {
		padding: 10upx;
		font-size: 28upx; // 本页字体大小
	}

	.main_top {
		display: flex;
		// align-items: center;
		justify-content: space-between;
		margin-bottom: 10upx;

		// 顶部搜索框
		&_search {
			flex: 1;
			padding-left: 20upx;
			margin-right: 20upx;
			box-sizing: border-box;
			height: 28upx * 2;
			border-radius: 28upx;
			border: 1upx solid #000;
		}

		.button {
			background-color: $buttonColor;
			color: #fff;
			padding: 0 60upx;
			display: inline-flex;
			align-items: center;
		}
	}

	// 顶部信息区
	.main_info {
		margin-bottom: 10upx;
		padding: 10upx;
		background-color: #fff;

		&_row {
			padding: 10upx 0;
			display: flex;
			justify-content: space-between;
			border-bottom: 2upx solid #000;

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

		&_item {
			flex: 1;
			flex-basis: 0;
			display: inline-flex;

			text:first-child {
				margin-right: 10upx;
			}
		}
	}

	// tabBar选项卡
	.tabBar {
		display: flex;
		justify-content: space-evenly;
		background-color: #fff;
		margin-bottom: 10upx;

		&-item {
			position: relative;
			flex: 1;
			flex-basis: 0;
			padding: 20upx 0;
			text-align: center;

			&::after {
				content: '';
				position: absolute;
				bottom: 0;
				left: 50%;
				display: block;
				width: 0;
				box-sizing: border-box;
				border: 1upx solid $buttonColor;
				transition: all 0.5s;
			}

			&.active {
				color: $buttonColor;

				&::after {
					left: 0;
					width: 100%;
				}
			}
		}
	}

	// 控件区
	.control {
		display: flex;
		justify-content: space-between;

		.controlList {
			display: flex;

			.button {
				margin: 0 5upx;

				&:last-child {
					margin-right: 0;
				}
			}
		}
	}

	// 滚动区
	.scvmabx {
		width: 100%;
		height: 60vh;
	}

	.list {
		display: flex;
		margin: 20upx 0;
		padding: 0 10upx;
		border-radius: 10upx;
		box-shadow: 0 0 20upx #d3832a;

		&.normal {
			background-color: none;
		}

		&.green {
			background: #eaffc9;
		}

		&.red {
			background: #ffc9c9;
		}

		.leftIcon {
			flex: none;
			margin-right: 30upx;
			// padding-top: 18upx;

			.checkImage {
				width: 48upx;
				height: 48upx;
			}
		}

		.rightMsg {
			flex: 1;
		}
	}


	.table_article {
		text-align: center;
		flex: 1;

		.table_head {
			display: flex;

			view {
				flex: 1;
			}
		}

		.table_body {
			display: flex;

			view {
				flex: 1;
				flex-basis: 1;
				word-break: break-all;
			}

		}
	}

	// 列表
	.tpbx {
		display: flex;
		align-items: center;
		// padding: 18upx 24upx;
		box-sizing: border-box;
		border-bottom: 4upx solid #EEEEEE;

		>image {
			flex: none;
			width: 64upx;
			height: 64upx;
			margin-right: 15upx;
		}

		>view {
			flex: 1;
			font-size: 28upx;
			font-weight: 400;
			color: #020B18;

			.numb {
				font-size: 28upx;
				color: #178AF2;
			}
		}
	}

	.viewnum {
		height: 100upx;
		display: flex;
		align-items: center;
		justify-content: space-around;

		>view {
			font-size: 28upx;
			font-weight: 400;
			color: #020B18;
		}
	}

	// 提交按钮
	.submitButton {
		position: fixed;
		color: #fff;
		background-color: $buttonColor;
		width: 50%;
		bottom: 30upx;
		left: 50%;
		transform: translateX(-50%);
	}

	// 弹出层
	.popUp {
		width: 100vw;
		height: 100vh;
		background: #00000033;
		position: fixed;
		top: 0;
		left: 0;
		display: flex;
		align-items: center;
		justify-content: center;

		.container {
			width: 70%;
			height: 35%;
			background: #fff;
			border-radius: 10upx;
			padding: 20upx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.button {
				margin: 0 20upx;
			}
		}
	}
</style>