<template>
	<view class="welcome">
		<view class="welT">资产信息</view>
		<view class="welBox">
			<!-- <input type="hidden" name="AIId" :value="AIId" id="AIId" /> -->
			<l-input title="资产名称" placeholder="请填写" :value="Ass_AssetsInfoItemEntity.AIASSName" disabled right />
			<l-input title="资产编号" placeholder="请填写" :value="Ass_AssetsInfoItemEntity.ACode" disabled right />
			<l-input title="明细编号" placeholder="请填写" :value="Ass_AssetsInfoItemEntity.AICode" disabled right />
			<l-input title="使用人员" placeholder="请填写" :value="displayListItem(Ass_AssetsInfoItemEntity, 'AIUsePeople')" disabled right />
			<l-input title="所在库房" placeholder="请填写" :value="displayListItem(Ass_AssetsInfoItemEntity, 'AIIStorageId')" disabled right />
			
		</view>
	</view>
</template>

<script>
import moment from 'moment';
import get from 'lodash/get';
import set from 'lodash/set';
import todayTime from '@/common/js/todayTime.js';
export default {
	data() {
		return {
			pageInfo: '',
			scheme: {
				AIUsePeople: {
					type: 'sourceData',
					dataSource: '1',
					dataSourceId: 'BaseUser,f_realname,f_userid'
				},
				AIIStorageId: {
					type: 'sourceData',
					dataSource: '1',
					dataSourceId: 'Ass_StorageData,sname,sid'
				}
			},
			userInfo: {},
			dataSource:{
				AIUsePeople:[],
				AIIStorageId:[]
			},
			AIId: '',
			Ass_AssetsInfoItemEntity:{}
		};
	},
	methods: {
		init() {
			// console.log(this.API)
			let _this = this;
			Promise.all([
				this.FETCH_DATASOURCE('BaseUser').then(data => {
					// console.log(data)
					this.dataSource.AIUsePeople = data.data.map(t => ({
						text: t.f_realname,
						value: t.f_userid
					}));
				}),
				this.FETCH_DATASOURCE('Ass_StorageData').then(data => {
					// console.log(data)
					this.dataSource.AIIStorageId = data.data.map(t => ({
						text: t.sname,
						value: t.sid
					}));
				}),
			
				() => {}
			]);
			_this.LOADING('加载数据…');
			_this.pageInfo = _this.GET_PARAM(); //获取页面传递参数
			_this.AIId=_this.pageInfo.AIId;
			_this.HTTP_GET('/learun/adms/AssetManagementSystem/Ass_AssetsInfoItem/getEntity', _this.pageInfo.AIId, '加载数据时出错').then(res => {
				this.HIDE_LOADING();
				console.log(res);
				_this.Ass_AssetsInfoItemEntity = _this.COPY(res.Ass_AssetsInfoItemEntity);
			});
		},
		// 显示列表中的标题项
		displayListItem(item, field) {
			const fieldItem = this.scheme[field];
			const value = item[field];
			// console.log(Object.values(this.GET_GLOBAL('dataDictionary').usersex));
			
			switch (fieldItem.type) {
				case 'currentInfo':
				case 'organize':
					return fieldItem.dataType === 'time' ? value : get(this.GET_GLOBAL(fieldItem.dataType), `${value}.name`, '');
					
				case 'dataItem':
					const sex = this.dataSource[field].find(t => t.value === String(value));
					return get(sex, 'text', '');
				
				case 'sourceData':
					const BCdPartyFace = this.dataSource[field].find(t => t.value === String(value));
					return get(BCdPartyFace, 'text', '');
				
				case 'radio':
				case 'select':
					const selectItem = this.dataSource[field].find(t => t.value === String(value));
					return get(selectItem, 'text', '');

				case 'checkbox':
					if (!value || value.split(',').length <= 0) {
						return '';
					}
					const checkboxItems = value.split(',');
					return this.dataSource[field]
						.filter(t => checkboxItems.includes(t.value))
						.map(t => t.text)
						.join('，');

				case 'datetime':
					if (!value) {
						return '';
					}
					return moment(value).format(Number(fieldItem.dateformat) === 0 ? 'YYYY年 M月 D日' : 'YYYY-MM-DD HH:mm');

				default:
					return value === null || value === undefined ? '' : value;
			}
		}
	},
	created() {
		this.userInfo = this.GET_GLOBAL('loginUser'); //获取登录信息
		this.init();
	}
};
</script>

<style lang="less" scoped>
/deep/ .cu-form-group {
	min-height: 40px;
}
.welcome {
	padding: 1px 0px 20px;
	background: #fff;
}

.welT {
	font-size: 16px;
	margin-bottom: 10px;
	line-height: 26px;
	padding: 0 12px;
}

.welT text {
	width: 26px;
	height: 26px;
	line-height: 24px;
	border: 1px solid #efefef;
	border-radius: 4px;
	float: right;
	text-align: center;
	color: #999;
}

.welLine {
	height: 1px;
	background: #efefef;
	// margin: 10px -12px;
}

.welInput {
	overflow: hidden;
	font-size: 14px;
	margin-top: 10px;
}

.welInput span {
	float: left;
	width: 26%;
	text-align: right;
	line-height: 30px;
}

.welInput input {
	display: block;
	margin-left: 28%;
	width: 72%;
	border: 1px solid #efefef;
	border-radius: 4px;
	height: 30px;
	line-height: 28px;
	padding: 0 10px;
	margin-bottom: 0;
}

.welCon {
	padding: 10px;
	border: 1px solid #efefef;
	margin-top: 18px;
	border-radius: 4px;
	position: relative;
}

</style>
