import Taro, { Component } from '@tarojs/taro' import { View, Input, Button, Text, Image } from '@tarojs/components' import URL from '../../serviceAPI.config' import './login.scss' class Login extends Component { config = { navigationBarTitleText: '登入' } constructor() { this.state = { username: '', password: '', backgroundImage: 'background-image:url(' + URL.Base + '/Public/images/bg3.jpg);' } } //用户信息姓名和电话号码接口 setUserInfoToStorage() { Taro.request({ url: URL.ShopWxStore, header: { 'Cookie': 'PFWSSS=' + Taro.getStorageSync('session_id'), } }) .then(res => { if (res.data.err_msg === 'success') { Taro.setStorageSync('user_identity', { username: res.data.otherData.userName, userphone: res.data.otherData.userPhone }) } else { Taro.showToast({ title: res.data.err_msg, icon: 'none', duration: 1500 }) } }) } loginApi() { Taro.request({ url: URL.Base + 'user-login', method: 'POST', dataType: 'json', data: { username: this.state.username, password: this.state.password, }, header: { 'content-type': 'application/x-www-form-urlencoded', 'X-Requested-With': 'XMLHttpRequest' } }) .then(res => { if (res.data.err_code === 0) { Taro.showToast({ title: res.data.err_msg && '登入成功', icon: 'success', duration: 1000 }) Taro.setStorageSync('session_id', res.data.session_id) Taro.setStorageSync('shopInfo', res.data.shop_info) Taro.setStorageSync('userInfo', res.data.user_info) this.setUserInfoToStorage() setTimeout(() => { // Taro.navigateBack({ // delta: 1 // }) Taro.switchTab({ url:'/pages/home/home' }) }, 1000); } else { Taro.showToast({ title: res.data.err_msg, icon: 'none', duration: 2000 }) } }) } usernameHandler(e) { let value = e.detail.value this.setState({ username: value }) } passwordHandler(e) { let value = e.detail.value this.setState({ password: value }) } loginHandler() { this.loginApi() } componentDidMount() { } componentWillReceiveProps(nextProps) { console.log(this.props, nextProps) } componentWillUnmount() { } componentDidShow() { } componentDidHide() { } render() { return ( 全屋定制商城 用户登入 立即注册 ) } } export default Login