<template>
	<view class="complaint-list">
		<!-- 顶部导航栏 -->
		<custom-navbar 
		  title="我的申诉" 
		  :show-back="true"
		  title-color="#000"
		  background-color="#FFFFFF"
		></custom-navbar>
		<view v-if="appeallist.length != 0">
			<view
				class="complaint-item"
				v-for="(appeal,index) in appeallist">
				<view class="box">
					<text class="date">{{appeal.date}}</text>
				</view>
				<view class="box">
					<text class="way">{{appeal.title}}</text>
				</view>
				<view class="box">
					<text class="reason">{{appeal.text}}</text>
				</view>
				<view class="images">
					<image
						class="img"
						v-for="(img,i) in appeal.photos"
						:src="img"
						mode="aspectFill"></image>
				</view>
				<view class="handle-btns">
					<view
						class="handle-btn"
						v-if="appeal.state == 1"
						@click="contact">
						<text class="handle-text">联系客服</text>
					</view>
					<view
						class="handle-btn"
						v-if="appeal.state == 1"
						@click="removeComplaint(appeal)">
						<text class="handle-text">撤销投诉</text>
					</view>
					<view
						class="handle-btn"
						v-if="appeal.state == 1"
						@click="lookComplaint(appeal)">
						<text class="handle-text">查看投诉</text>
					</view>
					<view
						class="handle-btn"
						@click="againComplaint(appeal)"
						v-if="appeal.state == 3">
						<text class="handle-text">再次发起</text>
					</view>
				</view>
				<!-- 状态 -->
				<view class="state">
					<text class="state-text">{{appeal.state == 1 ? '处理中' : appeal.state == 2 ? '处理完成' : appeal.state == 3 ? '已撤销' : ''}}</text>
				</view>
			</view>
		</view>
		<view class="nothings-box" v-else>
			<text class="nothings-text">暂无数据...</text>
		</view>
	</view>
</template>

<script>
import request from '../../utils/request';
	export default {
		data() {
			return {
				appeallist: [],
				user: {}
			}
		},
		async onLoad(options) {
			const user = await request.post('/user/getuser',{type: 1});
			this.user = user;
			// 获取申诉列表
			this.gegetappeallist();
		},
		methods: {
			gegetappeallist() {
				request.post('/user/gegetappeallist',{user_id: this.user.data.id}).then(res=>{
					this.appeallist = res.data;
				})
			},
			removeComplaint(appeal) {
				request.post('/user/revokeappeal',{order_number: appeal.order_number}).then(res=>{
					this.appeallist = res.data;
					if(res.state == 1) {
						uni.showToast({
							title: '撤销成功',
							icon: 'none'
						})
						// 更新申诉列表
						this.gegetappeallist();
					}else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			lookComplaint(appeal) {
				uni.navigateTo({
					url: '/pages/complaint/detail?number='+appeal.order_number
				})
			},
			// 再次发起
			againComplaint(appeal) {
			  uni.navigateTo({
				url: '/pages/complaint/add-complaint?number='+appeal.order_number
			  })
			},
			contact() {
				uni.navigateTo({
					url: '/pages/contact/contact'
				})
			}
		}
	}
</script>

<style>
.complaint-item {
  margin: 24rpx;
  padding: 24rpx;
  background-color: #fff;
  border-radius: 16rpx;
  position: relative;
}
.way {
  font-size: 28rpx;
  color: #333;
}
.date,.reason {
  font-size: 24rpx;
  color: #999;
  
}
.box {
  margin-bottom: 8rpx;
}
.images {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 24rpx;
  border-bottom: 2rpx solid #eee;
}
.img {
  width: 198rpx;
  height: 198rpx;
  background-color: #eee;
  border-radius: 20rpx;
}
.handle-btns {
  display: flex;
  flex-flow: row nowrap;
  justify-content: flex-end;
  align-items: center;
  padding-top: 24rpx;
}
.handle-btn {
  width: 140rpx;
  height: 56rpx;
  line-height: 56rpx;
  text-align: center;
  border: 2rpx solid #eee;
  border-radius: 28rpx;
  margin-left: 20rpx;
}
.handle-text {
  font-size: 28rpx;
  color: #333;
}
.state {
  position: absolute;
  top: 24rpx;
  right: 24rpx;
}
.state-text {
  font-size: 28rpx;
  font-weight: 700;
  color: #333;
}
.nothings-box {
	display: flex;
	flex-flow: row nowrap;
	justify-content: center;
	align-items: center;
	padding: 280rpx 0 0;
}
.nothings-text {
	font-size: 32rpx;
	font-weight: 500;
	color: #999999;
	text-align: center;
	font-style: italic;
}
</style>
