<template>
	<view>
		<view class="status_bar"></view>
		<view class="" style="position: relative;top: 44px;">
			<view style="position: fixed;z-index: 100;">
				<uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="四情基地"></uni-nav-bar>
				<u-icon name="plus-circle" class="tianjia" @click="clickRight"></u-icon>
			</view>
			<view class="bases_search">
				<view class="bases_search_text">
					<u-icon name="search" class="search" @click="search"></u-icon>
					<input type="text" v-model="data.search" placeholder="请输入基地名称" @input="searchinput" />
				</view>
			</view>
			<view class="bases_none" v-if="base_none">
				暂无数据
			</view>
			<view class="bases" v-else>
				<view class="bases_list" v-for="(items,index) in baselist" :key="index" @click="details(items.id)">
					<view class="bases_list_bgi">
						<image :src="items.base_img" mode=""></image>
						<view class="bgcolor"></view><!-- 黑色蒙版 -->
					</view>
					<view class="bases_list_text">
						<p >{{items.base_name}}</p>
						<p style="font-size: 24rpx;">面积：{{items.base_area}}</p>
						<p style="font-size: 24rpx;">联系人：{{items.base_charge}}</p>
						<p style="font-size: 24rpx;">联系电话：{{items.base_phone}}</p>
						<p style="font-size: 24rpx;">描述：{{items.base_describe}}</p>
					</view>
					<view class="bases_list_xiangqing">
						<u-icon name="more-dot-fill" class="" @click.native.stop="XQclick(items)"></u-icon>
					</view>
					<view class="photoshow">
						<image :src="'https://s3.hnyfwlw.com/webstaticimg/bigdata_app'+'/image/fourMoodBase/2.png'" mode=""></image>
						<image :src="'https://s3.hnyfwlw.com/webstaticimg/bigdata_app'+'/image/fourMoodBase/3.png'" mode=""></image>
						<image :src="'https://s3.hnyfwlw.com/webstaticimg/bigdata_app'+'/image/fourMoodBase/5.png'" mode=""></image>
						<view class="photoshow_num">
							{{items.num}}
						</view>
					</view>
				</view>
				<u-action-sheet :list="actionSheetList" v-model="post_show" @click="message"></u-action-sheet>
			</view>
		</view>
		<view class="top" v-if="isTop" @click="top">
			<image :src="'https://s3.hnyfwlw.com/webstaticimg/bigdata_app'+'/image/6209a98f0cb3b5086f2ca36152c9269.png'" mode=""></image>
		</view>
	</view>
</template>
<script>
	import {
		Debounce,
		Throttle
	} from "../../util/anitthro.js"
	export default {
		data() {
			return {
				data: {
					ret: 'list',
					search: '',
					page_size: 10,
					page: 1
				},
				baselist: [],
				actionSheetList: [{
					text: "编辑基地"
				}, {
					text: "删除基地"
				}],
				post_show: false,
				delid: "",
				facilitynum: "",
				isTop:false,
				jurisdiction:{
					addbase:false,
					alter:false
				},
				base_none:true//基地列表为空判断
			}
		},
		methods: {
			async getFourbase() { //基地列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=base.bases.base_list',
					data: this.data
				})
				console.log(res,'get four base')
				this.baselist = this.baselist.concat(res.data)
				if(this.baselist.length==0){
					this.base_none = true
				}else{
					this.base_none = false
				}
				for (var i = 0; i < this.baselist.length; i++) {
					var arr = this.baselist[i].base_equip.split("#")
					if (arr[0] == '') {
						arr.shift(1)
					}
					console.log(arr)
					this.baselist[i].num = arr.length
				}
				
				console.log(this.baselist,'------------------------- base list')
			},
			async delbase() { //基地列表
				const res = await this.$myRequest({
					url: '/api/api_gateway?method=base.bases.base_list',
					data: {
						ret: "del",
						base_id: this.delid.id
					}
				})
				if(res){
					uni.showToast({
						title: '操作成功！',
						duration: 2000,
						icon:"none"
					});
					
					this.baselist = []
					this.data.page = 1
					this.getFourbase()
				}
			},
			clickLeft() { //返回主页
				uni.switchTab({
					url: "../index/index"
				})
			},
			clickRight() { //添加基地
				if(this.jurisdiction.addbase){
					uni.navigateTo({
						url: "./addbase"
					})
				}else{
					uni.showToast({
						title: "您暂无权限进行此操作，如有需要，请联系管理员",
						icon: "none"
					})
				}
			},
			searchinput() { //搜索
				this.data.page = 1
				this.baselist = []
				Debounce(() => {
					this.getFourbase()
				}, 1000)()
			},
			search() { //搜索按钮
				this.data.page = 1
				this.baselist = []
				this.getFourbase()
				this.$forceUpdate()
			},
			details(id) { //详情页
				uni.navigateTo({
					url: "./basefacility?id=" + id
				})
			},
			XQclick(item) { //编辑
				this.post_show = !this.post_show
				this.delid = item
			},
			message(index) { //编辑或者删除
				console.log(index)
				if (index == 1) {
					console.log(this.delid.id)
					uni.showModal({
						title: '提示',
						content: '确定要删除该基地吗？',
						success: (res) => {
							if (res.confirm) {
								this.delbase()
								// this.baselist = []
								// this.data.page = 1
								// this.getFourbase()
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {
					if(this.jurisdiction.addbase){
						uni.navigateTo({
							url: "./modification?id=" + JSON.stringify(this.delid)
						})
					}else{
						uni.showToast({
							title: "您暂无权限进行此操作，如有需要，请联系管理员",
							icon: "none"
						})
					}
				}
				this.$forceUpdate()
			},
			top() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 500
				})
			}
		},
		onLoad() {
			console.warn('onload  four base')
			// this.getFourbase()
			
			uni.getStorage({
				key:"jurisdiction",
				success:(res)=>{
					console.log(JSON.parse(res.data))
					let items = JSON.parse(res.data).filter((item)=>{
						return item.pur_id == 25//"四情基地"
					})
					let items2 = items[0].children.filter((item)=>{
						return item.pur_id == 26//"基地管理"
					})
					console.log(items2)
					this.jurisdiction.addbase =items2[0].children.some((item)=>{
						return item.pur_id == 111//"新增"
					})
					this.jurisdiction.alter =items2[0].children.some((item)=>{
						return item.pur_id == 110//"修改"
					})
				},
			})
		},
		onReachBottom() { //滑动到底部加载
			console.log('on each bottom 2')
			this.data.page++
			this.getFourbase()
		},
		onShow() {
			console.warn('onshow  four base')
			this.data.page = 1
			this.baselist = []
			this.getFourbase()
			this.$forceUpdate()
		},
		onPageScroll(e) { //nvue暂不支持滚动监听，可用bindingx代替
			if (e.scrollTop > 200) { //距离大于200时显示
				this.isTop = true
			} else { //距离小于200时隐藏
				this.isTop = false
			}
		},
	}
