shuishen
2021-11-17 7f4f36e2594827091c5000d79a32d4ff21dd1123
src/views/home/indexEchart.js
@@ -1,769 +0,0 @@
import * as echarts from "echarts";
import nc from "../../../public/nc.json";
function left1Data(allData) {
  let nameArr = [];
  let data1 = [];
  let data2 = [];
  let data3 = [];
  let data4 = [];
  let data5 = [];
  // let legend = ["自招保安单位", "保安培训公司", "保安服务公司", "武装守押公司"];
  allData.forEach(item => {
    nameArr.push(item.name);
    data1.push(item.server.confess || 0);
    data2.push(item.server.staff || 0);
    data3.push(item.server.security || 0);
    data4.push(item.server.armed || 0);
    data5.push(item.server.region || 0);
  });
  nameArr.reverse();
  data1.reverse();
  data2.reverse();
  data3.reverse();
  data4.reverse();
  data5.reverse();
  let option = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow"
      },
      backgroundColor: "#031952", //设置背景图片 rgba格式
      color: "#fff",
      borderWidth: "0", //边框宽度设置1
      // borderColor: "gray", //设置边框颜色
      textStyle: {
        color: "#fff" //设置文字颜色
      }
    },
    color: [
      "#2ec7c9",
      "#b6a2de",
      "#5ab1ef",
      "#ffb980",
      // "#fac858",
      // "#73c0de",
      // "#3ba272",
      "#fc8452",
      "#9a60b4",
      "#3fb1e3",
      "#6be6c1",
      "#626c91",
      "#a0a7e6",
      "#c4ebad",
      "#96dee8"
    ],
    // legend: {
    //   data: ["自招保安单位", "保安培训公司", "保安服务公司", "武装守押公司"],
    //   bottom: "1%",
    //   itemWidth: 20,
    //   textStyle: {
    //     color: "#fff"
    //   },
    //   // formatter: function (legend1) {
    //   //   return legend1;
    //   // }
    // },
    grid: {
      top: "5%",
      left: "5%",
      right: "10%",
      bottom: "5%",
      containLabel: true
    },
    xAxis: {
      type: "value",
      axisLabel: {
        color: "#fff"
      },
      axisLine: {
        show: true
      },
      splitLine: {
        show: false
      }
    },
    yAxis: {
      type: "category",
      axisLabel: {
        color: "#fff"
      },
      data: nameArr
    },
    series: [
      {
        name: "自招保安单位",
        type: "bar",
        stack: "total",
        barWidth: 17,
        emphasis: {
          focus: "series"
        },
        data: data1
      },
      {
        name: "保安培训学校",
        type: "bar",
        stack: "total",
        emphasis: {
          focus: "series"
        },
        data: data2
      },
      {
        name: "本市保安公司",
        type: "bar",
        stack: "total",
        emphasis: {
          focus: "series"
        },
        data: data3
      },
      {
        name: "武装守押公司",
        type: "bar",
        stack: "total",
        emphasis: {
          focus: "series"
        },
        data: data4
      },
      {
        name: "分公司",
        type: "bar",
        stack: "total",
        emphasis: {
          focus: "series"
        },
        data: data5
      }
    ]
  };
  return option;
}
function left2Data(allData) {
  let nameArr = [];
  let data1 = [];
  let data2 = [];
  allData.forEach(item => {
    nameArr.push(item.name);
    data1.push(item.cz);
    data2.push(item.wcz);
  });
  let option = {
    tooltip: {
      trigger: "axis",
      axisPointer: {
        type: "shadow"
      },
      backgroundColor: "#031952", //设置背景图片 rgba格式
      color: "#fff",
      borderWidth: "0", //边框宽度设置1
      // borderColor: "gray", //设置边框颜色
      textStyle: {
        color: "#fff" //设置文字颜色
      }
    },
    color: [
      "#3fb1e3",
      "#0dad7b",
      "#73c0de",
      "#3ba272",
      "#fc8452",
      "#9a60b4",
      "#3fb1e3",
      "#6be6c1",
      "#626c91",
      "#a0a7e6",
      "#c4ebad",
      "#96dee8"
    ],
    legend: {
      data: ["持证人数", "未持证人数"],
      bottom: "1%",
      left: "13%",
      itemWidth: 20,
      textStyle: {
        color: "#fff"
      }
    },
    grid: {
      top: "10%",
      left: "5%",
      right: "6%",
      bottom: "4%",
      containLabel: true
    },
    xAxis: {
      type: "category",
      axisLabel: {
        color: "#fff",
        rotate: 40,
      },
      data: nameArr
    },
    yAxis: {
      type: "value",
      axisLabel: {
        color: "#fff"
      },
      boundaryGap: [0, 0.01],
      axisLine: {
        show: true
      },
      splitLine: {
        show: false
      }
    },
    series: [
      {
        name: "持证人数",
        type: "bar",
        // barWidth:30,
        barWidth: 15,
        stack: "total",
        emphasis: {
          focus: "series"
        },
        data: data1
      },
      {
        name: "未持证人数",
        type: "bar",
        stack: "total",
        emphasis: {
          focus: "series"
        },
        data: data2
      }
    ]
  };
  return option;
}
function left3Data(allData) {
  let data = [
    { value: allData[0].mnum ? Number(allData[0].mnum) : 0, name: "男" },
    { value: allData[0].gnum ? Number(allData[0].gnum) : 0, name: "女" }
  ];
  let option = {
    tooltip: {
      trigger: "item",
      formatter: "{a}<br>{b}:{c}({d}%)",
      axisPointer: {
        type: "shadow"
      },
      backgroundColor: "#031952", //设置背景图片 rgba格式
      color: "#fff",
      borderWidth: "0", //边框宽度设置1
      // borderColor: "gray", //设置边框颜色
      textStyle: {
        color: "#fff" //设置文字颜色
      }
    },
    color: ["#008DEC", "#886EFF"],
    // legend: {
    //   right: "8%",
    //   bottom: "10%",
    //   itemHeight: 10,
    //   show: true,
    //   selectedMode: false,
    //   textStyle: {
    //     color: "#fff"
    //   },
    //   data: ['男', '女'],
    //   orient: "vertical"
    // },
    grid: {
      top: "10%",
      left: "5%",
      right: "30%",
      bottom: "4%",
      containLabel: true
    },
    series: [
      {
        name: "性别比例",
        type: "pie",
        center: ["33%", "50%"],
        radius: "70%",
        data: data,
        label: {
          color: "#fff"
        }
      }
    ]
  };
  return option;
}
function right1Data(allData) {
  // let yueData = [
  //   "一月",
  //   "二月",
  //   "三月",
  //   "四月",
  //   "五月",
  //   "六月",
  //   "七月",
  //   "八月",
  //   "九月",
  //   "十月",
  //   "十一月",
  //   "十二月"
  // ];
  // let nameArr = [];
  // allData.forEach(a => {
  //   yueData.forEach(b => {
  //    console.log('a',a)
  //     // if(a){}
  //   });
  // });
  let option = {
    tooltip: {
      trigger: "axis"
    },
    color: [
      "#91cc75",
      "#fac858",
      "#73c0de",
      "#3ba272",
      "#fc8452",
      "#9a60b4",
      "#3fb1e3",
      "#6be6c1",
      "#626c91",
      "#a0a7e6",
      "#c4ebad",
      "#96dee8"
    ],
    legend: {
      data: ["现实表现差", "审查情况"],
      bottom: "5%",
      textStyle: {
        color: "#fff"
      }
    },
    grid: {
      left: "5%",
      right: "6%",
      bottom: "22%",
      top: "5%",
      containLabel: true
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      axisLabel: {
        color: "#fff"
      },
      data: ["1月", "2月", "3月", "4月", "5月", "6月", "7月"]
    },
    yAxis: {
      axisLabel: {
        color: "#fff"
      },
      type: "value"
    },
    series: [
      {
        name: "现实表现差",
        type: "line",
        stack: "总量",
        data: [120, 132, 101, 134, 90, 230, 210]
      },
      {
        name: "审查情况",
        type: "line",
        stack: "总量",
        data: [220, 182, 191, 234, 290, 330, 310]
      }
    ]
  };
  return option;
}
function right2Data(allData) {
  let option = {
    tooltip: {
      trigger: "axis"
    },
    color: [
      "#91cc75",
      "#fac858",
      "#73c0de",
      "#3ba272",
      "#fc8452",
      "#9a60b4",
      "#3fb1e3",
      "#6be6c1",
      "#626c91",
      "#a0a7e6",
      "#c4ebad",
      "#96dee8"
    ],
    legend: {
      data: ["未缴纳社保情况", "未持证情况"],
      bottom: "5%",
      textStyle: {
        color: "#fff"
      }
    },
    grid: {
      left: "5%",
      right: "6%",
      bottom: "22%",
      top: "5%",
      containLabel: true
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      axisLabel: {
        color: "#fff"
      },
      data: ["1月", "2月", "3月", "4月", "5月", "6月", "7月"]
    },
    yAxis: {
      type: "value",
      axisLabel: {
        color: "#fff"
      }
    },
    series: [
      {
        name: "未缴纳社保情况",
        type: "line",
        stack: "总量",
        data: [120, 132, 101, 134, 90, 230, 210]
      },
      {
        name: "未持证情况",
        type: "line",
        stack: "总量",
        data: [220, 182, 191, 234, 290, 330, 310]
      }
    ]
  };
  return option;
}
function right3Data(allData) {
  let data = [];
  let legendData = [];
  let datas = allData.sort((a, b) => {
    return b.Count - a.Count;
  });
  datas.forEach(item => {
    let obj = {
      name: item.jurname,
      value: item.Count
    };
    legendData.push(item.jurname);
    // sumValue += Number(item.Count)
    data.push(obj);
  });
  let option = {
    tooltip: {
      show: true,
      trigger: "item",
      formatter: "{a}<br>{b}:{c}({d}%)",
      backgroundColor: "#031952", //设置背景图片 rgba格式
      color: "#fff",
      borderWidth: "0", //边框宽度设置1
      // borderColor: "gray", //设置边框颜色
      textStyle: {
        color: "#fff" //设置文字颜色
      }
    },
    legend: {
      type: "scroll",
      right: "5%",
      top: "5%",
      itemHeight: 10,
      show: true,
      itemGap: 8,
      selectedMode: false,
      textStyle: {
        color: "#fff",
        fontSize: 9
      },
      data: legendData,
      orient: "vertical"
    },
    color: [
      "#91cc75",
      "#fac858",
      "#73c0de",
      "#3ba272",
      "#fc8452",
      "#9a60b4",
      "#3fb1e3",
      "#6be6c1",
      "#626c91",
      "#a0a7e6",
      "#c4ebad",
      "#96dee8"
    ],
    series: [
      {
        name: "分局预警占比",
        type: "pie",
        radius: ["40%", "70%"],
        center: ["35%", "55%"],
        avoidLabelOverlap: false,
        label: {
          show: false,
          position: "center"
        },
        // emphasis: {
        //   label: {
        //     show: true,
        //     fontSize: "12",
        //     fontWeight: "bold"
        //   }
        // },
        labelLine: {
          show: false
        },
        data: data
      }
      // {
      //     name: '面积模式',
      //     type: 'pie',
      //     radius: [20, 140],
      //     center: ['75%', '50%'],
      //     roseType: 'area',
      //     itemStyle: {
      //         borderRadius: 5
      //     },
      //     data: [
      //         {value: 30, name: 'rose 1'},
      //         {value: 28, name: 'rose 2'},
      //         {value: 26, name: 'rose 3'},
      //         {value: 24, name: 'rose 4'},
      //         {value: 22, name: 'rose 5'},
      //         {value: 20, name: 'rose 6'},
      //         {value: 18, name: 'rose 7'},
      //         {value: 16, name: 'rose 8'}
      //     ]
      // }
    ]
  };
  return option;
}
function middleData(allData, type) {
  var ncMap = nc;
  // var convertData = function (allData) {
  //   var res = [];
  //   for (var i = 0; i < data.length; i++) {
  //     var geoCoord = geoCoordMap[data[i].name];
  //     if (geoCoord) {
  //       res.push({
  //         name: data[i].name,
  //         value: geoCoord.concat(data[i].value)
  //       });
  //     }
  //   }
  //   return res;
  // };
  let name = "";
  let label = "";
  let symbolUrl = "";
  let geoData = [];
  allData["table"].forEach((item, i) => {
    let obj = {};
    if (type === 1) {
      name = "保安员名称";
      label =
        "押运人员:" +
        item.name +
        "<br />当前位置:" +
        item.location +
        "<br />所属公司:" +
        item.linkman +
        "<br />联系电话:" +
        item.tel;
      symbolUrl = require("/img/mapicon/people.png");
      obj = {
        name: label,
        value: allData["geoData"][i]
      };
    } else if (type === 2) {
      name = "押运车辆";
      label =
        "押运车辆车牌号:" +
        item.carNum +
        "<br />当前位置:" +
        item.location +
        "<br />所属公司:" +
        item.company +
        "<br />联系人:" +
        item.linkman +
        "<br />联系电话:" +
        item.tel;
      symbolUrl = require("/img/mapicon/car.png");
      obj = {
        name: label,
        value: allData["geoData"][i]
      };
    } else if (type === 3) {
      name = "枪支";
      label =
        "枪支编号:" +
        item.number +
        "<br />当前位置:" +
        item.location +
        "<br />所属公司:" +
        item.company +
        "<br />负责人:" +
        item.linkman +
        "<br />联系电话:" +
        item.tel;
      symbolUrl = require("/img/mapicon/gun.png");
      obj = {
        name: label,
        value: allData["geoData"][i]
      };
    }
    geoData.push(obj);
  });
  echarts.registerMap("ncMap", ncMap);
  // echarts.registerMap('chinaMapOutline', chinaMapOutline);
  let option = {
    // backgroundColor: '#181F4E',
    // tooltip: {
    //   trigger: 'item',
    // },
    tooltip: {
      trigger: "item",
      formatter: function(params) {
        if (typeof params.value[1] == "undefined") {
          return params.name;
        } else {
          return params.name;
        }
      },
      backgroundColor: "#031952", //设置背景图片 rgba格式
      color: "#fff",
      borderWidth: "0", //边框宽度设置1
      borderColor: "gray", //设置边框颜色
      extraCssText: "box-shadow: 0 0 3px rgba(   211,211,211, 0.5);",
      textStyle: {
        color: "#fff" //设置文字颜色
      }
    },
    geo: {
      // silent: true,
      map: "ncMap",
      show: true,
      zoom: 1.04,
      top: "8%",
      label: {
        show: false,
        color: "#fff",
        emphasis: {
          textStyle: {
            color: "#fff"
          }
        }
      },
      roam: true,
      itemStyle: {
        areaColor: "rgba(0,255,255,.02)",
        borderColor: "#00ffff",
        borderWidth: 1.5,
        shadowColor: "#00ffff",
        shadowOffsetX: 0,
        shadowOffsetY: 4,
        shadowBlur: 10
      },
      emphasis: {
        itemStyle: {
          color: "transparent", //悬浮背景
          textStyle: {
            color: "#fff"
          }
        }
      }
    },
    series: [
      {
        map: "ncMap",
        // silent: true,
        type: "map",
        geoIndex: 0,
        // aspectScale: 0.75, //长宽比
        zoom: 1.14,
        label: {
          show: false,
          color: "#fff"
        },
        emphasis: {
          label: {
            color: "#fff"
          }
        },
        top: "10%",
        roam: true,
        itemStyle: {
          areaColor: "rgba(0,255,255,.02)",
          borderColor: "#00ffff",
          borderWidth: 1.5,
          shadowColor: "#00ffff",
          shadowOffsetX: 0,
          shadowOffsetY: 4,
          shadowBlur: 10
        },
        emphasis: {
          itemStyle: {
            areaColor: "transparent", //悬浮背景
            textStyle: {
              color: "#fff"
            }
          }
        }
      },
      {
        name: name,
        type: "scatter",
        coordinateSystem: "geo",
        // roam: false,
        symbol: "image://" + symbolUrl,
        symbolSize: [30, 30],
        label: {
          show: false,
          color: "#fff",
          fontSize: 9
        },
        itemStyle: {
          color: "#FF0000" //标志颜色
        },
        data: geoData,
        showEffectOn: "render",
        rippleEffect: {
          brushType: "stroke"
        },
        hoverAnimation: true,
        emphasis: {
          scale: true
        },
        zlevel: 1
      }
    ]
  };
  return option;
}
export default {
  left1Data,
  left2Data,
  left3Data,
  right1Data,
  right2Data,
  right3Data,
  middleData
};