<template>
	<view class="page">
		<u-navbar title="新建房间" :border-bottom="false" :background="bgc" back-icon-color="#262B37" title-color='#262B37'
			title-size='36' height='40' id="navbar">
		</u-navbar>
       <view class="dalist">
       	  <view class="box">
       	  	<view class="name">
       	  		<view class="lt">
       	  			名称
       	  		</view>
       	  		<view class="rt">
       	  			<input type="text" placeholder="请输入房间名称"/> <image src="https://api.ccttiot.com/smartmeter/img/static/uCta8cp7uXd1lGjZS6sc" mode=""></image>
       	  		</view> 
       	  	</view>
       	  	<view class="name">
       	  		<view class="lt">
       	  			类型
       	  		</view>
       	  		<view class="rt" @click="show = true">
       	  			{{leixing}}  <image src="https://api.ccttiot.com/smartmeter/img/static/uCta8cp7uXd1lGjZS6sc" mode=""></image>
       	  		</view> 
       	  	</view>
       	  	<view class="name" style="border: none;">
       	  		<view class="lt">
       	  			是否开启保洁功能
       	  		</view>
       	  		<view class="rt">
       	  			<u-switch size="32" v-model="checked" active-color="#48893B" inactive-color="#eee"></u-switch>
       	  		</view> 
       	  	</view>
       	  </view>
       	  <view class="biaoqian">
       	  	<view class="name">
       	  		标签设置
       	  	</view>
       	  	<view class="bqliat">
       	  	    <view 
       	  	        class="bqitem" 
       	  	        v-for="(item, index) in biaoqianlist" 
       	  	        :key="index" 
       	  	        @click="btnbq(item.dictValue,index)" 
       	  	        :class="{ 'active': isSelected(index) }">
       	  	        {{ item.dictLabel }}
       	  	    </view>
       	  	</view>
       	  </view>
       	  <view class="biaoqian">
       	  	<view class="name">
       	  		房间照片
       	  	</view>
       	  	<image v-if="imgurl == ''" @click="getImage" src="https://api.ccttiot.com/smartmeter/img/static/uRBDOOtzMZgSbCcXQPGH" mode=""></image>
       	  	<image v-else :src="imgurl" mode=""></image>
       	  	<ksp-cropper mode="free" :width="150" :height="150" :maxWidth="1024" :maxHeight="1024" :url="url"
       	  		@cancel="oncancel" @ok="onok"></ksp-cropper>
       	  </view>
       	  
       	  <view class="biaoqian">
       	  	<view class="name">
       	  		价格设置
       	  	</view>
       	  	<view class="shoufei" @click="btnshoufei">
       	  		<view class="shang">
       	  			<view class="">
       	  				收费方式
       	  			</view>
       	  			<view class="">
       	  				<text>套餐1 </text> <image src="https://api.ccttiot.com/smartmeter/img/static/u0rIwef50qNN4aaeqSfl" mode=""></image>
       	  			</view>
       	  		</view>
       	  		<view class="shichang">
       	  			<view class="stop">
       	  				<view class="">
       	  					套餐时长
       	  				</view>
       	  				<view class="">
       	  					套餐价格(元)
       	  				</view>
       	  			</view>
       	  			<view class="stop" v-for="(item,index) in 4" :key="index" style="background-color: #F9F9F9;">
       	  				<view class="">
       	  					3小时
       	  				</view>
       	  				<view class="">
       	  					99.9
       	  				</view>
       	  			</view>
       	  		</view>
				<view class="wz">
					注：订单提前结束剩余消费时长、金额不返还
				</view>
       	  	</view>
<!-- 			<view class="shoufei" @click="btnguize">
				<view class="shang">
					<view class="">
						取消规则
					</view>
					<view class="">
						<text>取消规则1 </text> <image src="https://api.ccttiot.com/smartmeter/img/static/u0rIwef50qNN4aaeqSfl" mode=""></image>
					</view>
				</view>
				<view class="shichang">
					<view class="stop">
						<view class="">
							取消时长
						</view>
						<view class="">
							违约金
						</view>
						<view class="">
							说明
						</view>
					</view>
					<view class="stop" v-for="(item,index) in 4" :key="index" style="background-color: #F9F9F9;">
						<view class="">
							开始前30分钟外
						</view>
						<view class="">
							不收取
						</view>
						<view class="">
						     无
						</view>
					</view>
				</view>
			</view> -->
       	  </view>
       	  
       	  
       	  <u-select v-model="show" :list="list" @confirm="confirm"></u-select>
       	  <view class="anniu">
       	  	<view class="xinjian" @click="btndt">
       	  		取消
       	  	</view>
       	  	<view class="queren" @click="btnmd">
       	  		确认新建
       	  	</view>
       	  </view>
       </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                bgc: {
                	backgroundColor: "#fff",
                },
				leixing:'请选择类型',
				show:false,
				checked:false,
				list:[
					{
						value: '2',
						label: '棋牌'
					},
					{
						value: '1',
						label: '茶室'
					},
					{
						value: '3',
						label: '台球'
					},
				],
				type:'',
				biaoqianlist:[],
				selectedIndices:[],
				token:'',
				url:'',
				imgurl:''
				
			}
		},
		onLoad() {
            
		},
		onShow() {
			this.getbiaoqian()
			this.getQiniuToken()
		},
		methods: {
			// 点击选择收费
			btnshoufei(){
				uni.navigateTo({
					url:'/page_moban/shoufei'
				})
			},
			// 点击选择标签
			btnbq(dictValue,index) {
			const indexExists = this.selectedIndices.includes(index);
			    if (indexExists) {
			        this.selectedIndices = this.selectedIndices.filter(i => i !== index);
			    } else {
			        this.selectedIndices.push(index);
			    }
			},
			isSelected(index) {
			    return this.selectedIndices.includes(index);
			},
			// 获取标签
			getbiaoqian(){
				this.$u.get(`/appVerify/getDictData?dictType=ss_room_tags`).then((res) => {
					if (res.code == 200) {
						this.biaoqianlist = res.data
					}
				})
			},
			// 点击上传图片
			getImage() {
				uni.chooseImage({
					count: 1,
					success: (rst) => {
						this.url = rst.tempFilePaths[0]
						console.log(this.url);
					}
				})
			},
			onok(ev) {
				this.url = ""
				this.path = ev.path
				let _this = this
				let math = 'static/' + _this.$u.guid(20)
				wx.uploadFile({
					url: 'https://up-z2.qiniup.com',
					name: 'file',
					filePath: _this.path,
					formData: {
						token: _this.token, //后端返回的token
						key: 'smartmeter/img/' + math
					},
					success: function(res) {
						let str = JSON.parse(res.data)
						_this.imgurl = 'https://lxnapi.ccttiot.com/' + str.key
					}
				})
			},
			oncancel() {
			     // url设置为空，隐藏控件
			     this.url = "";
			},
			// 获取上传七牛云token
			getQiniuToken() {
				this.$u.get("/common/qiniu/uploadInfo").then((res) => {
					if (res.code == 200) {
						this.token = res.token
					}
				})
			},
			// 确认选择类型
			confirm(e){
				this.type = e[0].value
				this.leixing =e[0].label
			},
			// 点击确定新建房间
			btnmd(){
				
			},
			// 点击取消
			btndt(){
				uni.navigateBack()
			}
			
		}
	}
</script>

<style lang="scss">
	.active{
		background-color: #48893B !important;
		color: #fff !important;  
	}
	page {
		background: #F6F6F6;
	}
	.dalist{
		width: 100%;
		height: 80vh;
		overflow: scroll;
		padding-bottom: 40rpx;
		box-sizing: border-box;
	}
	.biaoqian{
		width: 680rpx;
		max-height: 1624rpx;
		background: #FFFFFF;
		padding: 44rpx 34rpx;
		box-sizing: border-box;
		margin: auto;
		margin-top: 22rpx;
		border-radius: 20rpx;
		.shoufei{
			margin-top: 30rpx;
			.wz{
				font-size: 24rpx;
				color: #3D3D3D;
				margin-top: 24rpx;
				margin-bottom: 20rpx;
			}
			.shichang{
				margin-top: 34rpx;
				.stop{
					display: flex;
					width: 618rpx;
					height: 76rpx;
					line-height: 76rpx;
					background: #F0F0F0;
					view{
						width: 50%;
						text-align: center;
						font-size: 28rpx;
						color: #3D3D3D;
					}
				}
			}
			.shang{
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				view{
					font-size: 32rpx;
					color: #3D3D3D;
					display: flex;
					align-items: center;
					image{
						width: 14rpx;
						height: 42rpx;
						margin-top: 0;
						margin-right: 10rpx;
					}
				}
			}
		}
		image{
			width: 144rpx;
			height: 144rpx;
			margin-top: 30rpx;
		}
		.name{
			font-weight: 600;
			font-size: 36rpx;
			color: #3D3D3D;
		}
		.bqliat{
			margin-top: 30rpx;
			display: flex;
			flex-wrap: wrap;
			.bqitem{
				margin-right: 10rpx;
				border: 1px solid #48893B;
				color: #48893B;
				padding: 10rpx;
				margin-top: 10rpx;
			}
			image{
				width: 226rpx;
				height: 58rpx;
			}
		}
	}
	.anniu{
		width: 750rpx;
		height: 152rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 8rpx 20rpx 0rpx rgba(0,0,0,0.3);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		position: fixed;
		left: 0;
		bottom: 0;
		display: flex;
		justify-content: space-between;
		padding: 0 36rpx;
		box-sizing: border-box;
		padding-top: 24rpx;
		.queren{
			width: 314rpx;
			height: 104rpx;
			background: #48893B;
			text-align: center;
			line-height: 104rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #FFFFFF;
			border-radius: 20rpx;
		}
		.xinjian{
			width: 314rpx;
			height: 104rpx;
			border: 2rpx solid #48893B;
			border-radius: 20rpx;
			text-align: center;
			line-height: 104rpx;
			font-weight: 600;
			font-size: 36rpx;
			color: #48893B;
		}
	}
	.box{
		width: 680rpx;
		max-height: 408rpx;
		background: #FFFFFF;
		margin: auto;
		margin-top: 22rpx;
		border-radius: 20rpx;
		.name{
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 618rpx;
			margin: auto;
			height: 110rpx;
			border-bottom: 1px solid #D8D8D8;
			.lt{
				font-size: 32rpx;
				color: #3D3D3D;
			}
			.rt{
				display: flex;
				align-items: center;
				input{
					text-align: right;
				}
				image{
					width: 14rpx;
					height: 42rpx;
					margin-left: 10rpx;
				}
			}
		}
	}


</style>