import Mock from 'mockjs'

//模拟企业信息返回数据
const custTags = ["001","010","100","011","110","101","111"]
//生成随机的结果

const generateBinaryCombination= ()=>{
    const index = Mock.Random.integer(0,custTags.length-1);
    return custTags[index];
}

const customerInfoList = Mock.mock({
    'list|87': [{
        'id|+1': 1,
        'custName': '@name',
        'belongBranchName': '@name',
        'belongOutletName': '@name',
        'belongUserName': '@name',
        'lpName': '@name',
        'custPhone': Mock.mock(/\d{11}/,'1[3-9]\d{9}'),
        'custScale|0-2}': 1,
        'custTag': generateBinaryCombination(),
        'custPattern|0-2':0
    }]
}).list;

export const CustomerBaseInfo = Mock.mock('/system/custBaseInfo/list','get',options=> {
    const params = JSON.parse(options.body);
    const {custPattern,pagenum,pagesize} = params;
    console.log(params);

    let filterData = customerInfoList.filter(item => custPattern==0)
    //分页返回
    const total = filterData.length;
    const currentPage = parseInt(pagenum) || 1;
    const currentPageSize = parseInt(pagesize) ||10;
    const start = (currentPage-1) * currentPageSize;
    const end = start+currentPageSize;
    const pageData = filterData.slice(start,end);
    return {
        code: 200,
        data: {
            total:total,
            pagesize: currentPageSize,
            pagenum: currentPage,
            rows: pageData
        },
        message:'查询成功!'
    }
}).setup({timeout:'300-400'})

