<template>
	<mobile-frame>
		<view class="main">
			<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 class="one" v-if="status!= '0'">
					<view class="left">团长建议</view>
					<view class="right">{{info.leader_suggest==true?'同意':info.leader_suggest==false?'不同意':'暂无'}}</view>
				</view>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				id: '',
				status: '',
				user: {},
				info: {},
				// 售后状态
				statusList: [],
				// 售后类型
				typeList: [],
				// 申请理由
				reasonList: [],
			};
		},
		onLoad: async function(e) {
			const that = this;
			that.$set(that, `id`, e.id || '');
			that.$set(that, `status`, e.status || '');
			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;
								if (that.status == '0') arr = await that.$api(`/afterSale/${that.id}`, 'GET')
								else arr = await that.$api(`/groupAfterSale/${that.id}`, 'GET', {}, 'group')
								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;

		.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>
