<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 4" :key="index">
					<text class="mt-20 fs-36">{{numberList[(index+1)]||0}}</text>
					<text class="mb-20 fs-24">{{index==0?'待处理':index==1?'待支付':index==2?'已完成':index==3?'已取消':''}}</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%;" v-if="list.length!=0">
				<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  fs-24">
							<image class="h-40 w-40 mr-15" src="/static/icon_gd.png"> </image>
							<text class="fs-32 fw-700" style="flex: 1;">{{item.communityName+item.room}}</text>
							<text
								:style="{ color: item.state==1?'#FF682D':item.state==2?'#EEA616':item.state==3?'#1FCA7C':'#23BBEE'}">
								{{item.state==1?'待处理':item.state==2?'待支付':item.state==3?'已完成':item.state==4?'已取消':''}}
							</text>
						</view>
						<text class="fs-28 br-6 pad-20 mtb-20"
							style="background: #EBF5F0;">{{item.repairsDescription}}</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.repairsImg)" :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.repairsTime}}</text>
							<text @tap.stop="onCz('设置费用',index)" v-if="item.state==1"
								style="color: #23BBEE;">设置费用</text>
							<text style="color: #27CC81;margin-left: 30rpx;">报修详情</text>
						</view>
					</view>
				</view>
			</scroll-view>
			<view style="padding-top: 300rpx;" v-if="list.length==0">
				<u-empty mode="data"></u-empty>
			</view>
			<u-popup :show="show" mode="center" @close="close" @open="open" round="10" v-if="show">
				<view class="flex-column mlr-50 pb-30" style="width:600rpx;text-align: center;">
					<text class="fs-32 fw-600 mtb-20">设置维修费用</text>
					<input class="br-6 mtb-20 h-100" placeholder="请输入维修费用金额" type="digit"
						style="background: #EBF5F0; border-radius: 20rpx;" v-model="price" />
					<view class="fullscreen-btn" @click="onCz('提交',index)">
						确定
					</view>
				</view>
			</u-popup>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				type: 0,
				tabIndex: 0,
				list: [],
				price: '',
				repairsId: '',
				numberList: '',
			};
		},
		onLoad(e) {
			this.type = e.type
		},
		onShow() {
			this.getList()
			this.getNumberList()
		},
		methods: {
			open() {
				this.show = true
			},
			close() {
				this.show = false
			},
			onClick(index) {
				this.tabIndex = index;
				this.getList()
			},
			onCz(e, index) {
				if (e == "详情") {
					this.$wskj.to("/pagesMine/pages/wx_xq?id=" + this.list[index].repairsId)
					return
				}
				if (e == "设置费用") {
					this.repairsId = this.list[index].repairsId
					this.open();
					return
				}
				if (e == "提交") {
					if (this.price == '') {
						this.$wskj.toast("请设置正确的金额")
						return
					}
					this.setMoney()
					return
				}

			},
			getNumberList() {
				const params = {
					url: '/api/repairs/maintainCountAll',
					method: 'GET',
				}
				this.$request(params).then(res => {
					this.numberList = res.data
				})
			},
			getList() {
				const params = {
					url: '/api/repairs/maintainListAll?state=' + (this.tabIndex + 1),
					method: 'GET',
				}
				this.$request(params).then(res => {
					this.list = res.data
				})
			},
			setMoney(id) {
				const params = {
					url: '/api/repairs/setMoney/' + this.repairsId + '/' + this.price,
					method: 'PUT',
				}
				this.$request(params).then(res => {
					this.close()
					this.getList()
					this.getNumberList()
				})
			}
		},
	};
</script>

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