<template>
	<view class="container">
		<form @submit="onSubmit">
			<view class="page-block">
				<view class="content">
					<view class="cell flex flex-y-center arr-r">
						<view class="title-block required">
							<text>等级</text>
						</view>
						<view class="desc">
							<picker mode="selector" :range="printerAddrList" @change="onPrinterAddrChange">
								<view :class="[printerAddr?'':'desc-placeholder','input-box']">{{printerAddr || '请选择'}}
								</view>
							</picker>
						</view>
					</view>
					
					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>等级名称</text>
						</view>
						<view class="desc">
							<input type="text" :value="obj.name" name="name" class="input-box"
								placeholder="请输入等级名称" placeholder-class="desc-placeholder">
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>升级条件</text>
						</view>
						<view class="desc">
							<input type="number" :value="obj.money" name="money" class="input-box"
								placeholder="累计完成订单金额满(元)" placeholder-class="desc-placeholder">		
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>折扣</text>
						</view>
						<view class="desc">
							<input type="digit" :value="obj.discount" name="discount" class="input-box"
								placeholder="请输入0.1~10之间的数字" placeholder-class="desc-placeholder">
						</view>
					</view>

					<view class="cell flex flex-y-center">
						<view class="title-block required">
							<text>会员等级状态</text>
						</view>
						<view class="desc">
							<view class="flex-center">
								<view class="checklist-box " @click="choicepay(item.status)"
									v-for="(item,index) of integral_arr" :key='index'
									:class="status==item.status?'actt':''">
									<view class="radio__inner" :class="status==item.status?'act_border':''">
										<view :class="status==item.status?'is-default-checked':''"
											class="radio__inner-icon radio__inner-icon ">
										</view>
									</view>
									<text class="checklist-text">{{item.name}}</text>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="footer-bar">
				<view class="content flex flex-center" style="background: none;">
					<button class="btn" hover-class="none" form-type="submit">
						{{obj.id?'修改':'添加'}}
					</button>
				</view>
			</view>

		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				printerAddrList: ['1', '2','3', '4','5', '6','7', '8','9','10'],
				printerAddr: '1',
				integral_arr:[
					{ status:1,
					  name:"开启",},
				    { status:2,
				      name:"关闭",}
				],
				level:1,
				status: 1,
				tableType: "",
				admin_id: "",
				info: {},
				obj:{},
			}
		},

		onLoad(e) {
			if (e.id) {
				this.info = e;
				this.http();
			}
			this.admin_id = uni.getStorageSync("admin_id");
			
		},


		methods: {
			choicepay(index) {
				this.status = index;
			},
			
			onPrinterAddrChange(e) {
				this.printerAddr = this.printerAddrList[e.detail.value];
				this.level = Number(e.detail.value) + 1;
			},
			http(){
				this.request({
					url:"Smdcshop/level_info",
					data: {
						id:this.info.id,
					}
				}).then(res => {
					if (res.code == 200) {
						this.obj=res.data;
						this.level= res.data.level;
						this.status=res.data.status;
						this.printerAddr = this.printerAddrList[this.level-1];
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},
		
			onSubmit(e) {
				let data =e.detail.value,url;
					data.level=this.level;
					data.status=this.status;
					data.admin_id=this.admin_id;
				if (this.info.id) {
					data.id = this.info.id
					url = "Smdcshop/level_update"
				} else {
					url = 'Smdcshop/level_add'
				}
				if (data.name == "") {
					uni.showToast({
						title: "请输入名称",
						icon: 'none'
					})
					return false
				}
				this.request({
					url,
					data: data
				}).then(res => {
					if (res.code == 200) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
						setTimeout(() => {
								uni.navigateBack()
						}, 2000)
					}
				}).catch((res) => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				});
			},
			
			
		}
	}
</script>

<style>
	@import url("../static/css/common.css");

	page {
		background-color: #F4F5F7;
	}
	.checklist-box {

		display: -webkit-box;
		display: -webkit-flex;
		display: flex;

		-webkit-box-orient: horizontal;
		-webkit-box-direction: normal;
		-webkit-flex-direction: row;
		flex-direction: row;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		margin: 5px 0;
		margin-right: 22px;
	}

	.radio__inner {
		-webkit-flex-shrink: 0;
		flex-shrink: 0;

		display: -webkit-box;
		display: -webkit-flex;
		display: flex;

		-webkit-box-pack: center;
		-webkit-justify-content: center;
		justify-content: center;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		position: relative;
		border: 1px solid #DCDFE6;
		border-radius: 2px;
		box-sizing: border-box;
		width: 16px;
		height: 16px;
		border-radius: 16px;
		background-color: #fff;
		z-index: 1;
		-webkit-transition: border-color .3s;
		transition: border-color .3s;
	}

	.radio__inner-icon {
		width: 8px;
		height: 8px;
		border-radius: 10px;
		opacity: 0;
		-webkit-transition: -webkit-transform .3s;
		transition: -webkit-transform .3s;
		transition: transform .3s;
		transition: transform .3s, -webkit-transform .3s;
	}

	.is-default-checked {
		opacity: 1;
		background-color: #007aff;
		-webkit-transform: rotate(45deg) scaleY(1);
		transform: rotate(45deg) scaleY(1);
	}
	
.act_border{
			border: 1rpx solid #007aff;
}

	.checklist-text {
		font-size: 28rpx;
		margin-left: 5px;
		-webkit-transition: color 0.2s;
		transition: color 0.2s;
		color: #000;
	}
</style>
