<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.zhType||'暂无'}}</text>
						<text>{{info.good_name||'暂无'}}</text>
					</view>
					<view class="spec textOver">
						<text>规格：{{info.spec_name||'暂无'}}</text>
					</view>
					<view class="num">
						<text>数量：{{info.num||'暂无'}}</text>
					</view>
					<view class="money">
						<text>￥{{info.money||'暂无'}}</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.buy_time||'暂无'}}</text>
			</view>
			<view class="two_1" v-if="info.sleader_name">
				<text>采购审批领导：</text>
				<text>{{info.sleader_name||'暂无'}}</text>
			</view>
			<view class="two_1" v-if="info.saccounting_name">
				<text>采购审批会计：</text>
				<text>{{info.saccounting_name||'暂无'}}</text>
			</view>
			<view class="two_1" v-if="info.cleader_name">
				<text>回款审批领导：</text>
				<text>{{info.cleader_name||'暂无'}}</text>
			</view>
			<view class="two_1" v-if="info.caccounting_name">
				<text>回款审批会计：</text>
				<text>{{info.caccounting_name||'暂无'}}</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.zhRole||'暂无'}}</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 class="four">
			<view class="left">
				<text>商品总价</text>
			</view>
			<view class="right">
				<text>￥{{info.total_money||'暂无'}}</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(`/OrderDetail/detail/${that.id}`, 'GET', {})
					if (res.errcode == '0') {
						res.data.zhStatus = that.searchDict(res.data.status, 'status')
						res.data.zhType = that.searchDict(res.data.good_type, 'type')
						res.data.zhRole = that.searchDict(res.data.user_role, 'role')
						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 '暂无'
				} else if (model == 'type') {
					data = that.typeList.find((i) => i.value == e);
					if (data) return data.label
					else return '暂无'
				} else {
					data = that.roleList.find((i) => i.code == e);
					if (data) return data.name
					else return '暂无'
				}
			},
			// 查询其他信息
			async searchOther() {
				const that = this;
				let res;
				// 查询状态
				res = await that.$api(`/DictData`, 'GET', {
					type: 'order_status',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `statusList`, res.data);
				// 查询类型
				res = await that.$api(`/DictData`, 'GET', {
					type: 'goods_type',
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `typeList`, res.data);
				// 查询角色
				res = await that.$api(`/Role`, 'GET', {
					is_use: '0',
				})
				if (res.errcode == '0') that.$set(that, `roleList`, 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);

						text:first-child {
							font-size: var(--font12Size);
							color: var(--mainColor);
							background-color: var(--f3CColor);
							border-radius: 5px;
							padding: 2px 5px;
						}
					}

					.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);
				}
			}
		}

		.four {
			display: flex;
			justify-content: space-between;
			margin: 2vw 2vw 0 2vw;
			padding: 2vw;
			border-radius: 10px;
			background-color: var(--mainColor);
			font-size: var(--font14Size);

			.left {
				color: var(--f85Color);
			}
		}
	}
</style>