custome.js 33.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052
import React, { PropTypes } from 'react';
import * as types from '../constants/ActionTypes';
import {getServiceContracts,getServiceContractDetail,terminateServiceContract,renewServiceContract,
        addServiceContract,editServiceContract,updateServiceContract,ownersServiceContract,getServiceContractOwners,
        getServiceContractItems,addCustomers,getCustomer,getCustomers,addProfiles,editProfiles,profilesCustomerDetail,
        addCustomerLegalEntitie,updateCustomerLegalEntitie,deleteCustomerLegalEntitie,getCustomerLegalEntities,
        addContactsCustomer,deleteContactsCustomer,getContactsCustomers,updateContactsCustomer,updateContactsOwner,
        getContactsCustomerOwners,getContactsAdmin,addContactsAdmin,updateContactsAdmin,getFormDefind,editCustomerBasic,importCustomers,
        getRemindSetting,updateRemindSetting,getAttachments,downloadAttachments,addAttachments,downloadCustoms,getRecordsUtil,getFailRecordsUtil,getCustomerName,
        postCustomerRecord,getCustomercomments,
        getCustomerLegalEntitiesPaged,
        getListCustomers,changeCustom,
        addFormField,
        editFormField,
        delFormField,
        getFormFieldDetail,
        getClassifyList,
        getBasicFormList,
      } from '../../utils/customeUtil';
import {SubmissionError,change,submit} from 'redux-form';
import { message,notification } from 'antd';
import { NotificationIcon } from '../../utils/comonOtherUtil';
import { formatFormDefindNew } from '../../utils/commonUtils';
import { downloadFileByUrl } from '../../utils/fileUtil';



//导入记录列表
export function getRecordsList(params) {
    return dispatch => {
        return getRecordsUtil(params).then(data => {
              dispatch({
                  type      : types.GET_RECORD_LIST,
                  recordList: data
              })
          }).catch(err => { throw err; });
    };
}

//导入失败记录列表
export function getFailRecordsList(params) {
    return dispatch => {
        return getFailRecordsUtil(params)
            .then(data => {
                dispatch({
                    type          : types.FAIL_RECORD_LIST,
                    failRecordList: data
                })
            })
            .catch(err => { throw err; });
    };
}

/*客户管理*/
const sortArray = (values) => {
    const sortKey = { 'name': 0, 'address': 1, 'brief_name': 2, 'contact_name': 3, 'contact_mobile': 4, 'contact_position': 5, 'industry': 6, 'source': 9, 'email': 7, 'phone': 8 }
    const temp = [], other = [];
    values.map((item, i) => {
        if (sortKey[item.name] >= 0) {
            temp[sortKey[item.name]] = item;
        } else {
            other.push(item);
        }
    });
    return formatFormDefindNew(temp.concat(other));
}
/*导入客户*/
export function importCustomersAct(params) {
    return dispatch => {
        return importCustomers(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    dispatch({
                        type: types.IMPORT_CUSTOMER,
                        is_import: 'failed',
                        errorMeg: '客户导入失败,请按照要求上传文件'
                    });
                } else {
                    if (data.errors && data.errors != '[]') {
                        const tempErrors = JSON.parse(data.errors), temp = [];
                        tempErrors.map((err, i) => {
                            temp.push(err.message);
                        })
                        dispatch({
                            type: types.IMPORT_CUSTOMER,
                            is_import: 'failed',
                            errorMeg: '上传文件信息填写不完全,请按照模版要求填写' + temp.join(",")
                        });
                    } else {
                        dispatch({
                            type: types.IMPORT_CUSTOMER,
                            is_import: 'success',
                            errorMeg: '客户数据导入完成,导入结果请到导入记录中查看'
                        });
                    }
                }
            })
            .catch(err => { throw err; });
    };
}
export function cleanCustomeImport() {
    return {
        type: types.IMPORT_CUSTOMER,
        is_import: 'init',
        errorMeg: ''
    }
}

/*加载客户列表   精简版本客户列表  */
export function loadCustomList(values) {
    return dispatch => {
        return getCustomers(values)
        // return getListCustomers(values)
            .then(data => {
                const { items = [] } = data;
                if (data.code && data.code >= 300) {
                    message.error(data.message)
                } else {
                    dispatch({
                        type: types.CUSTOM_LIST,
                        customList: data
                    })
                    return data;
                }

            })
            .catch(err => { throw err; });
    };
}
/*加载客户列表   */
export function loadCustomListDet(values) {
    return dispatch => {
        return getListCustomers(values)
            .then(data => {
            
                if (data.code && data.code >= 300) {
                    message.error(data.message)
                } else {
                    dispatch({
                        type: types.CUSTOM_LIST,
                        customList: data
                    })
                    dispatch(change('customer_container_search', 'total_count', data.total_count));
                }
                
            })
            .catch(err => { throw err; });
    };
}

// 添加跟进记录
export function postCustomerRecordAct(values) {
    return dispatch => {
        return postCustomerRecord(values)
            .then(data => {
              
                if (data.code && data.code >= 300) {
                    message.error(data.message)
                    dispatch(change('customer_container_form', 'recordBtnDisabled', false))
                } else {
                    dispatch(change('customer_container_form', 'showAddRecord', false))
                }
                return data;
            })
            .catch(err => { throw err; });
    };
}
//获取跟进记录列表
export function getCustomerCommentsAction(values) {
    return dispatch => {
        return getCustomercomments(values)
            .then(data => {  
                if (data.code && data.code >= 300) {
                    message.error(data.message)
                } else {
                    dispatch({
                        type: types.CUSTOM_COMMENTS_LIST,
                        customCommentsList:  data.items||[]
                    }) 
                }
            })
            .catch(err => { throw err; });
    };
}

export function cleanCustom() {
    return {
        type: types.CUSTOM_LIST,
        customList: {}
    }
}

/*编辑客户基本信息*/
export function editCustomerBasicAct(values, from) {
    return dispatch => {
        return editCustomerBasic(values)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message)
                } else {
                    message.success('更新成功!')
                    from && dispatch(submit('customer_container_search'))
                }
                return data
            })
            .catch(err => { throw err; });
    };
}

/*添加客户*/
export function createCustomer(params) {
    return dispatch => {
        dispatch({ type: 'MASK_SHOW', maskShow: true });
        return addCustomers(params)
            .then(data => {
                dispatch({ type: 'MASK_SHOW', maskShow: false });
                if (data.code && data.code >= 300) {
                    if (data.code == 409) {
                        dispatch({
                            type: types.ADD_FAIL,
                            is_fail: true,
                            add_custome_meg: data.message
                        });
                    } else {
                        dispatch({
                            type: types.ADD_FAIL,
                            is_fail: true,
                            add_custome_meg: data.message
                        });
                    }
                } else {
                    // dispatch(loadCustomList('limit=10&offset=0'));
                    dispatch(loadCustomListDet('limit=10&offset=0'));
                    dispatch({
                        type: types.ADD_FAIL,
                        is_fail: false,
                        add_custome_meg: "您所新建的客户已创建成功"
                    });
                }
                dispatch(change('step_one', 'current', 3));
            })
            .catch(err => { dispatch({ type: 'MASK_SHOW', maskShow: false }); throw err; });
    };
}

/*客户查重*/
export function getCustomerNameAct(name, type) {
    return dispatch => {
        return getCustomerName(name, type)
            .then(data => {
                if (data.code && data.code >= 300) {
                    if (type == 'link') {
                        dispatch(change('step_one','current',1))
                    } else {
                        message.success('公司名称可使用')
                    }
                } else {
                    // message.error('公司名称已存在')
                    message.error('客户被'+data.creator+'占用了')
                }
            })
            .catch(err => { throw err; });
    };
}

/*查看客户详情*/
export function getCustomerInfo(id) {
    return dispatch => {
        return getCustomer(id)
            .then(data => {
                dispatch({
                    type: types.GET_CUSTOM,
                    custom: data
                })
            })
            .catch(err => { throw err; });
    };
}

/*添加公司简介*/
export function addCompany(params) {
    return dispatch => {
        return addProfiles(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    dispatch(loadCompany(params.customer_id));
                }
            })
            .catch(err => { throw err; });
    };
}

/*编辑公司简介*/
export function editCompany(params) {
    return dispatch => {
        return editProfiles(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    message.success('编辑成功');
                    dispatch(loadCompany(params.customer_id));
                }
            })
            .catch(err => { throw err; });
    };
}

