<template>
	<view class='container'>
		<view style="background: linear-gradient( 180deg, #D9F5E8 0%, #FFFFFF 100%);padding-bottom: 200rpx;">
			<u-navbar :autoBack="true" placeholder="true" title="历史工单" bgColor="transparent">
			</u-navbar>
		</view>
		<view style="margin-top: -200rpx;">
			<view class="flex mlr-10">
				<view @click="onClick(index)" class="h-150 mlr-10 br-12 flex-column flex-between-center"
					style="flex: 1;background: #FFFFFF;"
					:style="{ color: index==0?'#FF682D':index==1?'#EEA616':index==2?'#1FCA7C':'#23BBEE'}"
					v-for="(item, index) in 3" :key="index">
					<text class="mt-20 fs-36">25</text>
					<text class="mb-20 fs-24">{{index==0?'待处理':index==1?'已完成':index==2?'已取消':''}}</text>
					<view v-if="index==tabIndex"
						style="background: #27CC81;height: 10rpx;width: 100%;border-radius: 12rpx;">
					</view>
					<view v-else style="background: #FFFFFF;height: 10rpx;width: 100%;border-radius: 12rpx;">
					</view>
				</view>
			</view>
		</view>
		<view class="overflow-y">
			<scroll-view scroll-y style="height: 100%;">
				<view v-for="(item, index) in list" :key="index" @click="onCz('详情',index)">
					<view class="flex-column br-12 mt-30 mlr-24 pad-20"
						style="box-shadow: 0px 0px 15px 1px rgba(142,142,142,0.16);background: white;">
						<view class="flex vh-center mt-20">
							<image class="h-40 w-40 mr-15" src="/static/icon_gd.png"> </image>
							<text class="fs-32 fw-700" style="flex: 1;">{{item.type==1?'我要投诉':'我要表扬'}}</text>
							<text>{{item.state==1?'待处理':item.state==2?'已完成':item.state==3?'已关闭':''}}</text>
						</view>
						<text class="fs-28 br-6 pad-20 mtb-20"
							style="background: #EBF5F0;">{{item.commentDescription}}</text>
						<scroll-view scroll-x="true" scroll-with-animation="true">
							<view class="flex">
								<view class="w-140 h-140 mr-15"
									v-for="(itemImg, index2) in $wskj.splitList(item.commentImg)" :key="index2">
									<image class="w-140 h-140" :src="itemImg"></image>
								</view>
							</view>
						</scroll-view>
						<view class="flex vh-center h-60 mt-20 fs-24">
							<text style="flex: 1;color: #000;">{{item.createTime}}</text>
							<text @tap.stop="onCz('关闭投诉表扬',index)" v-if="item.state==1"
								style="color: #23BBEE;">{{item.type==1?'关闭投诉':'关闭表扬'}}</text>
							<text style="color: #27CC81;margin-left: 30rpx;">{{item.type==1?'投诉详情':'表扬详情'}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 0,
				tabIndex: 0,
				list: [],
			};
		},
		onLoad(e) {
			this.type = e.type
		},
		onShow() {
			this.getList()
		},
		methods: {
			onClick(index) {
				this.tabIndex = index;
				this.getList()
			},
			onCz(e, index) {
				if (e == "详情") {
					this.$wskj.to("/pagesMain/pages/tsby_xq?id=" + this.list[index].id)
					return
				}
				if (e == "关闭投诉表扬") {
					this.gb(this.list[index].id);
					return
				}
			},
			getList() {
				const params = {
					url: '/api/comment/userListAll?state=' + (this.tabIndex + 1),
					method: 'GET',
				}
				this.$request(params).then(res => {
					this.list = res.data
				})
			},
			gb(id) {
				const params = {
					url: '/api/comment/cancel/' + id,
					method: 'PUT',
				}
				this.$request(params).then(res => {
					this.getList()

				})
			}
		},
	};
</script>

<style scoped>
	.container {
		height: 100vh;
		display: flex;
		flex-direction: column;
		background: #fff;
	}
</style>