<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="list-container" v-if="item">
				  <view class="list-item">
				    <view class="item-header">
				      <text class="item-title">{{ item.assemcode }}</text>
					  <text class="status-badge" :class="getStatusClass(item.status)">{{item.status}}</text>
				    </view>
				    <view 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.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>
			  
		    </scroll-view>

	</view>
</template>

<script>
	export default {
		props: {
			pallet: {
			  type: Object,
			  default: null
			}
		},
		data() {
			return {
				item: null,
				depts:[],
				dicts:[],
				status:[], // 状态
			}
		},
		mounted() {
		  this._initDetail();
		  this.getTypes();
		},
		watch: {
			pallet(data) {
			  this._initDetail(data);
			},
			deep: true, // 深度监听
			immediate: true, // 初次监听即执行
		},
		methods: {
			_initDetail(pallet = this.pallet) {
				this.item=pallet; 
				this.$forceUpdate();
			},
			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';
			  }
			},
			
		}
	}
</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: 20rpx 30rpx 30rpx;
	}
	
	.list-item {
	  border: 1rpx solid #eee;
	  border-radius: 12rpx;
	  margin-bottom: 20rpx;
	  overflow: hidden;
	}
	
	.item-header {
	  display: flex;
	  flex-direction: row;
	  align-items: center;
	  padding: 20rpx 30rpx;
	  background-color: #f9f9f9;
	}
	
	.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>
