<template>
	<view>
		<form @submit="formSubmit" >

		                <view class="uni-form-item uni-column">
		                    <view class="title">用户名</view>
		                    <input class="uni-input" name="username" placeholder="这是一个输入框" />
		                </view>
						<view class="uni-form-item uni-column">
						    <view class="title">密码</view>
						    <input class="uni-input" name="password" placeholder="这是一个输入框" />
						</view>
		                <view class="uni-btn-v">
		                    <button form-type="submit">登陆</button>
		                </view>
		            </form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
		methods:{
			formSubmit: function(e) {
				var formdata = e.detail.value
				console.log(formdata.username)
				uni.request({
				    url: 'http://127.0.0.1:8000/login/',
					method:'POST',
				    data: {
				        username: formdata.username,
						pwd: formdata.password,
				    },
				    success: (res) => {
				        console.log(res.data);
						if(res.data.code == 1){
							uni.showToast({
								icon:'error',
							    title: res.data.msg,
							    duration: 2000
							});
						}
						else{
							uni.setStorage({
							    key: 'token',
							    data: res.data.data.token
							});
							uni.navigateTo({
							    url: '../vip_index/index'
							});
						}
						
				    },
					fail(e) {
						uni.showToast({
						    title: '服务器出错，请联系管理员！',
						    duration: 2000
						});
					}
				});


			},
		}
		
	}
</script>

<style lang="scss">

</style>
