<template>
	<view>
		<cu-custom bgColor="bg-blue" :isBack="true" backUrl="/pages/index/index">
			<block slot="content">企业列表</block>
		</cu-custom>
		<view :style="[{top:CustomBar + 'px'}]">
			<view class="search-box">
				
				<view class="choose-box">
					<jp-picker v-model="parkId" rangeKey="label" rangeValue="value"
						:range="parkList2" empty="选择园区" :disabled="stype == 3">
					</jp-picker>
				</view>
				<view class="choose-box">
					<jp-picker v-model="parkId" rangeKey="label" rangeValue="value"
						:range="parkList" :disabled="stype == 3" empty="选择楼宇">
					</jp-picker>
				</view>
				
				<view class="input-box">
					<input type="text" placeholder="请输入企业名称" v-model="curWord" confirm-type="search"
					></input>
				</view>
				
				<text class="cuIcon-search color-white" @click="doSearch"></text>
			</view>
			
			<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" :up="upOption" @up="upCallback">
				<view class="cu-item" :class="modalName=='move-box-'+ index?'move-cur':''"
					v-for="(item, index) in dataList" :key="index" @touchstart="ListTouchStart"
					@touchmove="ListTouchMove" @touchend="ListTouchEnd" :data-target="'move-box-' + index">
					
					
					<view class="item-box" @click="gotoBuildInfo(item.id)">
						<view class="item-title">
							
							<view>
								{{item.name.substring(0,14)}}
							</view>
							<view class="btn-box" v-if="stype == 5">
								<view class="edit-botton" @click.stop="edit(item.id)">修改</view>
								<view class="del-botton" @click.stop="del(item.id)">删除</view>
							</view>
						</view>
						<view class="item-line">
							<view class="item-name">所属楼宇：</view>
							<view class="item-content">{{item.lyname}}</view>
						</view>
						<view class="item-line">
							<view class="item-name">所属楼层：</view>
							<view class="item-content">{{item.floor}}-{{item.des3}}</view>
						</view>
						<view class="item-line">
							<view class="item-name">联系人&emsp;：</view>
							<view class="item-content">{{item.lxr}}（{{item.phone}}）</view>
						</view>
					</view>
									
					
					
				</view>
			</mescroll-body>
			<uni-fab :pattern=" {
							color: '#7A7E83',
							backgroundColor: '#fff',
							selectedColor: '#007AFF',
							buttonColor: '#007AFF'
						}" horizontal="right" vertical="bottom" @fabClick="add" v-if="stype == 5"></uni-fab>
		</view>
	</view>
</template>

