<template>
	<view class="content">
		<view class="one">
			<view class="one_1">
				<text>
					<text class="iconfont icon-changshangguanli"></text>
					{{info.supplier_name}}
				</text>
				<text class="status">{{info.zhStatus}}</text>
			</view>
			<view class="one_2">
				<view class="left">
					<image v-if="info.spec_file" class="image"
						:src="info.spec_file&&info.spec_file.length>0?info.spec_file[0].url:''" mode="">
					</image>
					<image v-else class="image" :src="info.good_file&&info.good_file.length>0?info.good_file[0].url:''"
						mode="">
					</image>
				</view>
				<view class="right">
					<view class="name textOver">
						<text>{{info.good_name||'暂无'}}</text>
					</view>
					<view class="spec textOver">
						<text>规格：{{info.spec_name||'暂无'}}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="two">
			<view class="two_1">
				<text>订单号：</text>
				<text>{{info.order_id||'暂无'}}</text>
			</view>
			<view class="two_1">
				<text>厂商电话：</text>
				<text>{{info.supplier_tel||'暂无'}}</text>
			</view>
			<view class="two_1">
				<text>申请时间：</text>
				<text>{{info.apply_time||'暂无'}}</text>
			</view>
		</view>
		<view class="thr">
			<view class="thr_1">
				<text>申请人员：</text>
				<text>{{info.user_name||'暂无'}}</text>
			</view>
			<view class="thr_1">
				<text>申请人员电话：</text>
				<text>{{info.user_tel||'暂无'}}</text>
			</view>
			<view class="thr_1">
				<text>收货地址：</text>
				<text>{{info.address||'暂无'}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				user: {},
				info: {},
				// 字典表
				statusList: [],
				typeList: [],
				roleList: []
			}
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e && e.id || '');
			that.searchToken();
			await that.searchOther();
			await that.search();
		},
		methods: {
			searchToken() {
				const that = this;
				try {
					const res = uni.getStorageSync('token');
					if (res) that.$set(that, `user`, res);
				} catch (e) {
					uni.showToast({
						title: err.errmsg,
						icon: 'error',
						duration: 2000
					});
				}
			},
			async search() {
				const that = this;
				if (that.id) {
					const res = await that.$api(`/Upkeep/${that.id}`, 'GET', {})
					if (res.errcode == '0') {
						const arr = await that.$api(`/User/${res.data.user}`, 'GET', {})
						if (arr.errcode === 0) res.data.user_tel = arr.data.tel
						const aee = await that.$api(`/User/${res.data.supplier}`, 'GET', {})
						if (aee.errcode === 0) res.data.supplier_tel = aee.data.tel
						res.data.zhStatus = that.searchDict(res.data.status, 'status')
						that.$set(that, `info`, res.data)
					} else {
						uni.showToast({
							title: res.errmsg,
						});
					}
				}
			},
			// 查询字典表
			searchDict(e, model) {
				const that = this;
				let data
				if (model == 'status') {
					data = that.statusList.find((i) => i.value == e);
					if (data) return data.label
					else return '暂无'
				}
			},
			// 查询其他信息
			async searchOther() {
				const that = this;
				let res;
				// 查询状态
				res = await that.$api(`/DictData`, 'GET', {
					type: 'upkeep',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `statusList`, res.data);
			},
		}
	}
</script>

<style lang="scss">
	.content {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;
		background-color: var(--f9Color);

		.one {
			margin: 2vw 2vw 0 2vw;
			padding: 0 2vw;
			border-radius: 10px;
			background-color: var(--mainColor);

			.one_1 {
				display: flex;
				justify-content: space-between;
				padding: 2vw 0;
				font-size: var(--font16Size);
				border-bottom: 1px solid var(--f9Color);

				.status {
					font-size: var(--font14Size);
					color: var(--fF0Color);
				}
			}

			.one_2 {
				display: flex;
				padding: 2vw 0;

				.left {
					.image {
						width: 25vw;
						height: 25vw;
						border-radius: 5px;
						border: 1px solid var(--f9Color);
					}
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					width: 65vw;
					margin: 0 0 0 2vw;

					.name {
						padding: 1vw 0 0 0;
						font-size: var(--font14Size);
					}

					.spec {
						font-size: var(--font12Size);
					}

					.num {
						font-size: var(--font12Size);
						color: var(--f85Color);
					}

					.money {
						font-size: var(--font14Size);
						font-weight: bold;
						color: var(--fF0Color);
					}

				}
			}
		}

		.two {
			margin: 2vw 2vw 0 2vw;
			padding: 2vw;
			border-radius: 10px;
			background-color: var(--mainColor);

			.two_1 {
				padding: 2vw 0;
				font-size: var(--font14Size);

				text:first-child {
					color: var(--f85Color);
				}
			}
		}

		.thr {
			margin: 2vw 2vw 0 2vw;
			padding: 0 2vw;
			border-radius: 10px;
			background-color: var(--mainColor);

			.thr_1 {
				padding: 2vw 0;
				font-size: var(--font14Size);

				text:first-child {
					color: var(--f85Color);
				}
			}
		}
	}
</style>