<template>
	<view class="">
		<uni-nav-bar fixed="true" statusBar="true" left-icon="back" :title="dataInfo.assetName" @clickLeft="back">
		</uni-nav-bar>
		<view class="title">
			基本信息
		</view>
		<view class="list-wrap-1">
			<view class="item">
				<view class="s1">
					物料编码
				</view>
				<view class="s2">
					{{dataInfo.assetCode}}
				</view>
			</view>
			<view class="item">
				<view class="s1">
					物料类型
				</view>
				<view class="s2">
					{{dict.warehousingType[dataInfo.assetType]}}
				</view>
			</view>
			<view class="item">
				<view class="s1">
					牌号
				</view>
				<view class="s2">
					{{dataInfo.brandNum}}
				</view>
			</view>
			<view class="item">
				<view class="s1">
					型号
				</view>
				<view class="s2">
					{{dataInfo.modelType}}
				</view>
			</view>
			<view class="item">
				<view class="s1">
					计量单位
				</view>
				<view class="s2">
					{{dataInfo.unit}}
				</view>
			</view>
			<!-- <view class="item">
				<view class="s1">
					包装单位
				</view>
				<view class="s2">
					{{dataInfo.minPackUnit}}
				</view>
			</view> -->
			<view class="item">
				<view class="s1">
					库存总数
				</view>
				<view class="s2">
					{{dataInfo.realInventoryNum}}{{dataInfo.unit}}
				</view>
			</view>
			<!-- <view class="item">
				<view class="s1">
					包装数量
				</view>
				<view class="s2">
					{{dataInfo.measurementUnit}}
				</view>
			</view> -->
		</view>
		<view class="title">
			批次明细
		</view>
		<view class="table-wrap">
			<uni-table border stripe emptyText="暂无更多数据">
				<!-- 表头行 -->
				<uni-tr>
					<uni-th align="left" width="240rpx" :sortable="true"
						@sort-change="sortChange('batchNum',$event)">批次号</uni-th>
					<uni-th align="left" width="170rpx" :sortable="true"
						@sort-change="sortChange('realInventoryNum',$event)">库存数量</uni-th>
					<uni-th align="left" width="170rpx" :sortable="true"
						@sort-change="sortChange('measurementUnit',$event)">包装数量</uni-th>
					<uni-th align="left" width="170rpx" :sortable="true"
						@sort-change="sortChange('days',$event)">库龄(天)</uni-th>
				</uni-tr>
				<!-- 表格数据行 -->
				<uni-tr v-for="(item,index) in pcmxList" :key="index">
					<uni-td>
						<text class="pch" @click="goPch(item)">{{item.batchNum}}</text>
					</uni-td>
					<uni-td>{{item.realInventoryNum}}</uni-td>
					<uni-td>{{item.measurementUnit}}</uni-td>
					<uni-td>{{item.days}}</uni-td>
				</uni-tr>
			</uni-table>
		</view>
	</view>
</template>

<script>
	import {
		post
	} from '@/utils/api.js'
	export default {
		data() {
			return {
				// 基本信息
				dataInfo:'',
				// 列表维度
				dimension:'',
				pcmxList: [
				],
				dict: {
					warehousingType: {
						1: '生产设备',
						2: '舟皿',
						3: '物料',
						
						5: '周转车',
						6: '模具',
						7: "备品备件",
					}
				}
			}
		},
		onLoad(option) {
			console.log(option)
			this.dataInfo = JSON.parse(decodeURIComponent(option.info))
			this.dimension = option.dimension
			this.getData()
		},
		methods: {
			sortChange(type, e) {
				console.log(type, e)
				let order = e.order
				this.pcmxList.sort((a, b) => {
					switch (order) {
						// 下降
						case 'descending':
							return a[type] - b[type]
							break;
							// 上降
						case 'ascending':
							return b[type] - a[type]
							break;
							// 正常
						case null:
							break;
						default:
							break;
					}
				})
			},
			goPch(item){
				let par = {
					batchNum:item.batchNum,
					inventoryCode:item.assetCode,
					code:item.assetType
				}
				par = this.URLSearchParams(par)
				uni.navigateTo({
				  url: "/pages/warehouse/inventory/batch/batch?" + par,
				});
			},
			getData(){
				let par = {
					dimension:this.dimension,
					inventoryCode:this.dataInfo.assetCode,
					name:this.dataInfo.assetName,
				}
				par = this.URLSearchParams(par)
				post(this.apiUrl + "/InventoryBook/select/getDetail?"+par).then((res) => {
					if (res.success) {
						this.pcmxList = res.data.records
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.title {
		background-color: #70b603;
		color: #fff;
		font-size: 28rpx;
		padding: 20rpx 30rpx;
	}

	.list-wrap-1 {
		padding: 30rpx;

		.item {
			color: #000000;
			font-size: 28rpx;
			padding: 10rpx 0;
			display: flex;
			justify-content: space-between;
		}

		.item+.item {
			border-top: 1px dashed #555;
		}
	}
	.pch{
		text-decoration: underline;
		color: #70b603;
	}
</style>