<template>
	<div>
		<common ref="common" @asynCallBack="asynCallBack"></common>
		<top-header :pageTitle="pageTitle"></top-header>

		<div class="mui-content vongi-hdsq margin60">
			
			<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
				<div class="mui-scroll">
					<a @click="reloadList(0)" :class="'mui-control-item '+(listForm.status==0?'mui-active':'')">
						<span class="fyy-badge">待处理<span class="mui-badge" v-if="firstRecordsTotal" v-text="firstRecordsTotal"></span></span>
					</a>
					<a @click="reloadList(1)" :class="'mui-control-item '+(listForm.status==1?'mui-active':'')">
						已处理
					</a>
				</div>
			</div>
			
			<div v-if="recordList.length" id="slider" class="mui-slider mui-fullscreen ">
				
				<div class="mui-slider-group vongi-wybx">
					<div v-show="listForm.status==0" class="mui-slider-item mui-control-content">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<ul class="mui-table-view">
									<li v-for="(item,index) in recordList" :key="item.id" class="mui-table-view-cell vongi-wordcard vongi-meform-pho">
										<router-link :to="{name:'MasterPropertyComplaintInfo',query:{id:item.id}}">
											<div class="mui-media-body flew-sp">
												<div class="mui-col-xs-9" v-text="item.content"></div>
												<div class="mui-col-xs-3 color4fc5f7" v-text="item.statusN"></div>
											</div>
											<div v-if="item.img" class="fyy-upphoto flew">
												<div v-for="(iten,inden) in item.img.split(',').slice(0,3)" class="mui-col-xs-3">
													<img :src="iten" />
												</div>
												<span class="mui-badge" v-if="item.img.split(',').length>3" v-text="item.img.split(',').length"></span>
											</div>
											<p class="flew-items flew-sp">
												{{item.categoryN}}
												<span class='mui-ellipsis' v-text="item.createTime"></span>
											</p>
										</router-link>
										<div class="vongi-btn-x">
											<button type="button" class="mui-btn mui-btn-primary" @click="del(item)">撤销</button>
											<!-- <button type="button" class="mui-btn mui-btn-primary mui-btn-outlined">催办</button> -->
										</div>
									</li>
								</ul>

							</div>
						</div>
					</div>
					<div v-show="listForm.status==1" class="mui-slider-item mui-control-content">
						<div class="mui-scroll-wrapper">
							<div class="mui-scroll">
								<ul class="mui-table-view">
									<li v-for="(item,index) in recordList" :key="item.id" class="mui-table-view-cell vongi-wordcard vongi-meform-pho">
										<router-link :to="{name:'MasterPropertyComplaintInfo',query:{id:item.id}}">
											<div class="mui-media-body flew-sp">
												<div class="mui-col-xs-9" v-text="item.content"></div>
												<div class="mui-col-xs-3 color55f868" v-text="item.statusN"></div>
											</div>
											<div v-if="item.img" class="fyy-upphoto flew">
												<div v-for="(iten,inden) in item.img.split(',').slice(0,3)" class="mui-col-xs-3">
													<img :src="iten" />
												</div>
												<span class="mui-badge" v-if="item.img.split(',').length>3" v-text="item.img.split(',').length"></span>
											</div>
											<p class="flew-items flew-sp">
												{{item.categoryN}}
												<span class='mui-ellipsis' v-text="item.createTime"></span>
											</p>
										</router-link>
										<div class="vongi-btn-x">
											<button type="button" @click="goToInfo(item)" class="mui-btn mui-btn-primary mui-btn-outlined">查看回复</button>
										</div>
									</li>
								</ul>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<NullList :remark="'暂无投诉建议记录'" v-if="!recordList.length"></NullList>
		<div class="fyy-footer" style="z-index:99">
			<div class="bindfyy-btn"><button type="submit" class="mui-btn mui-btn-primary " @click="goToForm()">填写物业投诉建议</button></div>
		</div>

		<loading :visible="isLoading"></loading>
	</div>
</template>

<script>
	import * as API_Property from '@/apis/Master/property'
	import Common from '$project/components/Common.vue'
	import Loading from '$project/components/Loading.vue'
	import TopHeader from '$project/components/TopHeader.vue'
	import NavMenu from '@/components/NavMenu.vue'
	import NullList from '$project/components/NullList.vue'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	import isReachBottom from '$project/utils/isReachBottom'
	export default {
		name: 'MasterPropertyComplaintList',
		components: {
			Common,
			Loading,
			TopHeader,
			NavMenu,
			NullList
		},
		data() {
			return {
				isLoading: false,

				pageTitle: '投诉建议',

				listForm: {
					pageIndex: 1,
					pageSize: 20,
					totalPage: 1,
					type: 1,
					status: 0
				},
				recordList: [],
				firstRecordsTotal: 0,
			}
		},
		created() {},
		methods: {
			//获取列表
			getList() {
				this.isLoading = true;
				API_Property.getRepairAndComplaintList(this.listForm).then(response => {
					if (response) {
						if (this.listForm.pageIndex == 1) {
							this.recordList = response.data;
							this.listForm.pageIndex = response.pageNumber;
							this.listForm.totalPage = response.totalPage;
						} else {
							this.recordList = [
								...this.recordList,
								...response.data
							];
						}

						if (this.listForm.status == 0) {
							this.firstRecordsTotal = response.recordsTotal;
						}
					}
					this.listForm.pageIndex++;
					this.isLoading = false;
				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			//下拉事件
			handleScrool() {
				if (isReachBottom()) {
					console.log('到达底部')
					if (this.listForm.pageIndex <= this.listForm.totalPage && this.isLoading == false) {
						this.getList();
					} else {
						return;
					}
				}
			},
			//切换
			reloadList(status) {
				this.listForm.status = status;
				this.listForm.pageIndex = 1;
				this.getList();
			},
			//填写
			goToForm() {
				this.$router.push({
					name: 'MasterPropertyComplaintForm'
				})
			},
			//详情
			goToInfo(item) {
				this.$router.push({
					name: 'MasterPropertyComplaintInfo',
					query: {
						id: item.id
					}
				})
			},
			//撤销
			del(item) {
				var _this = this;
				var btnArray = ['否', '是'];
				mui.confirm('您确认删除吗？', ' ', btnArray, function(e) {
					if (e.index == 1) {
						_this.delAction(item)
					}
				})
			},
			delAction(item) {
				this.isLoading = true;
				API_Property.delRepairAndComplaint(item.id).then(response => {
					this.isLoading = false;
					mui.toast('撤销成功');

					this.listForm.pageIndex = 1;
					this.getList();

				}).catch(error => {
					this.isLoading = false;
					mui.toast(error);
				})
			},
			asynCallBack() {

			},
		},
		mounted() {
			this.getList();
			//监控下拉加载事件
			var _this = this;
			window.addEventListener('scroll', _this.handleScrool);
		},
		destroyed() {
			//销毁监听事件
			var _this = this;
			window.removeEventListener('scroll', _this.handleScrool);
		},
		computed: {
			...mapGetters({
				openId: 'wx_openid',
				token: 'token',
				person_data: 'person_data',
				person_popedom: 'person_popedom',
			})
		}
	}
</script>

<style scoped src="$project/assets/css/xpwyfyy.css"></style>
<style src="$project/assets/css/iconfont.css"></style>
<style scoped>
	.mui-segmented-control {
		position: fixed;
		top: 44px;
		z-index: 99;
		background-color: #eee;
	}
	
	.mui-fullscreen {
		position: unset;
		margin-top: 45px;
	}
</style>
