<template>
	<view class="u-page">
		<uni-section title="醇油坊" type="line">
			<uni-card :is-shadow="false" :isFull="true" :border="true">
				<text>
					醇油坊进销存管理平台，醇油坊项目监管工具。 v {{sssss}}
				</text>
			</uni-card>
			<uni-card title="登录" :thumbnail="avatar" sub-title="监管人员登录后进行监管记录等操作" extra="" note="Tips">
				<uni-forms ref="form" :modelValue="formData" :rules="rules">
					<uni-forms-item label="账号:" name="userName">
						<uni-easyinput prefixIcon="person" type="text" v-model="formData.userName"
							placeholder="请输入账号" />
					</uni-forms-item>
					<uni-forms-item label="密码:" name="password">
						<uni-easyinput prefixIcon="locked" type="password" v-model="formData.password"
							placeholder="请输入密码" />
					</uni-forms-item>
				</uni-forms>
				<button @click="dologin">登录</button>
			</uni-card>
		</uni-section>

	</view>
</template>

<script>
	import {
		getCurrentNo
	} from '@/plugins/APPUpdate';
	export default {
		data() {
			return {
				sssss: "",
				avatar: '/static/cyf.png',
				// 表单数据
				formData: {
					userName: 'admin',
					password: '123456'
				},
				rules: {
					// 对name字段进行必填验证
					name: {
						rules: [{
							required: true,
							errorMessage: '账号不可以为空'
						}]
					},
					// 对passwd字段进行必填验证
					passwd: {
						rules: [{
							required: true,
							errorMessage: '密码不可以为空'
						}]
					}
				},
			}
		},
		created() {
			plus.runtime.getProperty(plus.runtime.appid, (appInfo) => {
				// appInfo为当前应用程序的所有信息
				console.log("code", JSON.stringify(appInfo));
				// 获取版本名称
				console.log("code", appInfo.version);
				this.sssss = appInfo.version
				// 获取版本号
				console.log("code", appInfo.versionCode);

				// 获取当前应用id
				console.log("code", appInfo.appid);
			});
		},
		methods: {
			dologin() {
				let _this = this
				this.$refs.form
					.validate()
					.then(r => {
						_this.$store
							.dispatch('login', _this.formData)
							.then(uinfo => {
								console.log('MMMM:', uinfo)
								getApp().globalData.username = uinfo.name
								getApp().globalData.token = uinfo.tokenValue
								//存
								uni.setStorageSync('tokenValue', uinfo.tokenValue);
								console.log('gd--:', getApp().globalData)
								uni.redirectTo({
									url: '/pages/index/index',
								})
								// uni.switchTab({
								//     url: '/pages/home/FindFragment'
								// });

							})
							.catch(er => {
								console.log('EEEE:', er)
							})
					})
					.catch(err => {
						console.log('eeee:', err)
					})
			}
		},
	}
</script>

<style></style>