<template>
	<view class="v-pages v-pages-bg p-b-24">
		<view class="v-pages-search">
			<view class="search_box row flex-align-center">
				<view class="col">
					<input v-model="searchValue" @confirm="search" type="text" class="input" confirm-type="search"
						placeholder-style="color:#999" placeholder="输入线路名称" />
				</view>
				<view class="btn_img" @click="search()">
					<image src="/subPageB/static/img/icon-search.png" class="img"></image>
				</view>
			</view>

			<view class="dy_fx amt_30">
				<view @tap="changePanel" :class="[searchItemClass, selectedParam.hiddenSortPanel ? 'active' : '']"
					data-type="hiddenSortPanel">智能排序</view>
				<view @tap="changePanel" :class="[searchItemClass, selectedParam.hiddenAttributePanel ? 'active' : '']"
					data-type="hiddenAttributePanel">分类筛选</view>
			</view>
		</view>

		<scroll-view @scroll="onReachScroll" @bindscrolltolower="lower" class="scroll-view" :scroll-top="topNum"
			scrollY="true">
			<view class="v-pages-list" v-if="listDatas.length>0">
				<navigator hover-class="none"
					:url="'/subPageA/travelroute/travelroutedetail/travelroutedetail?id=' + itemName.id"
					v-for="(itemName, index) in listDatas" :key="index">
					<view class="list_item vertical circle">
						<view class="item_recommend normal" v-if="itemName.isrecommend=='YES'">
							热门推荐
						</view>
						<view class="item_image">
							<image mode="aspectFill" class="img" :src="itemName.hlogo"></image>
						</view>
						<view class="item_content">
							<view class="content-name">{{ itemName.hname }}</view>
							<view class="content-desc">{{ itemName.dicname }}</view>
						</view>
					</view>
				</navigator>
			</view>
			<view class="scroll-empty" v-else>
				<image class="empty-icon" src="https://eluyou.ailuquan.cn/upload/image/2024/mapIcon/daolan/no-data.png" mode="widthFix">
				</image>
				<view class="empty-tip">~ 暂无相关数据 ~</view>
			</view>
		</scroll-view>

		<view class="sort-page" :hidden="selectedParam.hiddenSortPanel">
			<view class="sort-group">
				<view @tap="selected"
					:class="[pageClass.sortItemClass, selectedParam.sortId == item.id ? 'sort-item-active' : '']"
					data-panel="hiddenSortPanel" data-type="sortId" :data-id="item.id"
					v-for="(item, index) in filter.sort" :key="index">
					{{ item.name }}
				</view>
			</view>
		</view>

		<view class="sort-page" :hidden="selectedParam.hiddenRegionPanel">
			<view class="sort-group">
				<view @tap="regionSelected"
					:class="[pageClass.sortItemClass, selectedParam.bm == item.bm ? 'sort-item-active' : '']"
					data-panel="hiddenRegionPanel" :data-name="item.title" data-type="bm" :data-id="item.bm"
					v-for="(item, index) in regionList" :key="index">
					{{ item.title }}
				</view>
			</view>
		</view>

		<view class="filter-page" :hidden="selectedParam.hiddenAttributePanel">
			<view class="filter-box">
				<scroll-view scrollY class="filter-hd">
					<view @tap="parentLevel"
						:class="[pageClass.filterHdItemClass, parentLevelItem == 'attribute_' + items.type ? 'filter-hd-item-active' : '']"
						:data-parentLevelItem="'attribute_' + items.type" v-for="(items, index) in filter.attribute"
						:key="index">
						{{ items.name }}
					</view>
				</scroll-view>
				<scroll-view scrollY class="filter-bd">
					<view class="filter-group" v-if="parentLevelItem == 'attribute_' + items.type"
						v-for="(items, index) in filter.attribute" :key="items.dicnum">
						<view @tap="childLevel"
							:class="[pageClass.filterBdItem, selectedFIlter['attribute_' + items.type] == 0 ? 'filter-bd-item-active' : '']"
							data-id="0" :data-type="'attribute_' + items.type">
							全部
						</view>
						<view @tap="childLevel"
							:class="[pageClass.filterBdItem, selectedFIlter['attribute_' + items.type] == item.dicnum ? 'filter-bd-item-active' : '']"
							:data-id="item.dicnum" :data-type="'attribute_' + items.type"
							v-for="(item, childIndex) in items.child" :key="childIndex">
							{{ item.dicname }}
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="control-bar-block">
				<view @tap="resetFilter" class="control-back-btn">恢复默认</view>
				<view @tap="confirmClick" class="control-confirm-btn">确定</view>
			</view>
		</view>

	</view>
	<!-- </mescroll-uni>
</view> -->
</template>

