<!--
 * @Title: 
 * @Description: 管理工作台
 * @Author: swp
 * @Date: 2022-08-24 10:49:21
 * @LastEditors: 
 * @LastEditTime: 2022-08-24 10:49:21
-->
<template>
	<view class="container">
		<uni-nav-bar dark :fixed="true" backgroundColor="#3F9EFF" statusBar="false" left-icon="left" left-text="返回"
			@clickLeft="toBack">
			<view class="nav-title">
				<text>{{title}}</text>
			</view>
		</uni-nav-bar>
		<uni-section title="行政区选择" type="line">
			<view class="search-block">
				<view style="padding-left: 10px;padding-right: 10px;">
					<uni-data-select v-model="cityRegionValue" :localdata="cityRegionData" @change="cityRegionChange"
						:clear="false" placeholder="请选择盟市"></uni-data-select>
				</view>
				<view style="padding-left: 10px;padding-right: 10px;margin-top: 10px;">
					<uni-data-select v-model="districtRegionValue" :localdata="districtRegionData"
						@change="districtRegionChange" placeholder="请选择区旗县"></uni-data-select>
				</view>
				<view style="padding-left: 10px;padding-right: 10px;margin-top: 10px;">
					<uni-data-select v-model="townRegionValue" :localdata="townRegionData" @change="townRegionChange"
						placeholder="请选择乡镇"></uni-data-select>
				</view>
				<view style="padding-left: 10px;padding-right: 10px;margin-top: 10px;">
					<uni-data-select v-model="countryRegionValue" :localdata="countryRegionData"
						@change="countryRegionChange" placeholder="请选择村"></uni-data-select>
				</view>
			</view>
		</uni-section>
		<view class="search-block">
			<view class="rtu-code">
				<uni-easyinput :styles="inputStyles" @input="searchRtuCodeValClear" prefixIcon="search"
					v-model="searchRtuCodeVal" placeholder="请录入危险区名称">
				</uni-easyinput>
			</view>
			<view class="submit-btn">
				<button type="default" @click="search">查 询</button>
			</view>
		</view>
		<view v-if="list.length>0">
			<uni-list>
				<uni-list-item v-for="item in list" :key="item.id">
					<template v-slot:body>
						<view class="list-item-block">
							<view class="line">
								<text class="title text-ellipsis text-underline" style="color: blue;"
									@click="selectDangerArea(item)">{{item.dangerAreaName}}</text>
							</view>
							<view class="line" style="margin-top: 5px;">
								<!-- <uni-icons class="input-uni-icon" type="map-pin-ellipse" size="18" color="orangered" /> -->
								<text class="lable">所属行政区：</text>
								<text class="content" style="color: gray;">{{item.adnm}}</text>
							</view>
						</view>
					</template>
				</uni-list-item>
			</uni-list>
			<uni-group>
				<view class="pagination-block">
					<uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total"
						@change="pageChange" />
				</view>
			</uni-group>
		</view>
		<view v-else class="view-flex-inline-center">
			<view style="margin-top: 10px;color: gray;font-size: 1rem;">暂无数据</view>
		</view>
	</view>
	</view>
</template>