<script>
	import uniFab from '@/components/uni-fab/uni-fab.vue';
	import loginService from '@/api/auth/loginService.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 使用mixin (在main.js注册全局组件)
		onShow(option) {
			this.$auth.checkLogin()
		},
		components: {
			uniFab
		},
		data() {
			return {
				searchForm: {},
				parkList2: [],
				curWord: "", //当前搜索关键词
				dataList: [], // 数据列表
				modalName: null,
				tablePage: {
					total: 0,
					currentPage: 1,
					pageSize: 10,
					orders: []
				},
				loading: false,
				parkId: '',
				parkList: [],
				stype: '',  // 企业 => 3  楼宇 => 2  园区 => 1  zfadmin => 4  admin=> 5
			}
		},
		created() {
			this.stype = uni.getStorageSync('stype')
			if (this.stype != 3) {
				this.getParkList()
				this.getParkList2()
			}
		},
		methods: {
			
			getParkList2() {
				loginService.parkList({
					current: 1,
					size: 1000000,
				}).then(({
					data
				}) => {
					this.parkList2 = data.records.map((item) => {
						return {
							label: item.parkName,
							value: item.id
						}
					})
					console.log(this.parkList2, '=============>')
				}).catch(e => {
					console.log(e)
				})
			},
			
			
			getParkList() {
				loginService.list({
					current: 1,
					size: 1000000,
				}).then(({
					data
				}) => {
					this.parkList = data.records.map((item) => {
						return {
							label: item.buildingName,
							value: item.id
						}
					})
					console.log(this.parkList, '=============>')
				}).catch(e => {
					console.log(e)
				})
			},
			
			
			// 新增
			add() {
				uni.navigateTo({
					url: '/pages/comEdit/comEdit'
				})
			},
			// 修改
			edit(id) {
				uni.navigateTo({
					url: '/pages/comEdit/comEdit?id=' + id
				})
			},
			gotoBuildInfo(id) {
				uni.navigateTo({
					url: `/pages/comEdit/comEdit?id=${id}&ischeck=1`
				})
			},
			// 删除
			del(id) {
				uni.showModal({
					title: '提示',
					content: '您确认要删除数据吗',
					showCancel: true,
					success: (res) => {
						if (res.confirm) {
							loginService.deleteCom(id).then(({
								data
							}) => {
								uni.showToast({
									title: data,
									icon: "success"
								})
								this.doSearch()
							})
						}
					}
				});
			},
			/*获取数据列表 */
			upCallback(page) {
				this.loading = true
				loginService.comlist({
					current: page.num,
					size: page.size,
					name: this.curWord,
					des1: this.parkId,
					orders: [{ column: 'a.create_date', asc: false }],
					...this.searchForm
				}).then(({
					data
				}) => {
					let curPageData = data.records
					this.mescroll.endBySize(curPageData.length, data.total);
					//如果是第一页需手动制空列表
					if (page.num == 1)
						this.dataList = [];
					//追加新数据
					this.dataList = this.dataList.concat(curPageData);
				}).catch(e => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
			
			// 输入监听
			inputWord(e) {
				
			},
			// 搜索
			doSearch() {
				this.dataList = []; // 先清空列表,显示加载进度
				this.mescroll.resetUpScroll();
			},
			// ListTouch触摸开始
			ListTouchStart(e) {
				this.listTouchStart = e.touches[0].pageX
			},

			// ListTouch计算方向
			ListTouchMove(e) {
				this.listTouchDirection = e.touches[0].pageX - this.listTouchStart > -60 ? 'right' : 'left'
			},

			// ListTouch计算滚动
			ListTouchEnd(e) {
				if (this.listTouchDirection == 'left') {
					this.modalName = e.currentTarget.dataset.target
				} else {
					this.modalName = null
				}
				this.listTouchDirection = null
			}
		}
	}
</script>

<style>
	.ellipsis-description {
		font-size: 12px;
		line-height: $line-height-base;
		display: -webkit-box;
		/*作为弹性伸缩盒子模型显示*/
		-webkit-line-clamp: 1;
		/*显示的行数；如果要设置2行加...则设置为2*/
		overflow: hidden;
		/*超出的文本隐藏*/
		text-overflow: ellipsis;
		/* 溢出用省略号*/
		-webkit-box-orient: vertical;
		/*伸缩盒子的子元素排列：从上到下*/
	}

	.cu-bar .search-form {
		background-color: white;
	}
	
	
	.item-box{
		width: 710rpx;
		margin-left: 20rpx;
		background: #FFFFFF;
		box-shadow: 0px 1px 3px 0px rgba(9,2,4,0.1);
		border-radius: 10px;
		padding-top: 20rpx;
		padding-left: 38rpx;
		padding-right: 10rpx;
		margin-top: 20rpx;
	}
	
	.item-title{
		position: relative;
		display: flex;
		justify-content: space-between;
		font-size: 30rpx;
		color: #333;
		font-weight: bold;
		align-items: center;
	}
	
	.item-line{
		display: flex;
		height: 48rpx;
		margin-top: 20rpx;
	}
	
	.subtitle{
		color: #E5880E;
	}
	
	.item-name{
		font-size: 30rpx;
		color: #333;
	}
	
	.item-content{
		color: #1497EF;
		font-size: 30rpx;
	}
	
	.btn-box{
		display: flex;
	}
	
	.line-zs{
		width: 2rpx;
		height: 30rpx;
		background: #36A7F3;
	}
	
	.edit-botton{
		width: 100rpx;
		height: 48rpx;
		line-height: 48rpx;
		color: #fff;
		font-size: 28rpx;
		margin-right: 20rpx;
		border-radius: 10rpx;
		background: #5A9EE9;
		text-align: center;
	}
	
	.del-botton{
		width: 100rpx;
		height: 48rpx;
		line-height: 48rpx;
		color: #fff;
		font-size: 28rpx;
		margin-right: 20rpx;
		border-radius: 10rpx;
		background: #F27C85;
		text-align: center;
	}
	
	.color-white{
		color: #fff;
		font-size: 40rpx;
		line-height: 60rpx;
	}
	
	.search-box{
		background: #36A7F3;
		display: flex;
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-bottom: 10rpx;
	}
	
	.input-box{
		background: #fff;
		height: 60rpx;
		width: 420rpx;
		display: flex;
		align-items: center;
		border-radius: 30rpx;
		padding-left: 10rpx;
		margin-right: 20rpx;
	}
	
	.choose-box{
		background: #fff;
		width: 200rpx;
		border-radius: 30rpx;
		height: 60rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
	}
	
	
</style>