</script>
<style lang="scss">
	.tianjia {
		position: absolute;
		top: 24rpx;
		right: 24rpx;
		font-size: 38rpx;
	}

	.bases_search {
		width: 100%;
		position: fixed;
		top: 88px;
		z-index: 100;
		background-color: #FFFFFF;

		.bases_search_text {
			width: 90%;
			margin: 0 auto;
			background-color: #F8F8F8;
			height: 60rpx;
			border-radius: 30rpx;
			display: flex;
			line-height: 60rpx;

			.search {
				padding: 0 20rpx;
				font-size: 34rpx;
			}

			input {
				width: 80%;
				margin-top: 10rpx;
				font-size: 28rpx;
			}
		}
	}
	.bases_none{
		width: 100%;
		position: relative;
		top: 200rpx;
		font-size: 36rpx;
		text-align: center;
	}
	.bases {
		width: 100%;
		position: relative;
		top: 170rpx;
		.bases_list {
			width: 90%;
			margin: 0 auto 20rpx;
			height: 276rpx;
			position: relative;

			.bases_list_bgi {
				.bgcolor {
					width: 100%;
					height: 276rpx;
					background-color: rgba(0, 0, 0, 0.3);
					border-radius: 25rpx;
				}

				image {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					height: 276rpx;
					border-radius: 25rpx;
					z-index: -1;
				}
			}

			.bases_list_text {
				position: absolute;
				top: 0;
				left: 0;
				z-index: 10;
				padding: 40rpx;
				color: #FFFFFF;
				width: 100%;
				box-sizing: border-box;
				p:first-child{
					font-size: 36rpx;
					width: 90%;
				}
				p:nth-child(3){
					width: 70%;
				}
				p:last-child{
					width: 70%;
				}
				p {
					margin-bottom: 10rpx;
					overflow: hidden;//溢出隐藏
					white-space: nowrap;//禁止换行
					text-overflow: ellipsis;//...
				}
			}

			.bases_list_xiangqing {
				position: absolute;
				top: 20rpx;
				right: 20rpx;
				transform: rotate(90deg);
				font-size: 26rpx;
				color: #FFFFFF;
				width: 40rpx;
				height: 40rpx;
				z-index: 99999;
			}

			.photoshow {
				width: 160rpx;
				height: 34rpx;
				display: flex;
				position: absolute;
				bottom: 26rpx;
				right: 36rpx;
				background-color: #a7a8a0;
				border-radius: 18rpx;
				padding: 4rpx;

				image {
					width: 32rpx;
					height: 32rpx;
					margin-right: 4rpx;
				}

				.photoshow_num {
					width: 50rpx;
					height: 30rpx;
					border: 1px solid #FFFFFF;
					border-radius: 17rpx;
					text-align: center;
					line-height: 28rpx;
					font-size: 24rpx;
					color: #FFFFFF;
				}
			}
		}
	}

	.top {
		position: fixed;
		right: 30px;
		bottom: 100px;
		z-index: 100;

		image {
			width: 100rpx;
			height: 100rpx;
		}
	}
</style>