/*客户公司简介*/
export function loadCompany(id) {
    return dispatch => {
        return profilesCustomerDetail(id)
            .then(data => {
                dispatch({
                    type: types.GET_COMPANY_INFO,
                    company: data
                })
            })
            .catch(err => { throw err; });
    };
}
/*清楚客户公司简介*/
export function cleanCompany() {
    return {
        type: types.GET_COMPANY_INFO,
        company: {}
    };
}

/*添加法务实体*/
export function createCustomerLegalEntitie(params) {
    return dispatch => {
        return addCustomerLegalEntitie(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message)
                    throw new SubmissionError({ _error: data.message });
                } else {
                    // dispatch(loadCustomerLegalEntities(params.customer_id));
                    dispatch(submit('legal_customer_list_search'))
                    dispatch(change('custom_det_form', 'showAddLegal', false))
                }
            })
            .catch(err => { throw err; });
    };
}

/*获取客户下的法务实体列表*/
export function loadCustomerLegalEntities(id) {
    return dispatch => {
        return getCustomerLegalEntities(id)
            .then(data => {
                const {items=[]} = data;
                dispatch({
                    type: types.LOAD_CUSTOMER_LEGAL_ENTITIES,
                    legalEntities: data
                });
                return items;
            })
            .catch(err => { throw err; });
    };
}
/*获取客户下的法务实体列表     支持分页*/  
export function getCustomerLegalEntitiesPagedAction(val) {
    return dispatch => {
        return getCustomerLegalEntitiesPaged(val)
            .then(data => {
                const {items=[],total_count=''} = data;
                dispatch({
                    type: types.LOAD_CUSTOMER_LEGAL_ENTITIES,
                    legalEntities: data
                });
                dispatch(change('legal_customer_list_search', 'total_count', total_count))
                return items;
            })
            .catch(err => { throw err; });
    };
}


export function clearCustomerLegalEntities() {//清空客户下的法务实体列表
    return dispatch => {
        dispatch({
            type: types.LOAD_CUSTOMER_LEGAL_ENTITIES,
            legalEntities: {}
        })
    };
}

/*修改法务实体*/
export function changeCustomerLegalEntitie(params) {
    return dispatch => {
        return updateCustomerLegalEntitie(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                    // throw new SubmissionError({ _error: data.message });
                    dispatch(change('legal_form','showEditLegal',true))
                } else {
                    // dispatch(loadCustomerLegalEntities(params.customer_id));
                    dispatch(submit('legal_customer_list_search'))
                    message.success('编辑成功');
                    dispatch(change('legal_form','showEditLegal',false))
                }
            })
            .catch(err => { throw err; });
    };
}


/*删除法务实体*/
export function delCustomerLegalEntitie(params) {
    return dispatch => {
        return deleteCustomerLegalEntitie(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    message.success('删除成功');
                    // dispatch(loadCustomerLegalEntities(params.customer_id));
                    dispatch(submit('legal_customer_list_search'))
                }
            })
            .catch(err => { throw err; });
    };
}

/*添加客户联系人*/
export function createContactsCustomer(params) {
    return dispatch => {
        return addContactsCustomer(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error('该客户对接人已存在');
                } else {
                    dispatch(loadContactsCustomers(params.id));
                }
            })
            .catch(err => { throw err; });
    };
}

/*列表客户联系人*/
export function loadContactsCustomers(id) {
    return dispatch => {
        return getContactsCustomers(id)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    dispatch({
                        type: types.LOAD_CONTACTS_CUSTOMER,
                        contacts: data
                    })
                }
            })
            .catch(err => { throw err; });
    };
}

/*修改客户联系人*/
export function changeContactsCustomer(params) {
    return dispatch => {
        return updateContactsCustomer(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    dispatch(loadContactsCustomers(params.customer_id));
                }
            })
            .catch(err => { throw err; });
    };
}

/*删除客户联系人*/
export function delContactsCustomer(params) {
    return dispatch => {
        return deleteContactsCustomer(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    message.success('删除成功');
                    dispatch(loadContactsCustomers(params.customer_id));
                }
            })
            .catch(err => { throw err; });
    };
}

/*列表客户负责人*/
export function loadContactsCustomerOwners(id) {
    return dispatch => {
        return getContactsCustomerOwners(id)
            .then(data => {
                dispatch({
                    type: types.LOAD_CONTACTS_OWNERS,
                    owners: data
                })
            })
            .catch(err => { throw err; });
    };
}