<script>
	export default {
		data() {
			return {
				searchItemClass: 'search-tip-item',
				pageClass: {
					sortItemClass: 'sort-item',
					filterHdItemClass: 'filter-hd-item',
					filterBdItem: 'filter-bd-item'
				},
				priceSymbol: '',
				destinationBak: 'all',
				destination: 'all',
				filter: [],
				regionList: [],
				parentLevelItem: 'attribute_ltype',
				defaultFilter: {
					attribute_ltype: 0
				},
				latitude: 0,
				longitude: 0,
				selectedFIlterBak: {
					attribute_ltype: 0
				},
				selectedFIlter: {
					attribute_ltype: 0
				},
				selectedParam: {
					sortId: 2,
					bm: '',
					hiddenSortPanel: !0,
					hiddenAttributePanel: !0,
					hiddenRegionPanel: !0
				},
				param: {
					page: 1,
					noData: !1,
					loading: !1,
					finished: !1
				},
				listDatas: [],
				topNum: 0,
				rootPaht: this.$config.ROOTPATH,
				stype: '',
				regionname: '区域',
				searchValue: "",
				netType: true
			};
		},
		onLoad(option) {
			var that = this;
			this.$util.getNetworkType(
				function(res) {
					if (res.networkType === 'none') {
						uni.showToast({
							title: that.$param.netMsg,
							icon: "none",
							duration: 2000
						})
						that.netType = false;
					}
				},
				function() {
					uni.showToast({
						title: that.$param.netMsg,
						icon: "none",
						duration: 2000
					})
					that.netType = false;
				}
			)
			if (!that.netType) {
				return;
			}
			this.$util.hideLoadingByTime();
			uni.showLoading({
				title: '加载中',
				mask: true
			});
			this.initData();
			var region = option.region;
			if (region != null && region != '') {
				this.selectedParam.bm = region;
				this.get_data(region);
			} else {
				this.getRedisData();
			}
			this.getRedisRegion();
			this.get_attribute(); /* this.requestLocation(), */
			that.$util.saveOperatorLog(that, 'FUN', '线路');
		},
		onShow() {
			this.destinationBak != this.destination && (this.initData(), this.get_data(this.selectedParam.bm));
		},
		methods: {

			initData: function() {
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				var param = {};
				param.page = 1;
				param.noData = false;
				param.finished = false;

				this.param = param;
				this.listDatas = [];
				this.destinationBak = this.destination;
			},
			selected: function(event) {
				this.initData();
				var dataset = event.currentTarget.dataset;
				var param = this.selectedParam;

				param[dataset.type] = dataset.id;
				param.hiddenSortPanel = !0;

				//console.log(dataset.id);
				this.selectedParam = param;

				this.get_data(this.selectedParam.bm);
			},
			regionSelected: function(event) {
				this.initData();
				var dataset = event.currentTarget.dataset;
				var param = this.selectedParam;

				param[dataset.type] = dataset.id;
				param.hiddenRegionPanel = !0;

				//console.log(dataset.id);
				this.selectedParam = param;
				this.regionname = dataset.name;
				this.get_data(this.selectedParam.bm);
			},
			changePanel: function(event) {
				var dataSet = event.currentTarget.dataset,
					selectedParam = this.selectedParam;
				'hiddenSortPanel' == dataSet.type ? (selectedParam.hiddenAttributePanel = !0, selectedParam
						.hiddenRegionPanel = !0) : (selectedParam.hiddenSortPanel = !0),
					(selectedParam[dataSet.type] = !selectedParam[dataSet.type]),
					(this.selectedParam = selectedParam);
			},
			changeRegionPanel: function(event) {
				var dataSet = event.currentTarget.dataset,
					selectedParam = this.selectedParam;
				if ('hiddenRegionPanel' == dataSet.type) {
					selectedParam.hiddenAttributePanel = !0;
					selectedParam.hiddenSortPanel = !0;
				} else {
					selectedParam.hiddenRegionPanel = !0;
				}
				(selectedParam[dataSet.type] = !selectedParam[dataSet.type]), (this.selectedParam = selectedParam);
			},

			resetFilter: function() {
				this.selectedFIlter = {
					attribute_ltype: 0
				}
				this.stype = 0
			},
			confirmClick: function() {
				this.initData();
				//设置选中的筛选项
				var selectedParam = this.selectedParam;
				(selectedParam.hiddenAttributePanel = true), (this.selectedFIlterBak = this.selectedFIlter);
				this.stype = this.selectedFIlterBak.attribute_ltype;
				this.parentLevelItem = 'attribute_ltype';
				this.selectedParam = selectedParam;

				this.get_data(this.selectedParam.bm);
			},
			parentLevel: function(t) {
				var currentTarget = t.currentTarget.dataset;
				//console.log("aaaaaaaaaaaaaaaaa"+a.parentlevelitem);
				this.parentLevelItem = currentTarget.parentlevelitem;
			},
			childLevel: function(t) {
				var a = t.currentTarget.dataset,
					e = this.selectedFIlter;

				this.selectedFIlterBak = e;
				e[a.type] = a.id;
				this.selectedFIlter = e;
			},
			search: function() {
				this.initData();
				this.get_data(this.selectedParam.bm);
			},
			getRedisRegion: function() {
				var that = this;
				var data = {
					key: that.$param.userkey + '_mdd_list'
				};
				that.$Request.post(that.$config.getRedisData, data).then(res => {
					if (res.status == 200) {
						that.regionList = res.data.mddList;
						var all = {
							bm: '',
							title: '全部'
						};
						that.regionList.unshift(all);
						for (var i = 0; i < that.regionList.length; i++) {
							if (that.regionList[i].bm == that.selectedParam.bm) {
								that.regionname = that.regionList[i].title;
							}
						}
					} else {
						that.getRegion();
					}
				});
			},
			getRegion: function() {
				var that = this;
				var url = this.$config.getMessageInfoFormFilter;
				var data = {
					type: this.$param.mddType,
					userkey: this.$param.userkey,
					pageSize: 100,
					sort: '2'
				};
				this.$Request.post(url, data).then(res => {
					var flag = that.$util.isSuccess(res);
					if (!flag) {
						return;
					}
					that.regionList = res.data;
					var all = {
						bm: '',
						title: '全部'
					};
					that.regionList.unshift(all);
					for (var i = 0; i < that.regionList.length; i++) {
						if (that.regionList[i].bm == that.selectedParam.bm) {
							that.regionname = that.regionList[i].title;
						}
					}
				});
			},
			get_attribute: function() {
				var that = this;
				var url = this.$config.getCondition;
				var data = {
					type: 'line',
					userkey: this.$param.userkey,
					condition: this.$param.lineType
				};

				this.$Request.post(url, data).then(res => {
					var flag = that.$util.isSuccess(res);
					if (!flag) {
						return;
					}
					this.filter = res.data;
				});
			},
			onReachScroll: function(t) {
				t.detail.scrollTop > 50 ? (this.floorstatus = true) : (this.floorstatus = false);
				var a = this.param;
				a.noData || a.finished || a.loading || this.get_data(this.selectedParam.bm);
			},
			getRedisData: function() {
				var that = this;
				var data = {
					key: this.$param.userkey + '_line_list'
				};
				that.$Request.post(that.$config.getRedisData, data).then(res => {
					if (res.status == 200) {
						// that.param.page += 1;
						var listDatas = that.listDatas,
							dataListLen = res.data.lineList.length;
						if (
							(dataListLen == that.pageSize ?
								(that.param.page += 1) :
								(that.param.page = 1 && 0 == dataListLen ? (that.param.noData = true) : (that
									.param.finished = true)),
								(that.param.loading = false),
								dataListLen > 0)
						) {
							for (var i = 0; i < dataListLen; i++) {
								var item = {
									id: res.data.lineList[i].guid,
									hlogo: that.rootPaht + res.data.lineList[i].llogo,
									hname: res.data.lineList[i].lname,
									isrecommend: res.data.lineList[i].isrecommend,
									dicname: res.data.lineList[i].ltype
								};
								that.listDatas.push(item);
								uni.hideLoading();
							}
						}
					} else {
						that.get_data(this.selectedParam.bm);
					}
				});
			},
			get_data: function(selectRegion) {
				var that = this;
				that.param.loading = true;
				//var level = this.selectedFIlterBak['attribute_hlevel'];
				var region = selectRegion;
				// if (selectRegion != undefined && selectRegion != null && selectRegion != '') {
				// 	region = selectRegion;
				// }
				var requestData = {
					userkey: that.$param.userkey,
					pageSize: 10,
					region: region,
					pageno: that.param.page,
					sort: that.selectedParam.sortId,
					type: null == that.stype || 0 == that.stype ? '' : that.stype,
					title: this.searchValue
					// level: (null == level || 0 == level) ? '' : level,
					// lng:this.$param.clng,
					// lat:this.$param.clat
				};
				that.$Request.post(that.$config.getLineInfoFormFilterByPage, requestData).then(res => {
					var flag = that.$util.isSuccess(res);
					if (!flag) {
						uni.hideLoading();
						return;
					}
					var listDatas = that.listDatas,
						dataListLen = res.data.length;
					if (
						(dataListLen == requestData.pageSize ?
							(that.param.page += 1) :
							(that.param.page = 1 && 0 == dataListLen ? (that.param.noData = true) : (that.param
								.finished = true)),
							(that.param.loading = false),
							dataListLen > 0)
					) {
						for (var i = 0; i < dataListLen; i++) {
							var item = {
								id: res.data[i].guid,
								hlogo: that.rootPaht + res.data[i].llogo,
								hname: res.data[i].lname,
								dicname: res.data[i].ltype,
								isrecommend: res.data[i].isrecommend,
								// hphone: res.data[i].hphone,
								// price: res.data[i].playday,
								// distance: res.data[i].areaname
							};
							that.listDatas.push(item);
						}
					}
					uni.hideLoading();
				});
			}
		}
	};
</script>

<style>
	page {
		background: #f5f6fa;
	}
	.sort-page {
		top:180rpx;
	}

	.filter-page {
		top: 180rpx;
	}
</style>
