<template>
	<view class="container">
		<!-- 主内容区域 -->
		    <scroll-view class="content" scroll-y="true">
				
		      <!-- 基础信息 -->
		      <view class="section">
		        <view class="section-header">
		          <text class="section-title">基础信息</text>
		        </view>
		        <view class="info-card" v-if="pallet">
		          <view class="info-row">
		            <text class="label">工装托盘编号:</text>
		            <text class="value">{{pallet.palletNo || '-' }}</text>
		          </view>
		         <!-- <view class="info-row">
		            <text class="label">外形尺寸:</text>
		            <text class="value">{{pallet.size || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">载重:</text>
		            <text class="value">{{pallet.load || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">使用状态:</text>
		            <text class="value status-used">{{ retType(pallet.palletStatus,3) || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">创建日期:</text>
		            <text class="value">{{pallet.createDate || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">备注:</text>
		            <text class="value">{{pallet.remark || '-' }}</text>
		          </view> -->
		          <view class="info-row">
		            <text class="label">转运状态:</text>
		            <text class="value status-transit">{{ retType(pallet.status,1)|| '-' }}</text>
		          </view>
		         <!-- <view class="info-row">
		            <text class="label">当前转运状态:</text>
		            <text class="value">{{pallet.deliveryId || '-' }}</text>
		          </view> -->
		          <view class="info-row">
		            <text class="label">存放部门:</text>
		            <text class="value">{{ retType(pallet.departCode,2) || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">存放工场:</text>
		            <text class="value">{{pallet.workshop || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">存放区域:</text>
		            <text class="value">{{pallet.location || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">存放地址:</text>
		            <text class="value">{{pallet.address || '-' }}</text>
		          </view>
		           <view class="info-row">
		            <text class="label">确认时间:</text>
		            <text class="value">{{pallet.confirmTime || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">确认人员:</text>
		            <text class="value">{{pallet.confirmName || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">存放天数:</text>
		            <text class="value">{{pallet.stayDays || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">装盘船只:</text>
		            <text class="value">{{pallet.loadProject || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">装盘安装托盘表号:</text>
		            <text class="value">{{pallet.loadInst || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">装盘数量:</text>
		            <text class="value">{{pallet.loadQty || '-' }}</text>
		          </view>
				  <view class="info-row">
				    <text class="label">装盘信息:</text>
				    <text class="value">{{pallet.loadDesc || '-' }}</text>
				  </view>
				  <view class="info-row" v-if="pallet.status=='03'||pallet.status=='04'">
				    <text class="label">去向部门:</text>
				    <text class="value">{{ retType(pallet.toDepartCode,2) || '-' }}</text>
				  </view>
				  <view class="info-row" v-if="pallet.status=='03'||pallet.status=='04'">
				    <text class="label">去向工场:</text>
				    <text class="value">{{pallet.toWorkshop || '-' }}</text>
				  </view>
				  <view class="info-row" v-if="pallet.status=='03'||pallet.status=='04'">
				    <text class="label">去向位置:</text>
				    <text class="value">{{pallet.toLocation || '-' }}</text>
				  </view>
				  <view class="info-row" v-if="pallet.status=='03'||pallet.status=='04'">
				    <text class="label">去向地址:</text>
				    <text class="value">{{pallet.toAddress || '-' }}</text>
				  </view>
				  <view class="info-row">
				    <text class="label">转运时间:</text>
				    <text class="value">{{pallet.fromTime || '-' }}</text>
				  </view>
				  <view class="info-row">
				    <text class="label">转运人员:</text>
				    <text class="value">{{pallet.fromName || '-' }}</text>
				  </view>
		          <!-- <view class="info-row">
		            <text class="label">装盘时间:</text>
		            <text class="value">{{pallet.loadTime || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">装盘人:</text>
		            <text class="value">{{pallet.loadName || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">配送单号:</text>
		            <text class="value">{{pallet.deliveryNo || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">车辆牌号:</text>
		            <text class="value">{{pallet.deliveryCar || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">配送/转运部门:</text>
		            <text class="value">{{ retType(pallet.fromDepartCode,2)|| '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">配送/转运工场:</text>
		            <text class="value">{{pallet.fromWorkshop || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">配送/转运区域:</text>
		            <text class="value">{{pallet.fromLocation || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">配送/转运地址:</text>
		            <text class="value">{{pallet.fromAddress || '-' }}</text>
		          </view>
		           
		          <view class="info-row">
		            <text class="label">配送/转运人员电话:</text>
		            <text class="value">{{pallet.fromPhone || '-' }}</text>
		          </view> -->
		          <!-- <view class="info-row">
		            <text class="label">配送/转运备注:</text>
		            <text class="value">{{pallet.fromRemark || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">去向接收人员:</text>
		            <text class="value">{{pallet.toName || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">去向接收人员电话:</text>
		            <text class="value">{{pallet.toPhone || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收部门:</text>
		            <text class="value">{{ retType(pallet.receiveDepartCode,2) || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收工场:</text>
		            <text class="value">{{pallet.receiveWorkshop || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收区域:</text>
		            <text class="value">{{pallet.receiveLocation || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收地址:</text>
		            <text class="value">{{pallet.receiveAddress || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收时间:</text>
		            <text class="value">{{pallet.receiveTime || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收人员:</text>
		            <text class="value">{{pallet.receiveName || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收人员电话:</text>
		            <text class="value">{{pallet.receivePhone || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">接收备注:</text>
		            <text class="value">{{pallet.receiveRemark || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">卸盘时间:</text>
		            <text class="value">{{pallet.finishTime || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">卸盘人员:</text>
		            <text class="value">{{pallet.finishName || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">卸盘人员电话:</text>
		            <text class="value">{{pallet.finishPhone || '-' }}</text>
		          </view>
		          <view class="info-row">
		            <text class="label">卸盘备注:</text>
		            <text class="value">{{pallet.finishRemark || '-' }}</text>
		          </view> -->
		        </view>
		      </view>
		
		      <!-- 装盘明细 -->
		      <view class="section">
		        <view class="section-header">
		          <text class="section-title">装盘明细（{{pallet&&pallet.instdetailList?pallet.instdetailList.length:0}}）</text>
		        </view>
		        <view class="list-container" v-if="pallet&&pallet.instdetailList">
		          <view v-for="(item, index) in pallet.instdetailList" :key="index" class="list-item">
					  
					<view class="item-header" @click="gotocxDetail(item.instno,item.project)">
						<text class="item-tip">{{ item.groupDesc }} ({{ item.qty?parseFloat(item.qty).toFixed(2):'0.00'}})</text>
					</view>
					
		            <view class="item-header" @click="toggleDetail(index)">
		              <text class="item-title">{{ item.assemcode }} ({{ item.qty?parseFloat(item.qty).toFixed(2):'0.00' }})</text>
					  <!-- <text class="status-badge" :class="getStatusClass(item.status)">{{item.status}}</text> -->
		              <uni-icons :type="expandedIndex === index ? 'arrowup' : 'arrowdown'" size="16" color="#999"></uni-icons>
		            </view>
		            <view v-if="expandedIndex === index" class="item-content">
		              <view class="detail-row">
		                <text class="label">工程编号:</text>
		                <text class="value">{{ item.project }}</text>
		              </view>
					  <view class="detail-row">
					    <text class="label">安装托盘表号:</text>
					    <text class="value">{{ item.instno }}</text>
					  </view>
		              <view class="detail-row">
		                <text class="label">制作图号:</text>
		                <text class="value">{{ item.dwgno }}</text>
		              </view>
		              <!-- <view class="detail-row">
		                <text class="label">分段号:</text>
		                <text class="value">{{ item.section }}</text>
		              </view> -->
		              <view class="detail-row">
		                <text class="label">规格:</text>
		                <text class="value">{{ item.spec }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">材质:</text>
		                <text class="value">{{ item.grd }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">数量:</text>
		                <text class="value">{{ item.qty }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">重量:</text>
		                <text class="value">{{ item.weight }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">表面处理:</text>
		                <text class="value">{{ item.treatment }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">涂装代码:</text>
		                <text class="value">{{ item.paintcode }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">修改类型:</text>
		                <text class="value">{{ item.modifyType }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">修改卡号:</text>
		                <text class="value">{{ item.modifyKh }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">修改通知单号:</text>
		                <text class="value">{{ item.modifyDwgno }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">修改日期:</text>
		                <text class="value">{{ item.modifyDate }}</text>
		              </view>
		              <!-- <view class="detail-row">
		                <text class="label">生产状态:</text>
		                <text class="value">{{ item.status }}</text>
		              </view> -->
		             <!-- <view class="detail-row">
		                <text class="label">状态日期:</text>
		                <text class="value">{{ item.statusDate }}</text>
		              </view> -->
		              <view class="detail-row">
		                <text class="label">制作单位:</text>
		                <text class="value">{{ item.manuDept }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">处理单位:</text>
		                <text class="value">{{ item.treatDept }}</text>
		              </view>
		              <!-- <view class="detail-row">
		                <text class="label">配送单位:</text>
		                <text class="value">{{ item.deliverDept }}</text>
		              </view> -->
		              <view class="detail-row">
		                <text class="label">工装托盘编号:</text>
		                <text class="value">{{ item.palletNo }}</text>
		              </view>
		              <!-- <view class="detail-row">
		                <text class="label">工装托盘转运记录ID:</text>
		                <text class="value">{{ item.deliveryId }}</text>
		              </view> -->
		              <!-- <view class="detail-row">
		                <text class="label">配送单号:</text>
		                <text class="value">{{ item.deliveryNo }}</text>
		              </view> -->
		              <view class="detail-row">
		                <text class="label">配送车辆:</text>
		                <text class="value">{{ item.deliveryCar }}</text>
		              </view>
		              <!-- <view class="detail-row">
		                <text class="label">配送日期:</text>
		                <text class="value">{{ item.deliveryDate }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">配送备注:</text>
		                <text class="value">{{ item.deliveryRemark }}</text>
		              </view> -->
		              <view class="detail-row">
		                <text class="label">需求日期:</text>
		                <text class="value">{{ item.requireRate }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">需求单位:</text>
		                <text class="value">{{ retType(item.requireDepartCode,2) }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">配送地址:</text>
		                <text class="value">{{ item.requireAddress }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">接收人员:</text>
		                <text class="value">{{ item.requireName }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">接收人员电话:</text>
		                <text class="value">{{ item.requirePhone }}</text>
		              </view>
		              <!-- <view class="detail-row">
		                <text class="label">实际接收日期:</text>
		                <text class="value">{{ item.receiveDate }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">实际接收人员:</text>
		                <text class="value">{{ item.receiveName }}</text>
		              </view>
		              <view class="detail-row">
		                <text class="label">实际接收备注:</text>
		                <text class="value">{{ item.receiveRemark }}</text>
		              </view> -->
		            </view>
		          </view>
		        </view>
		      </view>
		
		      <!-- 配送、转运图片 -->
		      <view class="section">
		        <view class="section-header">
		          <text class="section-title">配送、转运图片</text>
		        </view>
		        <view class="image-grid" v-if="pallet&&pallet.files">
		          <view class="image-item" v-for="(img, index) in pallet.files" :key="index">
		            <image :src="img" mode="aspectFill" @click="prviewImage(index)" class="image"></image>
		          </view>
		        </view>
		      </view>
		
		      <!-- 零散物资信息 -->
		      <!-- <view class="section">
		        <view class="section-header">
		          <text class="section-title">零散物资信息</text>
		        </view>
		        <view class="info-card" v-if="pallet&&pallet.other">
		         <view class="info-row">
		            <text class="label">物资名称:</text>
		            <text class="value">螺丝钉</text>
		          </view>
		          <view class="info-row">
		            <text class="value">{{pallet.other}}</text>
		          </view>
		        </view>
		      </view> -->
			  
		    </scroll-view>

	</view>
</template>

<script>
	export default {
		props: {
		   palletAll: {
		     type: Object,
		     default: function () {
		       return {
			   };
		     }
		   }
		},
		data() {
			return {
				depts:[],
				dicts:[],
				status:[],
				palletStatus:[],
				pallet:{},
				expandedIndex:null,
				
			}
		},
		mounted() {
		  this._initDetail();
		  this.getTypes();
		},
		watch: {
			palletAll(data) {
			  this._initDetail(data);
			},
			deep: true, // 深度监听
			immediate: true, // 初次监听即执行
		},
		methods: {
			gotocxDetail(instno,project){
				uni.navigateTo({
					url:  `/pages/pallet/tpcxtk?instno=${instno}&project=${project}`
				});
			},
			_initDetail(palletAll = this.palletAll) {
				this.pallet=palletAll;
				// 加载详情
				this.openPalletDetail();
			},
			// 获取托盘详情
			async openPalletDetail() { 
					if(this.pallet.palletNo){
						uni.showLoading({
							title: '数据加载中...'
						});
						const {data: res} = await uni.$http.get('/getInstdetail',{ // /getPalletAll
							palletNo: this.pallet.palletNo
						});
						if(res.success){ 
							if(res.data)
							{
								this.pallet["instdetailList"]=res.data;
			// 					this.pallet["instdetailList"]=[{
			//     "id": "b0ce28eb-cf71-466f-952f-17b7663c29f2",
			//     "project": "T300K-106",
			//     "instno": "9201FP12010MV",
			//     "dwgno": "9201MP12MVM",
			//     "section": "9201",
			//     "assemcode": "40-CW02-L3S-05",
			//     "spec": "21.3*2.11",
			//     "grd": "A312 TP316",
			//     "qty": "1.000000",
			//     "weight": "0.6500",
			//     "treatment": "钝化",
			//     "status": "配送出库",
			//     "statusDate": "2026/01/07",
			//     "manuDept": "九作业区",
			//     "treatDept": "永合机电",
			//     "deliverDept": "集配组",
			//     "palletNo": "",
			//     "deliveryCar": "284",
			//     "deliveryDate": "2026/01/07",
			//     "deliveryRemark": "协商 (刘文禄 2026/01/06)",
			//     "requireDate": "2026/01/05",
			//     "requireDepartCode": "P30000",
			//     "requireAddress": "分段二部装焊厂房（钢加配送）",
			//     "requireName": "郝名远",
			//     "requirePhone": "13500795290",
			//     "groupDesc": "T300K-106 9201FP12010MV",
			//     "uniStr": "T300K-106 9201FP12010MV 40-CW02-L3S-05\n21.3*2.11 A312 TP316 1.000000"
			// }]
								this.$forceUpdate(); 
							} 
						} 
					}
					
				},
			toggleDetail(index) {
			  if (this.expandedIndex === index) {
			    this.expandedIndex = null;
			  } else {
			    this.expandedIndex = index;
			  }
			},
			getTypes() {
				//获取数据字典
				this.gcs=[];
				this.status=[];
				var commondata = uni.getStorageSync("commondata");
				if(commondata){
					var data = JSON.parse(commondata);
					if(data){ 
						this.dicts=data.dicts;
						this.depts=data.depts; 
						this.dicts.forEach(cell=>{ 
							// console.log(cell.bmlb)
							if("TPZT"==cell.bmlb){
								// 托盘转运状态
								this.status.push(cell);
							}
							if("SYZT"==cell.bmlb){
								 
								// 托盘转运状态
								this.palletStatus.push(cell);
							}
							 
						});
						this.$forceUpdate();
					}
				}
				else{ 
					this.dicts=[];
					this.depts=[];
					this.status=[];
				}
			},
			retType(type,str) {
				var rets = '';
				if(str==1){
					// 状态
					this.status.forEach((cell,idx)=>{
						if(type==cell.bm){
							rets=cell.bmsm;
							return;
						}
					});
				}
				else if(str==3){
					// 使用状态  
					this.palletStatus.forEach((cell,idx)=>{
						if(type==cell.bm){
							rets=cell.bmsm;
							return;
						}
					});
				}
				else if(str==2){
					// 部门
					this.depts.forEach((cell,idx)=>{
						if(type==cell.departCode){
							rets=cell.departName;
							return;
						}
					});
				}
				if(!rets){
					rets=type
				}
				return rets;
			},
			getStatusClass(status) {
			  switch (status) {
			    case '表面接收':
			      return 'status-waiting';
			    case '建立任务':
			      return 'status-delivered';
			    case '内表面接收':
			      return 'status-receivedf';
				case '配盘完工':
				  return 'status-received';
				case '配送出库':
				  return 'status-outbound';
				case '完工转运':
				  return 'status-complete';
			    default:
			      return 'status-default';
			  }
			},
			prviewImage(index) {
				if(this.pallet&&this.pallet.files){
					uni.previewImage({
						urls: this.pallet.files,
						current: index
					});
				}
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.container {
	  height: 100%;
	  background-color: #f5f5f5;
	}
	
	.navbar {
	  display: flex;
	  align-items: center;
	  height: 88rpx;
	  background-color: #fff;
	  padding: 0 30rpx;
	  box-sizing: border-box;
	  position: relative;
	  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.1);
	}
	
	.nav-left,
	.nav-right {
	  width: 60rpx;
	  display: flex;
	  align-items: center;
	}
	
	.nav-title {
	  flex: 1;
	  text-align: center;
	  font-size: 34rpx;
	  font-weight: bold;
	  color: #333;
	}
	
	.content {
	  height: calc(100%);
	  padding: 0;
	  box-sizing: border-box;
	}
	
	.section {
	  background-color: #fff;
	  border-radius: 16rpx;
	  margin-bottom: 20rpx;
	  overflow: hidden;
	  box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	}
	
	.section-header {
	  padding: 30rpx;
	  border-bottom: 1rpx solid #eee;
	}
	
	.section-title {
	  font-size: 32rpx;
	  font-weight: bold;
	  color: #333;
	}
	
	.info-card {
	  padding: 30rpx;
	}
	
	.info-row {
	  display: flex;
	  margin-bottom: 20rpx;
	}
	
	.info-row:last-child {
	  margin-bottom: 0;
	}
	
	.label {
	  width: 200rpx;
	  font-size: 28rpx;
	  color: #666;
	  line-height: 1.5;
	}
	
	.value {
	  flex: 1;
	  font-size: 28rpx;
	  color: #333;
	  line-height: 1.5;
	}
	
	.status-used {
	  color: #ff6b35;
	}
	
	.status-transit {
	  color: #4a90e2;
	}
	
	.list-container {
	  padding: 0 30rpx 30rpx;
	}
	
	.list-item {
	  border: 1rpx solid #eee;
	  border-radius: 12rpx;
	  margin-top: 20rpx;
	  overflow: hidden;
	}
	
	.item-header {
	  display: flex;
	  flex-direction: row;
	  align-items: center;
	  padding: 20rpx 30rpx;
	  background-color: #f9f9f9;
	}
	.item-header-tip {
	  display: flex;
	  flex-direction: row;
	  align-items: center;
	  padding: 20rpx 20rpx 0;
	  background-color: #f9f9f9;
	}
	.item-tip{
		display: flex;
		flex: 1;
		font-size: 30rpx;
		font-weight: bold;
		color: #007aff;
		padding: 12rpx;
		border-radius: 10rpx;
		border: 1rpx solid #007aff;
	}
	.item-title {
		display: flex;
		flex: 1;
	  font-size: 30rpx;
	  font-weight: bold;
	  color: #333;
	}
	
	.item-content {
	  padding: 20rpx 30rpx;
	}
	
	.detail-row {
	  display: flex;
	  margin-bottom: 15rpx;
	}
	
	.detail-row:last-child {
	  margin-bottom: 0;
	}
	
	.image-grid {
	  display: grid;
	  grid-template-columns: repeat(3, 1fr);
	  gap: 20rpx;
	  padding: 30rpx;
	}
	
	.image-item {
	  border-radius: 12rpx;
	  overflow: hidden;
	  aspect-ratio: 1;
	}
	
	.image {
	  width: 100%;
	  height: 100%;
	}
	
	.status-badge {
	  padding: 6rpx 12rpx;
	  border-radius: 10rpx;
	  font-size: 24rpx;
	  color: #fff;
	  display: flex;
	  align-items: center;
	  margin-right: 10rpx;
	}
	
	.status-waiting {
	  background-color: #faad14;
	}
	
	.status-delivered {
	  background-color: #1890ff;
	}
	
	.status-receivedf {
	  background-color: #52c41a;
	}
	
	.status-received {
	  background-color: #18b566;
	}
	
	.status-outbound {
	  background-color: #fca600;
	}
	 
	.status-complete {
	  background-color: #c191e8;
	}
	 
	.status-default {
	  background-color: #f5f5f5;
	  color: #666666;
	}

</style>
