Przeglądaj źródła

报备客户添加

wushaodong 4 lat temu
rodzic
commit
1f274fcedb

+ 24 - 2
jscore/models/customer.js

@@ -4,13 +4,14 @@ import ResponseError from '../components/ResponseError';
 import TurnPage from '../components/TurnPage';
 import {REFRESH_STATE} from 'react-native-refresh-flatlist';
 
-let reportCustomerData=[];
+let reportCustomerData = [];
 export default {
     namespace: 'customer',
     state: {
         loading: false,
         reportCustomerDataRState: REFRESH_STATE.Ready,
-        reportCustomerData:[]
+        reportCustomerData: [],
+        projectDict: [],
     },
     reducers: {
         updateState(state, {payload}) {
@@ -40,6 +41,27 @@ export default {
                 yield put(createAction('queryList')({reportCustomerDataRState: REFRESH_STATE.Ready}));
             }
         },
+        * fetchReportDict({payload, callback}, {call, put}) {
+            const response = yield call(customer.queryReportDict);
+            if (!response.code) {
+                if (callback) {
+                    callback(response.data);
+                }
+                yield put(createAction('queryList')({projectDict: response.data.project}));
+            } else {
+                ResponseError(response);
+            }
+        },
+        * saveReportCustomer({payload, callback}, {call, put}) {
+            const response = yield call(customer.saveReportCustomer, payload);
+            if (!response.code) {
+                if (callback) {
+                    callback();
+                }
+            } else {
+                ResponseError(response);
+            }
+        },
     },
     subscriptions: {
         setup({dispatch}) {

+ 14 - 0
jscore/pages/Sales/Index.js

@@ -4,6 +4,8 @@ import {createStackNavigator} from 'react-navigation-stack';
 import NavigationOptions from '../../components/NavbarOptions';
 import SalesHome from './Home';
 import ReportCustomerList from './ReportCustomerList';
+import ReportCustomerAdd from './ReportCustomerAdd';
+import SearchProject from './SearchProject';
 
 const HomeStack = createStackNavigator({
         SalesHome: {
@@ -18,6 +20,18 @@ const HomeStack = createStackNavigator({
                 title: '客户报备',
             },
         },
+        ReportCustomerAdd: {
+            screen: ReportCustomerAdd,
+            navigationOptions: {
+                title: '报备客户',
+            },
+        },
+        SearchProject: {
+            screen: SearchProject,
+            navigationOptions: {
+                title: '选择项目',
+            },
+        },
     },
     {
         initialRouteName: 'SalesHome',

+ 247 - 0
jscore/pages/Sales/ReportCustomerAdd.js

@@ -0,0 +1,247 @@
+import React, {Component} from 'react';
+import {
+    View,
+    Text, StyleSheet, ScrollView, StatusBar, DeviceEventEmitter, KeyboardAvoidingView, Platform,
+} from 'react-native';
+
+import {connect} from 'react-redux';
+import {
+    Provider,
+    Button,
+    Toast,
+    List,
+    Picker,
+    InputItem,
+} from '@ant-design/react-native';
+import RadioModal from '../../components/RadioModal';
+import ComponentsStyles from '../../components/ComponentsStyles';
+import CheckValid from '../../components/CheckValid';
+
+@connect(customer => ({...customer}))
+class ReportCustomerAdd extends Component {
+    // 报备客户
+    constructor(props) {
+        super(props);
+        this.state = {
+            name: '',
+            tel: '',
+            gender: 2,
+            village: '',
+            address: '',
+            source: '',
+            project: [],
+            notes: '',
+
+            project_text: '请选择',
+            CUSTOMER_SOURCE: [],
+        };
+    }
+
+    componentDidMount() {
+        this._fetchData();
+    }
+
+    _fetchData = () => {
+        this.props.dispatch({
+            type: 'customer/fetchReportDict',
+            callback: (data) => {
+                let CUSTOMER_SOURCE = [];
+                data.source.map((item, index) => {
+                    CUSTOMER_SOURCE.push({
+                        value: item.id, label: item.name,
+                    });
+                });
+                this.setState({CUSTOMER_SOURCE});
+            },
+        });
+    };
+
+    onSave = () => {
+        if (!this.state.name) {
+            Toast.info('请填写姓名', 1);
+            return;
+        }
+        if (!this.state.tel) {
+            Toast.info('请填写手机号', 1);
+            return;
+        }
+        if (!CheckValid(this.state.tel, 'tel')) {
+            Toast.info('请填写正确的手机号', 1);
+            return;
+        }
+        if (!this.state.village) {
+            Toast.info('请填写小区', 1);
+            return;
+        }
+        if (!this.state.address) {
+            Toast.info('请填写地址', 1);
+            return;
+        }
+        if (!this.state.source.length) {
+            Toast.info('请选择来源', 1);
+            return;
+        }
+        if (!this.state.project.length) {
+            Toast.info('请选择项目', 1);
+            return;
+        }
+
+        this.props.dispatch({
+            type: 'customer/saveReportCustomer',
+            payload: this.state,
+            callback: () => {
+                DeviceEventEmitter.emit('backRefesh');
+                this.props.navigation.goBack();
+            },
+        });
+    };
+    onProjectPress = () => {
+        this.props.navigation.navigate('SearchProject', {
+            callback: this.setProject,
+            checked_ids:this.state.project,
+            checked_names:this.state.project_text,
+        });
+    };
+    setProject = (ids, name) => {
+        this.setState({project_text: name, project: ids});
+    };
+
+    render() {
+        const {loading} = this.props.customer;
+        const isIOS = Platform.OS === 'ios' ? true : false;
+        return (
+            <KeyboardAvoidingView behavior={'padding'} enabled={isIOS} style={{backgroundColor: '#fff', flex: 1}}>
+                <StatusBar backgroundColor={'#fff'} barStyle='dark-content'/>
+                <Provider>
+                    <ScrollView keyboardShouldPersistTaps={'handled'}>
+                        <List style={styles.listStyle}>
+                            <InputItem
+                                clear
+                                value={this.state.name}
+                                onChange={value => {
+                                    this.setState({
+                                        name: value,
+                                    });
+                                }}
+                                placeholder="请输入客户姓名"
+                            >
+                                <Text style={ComponentsStyles.requiredText}>姓名</Text>
+                            </InputItem>
+
+                            <View style={ComponentsStyles.genderStyle}>
+                                <Text style={[ComponentsStyles.requiredText, {textAlignVertical: 'center'}]}>性别</Text>
+                                <RadioModal
+                                    selectedValue={this.state.gender.toString()}
+                                    onValueChange={id => this.setState({type: id})}
+                                    style={ComponentsStyles.radioStyle}
+                                    innerStyle={{
+                                        width: 50,
+                                    }}
+                                >
+                                    <Text value="1">女</Text>
+                                    <Text value="2">男</Text>
+                                </RadioModal>
+                            </View>
+
+                            <InputItem
+                                clear
+                                type={'number'}
+                                value={this.state.tel}
+                                onChange={value => {
+                                    this.setState({
+                                        tel: value,
+                                    });
+                                }}
+                                placeholder="请输入电话"
+                            >
+                                <Text style={ComponentsStyles.requiredText}>电话</Text>
+                            </InputItem>
+
+                            <InputItem
+                                clear
+                                value={this.state.village}
+                                onChange={value => {
+                                    this.setState({
+                                        village: value,
+                                    });
+                                }}
+                                placeholder="请输入小区"
+                            >
+                                <Text style={ComponentsStyles.requiredText}>小区</Text>
+                            </InputItem>
+
+                            <InputItem
+                                clear
+                                value={this.state.address}
+                                onChange={value => {
+                                    this.setState({
+                                        address: value,
+                                    });
+                                }}
+                                placeholder="请输入地址"
+                            >
+                                <Text style={ComponentsStyles.requiredText}>地址</Text>
+                            </InputItem>
+
+                            <Picker
+                                data={this.state.CUSTOMER_SOURCE}
+                                cols={1}
+                                value={this.state.source}
+                                onChange={text => {
+                                    this.setState({
+                                        source: text,
+                                    });
+                                }}
+                            >
+                                <List.Item arrow="horizontal">
+                                    <Text style={ComponentsStyles.requiredText}>来源</Text>
+                                </List.Item>
+                            </Picker>
+                            <List.Item
+                                arrow="horizontal"
+                                extra={
+                                    <Text
+                                        style={{fontSize: 17, width: 200, textAlign: 'right'}}
+                                        onPress={() => this.onProjectPress()}>
+                                        {this.state.project_text}
+                                    </Text>}
+                            >
+                                <Text style={ComponentsStyles.requiredText}>项目</Text>
+                            </List.Item>
+
+                            <InputItem
+                                clear
+                                value={this.state.notes}
+                                onChange={value => {
+                                    this.setState({
+                                        notes: value,
+                                    });
+                                }}
+                                placeholder="请输入备注"
+                            >
+                                <Text style={ComponentsStyles.font15}>备注</Text>
+                            </InputItem>
+                        </List>
+                    </ScrollView>
+                    <Button
+                        onPress={this.onSave}
+                        type="primary"
+                        loading={loading}
+                        disabled={loading}
+                        style={ComponentsStyles.button}>保存</Button>
+                </Provider>
+            </KeyboardAvoidingView>
+        );
+    }
+}
+
+const styles = StyleSheet.create({
+    listStyle: {
+        marginTop: 5,
+    },
+    dateInput: {
+        borderWidth: 0,
+        alignItems: 'flex-end',
+    },
+});
+export default ReportCustomerAdd;

+ 3 - 3
jscore/pages/Sales/ReportCustomerList.js

@@ -58,7 +58,7 @@ class ReportCustomerList extends Component {
         const item = data.item;
         return (
             <TouchableOpacity style={ComponentsStyles.mainTouch}
-                              onPress={() => this.props.navigation.navigate('', {item})}>
+                              onPress={() => this.props.navigation.navigate('')}>
                 <View style={{flexDirection: 'row'}}>
                     {/*姓名 电话*/}
                     <View style={{flex: 1, justifyContent: 'flex-start', flexDirection: 'row'}}>
@@ -88,7 +88,7 @@ class ReportCustomerList extends Component {
                 <View style={{flexDirection: 'row', flex: 1, paddingTop: 5}}>
                     <View style={ComponentsStyles.itemView}>
                         <Text style={ComponentsStyles.icon}>{'\ue6cc'}</Text>
-                        <Text style={{fontSize: 15}}>{item.create_time}</Text>
+                        <Text style={{fontSize: 15}}>{item.create_time_f}</Text>
                     </View>
 
                     <Text
@@ -103,7 +103,7 @@ class ReportCustomerList extends Component {
         if (!prem) {
             return;
         }
-        this.props.navigation.navigate('');
+        this.props.navigation.navigate('ReportCustomerAdd');
     };
 
     render() {

+ 76 - 0
jscore/pages/Sales/SearchProject.js

@@ -0,0 +1,76 @@
+import React, {Component} from 'react';
+import {
+    View,
+    Text, StyleSheet, ScrollView,
+} from 'react-native';
+
+import {connect} from 'react-redux';
+import {Button, Checkbox, List,} from '@ant-design/react-native';
+import ComponentsStyles from '../../components/ComponentsStyles';
+const CheckboxItem = Checkbox.CheckboxItem;
+
+@connect(customer => ({...customer}))
+class SearchProject extends Component {
+    // 多选项目
+    constructor(props) {
+        super(props);
+        const checked_names = this.props.navigation.state.params.checked_names
+        this.state = {
+            callback: this.props.navigation.state.params.callback,
+            ids: this.props.navigation.state.params.checked_ids ?? [], // 加载已选择的项目
+            names: checked_names && checked_names !== '请选择' ? checked_names.split(',') : [],
+        };
+    }
+
+    onChange = (checked, item) => {
+        let {ids, names} = this.state;
+        if (checked) {
+            ids.push(item.id);
+            names.push(item.name);
+        } else {
+            ids.splice(ids.indexOf(item.id), 1);
+            names.splice(names.indexOf(item.name), 1);
+        }
+        this.setState({names, ids});
+    };
+
+    onSave = () => {
+        const name = this.state.names.join(',')
+        this.state.callback(this.state.ids, name ? name : '请选择')
+        this.props.navigation.goBack();
+    };
+
+    render() {
+        const {projectDict} = this.props.customer;
+        return (
+            <View style={{flex: 1, backgroundColor: '#fff'}}>
+                <ScrollView>
+                    <List style={{flex: 1}}>
+                        {projectDict.map((item, index) => {
+                            // 判断是否选择过了
+                            const checked = this.state.ids.indexOf(item.id) > -1 ? true : false
+                            return (<CheckboxItem
+                                    key={index}
+                                    checked={checked}
+                                    onChange={event => {
+                                        this.onChange(event.target.checked, item);
+                                    }}
+                                >
+                                    {item.name}
+                                </CheckboxItem>
+                            );
+                        })}
+                    </List>
+                </ScrollView>
+                <Button
+                    type="primary"
+                    onPress={() => this.onSave()}
+                    style={ComponentsStyles.button}><Text
+                    style={{color: '#fff'}}>确定</Text>
+                </Button>
+            </View>
+        );
+    }
+}
+
+export default SearchProject;

+ 20 - 0
jscore/services/customer.js

@@ -6,3 +6,23 @@ export async function queryReportCustomerData(params) {
         `/customer/report_customer/?${stringify(params)}`,
     );
 }
+
+export async function queryReportDict() {
+    return request(`/customer/dict/`);
+}
+
+export async function saveReportCustomer(params) {
+    let formdata = new FormData();
+    formdata.append('name', params.name);
+    formdata.append('gender', params.gender);
+    formdata.append('tel', params.tel);
+    formdata.append('village', params.village);
+    formdata.append('address', params.address);
+    formdata.append('source', params.source[0]);
+    formdata.append('project', JSON.stringify(params.project));
+    formdata.append('notes', params.notes);
+    return request("/customer/report_customer/", {
+        method: "POST",
+        body: formdata,
+    })
+}

+ 9 - 7
jscore/services/user.js

@@ -3,7 +3,7 @@ import request from './../utils/request';
 
 export async function authLogin(params) {
     let formdata = new FormData();
-    formdata.append("token", params.token);
+    formdata.append('token', params.token);
 
     return request('/account/token_refresh/', {
         method: 'POST',
@@ -13,8 +13,8 @@ export async function authLogin(params) {
 
 export async function login(params) {
     let formdata = new FormData();
-    formdata.append("username", params.username);
-    formdata.append("password", params.password);
+    formdata.append('username', params.username);
+    formdata.append('password', params.password);
 
     return request('/account/login/', {
         method: 'POST',
@@ -29,17 +29,19 @@ export async function loginOut() {
 export async function queryHomeCount() {
     return request(`/account/statistics/`);
 }
+
 export async function queryTipsCount() {
     return request(`/customer/list_count/`);
 }
 
+
 //修改密码
 export async function changePassword(params) {
     let formdata = new FormData();
-    formdata.append('old_password', params.old_password)
-    formdata.append('confirm_password', params.new_password_repeat)
-    formdata.append('new_password', params.new_password)
-    return request(`/account/employee/change_password/?id=`+params.user_id, {
+    formdata.append('old_password', params.old_password);
+    formdata.append('confirm_password', params.new_password_repeat);
+    formdata.append('new_password', params.new_password);
+    return request(`/account/employee/change_password/?id=` + params.user_id, {
         method: 'POST',
         body: formdata,
     });