Commit 72200187 by 姜雷

完善部分请求逻辑

parent 7fb9bf61
import { baseFetch } from './index';
export const fetchAllArea = () =>
baseFetch({
url: '/area/queryAreaList',
});
import { CustomerBeanAccountVo, AccountParams } from './baseClass';
import { customerFetch, ResponseDataEntity } from '.';
export const fetchBeanCount = (
data: AccountParams,
): Promise<ResponseDataEntity<CustomerBeanAccountVo[]>> =>
customerFetch({
url: '/customerAccount/queryAccount',
method: 'POST',
data: data,
});
import createFetch from './index';
import { BASE_SERVER_URL } from '../constants/index';
const fetch = createFetch(BASE_SERVER_URL + '/dcxy/api');
export const fetchAllCampus = () =>
fetch({
url: '/campus/all',
});
import { customerFetch, ResponseDataEntity } from '.';
import { LoginInfoVo } from './baseClass';
export class LoginParams {
/** 登陆标识 */
token?: string;
/** 账号 */
loginAccount?: string;
/** 密码 */
passWord?: string;
}
export const appLogin = (data: LoginParams) =>
customerFetch({
url: '/app/customer/login',
data: data,
});
export class PwdParams {
/** 账号 */
loginAccount: string;
/** 密码 */
password: string;
/** 验证码 */
verification: string;
}
export const changePwdByCellphone = (data: PwdParams) =>
customerFetch({
url: `/app/customer/apwd/${data.loginAccount}/${data.password}/${
data.verification
}`,
method: 'PUT',
});
import Taro, { request } from '@tarojs/taro';
import store from '../store/index';
import {
OLD_BASE_SERVER_URL,
BASE_SERVER_URL,
CUSTOMER_SERVER_URL,
} from '../constants/index';
export type ResponseDataEntity<T> = {
code: number;
......@@ -14,7 +19,7 @@ type ResponseEntity = {
};
const createFetch = (basePath: string) => {
return (entity: request.Param): Promise<ResponseEntity> => {
return (entity: request.Param) => {
const token = store.getState().userinfo.token;
return Taro.request({
...entity,
......@@ -37,4 +42,8 @@ const createFetch = (basePath: string) => {
};
};
export const oldBaseFetch = createFetch(OLD_BASE_SERVER_URL);
export const baseFetch = createFetch(BASE_SERVER_URL);
export const customerFetch = createFetch(CUSTOMER_SERVER_URL);
export default createFetch;
import createFetch, { ResponseDataEntity } from './index';
import { CUSTOMER_SERVER_URL } from '../constants/index';
import { ConsumeOrderResponse } from './baseClass';
import { customerFetch, ResponseDataEntity } from './index';
const fetch = createFetch(CUSTOMER_SERVER_URL);
export class AllParams {
export class Params {
/** 会员id */
customerId: number;
/** 订单状态 1未支付 2已支付 为空时查询的全部 */
orderState?: string;
/** 最后一页最后一条订单ID */
lastOrderId?: number;
/** 每页条数 */
pageSize?: number;
}
export const fetchAllOrder = (params: AllParams) =>
fetch({
export const fetchAllOrder = (params: Params) =>
customerFetch({
url: '/consumeOrder/pageAllList',
data: params,
});
export const fetchOrder = (params: AllParams) =>
fetch({
export const fetchPayOrder = (
params: Params,
): Promise<ResponseDataEntity<ConsumeOrderResponse>> =>
customerFetch({
url: '/consumeOrder/pageList',
data: {
...params,
......@@ -31,7 +33,7 @@ type DetailParams = {
id: number;
};
export const fetchOrderDetail = (data: DetailParams) =>
fetch({
customerFetch({
url: '/consumeOrder/getDetail',
data: data,
});
import createFetch, { ResponseDataEntity } from './index';
import { BASE_SERVER_URL } from '../constants/index';
import { oldBaseFetch, baseFetch, ResponseDataEntity } from './index';
const fetch = createFetch(BASE_SERVER_URL + '/wx/api');
type LoginPramas = {
code: string;
};
......@@ -14,24 +12,31 @@ export interface LoginReponse extends ResponseDataEntity<LoginReponseData> {
}
export const login = (data: LoginPramas) =>
fetch({
url: '/user/login2',
oldBaseFetch({
url: '/wx/api/user/login2',
data: data,
});
export const fetchValidateCode = () =>
fetch({
url: '/getValidateCode',
oldBaseFetch({
url: '/wx/api/getValidateCode',
});
export const getImageVcode = () =>
fetch({
url: '/getImageValidateCode',
type ImageVcodePramas = {
effective?: number;
loginName: string;
codeNum?: number;
};
export const getImageVcode = (data: ImageVcodePramas) =>
baseFetch({
url: `/common/getCode?loginName=${data.loginName}&codeNum=4`,
method: 'POST',
data: data,
});
export const getVcode = entity =>
fetch({
url: '/getValidateCode',
oldBaseFetch({
url: '/wx/api/getValidateCode',
method: 'POST',
data: entity,
});
......@@ -40,8 +45,8 @@ type RegisiterPramas = {};
// type RegisiterReponseData = {};
export const fetchWxUserRegister = (entity: RegisiterPramas) =>
fetch({
url: '/user/regisiter2',
baseFetch({
url: '/wx/api/user/regisiter2',
method: 'POST',
data: entity,
});
......@@ -24,9 +24,9 @@ class App extends Component {
*/
config: Config = {
pages: [
'pages/index/index',
'pages/Order/OrderPay/OrderPay',
'pages/Order/OrderList/OrderList',
'pages/index/index',
'pages/BarCode/BarCode',
'pages/Home/Home',
'pages/Announcement/Announcement',
......
.Modal {
.mask {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
width: 100%;
height: 100%;
background-color: rgba(25, 25, 25, 0.2);
z-index: 99;
}
.Modal-Dialog {
position: absolute;
top: 208px;
left: 50%;
transform: translate(-50%);
width: 540px;
background-color: #fff;
border-radius: 24px;
z-index: 100;
}
.Modal-title {
box-sizing: border-box;
padding: 0 20px;
height: 88px;
line-height: 88px;
width: 100%;
text-align: center;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
font-size: 32px;
border-bottom: 1px solid #eee;
}
.Modal-body {
padding: 30px 26px;
}
.Modal-footer {
border-top: 1px solid #eee;
display: flex;
height: 88px;
line-height: 88px;
.Modal-footerItem {
width: 100%;
text-align: center;
font-size: 32px;
color: #666;
}
.Modal-footerItem.cancel {
box-sizing: border-box;
border-right: 1px solid #eee;
}
.Modal-footerItem.confirm {
color: #6180f4;
}
}
}
import { Component } from '@tarojs/taro';
import { ComponentClass } from 'react';
import { View } from '@tarojs/components';
import './Modal.scss';
type PageOwnProps = {
children?: JSX.Element | JSX.Element[] | string;
visiabled: boolean;
title: string;
onCancel: () => void;
onSubmit: () => void;
};
type PageState = {};
interface Modal {
props: PageOwnProps;
state: PageState;
}
class Modal extends Component {
static externalClasses = ['body-class'];
static defaultProps = {
visiabled: false,
title: '提示',
};
cancelHandle() {
const { onCancel } = this.props;
onCancel && onCancel();
}
submitHandle() {
const { onSubmit } = this.props;
onSubmit && onSubmit();
}
render() {
const { visiabled, title } = this.props;
return visiabled ? (
<View className='Modal'>
<View className='mask' />
<View className='Modal-Dialog'>
<View className='Modal-title'>{title}</View>
<View className='Modal-body body-class'>{this.props.children}</View>
<View className='Modal-footer'>
<View
className='Modal-footerItem cancel'
onClick={this.cancelHandle}>
取消
</View>
<View
className='Modal-footerItem confirm'
onClick={this.submitHandle}>
确定
</View>
</View>
</View>
</View>
) : null;
}
}
export default Modal as ComponentClass<PageOwnProps, PageState>;
.Vcode-Content {
.Vcode-Content-box {
display: flex;
justify-content: space-between;
height: 76px;
}
.Vcode-input {
width: 308px;
height: 76px;
line-height: 76px;
text-align: center;
background-color: #e6ebfd;
border-radius: 12px;
}
.Vcode-canvas {
width: 146px;
height: 76px;
background-color: #6180f4;
border-radius: 12px;
overflow: hidden;
}
}
.Vcode.Counting {
color: #999;
}
import { ComponentClass } from 'react';
import Taro, { Component } from '@tarojs/taro';
import { View } from '@tarojs/components';
import { View, Input, Canvas } from '@tarojs/components';
import { getVcode, getImageVcode } from '../../api/wx';
import Modal from '../Modal/Modal';
import './Vcode.scss';
import { getVcode } from '../../api/wx';
import { ResponseDataEntity } from 'src/api';
type PageOwnProps = {
text?: string;
......@@ -14,6 +15,9 @@ type PageState = {
counting: boolean;
count: number;
timer: number | null;
showImgBox: boolean;
vcode: number | null;
inputCode: string;
};
interface Vcode {
......@@ -32,6 +36,9 @@ class Vcode extends Component {
counting: false,
count: 10,
timer: null,
showImgBox: false,
vcode: null,
inputCode: '',
};
}
......@@ -42,9 +49,58 @@ class Vcode extends Component {
}
}
clickHandle() {
showImgCode() {
const { cellphone } = this.props;
if (cellphone && cellphone.length == 11) {
getImageVcode({
loginName: cellphone,
})
.then((res: ResponseDataEntity<number>) => {
const { data } = res;
this.setState({
vcode: data,
});
this.renderImg(data);
})
.catch(console.error);
this.setState({
showImgBox: true,
});
this.renderImg(1234);
} else {
Taro.showToast({
title: '输入正确的手机号',
icon: 'none',
mask: true,
});
}
}
closeImageBox() {
const ctx = Taro.createCanvasContext('Vcode', this);
ctx.setFillStyle('#6180f4');
ctx.fillRect(0, 0, 73, 38);
ctx.draw();
this.setState({
showImgBox: false,
});
}
renderImg(vcode: number) {
const ctx = Taro.createCanvasContext('Vcode', this);
ctx.setFillStyle('#6180f4');
ctx.fillRect(0, 0, 73, 38);
ctx.font = '26px arial';
// ctx.font('normal', '500', 26, 'arial');
ctx.setFillStyle('#fff');
ctx.fillText(vcode.toString(), 10, 30, 146); //画布上添加验证码
ctx.draw();
}
clickHandle() {
const { vcode, inputCode } = this.state;
if (vcode && vcode.toString() == inputCode) {
const { cellphone } = this.props;
getVcode({
tel: cellphone,
})
......@@ -54,13 +110,17 @@ class Vcode extends Component {
title: res.msg,
mask: true,
});
this.setState({
vcode: null,
inputCode: '',
showImgBox: false,
});
})
.catch(console.error);
} else {
Taro.showToast({
title: '输入正确的手机号',
title: '请输入正确的验证码',
icon: 'none',
mask: true,
});
}
}
......@@ -90,13 +150,39 @@ class Vcode extends Component {
}
render() {
const { defaultText, counting, count } = this.state;
return counting ? (
const { defaultText, counting, count, showImgBox, inputCode } = this.state;
return (
<View>
{counting ? (
<View className='vcode-classname Vcode Counting'>{`${count}S后重发`}</View>
) : (
<View className='vcode-classname Vcode' onClick={this.clickHandle}>
<View className='vcode-classname Vcode' onClick={this.showImgCode}>
{defaultText}
</View>
)}
<Modal
visiabled={showImgBox}
title='请输入图形验证码'
onCancel={this.closeImageBox}
onSubmit={this.clickHandle}
body-class='Vcode-Content'>
<View className='Vcode-Content-box'>
<Input
className='Vcode-input'
type='number'
maxLength={4}
value={inputCode}
onInput={({ detail: { value } }) => {
this.setState({
inputCode: value,
});
return value;
}}
/>
<Canvas className='Vcode-canvas' canvasId='Vcode' />
</View>
</Modal>
</View>
);
}
}
......
export const APP_ID = 'wxf5912b79bba23663';
export const BASE_SERVER_URL = 'https://ex-dev-selfbase.168cad.top';
export const CUSTOMER_SERVER_URL = 'http://ex-dev-dcxy-customer-app.168cad.top';
export const OLD_BASE_SERVER_URL = 'https://ex-dev-selfbase.168cad.top';
export const BASE_SERVER_URL = 'https://ex-dev-dcxy-base-app.168cad.top';
export const CUSTOMER_SERVER_URL =
'https://ex-dev-dcxy-customer-app.168cad.top';
......@@ -7,16 +7,26 @@ import RefreshIcon from '../../images/barcode/icon_shuaxin@2x.png';
import wxbarcode from 'wxbarcode';
import './BarCode.scss';
import { UserState } from '../../store/rootReducers/userinfo';
import { connect } from '@tarojs/redux';
type PageStateProps = {
userinfo: UserState;
};
type PageOwnProps = {};
type PageState = {
showBig: boolean;
};
type IProps = PageStateProps & PageOwnProps;
interface BarCode {
props: PageOwnProps;
props: IProps;
state: PageState;
}
@connect(({ userinfo }) => ({
userinfo,
}))
class BarCode extends Component {
constructor(props: PageOwnProps) {
super(props);
......@@ -26,14 +36,16 @@ class BarCode extends Component {
}
componentWillMount() {
wxbarcode.barcode('BarCode', '12345678901234567', 646, 188);
const { userinfo } = this.props;
wxbarcode.barcode('BarCode', userinfo.idBar, 646, 188);
}
drawBarCode(showBig: boolean) {
const { userinfo } = this.props;
if (showBig) {
wxbarcode.barcode('BarCode', '12345678901234567', 646, 188);
wxbarcode.barcode('BarCode', userinfo.idBar, 646, 188);
} else {
wxbarcode.barcode('BarCode', '12345678901234567', 700, 364);
wxbarcode.barcode('BarCode', userinfo.idBar, 700, 364);
}
}
......
......@@ -15,8 +15,56 @@ import UserHeaderM from '../../images/home/img_boy_touxiang@2x.png';
import UserHeaderF from '../../images/home/img_girl_touxiang@2x.png';
import './Home.scss';
import { connect } from '@tarojs/redux';
import { UserState } from '../../store/rootReducers/userinfo';
import { fetchBeanCount } from '../../api/bean';
type PageStateProps = {
userinfo: UserState;
};
type PageState = {
commBean: number;
hairDryerBean: number;
};
interface Home {
props: PageStateProps;
state: PageState;
}
@connect(({ userinfo }) => ({
userinfo,
}))
class Home extends Component {
constructor(props) {
super(props);
this.state = {
commBean: 0.0,
hairDryerBean: 0.0,
};
}
componentWillMount() {
const { userinfo } = this.props;
fetchBeanCount({
id: userinfo.customerId,
areaId: userinfo.areaId,
customerPhone: userinfo.customerPhone,
serviceIdList: [],
})
.then(res => {
const data = res.data;
let commBeanItem = data.find(item => item.serviceId === '1');
let hairDryerBeanItem = data.find(item => item.serviceId === '1');
let commBean = commBeanItem ? commBeanItem.money : 0.0;
let hairDryerBean = hairDryerBeanItem ? hairDryerBeanItem.money : 0.0;
this.setState({
commBean,
hairDryerBean,
});
})
.catch(console.error);
}
goSetting() {
Taro.navigateTo({
url: '/pages/UserSetting/UserSetting',
......@@ -34,7 +82,15 @@ class Home extends Component {
});
}
goBarCode() {
Taro.navigateTo({
url: '/pages/BarCode/BarCode',
});
}
render() {
const { userinfo } = this.props;
const { commBean, hairDryerBean } = this.state;
return (
<View className='Home'>
<View className='Home-UserBox'>
......@@ -46,33 +102,37 @@ class Home extends Component {
<Image className='bg' src={UserBoxBg} />
<View className='Home-UserBox-info'>
<View className='Home-UserBox-other'>
<View className='Home-UserBox-name'>中小</View>
<View className='Home-UserBox-tel'>16878964216</View>
<View className='Home-UserBox-addr'>成都师范学校-温江小区</View>
<View className='Home-UserBox-name'>{userinfo.customerName}</View>
<View className='Home-UserBox-tel'>{userinfo.customerPhone}</View>
<View className='Home-UserBox-addr'>{userinfo.areaName}</View>
</View>
{userinfo.customerSex === '2' ? (
<Image className='Home-UserBox-headimg' src={UserHeaderM} />
) : (
<Image className='Home-UserBox-headimg' src={UserHeaderF} />
)}
</View>
<View className='Home-UserBox-line' />
<View className='Home-UserBox-Bean'>
<View className='Home-UserBox-BeanItem'>
<Image className='Home-UserBox-BeanIcon' src={HBeanIcon} />
<Text>吹风豆:</Text>
<Text className='Home-UserBox-BeanCount'>2.35</Text>
<Text className='Home-UserBox-BeanCount'>{hairDryerBean}</Text>
</View>
<View className='Home-UserBox-BeanItem'>
<Image className='Home-UserBox-BeanIcon' src={TBeanIcon} />
<Text>通用豆:</Text>
<Text className='Home-UserBox-BeanCount'>2.35</Text>
<Text className='Home-UserBox-BeanCount'>{commBean}</Text>
</View>
</View>
<View className='Home-UserBox-Order'>
<Text className='Home-UserBox-Order-text'>我的订单</Text>
<View className='Home-UserBox-Order-right'>
<View className='Home-UserBox-Order-right' onClick={this.goOrder}>
<Image className='Home-UserBox-Order-icon' src={ArrowIcon} />
</View>
</View>
</View>
<View className='Home-HairDryer'>
<View className='Home-HairDryer' onClick={this.goBarCode}>
<Image className='bg' src={HairDryerBg} />
<View className='Home-HairDryer-shadow' />
<View className='Home-HairDryer-text'>
......@@ -99,4 +159,4 @@ class Home extends Component {
}
}
export default Home as ComponentClass;
export default Home as ComponentClass<PageStateProps, PageState>;
......@@ -3,6 +3,14 @@ import Taro, { Component, Config } from '@tarojs/taro';
import { View, Button, Text, Input, Navigator } from '@tarojs/components';
import './Login.scss';
import { appLogin } from '../../api/customer';
import { connect } from '@tarojs/redux';
import { updateUserInfo } from '../../store/rootReducers/userinfo';
import { LoginInfoVo } from '../../api/baseClass';
type PageDispatchProps = {
updateUserInfo: (e: LoginInfoVo) => void;
};
type PageState = {
account: string;
......@@ -10,9 +18,18 @@ type PageState = {
};
interface Login {
props: PageDispatchProps;
state: PageState;
}
@connect(
() => ({}),
dispatch => ({
updateUserInfo(data: LoginInfoVo) {
dispatch(updateUserInfo(data));
},
}),
)
class Login extends Component {
config: Config = {
navigationBarTitleText: '多彩校园',
......@@ -26,11 +43,47 @@ class Login extends Component {
};
}
loginHandle() {
validataLoginData(): boolean {
const { account, pwd } = this.state;
if (!account || account.length !== 11) {
Taro.showToast({
title: '请输入手机号码',
icon: 'none',
});
return false;
}
if (!pwd || pwd.length < 6) {
Taro.showToast({
title: '请输入密码',
icon: 'none',
});
return false;
}
return true;
}
loginHandle(): void {
if (this.validataLoginData()) {
const { account, pwd } = this.state;
console.log('in loginHandle');
appLogin({
loginAccount: account,
passWord: pwd,
})
.then(res => {
const data = res.data;
console.log(data);
this.props.updateUserInfo(data);
Taro.navigateTo({
url: '/pages/Home/Home',
});
})
.catch(console.error);
}
}
render() {
const { account, pwd } = this.state;
return (
<View className='Login'>
<View className='Login-title'>欢迎来到多彩校园</View>
......@@ -39,12 +92,27 @@ class Login extends Component {
className='Login-input'
placeholder-class='Login-input-placeholder'
placeholder='请输入账号手机号'
type='number'
value={account}
onInput={({ detail: { value } }) => {
this.setState({
account: value,
});
return value;
}}
/>
<Input
className='Login-input'
placeholder-class='Login-input-placeholder'
password
placeholder='请输入密码'
value={pwd}
onInput={({ detail: { value } }) => {
this.setState({
pwd: value,
});
return value;
}}
/>
</View>
......@@ -71,4 +139,4 @@ class Login extends Component {
}
}
export default Login as ComponentClass<{}, PageState>;
export default Login as ComponentClass<PageDispatchProps, PageState>;
......@@ -9,10 +9,12 @@ import './OrderList.scss';
import { toggleOrderState } from './actions';
import { StoreState } from './store';
import { fetchAllOrder } from '../../../api/order';
import { fetchAllOrder, fetchPayOrder } from '../../../api/order';
import { UserState } from '../../../store/rootReducers/userinfo';
type PageStateProps = {
orderList: StoreState;
userinfo: UserState;
};
type PageDispatchProps = {
toggleOrderState: (state: String) => void;
......@@ -27,8 +29,9 @@ interface OrderList {
}
@connect(
({ OrderList }) => ({
({ OrderList, userinfo }) => ({
orderList: OrderList,
userinfo,
}),
dispatch => ({
toggleOrderState(state: String) {
......@@ -43,6 +46,33 @@ class OrderList extends Component {
constructor(props: PageProps) {
super(props);
}
componentWillMount() {
this.getPayOrderHandle();
}
getPayOrderHandle(lastOrderId?: number) {
const { userinfo } = this.props;
fetchPayOrder(
lastOrderId
? {
customerId: userinfo.customerId,
pageSize: 10,
lastOrderId,
}
: {
customerId: userinfo.customerId,
pageSize: 10,
},
)
.then(res => {
console.log(res);
})
.catch(console.error);
}
getAllOrderHandle() {}
goPayPage(data) {
this.$preload(data);
Taro.navigateTo({
......
......@@ -7,6 +7,7 @@ import pwdShowIcon from '../../images/login/setting_see_icon@2x.png';
import ToastBox from '../../components/ToastBox/ToastBox';
import './ResetPwd.scss';
import { changePwdByCellphone } from '../../api/customer';
type PageOwnProps = {};
type PageState = {
......@@ -30,7 +31,7 @@ class ResetPwd extends Component {
constructor(props: PageOwnProps) {
super(props);
this.state = {
cellphone: '',
cellphone: '18108096099',
vcode: '',
pwd: '',
checkPwd: '',
......@@ -90,13 +91,23 @@ class ResetPwd extends Component {
return true;
}
resetPwd() {
// this.refs.ToastBox.showToast('修改成功');
if (this.validatePwdForm()) {
const { cellphone, pwd, vcode } = this.state;
changePwdByCellphone({
loginAccount: cellphone,
password: pwd,
verification: vcode,
})
.then(() => {
this.refs.ToastBox.showToast('修改成功');
console.log('回到登陆');
setTimeout(() => {
Taro.redirectTo({
url: '/pages/Login/Login',
});
}, 2000);
})
.catch(console.error);
}
}
render() {
......@@ -129,6 +140,12 @@ class ResetPwd extends Component {
placeholder='请输入验证码'
maxLength={6}
value={vcode}
onInput={({ detail: { value } }) => {
this.setState({
vcode: value,
});
return value;
}}
/>
<Vcode
vcode-classname='registerBox-getVcode'
......
......@@ -4,24 +4,34 @@ import { connect } from '@tarojs/redux';
import { View, Text, Input, Image, ScrollView } from '@tarojs/components';
import SearchIcon from '../../images/login/icon_search@2x.png';
import { Campus, CampusList } from '../../types/Campus/Campus';
import { fetchAllCampus } from '../../api/campus';
import { fetchAllArea } from '../../api/area';
import { UserState, updateUserInfo } from '../../store/rootReducers/userinfo';
import User from 'src/types/User/User';
import './SelectCampus.scss';
type Area = {
id: number;
areaName: string;
initial?: string;
};
type AreaList = Array<{
firstPin: string;
children: Array<Area>;
}>;
type PageStateProps = {
userinfo: UserState;
};
type PageDispatchProps = {
updateUserInfo: (e: User) => void;
updateUserInfo: (e: UserState) => void;
};
type PageState = {
campusList: CampusList;
filterList: CampusList;
pinList: Array<string>;
campusList: AreaList;
filterList: AreaList;
filterName: string;
showToast: boolean;
localText: string;
......@@ -39,7 +49,7 @@ interface SelectCampus {
userinfo,
}),
dispatch => ({
updateUserInfo(entity: User) {
updateUserInfo(entity: UserState) {
dispatch(updateUserInfo(entity));
},
}),
......@@ -53,6 +63,7 @@ class SelectCampus extends Component {
super(props);
this.state = {
filterName: '',
pinList: [],
campusList: [],
filterList: [],
showToast: false,
......@@ -66,22 +77,22 @@ class SelectCampus extends Component {
}
getList() {
fetchAllCampus()
fetchAllArea()
.then(res => {
console.log(res);
let campusIndexArr: Array<string> = [];
let campusList: CampusList = [];
res.data.map((campus: Campus) => {
let firstPin = campus.firstPin;
let campusList: AreaList = [];
res.data.map((area: Area) => {
let firstPin = area.initial;
if (firstPin) {
let index = campusIndexArr.indexOf(firstPin);
if (index > -1) {
campusList[index].children.push(campus);
campusList[index].children.push(area);
} else {
campusIndexArr.push(firstPin);
campusList.push({
firstPin: firstPin,
children: [campus],
children: [area],
});
}
}
......@@ -89,6 +100,7 @@ class SelectCampus extends Component {
this.setState({
campusList: campusList,
filterList: campusList,
pinList: campusIndexArr,
});
})
.catch(err => {
......@@ -99,10 +111,9 @@ class SelectCampus extends Component {
searchList() {
let { filterName, campusList } = this.state;
if (filterName) {
const filterList = campusList.reduce(
(totalArr: CampusList, campusItem) => {
const filterList = campusList.reduce((totalArr: AreaList, campusItem) => {
let arr = campusItem.children.filter(
i => i.name.indexOf(filterName) > -1,
i => i.areaName.indexOf(filterName) > -1,
);
if (arr.length > 0) {
totalArr.push({
......@@ -111,9 +122,7 @@ class SelectCampus extends Component {
});
}
return totalArr;
},
[],
);
}, []);
this.setState({
filterList: filterList,
});
......@@ -144,21 +153,18 @@ class SelectCampus extends Component {
}
bindCampus({ target: { dataset } }) {
const {
campus: { id, name, schoolId },
} = dataset;
const { id, areaName }: Area = dataset.campus;
this.props.updateUserInfo({
campusId: id,
campusName: name,
schoolId: schoolId,
areaId: id,
areaName: areaName,
});
Taro.navigateBack();
}
render() {
const {
campusList,
pinList,
filterList,
filterName,
showToast,
......@@ -184,12 +190,12 @@ class SelectCampus extends Component {
</View>
</View>
<View className='infoBar'>
{campusList.map(item => (
{pinList.map(item => (
<View
key={item.firstPin}
key={item}
className='infoItem'
onClick={() => this.showToastHandle(item.firstPin)}>
{item.firstPin}
onClick={() => this.showToastHandle(item)}>
{item}
</View>
))}
</View>
......@@ -212,7 +218,7 @@ class SelectCampus extends Component {
className='locationItem'
data-campus={campus}
onClick={this.bindCampus}>
{campus.name}
{campus.areaName}
</View>
))}
</View>
......
import User from '../../types/User/User';
import Action from '../../types/Store/Actions';
export interface UserState extends User {
export class UserState {
login?: boolean;
areaId?: number;
areaName?: string;
birthDay?: string;
createAt?: string;
createLoginDate?: string;
customerHead?: string;
customerId?: number;
customerName?: string;
customerPhone?: string;
customerSex?: string;
customerType?: string;
email?: string;
entranceDate?: string;
hardwareAccount?: string;
hardwarePwd?: string;
hardwareState?: string;
hardwarelastDate?: string;
idBar?: string;
idCard?: string;
isFirstRecharge?: number;
lastLoginDate?: string;
loginAccount?: string;
loginPwd?: string;
loginPwdSalt?: string;
loginState?: string;
state?: string;
studentNo?: string;
token?: string;
updateAt?: string;
updateLoginDate?: string;
version?: string;
}
const INITIAL_STATE = {
login: false,
areaId: undefined,
areaName: '',
birthDay: '',
createAt: '',
createLoginDate: '',
customerHead: '',
customerId: undefined,
customerName: '',
customerPhone: '',
customerSex: '',
customerType: '',
email: '',
entranceDate: '',
hardwareAccount: '',
hardwarePwd: '',
hardwareState: '',
hardwarelastDate: '',
idBar: '',
idCard: '',
isFirstRecharge: undefined,
lastLoginDate: '',
loginAccount: '',
loginPwd: '',
loginPwdSalt: '',
loginState: '',
state: '',
studentNo: '',
token: '',
id: '',
campusId: null,
campusName: '',
schoolId: null,
name: '',
headPic: '',
updateAt: '',
updateLoginDate: '',
version: '',
};
export const updateUserInfo = (entity: User): Action => ({
export const updateUserInfo = (entity: UserState): Action => ({
type: 'UPDATE_USERINFO',
payload: entity,
});
......
type User = {
id?: string;
campusId?: number | null;
campusName?: string;
schoolId?: number | null;
name?: string;
headPic?: string;
};
export default User;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment