<template>
	<mobile-frame>
		<view class="main">
			<view class="goods" v-if="info.goods">
				<view class="url">
					<image class="image"
						:src="info.goods.goods.file&&info.goods.goods.file.length>0?info.goods.goods.file[0].url:''"
						mode=""></image>
				</view>
				<view class="goodsname">
					{{info.goods.goods.name}}
					<view class="specs">
						{{info.goods.name}}
					</view>
				</view>
				<view class="goodsother">
					<view v-if="info.order_detail.type=='0'" class="price">
						¥{{info.goods.price}}
					</view>
					<view v-else class="price">
						¥{{info.goods.group_config.money}}
					</view>
					<view class="num">
						×{{info.goods.buy_num}}
					</view>
				</view>
			</view>
			<view class="info">
				<view class="one">
					<view class="left">售后状态</view>
					<view class="right">{{info.zhStatus||'暂无'}}</view>
				</view>
				<view class="one">
					<view class="left">售后类型</view>
					<view class="right">{{info.zhType||'暂无'}}</view>
				</view>
				<view class="one">
					<view class="left">申请时间</view>
					<view class="right">{{info.apply_time||'暂无'}}</view>
				</view>
				<view class="one">
					<view class="left">售后结束时间</view>
					<view class="right">{{info.end_time||'暂无'}}</view>
				</view>
				<view class="one">
					<view class="left">售后描述</view>
					<view class="right">{{info.desc||'暂无'}}</view>
				</view>
				<view class="one">
					<view class="left">申请理由</view>
					<view class="right">{{info.zhReason||'暂无'}}</view>
				</view>
				<view class="one" v-if="info.type!='3'">
					<view class="left">退款金额</view>
					<view class="right">￥{{info.money||0}}</view>
				</view>
				<view class="one" v-if="info.type!='1'">
					<view class="left">用户退货单号</view>
					<view class="right">{{info.transport.customer_transport_no||'暂无'}}</view>
				</view>
				<view class="one" v-if="info.type=='3'">
					<view class="left">商家退货单号</view>
					<view class="right">{{info.transport.shop_transport_no||'暂无'}}</view>
				</view>
				<view class="one">
					<view class="left">售后处理人</view>
					<view class="right">{{info.deal_person.name||'暂无'}}</view>
				</view>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				user: {},
				info: {},
				// 售后状态
				statusList: [],
				// 售后类型
				typeList: [],
				// 申请理由
				reasonList: [],
			};
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e.id || '');
			await that.searchOther();
			await that.watchLogin();
		},
		methods: {
			// 查询其他信息
			async searchOther() {
				const that = this;
				let res;
				res = await that.$api(`/dictData`, 'GET', {
					code: "afterSale_status"
				});
				if (res.errcode == '0') {
					that.$set(that, `statusList`, res.data)
				}
				res = await that.$api(`/dictData`, 'GET', {
					code: "afterSale_type"
				});
				if (res.errcode == '0') {
					that.$set(that, `typeList`, res.data)
				}
				res = await that.$api(`/dictData`, 'GET', {
					code: "afterSale_reason"
				});
				if (res.errcode == '0') {
					that.$set(that, `reasonList`, res.data)
				}
			},
			// 监听用户是否登录
			watchLogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: async function(res) {
						let user = that.$jwt(res.data);
						if (user) {
							that.$set(that, `user`, user);
							if (that.id) {
								//售后详情
								let arr = await that.$api(`/afterSale/${that.id}`, 'GET')
								if (arr.errcode == '0') {
									let status = that.statusList.find(i => i.value == arr.data.status)
									if (status) arr.data.zhStatus = status.label;
									let type = that.typeList.find(i => i.value == arr.data.type)
									if (type) arr.data.zhType = type.label;
									let reason = that.reasonList.find(i => i.value == arr.data.reason)
									if (reason) arr.data.zhReason = reason.label;
									that.$set(that, `info`, arr.data)
								}
							}
						}
					},
					fail: function(err) {
						uni.navigateTo({
							url: `/pages/login/index`
						})
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.goods {
			display: flex;
			border-bottom: 1px dashed #f1f1f1;
			padding: 2vw;
			width: 96vw;

			.url {
				width: 20vw;

				.image {
					width: 100%;
					height: 20vw;
					border-radius: 5px;

				}
			}

			.goodsname {
				display: flex;
				flex-direction: column;
				width: 60vw;
				padding: 0 2vw;
				font-size: 16px;

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

			}

			.goodsother {
				width: 15vw;
				text-align: right;
			}
		}

		.info {
			padding: 2vw;

			.one {
				display: flex;
				justify-content: space-between;
				padding: 2vw;

				.left {
					color: #696969;
					font-size: var(--font14Size);
				}

				.right {
					width: 60vw;
					text-align: right;
					color: #A9A9A9;
					font-size: var(--font14Size);
				}
			}
		}
	}
</style>