/*更新客户负责人*/
export function changeContactsCustomerForService(params) {
    return dispatch => {
        return updateContactsOwner(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    message.error(data.message);
                } else {
                    message.success('编辑成功');
                    dispatch(loadContactsCustomerOwners(params.id));
                }
                return data;
            })
            .catch(err => { throw err; });
    };
}

/*获取根账号*/
export function getAdminAction(params) {
    return dispatch => {
        return getContactsAdmin(params)
            .then(data => {
                dispatch({
                    type: types.LOAD_CONTACTS_ADMIN,
                    adminDate: data
                })
            })
            .catch(err => { throw err; });
    };
}
/*客户账号信息开通账号*/
export function createContactsAdmin(params) {
    return dispatch => {
        return addContactsAdmin(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    notification.open({
                        message: '错误',
                        description: '开通失败,' + data.message,
                        icon: <NotificationIcon type='error' />,
                    });
                } else {
                    notification.open({
                        message: '成功',
                        description: '开通成功',
                        icon: <NotificationIcon type='success' />,
                    });
                    dispatch(getAdminAction(params.id));
                }
                return data;
            })
            .catch(err => { throw err; });
    };
}

/*客户账号信息变更账号*/
export function changeCustomAction(params) {
    return dispatch => {
        return changeCustom(params)
            .then(data => {
                if (data.code && data.code >= 300) {
                    notification.open({
                        message: '错误',
                        description: '变更失败,' + data.message,
                        icon: <NotificationIcon type='error' />,
                    });
                } else {
                    notification.open({
                        message: '成功',
                        description: '变更成功',
                        icon: <NotificationIcon type='success' />,
                    });
                    dispatch(getAdminAction(params.id));
                    return data;
                }
                
            })
            .catch(err => { throw err; });
    };
}

/*停用/启用账号*/
export function changeContactsAdmin(params) {
    return dispatch => {
        return updateContactsAdmin(params)
            .then(data => {
                dispatch(getAdminAction(params.customer_id));
            })
            .catch(err => { throw err; });
    };
}


/*服务合同*/
/*加载服务列表*/
export function loadServiceContractsList(params) {
    return dispatch => {
        return getServiceContracts(params)
            .then(data => {
                if(data.code &&data.code >= 300){
                    notification.open({
                        message: '错误',
                        description: '变更失败,' + data.message,
                        icon: <NotificationIcon type='error' />,
                    });
                }else{
                    const { items = [], total_count } = data;
                    dispatch({
                        type: types.SERVER_LIST,
                        serverList: data
                    })
                    if (params.indexOf('all=true') == -1) {
                        dispatch(change('search_list_custom', 'total_count', total_count));
                    }
                    return items;
                }
            })
            .catch(err => { throw err; });
    };
}

export function clearServiceContract(params) {
  return dispatch => {
      dispatch({
        type      : types.SERVER_LIST,
        serverList: {}
      })
  };
}

/*加载单个服务列表*/
export function loadServiceContractsCustome(params) {
    return dispatch => {
        return getServiceContracts(params)
            .then(data => {
                const { items = [], total_count } = data
                dispatch({
                    type: types.SERVER_LIST_CUSTOME,
                    serverListCustom: data
                });
                return data;
            })
            .catch(err => { throw err; });
    };
}

/*search加载单个服务列表*/
export function loadServiceContractsCustomeSearch(params) {
    return dispatch => {
        return getServiceContracts(params)
            .then(data => {
                const { items = [], total_count } = data
                dispatch({
                    type: types.SERVER_LIST_CUSTOME_SEARCH,
                    serverListCustomSearch: data
                })
            })
            .catch(err => { throw err; });
    };
}



/*清空合同列表*/
export function clearServiceContractsList() {
    return dispatch => {
        dispatch({
            type: types.SERVER_LIST_CUSTOME,
            serverListCustom: {}
        })
    };
}

/*清空合同列表search*/
export function clearServiceContractsListSearch() {
    return dispatch => {
        dispatch({
            type: types.SERVER_LIST_CUSTOME_SEARCH,
            serverListCustomSearch: {}
        })
    };
}


/*添加服务合同*/
export function createServiceContract(params) {
    return dispatch => {
        dispatch({ type: 'MASK_SHOW', maskShow: true });
        return addServiceContract(params)
            .then(data => {
                dispatch({ type: 'MASK_SHOW', maskShow: false });
                if (data && data.id) {
                    message.success('新增服务合同成功');
                    document.location.href = "#container/customService/0"
                } else if (data.message) {
                    if (data.errors) {
                        message.error(data.errors);
                    }
                }
            })
            .catch(err => { dispatch({ type: 'MASK_SHOW', maskShow: false }); throw err; });
    };
}
/*编辑服务合同*/
export function editServiceContractAct(params) {
    return dispatch => {
        return editServiceContract(params)
            .then(data => {
                if (data.code >= 300) {
                    if (data.errors && data.errors != '[]') {
                        //  let messageArr = [],errorMeg;
                        //  const newMessage = JSON.parse(data.errors);
                        //  newMessage.map(data=>{
                        //    messageArr.push(data.message);
                        //  });
                        //  errorMeg = messageArr.stringify()
                        //  message.error(errorMeg);
                    } else {
                        message.error(data.message);
                    }
                } else {
                    message.success('修改服务合同成功');
                    document.location.href = "#container/customService/0"
                }
            })
            .catch(err => { throw err; });
    };
}
export function cleanServerContractInfo() {
    return {
        type: types.SERVER_CONTRACT_INFO,
        serverContractInfo: ''
    }
}
/*查看服务合同详情*/
export function getServiceContractInfo(id) {
    return dispatch => {
        return getServiceContractDetail(id)
            .then(data => {
                dispatch({
                    type: types.SERVER_CONTRACT_INFO,
                    serverContractInfo: data
                });
                return data;
            })
            .catch(err => { throw err; });
    };
}

/*终止服务合同*/
export function stopServiceContract(params) {
    return dispatch => {
        return terminateServiceContract(params)
            .then(data => {
                if (data && data.code == 200) {
                    message.success('终止服务合同成功');
                    dispatch(loadServiceContractsList('?offset=0&limit=10&type=0'));
                    return data;
                }
            })
            .catch(err => { throw err; });
    };
}

/*续签服务合同*/
export function repeatServiceContract(params) {
    return dispatch => {
        return renewServiceContract(params)
            .then(data => {
                if (data && data.code == 200) {
                    message.success('续签服务合同成功');
                    document.location.href = "#container/customService/0"
                }
                // dispatch(loadServiceContractsList('?offset=0&limit=10&type=0'));
            })
            .catch(err => { throw err; });
    };
}

/*变更服务合同*/
export function changeServiceContract(params) {
    return dispatch => {
        return updateServiceContract(params)
            .then(data => {
                dispatch(loadServiceContractsList());
            })
            .catch(err => { throw err; });
    };
}

/*获取服务合同负责人列表*/
export function loadServiceContractOwners(id) {
    return dispatch => {
        return getServiceContractOwners(id)
            .then(data => {
                dispatch({
                    type: types.SERVER_CONTRACT_OWNERS,
                    serverContractOwners: data
                })
            })
            .catch(err => { throw err; });
    };
}

/*获取服务合同内容列表*/
export function loadServiceContractItems(id) {
    return dispatch => {
        return getServiceContractItems(id)
            .then(data => {
                dispatch({
                    type: types.SERVER_CONTRACT_ITEMS,
                    serverContractItems: data
                })
            })
            .catch(err => { throw err; });
    };
}

/*分配/变更负责人*/
export function changeOwnersServiceContract(params) {
    return dispatch => {
        return ownersServiceContract(params)
            .then(data => {
                if (data && data.code >= 300) {
                    message.error(data.message);
                    throw new SubmissionError({ _error: data.message });
                }
                dispatch(getServiceContractInfo(params.id));
            })
            .catch(err => { throw err; });
    };
}


/*获取提醒 - 设置*/
export function loadRemindSettingAction() {
    return dispatch => {
        return getRemindSetting()
            .then(data => {
                dispatch({
                    type: types.LOAD_REMIND_SETTING,
                    remindSetting: data
                });
            })
            .catch(err => { throw err; });
    };
}
//获取提醒 - 添加修改
export function changeRemindSettingAction(params) {
    return dispatch => {
        return updateRemindSetting(params)
            .then(data => {
                if (data && data.id) {
                    message.success('服务合同到期提醒设置成功');
                    dispatch(loadRemindSettingAction());
                    dispatch(submit('search_list_custom'));
                    return data;
                }
            })
            .catch(err => { throw err; });
    };
}


