<template>
	<view class="boxContent">

		<view class="box-header">
			<view class="search-wrap">
				<!-- 如果使用u-search组件，必须要给v-model绑定一个变量 -->
				<u-search v-model="keyword" placeholder="地址/河道等" @change="tosearch()" @search="tosearch()" height="56"
					:action-style="{color: '#fff'}">
				</u-search>
			</view>
			<u-dropdown ref="uDropdown" :close-on-click-mask="mask">
				<u-dropdown-item title="问题类型">
					<view class="slot-content">
						<view class="item-box">
							<view class="item" :class="[item.active ? 'active' : '']" @tap="tagClick(index)"
								v-for="(item, index) in options1" :key="index">
								{{item.label}}
							</view>
						</view>
						<u-button type="primary" @click="tosearch">确定</u-button>
					</view>
				</u-dropdown-item>
				<u-dropdown-item v-model="value3" :title="value3==''?'工单状态':value3" @change="toChangeStatus()"
					:options="options3">
				</u-dropdown-item>
			</u-dropdown>
		</view>
		<view class="list" style="padding-top: 188rpx;">
			<block v-for="(item, index) in dataList">
				<u-card :title="item.created_at" @click="todetail(item.id)" padding="20" margin="20rpx" :border="true"
					:sub-title="item.created_at" :thumb="thumb" thumb-width="36">
					<view class="" slot="body">
						<u-row gutter="16">
							<u-col span="3">
								<view class="demo-layout bg-purple">问题类别：</view>
							</u-col>
							<u-col span="3">
								<view class="demo-layout bg-purple-light">{{item.feedback_department.name}}</view>
							</u-col>
							<u-col span="3">
								<view class="demo-layout bg-purple">问题内容：</view>
							</u-col>
							<u-col span="3">
								<view class="demo-layout bg-purple-light">{{item.created_at}}</view>
							</u-col>
						</u-row>
						<u-row gutter="16">
							<u-col span="3">
								<view class="demo-layout bg-purple">反馈科室：</view>
							</u-col>
							<u-col span="3">
								<view class="demo-layout bg-purple-light">{{item.feedback_department.name}}</view>
							</u-col>
							<u-col span="3">
								<view class="demo-layout bg-purple">提交日期：</view>
							</u-col>
							<u-col span="3">
								<view class="demo-layout bg-purple-light">{{item.created_at}}</view>
							</u-col>
						</u-row>
						<u-row gutter="16">
							<u-col span="3">
								<view class="demo-layout bg-purple">描述：</view>
							</u-col>
							<u-col span="9">
								<view class="demo-layout bg-purple-light">{{item.content}}</view>
							</u-col>
						</u-row>
					</view>
					<view class="footer" slot="foot">
						<block >
							<u-button type="primary"  size="mini"
								@click="toOperate(item.id)" :ripple="true">工单处理
							</u-button>
						</block>
						<block >
							<u-button type="primary"  size="mini" @click="toAssin(item.id)"
								:custom-style="customStyle" :ripple="true">工单分配
							</u-button>
						</block>
					</view>
				</u-card>

			</block>

			<u-empty text="暂无数据" margin-top="200" v-if="dataList.length==0" mode="list"></u-empty>
		</view>
	</view>


