export function setFunnelOptions() {
  var colors = ['#5583f7', '#8400ff', '#35b63d', '#f77736']
  var url = ''

  var lineargroup = [
    {
      value: 80,
      name: '目标',
      oriname: '意向',
      number: 98756,
      color: ['rgba(29,211,137,0.8)', 'rgba(29,211,137,0)']
    },
    {
      value: 60,
      name: '方案率',
      oriname: '方案',
      number: 98756,
      color: ['rgba(102,142,255,0.7)', 'rgba(102,142,255,0)']
    },
    {
      value: 40,
      name: '商務率',
      oriname: '商務',
      number: 78756,
      color: ['rgba(255,198,82,0.6)', 'rgba(255,198,82,0)']
    },
    {
      value: 20,
      name: '成交率',
      oriname: '即將成交',
      number: 68756,
      color: ['rgba(255,110,115,0.5)', 'rgba(255,110,115,0)']
    }
  ]

  var data1 = []

  for (var i = 0; i < lineargroup.length; i++) {
    var obj1 = {
      value: lineargroup[i].value,
      num: '',
      name: lineargroup[i].oriname
    }

    data1.push(obj1)
  }

  var option = {
    backgroundColor: '#ffffff',
    color: colors,
    grid: {
      top: '0',
      left: '0',
      right: 0
    },
    xAxis: {
      show: false
    },
    yAxis: [
      {
        show: false
      }
    ],
    series: [
      {
        top: 0,
        type: 'funnel',
        height: '400',
        gap: 20,
        minSize: 150,
        left: '20%',
        width: '60%',
        label: {
          show: true,
          position: 'inside',
          fontSize: '18',
          formatter: function(d) {
            var ins = d.name + '{aa|}\n' + d.data.num
            return ins
          },
          rich: {
            aa: {
              padding: [8, 0, 6, 0]
            }
          }
        },
        data: data1
      },
      {
        type: 'pictorialBar',
        name: '',
        symbolSize: ['32', '0'],
        symbolPosition: 'center',
        animation: true,
        symbolClip: true,
        z: 10,
        data: [
          {
            value: 100
          },
          {
            value: 100
          },
          {
            value: 100
          },
          {
            value: 100
          }
        ]
      }
    ]
  }
  return option
}

export function setLineOptions({ xData, seriesData, unit = '' }) {
  const option = {
    tooltip: {
      trigger: 'axis',
      formatter: (item)=>{
        let label = ''
        if( unit==='%'){
          label =   item[0].name + "</br>" + (item[0].value * 100).toFixed(2) + unit
        }else if(unit==='分'){
          label =   item[0].name + "</br>" + (item[0].value / 100).toFixed(2) + '元'
        }else{
          label = item[0].name + "</br>" + item[0].value + unit
        }
        return  label
      }
    },
    xAxis: {
      type: 'category',
      data: xData
    },
    yAxis: {
      type: 'value',
      axisLabel: {
        formatter: (value)=>{
          let label = ''
          if(unit==='%'){
            label =  (value * 100).toFixed(2) + unit
          }else if(unit==='分'){
            label =  (value / 100).toFixed(2) + '元'
          }else{
            label = value + unit
          }
          return label
        }
      }
    },
    series: [
      {
        data: seriesData,
        type: 'line',
        smooth: true,
      }
    ]
  }
  return option
}