//列表纸制服务合同
export function loadAttachments(params) {
    return dispatch => {
        return getAttachments(params)
            .then(data => {
                const { items = [] } = data;
                dispatch({
                    type: types.LOAD_ATTACHMENTS,
                    attachments: items
                })
                dispatch(change('custom_stop_form', 'images', items));
            })
            .catch(err => { throw err; });
    };
}

//上传纸制服务合同
export function addAttachmentsAction(params) {
    return dispatch => {
        return addAttachments(params)
            .then(data => {
                if (data.code && data.code == '200')
                    message.success('上传成功');
                dispatch(submit('search_list_custom'));
            })
            .catch(err => { throw err; });
    };
}

//下载纸制服务合同
export function downloadAttachmentsAction(params) {
    return dispatch => {
        dispatch({ type: 'MASK_SHOW', maskShow: true });
        return downloadAttachments(params)
            .then(data => {
                const { download_path = '' } = data;
                if (download_path) {
                    downloadFileByUrl(download_path);
                }
                dispatch({ type: 'MASK_SHOW', maskShow: false });
            })
            .catch(err => { dispatch({ type: 'MASK_SHOW', maskShow: false }); throw err; });
    };
}
//导出客户列表
export function exportCustomAction(params){
  return dispatch => {
      return downloadCustoms(params)
          .then(data => {
              const {download_path=''} = data;
              if(download_path){
                 downloadFileByUrl(download_path);
              }

          })
          .catch(err => {throw err; });
  };
}

export function getBasicFormListAction(params) {
    return dispatch => {
      return getBasicFormList(params)
        .then(data => {
          const { items = [] } = data
          dispatch({
            type: types.LOAD_CRM_FORM_LIST,
            formBasicList: items
          })
          return data
        })
        .catch(err => { throw err })
    };
  }

// 获取表单定义
export function loadFormDefind() {
    return dispatch => {
        return getFormDefind()
            .then(data => {
                const { items = [] } = data
                dispatch({
                    type: types.LOAD_FORM_DEFIND,
                    formDefind: formatFormDefindNew(items)
                })
            })
            .catch(err => { throw err })
    }
}



// 添加表单定义字段
export function addFormFieldAction(params) {
    return dispatch => {
        return addFormField(params).then(data => {
            if (data.code && data.code >= 300) {
                notification.open({
                    message: '错误',
                    description: '添加失败,' + data.message,
                    icon: <NotificationIcon type='error' />,
                })
            } else {
                notification.open({
                    message: '成功',
                    description: '添加成功',
                    icon: <NotificationIcon type='success' />,
                })
                dispatch(loadFormDefind())
                dispatch(change('customer_tmp_setting_form', 'showFieldStatus', false ))
            }
            return data
        })
    }
}


// 编辑表单定义字段
export function editFormFieldAction(params) {
    return dispatch => {
        return editFormField(params).then(data => {
            if (data.code && data.code >= 300) {
                notification.open({
                    message: '错误',
                    description: '更新失败,' + data.message,
                    icon: <NotificationIcon type='error' />,
                })
            } else {
                notification.open({
                    message: '成功',
                    description: '更新成功',
                    icon: <NotificationIcon type='success' />,
                })
                dispatch(loadFormDefind())
                dispatch(change('customer_tmp_setting_form', 'showFieldStatus', false ))
            }
            return data
        })
    }
}


// 删除表单定义字段
export function delFormFieldAction(id) {
    return dispatch => {
        return delFormField(id).then(data => {
            if (data.code && data.code >= 300) {
                notification.open({
                    message: '错误',
                    description: '删除失败,' + data.message,
                    icon: <NotificationIcon type='error' />,
                })
            } else {
                notification.open({
                    message: '成功',
                    description: '删除成功',
                    icon: <NotificationIcon type='success' />,
                })
                dispatch(loadFormDefind())
            }
            return data
        })
    }
}

// 获取表单单个字段详情
export function getFormFieldDetailAction(id) {
    return dispatch => {
        return getFormFieldDetail(id).then(data => {
            return data
        })
    }
}

// 获取自定义表单分类列表
export function getClassifyListAction(params) {
    return dispatch => {
        return getClassifyList(params).then(data => {
            return data
        })
    }
}