Jelajahi Sumber

添加项目

wushaodong 4 tahun lalu
induk
melakukan
d093abcc93

+ 8 - 0
jscore/models/customer.js

@@ -173,6 +173,14 @@ export default {
                 ResponseError(response);
             }
         },
+        * addCustomerProject({payload, callback}, {call, put}) {
+            const response = yield call(customer.addCustomerProject, payload);
+            if (!response.code) {
+                callback()
+            } else {
+                ResponseError(response);
+            }
+        },
     },
     subscriptions: {
         setup({dispatch}) {

+ 29 - 1
jscore/pages/Sales/ReviewDetail.js

@@ -6,7 +6,7 @@ import {
     ScrollView,
     Dimensions, DeviceEventEmitter,
 } from 'react-native';
-import {Tabs, Provider, Button, Modal, List} from '@ant-design/react-native';
+import {Tabs, Provider, Button, Modal, Toast, List} from '@ant-design/react-native';
 import {createAction} from '../../utils';
 import {connect} from 'react-redux';
 import CallPhone from '../../components/CallPhone';
@@ -196,6 +196,20 @@ class ReviewDetail extends Component {
         </View>;
     };
 
+    addProject = (ids, name) => {
+        this.props.dispatch({
+            type: 'customer/addCustomerProject',
+            payload: {projects: ids, id: this.state.getParm.customer},
+            callback: () => {
+                Toast.info('添加成功!', 1, () => {
+                    DeviceEventEmitter.emit('backRefesh');
+                    this.props.navigation.goBack();
+                });
+
+            },
+        });
+    };
+
     render() {
         const {reviewRecordData, reviewRecordRState, customerDetail} = this.props.customer;
 
@@ -297,6 +311,20 @@ class ReviewDetail extends Component {
                                 >修改信息</Text>
                             </List.Item>
 
+                            <List.Item>
+                                <Text
+                                    style={styles.modalText}
+                                    onPress={() => {
+                                        this.props.navigation.navigate('SearchProject', {
+                                            callback: this.addProject,
+                                            disabled_ids: customerDetail.project,
+                                        });
+                                        this.setState({moreModelVisible: false});
+                                    }
+                                    }
+                                >添加项目</Text>
+                            </List.Item>
+
                             <List.Item onPress={() => this.setState({moreModelVisible: false})}>
                                 <Text style={styles.modalText}>取消</Text>
                             </List.Item>

+ 47 - 28
jscore/pages/Sales/SearchProject.js

@@ -5,7 +5,7 @@ import {
 } from 'react-native';
 
 import {connect} from 'react-redux';
-import {Button, Checkbox, List,} from '@ant-design/react-native';
+import {Button, Checkbox, Toast, Provider, List} from '@ant-design/react-native';
 import ComponentsStyles from '../../components/ComponentsStyles';
 const CheckboxItem = Checkbox.CheckboxItem;
 
@@ -14,14 +14,25 @@ class SearchProject extends Component {
     // 多选项目
     constructor(props) {
         super(props);
-        const checked_names = this.props.navigation.state.params.checked_names
+        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(',') : [],
+            // 客户添加项目
+            disabled_ids: this.props.navigation.state.params.disabled_ids ?? [], // 加载已添加的项目
         };
     }
 
+    componentDidMount() {
+        this._fetchData();
+    }
+
+    _fetchData = () => {
+        this.props.dispatch({
+            type: 'customer/fetchReportDict',
+        });
+    };
     onChange = (checked, item) => {
         let {ids, names} = this.state;
         if (checked) {
@@ -35,8 +46,12 @@ class SearchProject extends Component {
     };
 
     onSave = () => {
-        const name = this.state.names.join(',')
-        this.state.callback(this.state.ids, name ? name : '请选择')
+        if (!this.state.ids.length) {
+            Toast.info('请选择项目', 1);
+            return false;
+        }
+        const name = this.state.names.join(',');
+        this.state.callback(this.state.ids, name ? name : '请选择');
         this.props.navigation.goBack();
     };
 
@@ -44,30 +59,34 @@ class SearchProject extends Component {
         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>
+                <Provider>
+                    <ScrollView>
+                        <List style={{flex: 1}}>
+                            {projectDict.map((item, index) => {
+                                // 判断是否选择过了
+                                const checked = this.state.ids.indexOf(item.id) > -1 ? true : false;
+                                const disabled = this.state.disabled_ids.indexOf(item.id) > -1 ? true : false;
+                                return (<CheckboxItem
+                                        key={index}
+                                        checked={checked}
+                                        disabled={disabled}
+                                        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>
+                </Provider>
             </View>
         );
     }

+ 9 - 0
jscore/services/customer.js

@@ -34,6 +34,15 @@ export async function dispatchUser(params) {
     });
 }
 
+export async function addCustomerProject(params) {
+    let formdata = new FormData();
+    formdata.append('projects', JSON.stringify(params.projects));
+    return request('/customer/new_customer/' + params.id + '/add_projects/', {
+        method: 'POST',
+        body: formdata,
+    });
+}
+
 export async function editCustomerInfo(params) {
     let formdata = new FormData();
     formdata.append('name', params.name);