</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#007AFF'
				},
				mask: true,
				dataList: [],
				thumb: "/static/img/location.png",
				currentPage: 0,
				customStyle: {
					marginLeft: '20px'
				},
				currentRole: "inspector", //前端用户角色：inspector巡查员，manager管理员，operator现场处置人员
				value1Arr: [],
				value1: "",
				value2: '',
				value3: '',
				value3v: '',
				keyword: "",
				title: "",
				stat: [],
				options1: [],
				options2: [],
				options3: [{
					label: "所有",
					value: "所有",
					v: ""
				}, {
					label: "待处理",
					value: "待处理",
					v: "save"
				}, {
					label: "处理中",
					value: "处理中",
					v: "ongong"
				}, {
					label: "已处理",
					value: "已处理",
					v: "finashed"
				}]
			}
		},
		onReachBottom: function(e) {
			this.loadPage(this.currentPage + 1);
		},
		onPullDownRefresh: function(e) {
			this.loadPage(1);
		},
		onShow: function() {
			var that = this;
		},
		onLoad(options) {
			this.loadPage(1);
		},
		methods: {
			toChangeStatus: function(value) {
				var jsonSearch = this.options3.filter(function(e) {
					return e.value == value;
				});
				this.value3v = jsonSearch[0].v;
				console.log(jsonSearch)
				this.loadPage(1)
				this.$refs.uDropdown.close();
			},
			tosearch() {
				this.value1Arr = [];
				for (var m of this.options1) {
					if (m.active) {
						this.value1Arr.push(m.value);
					}
				}
				this.loadPage(1)
				this.$refs.uDropdown.close();
			},
			tagClick(index) {
				this.options1[index].active = !this.options1[index].active;
			},
			loadAreaList: function() {
				var that = this;
				that.options1 = [];
				this.util.request({
					api: 'worker/get-zones',
					utilSuccess: function(res) {
						for (var m of res) {
							that.options1.push({
								label: m.name,
								value: m.id,
								active: false
							});
						}
					},
					utilFail: function(res) {
						console.log(res)
					}
				});
			},

			toAssin: function(id) {
				uni.navigateTo({
					url: "../assign/assign?id=" + id
				})
			},
			toOperate: function(id) {
				uni.navigateTo({
					url: "../operate/operate?id=" + id
				})
			},
			add: function() {
				uni.navigateTo({
					url: "../addPatrol/addPatrol"
				})
			},
			todetail: function(id) {
				uni.navigateTo({
					url: "../patrolInfo/info?id=" + id
				})
			},
			loadPage: function(page) {
				uni.hideKeyboard()
				var that = this;
				this.util.request({
					bindThis: that,
					api: '/api/mobile/common-inspection/index',
					customLoading: false,
					data: {
						page: page,
						page_size: 5,
						keyword: that.keyword
					},
					utilSuccess: function(r) {
						var res = r.data;
						uni.stopPullDownRefresh(); // 服务器总条数 < 每页条数, 会将第一页的条数重新返回

						var hasNoMore = that.dataList.length < 5 && page > 1;
						if (hasNoMore || res.length == 0 && page > 1) {
							// 已加载到最后一页
							uni.showToast({
								title: '已加载到最后一页',
								icon: 'none'
							});
							return;
						}
						var dataList = that.dataList;


						if (page == 1) {
							dataList = res;
						} else {
							dataList.push(...res);
						}
						for (var m of dataList) {
							m.created_at = m.created_at.split("T")[0]
						}
						console.log(dataList)

						that.currentPage = page;
						that.dataList = dataList;
					},
					utilFail: function(res) {
						uni.stopPullDownRefresh();

						if (page == 1) {

							that.currentPage = page;
						}

						this.util.alert(res);
					}
				});
			}

		}

	}
</script>
<style>
	.boxContent {
		background: #f3f4f6;
		min-height: 100vh;
	}

	.footer {
		display: flex;
		justify-content: flex-end;
	}

	.box-header {

		position: fixed;
		top: 0;
		width: 100%;
		z-index: 99;
	}


	.u-row {
		margin: 10rpx 0;
		font-size: 28rpx;
	}
	.u-card{
		z-index: 1;
	}
</style>


<style scoped lang="scss">
	.search-wrap {
		background: #007AFF;
		padding: 20rpx;
	}

	.u-config-wrap {
		padding: 30rpx;
	}

	.bg-purple {
		font-weight: bold;
	}

	.slot-content {
		background-color: #FFFFFF;
		padding: 24rpx;

		.item-box {
			margin-bottom: 50rpx;
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.item {
				border: 1px solid $u-type-primary;
				color: $u-type-primary;
				padding: 8rpx 40rpx;
				border-radius: 100rpx;
				margin-top: 30rpx;
			}

			.active {
				color: #FFFFFF;
				background-color: $u-type-primary;
			}
		}
	}
</style>
