<template>
	<view class="">
		<form @submit="sub">
			<view class="body">
				<input class="input" style="display:none;" name="id" :value=id />
				归属人：<input class="input" name="name" placeholder="员工姓名,如:李小明" :value=name />
			</view>
			<view class="body">
				登录名：<input class="input" name="userName" placeholder="如:lxm" :value=username />
			</view>
			<view v-if="flag=='add'" class="body">
				登录密码：<input class="input" password name="password" />
			</view>
			<view v-if="flag=='add'" class="body">
				确认密码：<input class="input" password name="password1" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">权限选择</view>
				<radio-group name="level">
					<label class="radio">
						<radio class="radio" value="1" :checked="1==level" /><text>录入</text>
					</label>
					</br>
					<label class="radio">
						<radio class="radio" value="2" :checked="2==level" /><text>录入，查询，修改</text>
					</label>
					</br>
					<label class="radio">
						<radio class="radio" value="3" :checked="3==level" /><text>添加用户,修改权限及包含1和2</text>
					</label>
				</radio-group>
			</view>
			<view class="">
				<button type="primary" formType="submit" class="button">
					<p v-if="flag=='add'" class="p">添加</p>
					<p v-if="flag=='update'" class="p">提交</p>
					<p v-if="flag=='delete'" class="p">删除</p>
				</button>
			</view>
			<!-- <view v-if="flag=='update'" class="">
				<button type="primary" formType="submit" class="button">
					<p class="p">提交</p>
				</button>
			</view>
			<view v-if="flag=='delete'" class="">
				<button type="primary" formType="submit" class="button">
					<p class="p">删除</p>
				</button>
			</view> -->
		</form>
	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'

	export default {

		data() {
			return {
				id: '',
				name: '',
				username: "",
				flag: "",
				flagUser: "",
				level: '',
				parm: {
					name: null,
					id: null
				},

			};
		},
		onPullDownRefresh() {},
		onShow() {

			var token = uni.getStorageSync("token");
			if (token.length > 1) {
				var name = uni.getStorageSync("name");
				this.flag = uni.getStorageSync("flag");
				if (this.flag != "add") {
					var flagUser = uni.getStorageSync("flagUser");
					this.flagUser = flagUser;
					this.name = flagUser.name;
					this.username = flagUser.userName;
					this.level = flagUser.level;
					this.id = flagUser.id;
				}
			} else {
				uni.reLaunch({
					url: '../Login/Login',
				});
			}
		},
		onLoad() {

		},
		methods: {
			// ...mapActions('chart', ['updata']),
			sub(event) {
				var serverUrl = this.serverurl;
				const {
					value: user
				} = event.detail;
				var password = user.password;
				var password1 = user.password1;
				if (password != password1) {
					uni.showModal({
						title: '提示',
						content: '两次输入密码不一致',
					});
					return null;
				}
				//url=add,delete....
				var url = uni.getStorageSync("flag");
				if (url == 'add') {
					this.$store.dispatch(url, user).then(_ => {
						uni.showModal({
							title: '提示',
							content: _.message,
						});

					});
				} else {
					var token = uni.getStorageSync("token");
					uni.request({
						url: serverUrl + "/TUser/"+url,
						method: "POST",
						data:{
							"id":user.id,
							"name":user.name,
							"level":user.level
						},
						header: {
							'token': token
						},
						success: (Result) => {
							var res = Result;
							uni.showModal({
								title: '提示',
								content: res.data.message,
							});
						}
					});
				}


			},
		}
	}
</script>

<style>
	.body {
		background-color: #FFFFFF;
		padding: 20upx 20upx 20upx 20upx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.input {
		/* padding: 10upx 20upx 10upx 0upx; */
		padding-left: 20upx;
		padding-top: 10upx;
		background-color: #FFFFFF;
		width: 500upx;
		height: 50upx;
		box-shadow: 0upx 0upx 20upx #D3D3D3;
		border-radius: 5upx;
	}

	.button {
		margin: auto;
		width: 60%;
		height: 100upx;
	}

	.p {
		/* #ifdef H5 */
		top: -13%;
		/* #endif */
		width: 80upx;
		height: 60upx;
		font-size: 40upx;
		padding-top: 6upx;
		/* #ifndef H5 */
		padding-top: 10upx;
		/* #endif */

		position: absolute;
		/* 水平居中 */
		left: 50%;
		-webkit-transform: translateX(-50%);
		transform: translateX(-50%);
	}

	.radio {
		padding-top: 20upx;
		padding-left: 30upx;
	}
</style>