<script>
	import http from '@/http/api.js';
	export default {
		name: 'regionSelect',
		components: {},
		data() {
			return {
				title: '危险区选择',
				cityRegionValue: '',
				districtRegionValue: '',
				townRegionValue: '',
				countryRegionValue: '',
				cityRegionData: [],
				districtRegionData: [],
				townRegionData: [],
				countryRegionData: [],
				pageSize: 10,
				pageCurrent: 1,
				total: 0,
				list: [],
				searchRtuCodeVal: '',
				query: {},
				inputStyles: {
					color: '#808080',
					borderColor: '#d3d3d3'
				},
				loading: false,
				searchViewStyles: {
					width: '100%',
					height: '40px'
				},
			}
		},
		computed: {

		},
		onInit(option) {

		},
		onLoad(option) {
			this.getCityRegion({});
		},
		onShow() {

		},
		onReady() {

		},
		methods: {
			//返回上一页
			toBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 分页触发
			pageChange(e) {
				this.pageCurrent = e.current;
				let params = {};
				if (this.searchRtuCodeVal != '' && this.searchRtuCodeVal.length > 0) {
					params['dangerAreaName'] = this.searchRtuCodeVal;
				}
				this.getDangerAreaPage(params);
			},
			cityRegionChange(e) {
				this.cityRegionValue = e;
				this.districtRegionData = [];
				this.districtRegionValue = '';
				this.townRegionData = [];
				this.townRegionValue = '';
				this.countryRegionData = [];
				this.countryRegionValue = '';
				let p = {
					'parentCode': this.cityRegionValue
				}
				this.getDistrictRegion(p);
				this.pageCurrent = 1;
				this.query['adcd'] = this.cityRegionValue;
				this.getDangerAreaPage({});
			},
			districtRegionChange(e) {
				if (e == undefined || e == null || e == '') {
					this.districtRegionValue = '';
					this.townRegionData = [];
					this.townRegionValue = '';
					this.countryRegionData = [];
					this.countryRegionValue = '';
					this.pageCurrent = 1;
					this.query['adcd'] = this.cityRegionValue;
					this.getDangerAreaPage({});
				} else {
					this.districtRegionValue = e;
					this.townRegionData = [];
					this.townRegionValue = '';
					this.countryRegionData = [];
					this.countryRegionValue = '';
					let p = {
						'parentCode': this.districtRegionValue
					}
					this.getTownRegion(p);
					this.pageCurrent = 1;
					this.query['adcd'] = this.districtRegionValue;
					this.getDangerAreaPage({});
				}
			},
			townRegionChange(e) {
				if (e == undefined || e == null || e == '') {
					this.townRegionValue = '';
					this.countryRegionData = [];
					this.countryRegionValue = '';
					this.pageCurrent = 1;
					this.query['adcd'] = this.districtRegionValue;
					this.getDangerAreaPage({});
				} else {
					this.townRegionValue = e;
					this.countryRegionData = [];
					this.countryRegionValue = '';
					let p = {
						'parentCode': this.townRegionValue
					}
					this.getCountryRegion(p);
					this.pageCurrent = 1;
					this.query['adcd'] = this.townRegionValue;
					this.getDangerAreaPage({});
				}
			},
			countryRegionChange(e) {
				if (e == undefined || e == null || e == '') {
					this.countryRegionValue = '';
					this.pageCurrent = 1;
					this.query['adcd'] = this.townRegionValue;
					this.getDangerAreaPage({});
				} else {
					this.countryRegionValue = e;
					this.pageCurrent = 1;
					this.query['adcd'] = this.countryRegionValue;
					this.getDangerAreaPage({});
				}
			},
			getCityRegion(params = {}) {
				let that = this;
				http.request({
					url: '/galaxy-business/baseinfo/region/whole/yj/list',
					method: 'GET',
					data: params,
				}).then(res => {
					that.cityRegionData = res.data.map(item => {
						return {
							value: item.adcd,
							text: item.adnm,
						}
					})
				}).catch(err => {
					console.log(err)
				})
			},
			getDistrictRegion(params = {}) {
				let that = this;
				http.request({
					url: '/galaxy-business/baseinfo/region/whole/yj/list',
					method: 'GET',
					data: params,
				}).then(res => {
					that.districtRegionData = res.data.map(item => {
						return {
							value: item.adcd,
							text: item.adnm,
						}
					})
				}).catch(err => {
					console.log(err)
				})
			},
			getTownRegion(params = {}) {
				let that = this;
				http.request({
					url: '/galaxy-business/baseinfo/region/whole/yj/list',
					method: 'GET',
					data: params,
				}).then(res => {
					that.townRegionData = res.data.map(item => {
						return {
							value: item.adcd,
							text: item.adnm,
						}
					})
				}).catch(err => {
					console.log(err)
				})
			},
			getCountryRegion(params = {}) {
				let that = this;
				http.request({
					url: '/galaxy-business/baseinfo/region/whole/yj/list',
					method: 'GET',
					data: params,
				}).then(res => {
					that.countryRegionData = res.data.map(item => {
						return {
							value: item.adcd,
							text: item.adnm,
						}
					})
				}).catch(err => {
					console.log(err)
				})
			},
			getDangerAreaPage(params = {}) {
				const current = this.pageCurrent;
				const size = this.pageSize;
				let postData = Object.assign(params, this.query);
				let that = this;
				http.request({
					url: '/galaxy-business/map/dangerarea/page',
					method: 'GET',
					params: {
						current,
						size,
					},
					data: postData,
				}).then(res => {
					if (res.data.records != null) {
						that.list = res.data.records;
					}
					this.total = res.data.total;
				}).catch(err => {
					console.log(err)
				})
			},
			search() {
				this.pageCurrent = 1;
				let params = {};
				if (this.searchRtuCodeVal != '' && this.searchRtuCodeVal.length > 0) {
					params['dangerAreaName'] = this.searchRtuCodeVal;
				}
				this.getDangerAreaPage(params);
			},
			searchRtuCodeValClear(e) {
				if (e == null || e == '' || e.length == 0) {
					this.searchRtuCodeVal = '';
					this.getDangerAreaPage({});
				}
			},
			onBackPress() {
				// #ifdef APP-PLUS
				plus.key.hideSoftKeybord();
				// #endif
			},
			selectDangerArea(item) {
				let p = {
					'dangerAreaId': item.dangerAreaPid,
					'dangerAreaName': item.dangerAreaName
				};
				uni.$emit('dangerAreaId', JSON.stringify(p))
				this.toBack();
			},
		}
	}
</script>

<style lang="scss" scoped>
	$nav-height: 75px;

</style>