<template>
  <div class="m-jdjs">
    <div class="m-jdjs-js">
      <div class="m-jdjs-js-img">
        <img src="../linshi/jiedaotu.jpg" />
      </div>
      <div class="m-jdjs-js-txt">
        {{ overview }}
      </div>
    </div>
    <title-small text="重点关注人群" />
    <div class="event-statistics">
      <div
        id="zdgz"
        v-loading="loading"
        element-loading-text="加载中..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0,0,0,0.5)"
        style="height: 170px"
      />
    </div>
    <title-small text="不满意风险人员">
      <span class="date-span">
        <el-date-picker
          popper-class="date-current-weiyi"
          :append-to-body="false"
          v-model="rffxDate"
          format="yyyy-MM"
          value-format="yyyy-MM"
          @change="changeDate"
          type="month"
          :clearable="false"
          placeholder="选择月"
        >
        </el-date-picker>
      </span>
    </title-small>
    <div class="f-flex white f-mean">
      <div class="f-hflex"  @click="
        $router.push(
          '/dataBoard/satisfactionEval/potentialPeople?type=shuji&countType=service&satisfactionSource=satisfaction_12345'
        )
      ">
        <div><span class="f-pingfang">12345热线投诉人数</span></div>
        <div class="f-darkGray" ><b class="f-font34 f-yellow">12</b>人</div>
      </div>
      <div class="f-hflex"  @click="
        $router.push(
          '/dataBoard/satisfactionEval/potentialPeople?type=shuji&countType=service&satisfactionSource=satisfaction_province'
        )
      ">
        <div><span class="f-pingfang">满意度调查不满意人数</span></div>
        <div class="f-darkGray"><b class="f-font34 f-green">12</b>人</div>
      </div>
      <div class="f-hflex"  @click="
        $router.push(
          '/dataBoard/satisfactionEval/potentialPeople?type=shuji&countType=service&satisfactionSource=satisfaction_community'
        )
      ">
        <div><span class="f-pingfang">社区自评不满意人数</span></div>
        <div class="f-darkGray"><b class="f-font34 f-skyBlue">12</b>人</div>
      </div>
    </div>
  </div>
</template>
<script>
import titleSmall from "@/views/dataBoard/satisfactionEval/components/Title/titleSmall.vue";
import * as echarts from "echarts";
import resiCategoryMap from "@/views/business/resi-category-map.js";

export default {
  name: "jdjs",
  props: {
    currentLevelData: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      orgId: this.$store.state.chooseArea.chooseName,
      report: "",
      overview: "",
      loading: false,
      rffxDate:''
    };
  },
  watch: {
    currentLevelData(val) {
      if (val.orgId) {
        this.getReport(val);
        // this.getData();
      }
    },
  },
  mounted() {
    this.getReport(this.currentLevelData);
      this.getData();
  },
  components: {
    titleSmall,
  },
  methods: {
    getReport({ orgId, orgLevel }) {
      this.$http
        .get(
          "/actual/base/streetOverview/communityOverview?orgId=" +
            orgId +
            "&level=" +
            orgLevel
        )
        .then(({ data: { data } }) => {
          this.overview = data;
        });
      this.$http
        .get(
          "/actual/base/streetOverview/summaryReport?orgId=" +
            orgId +
            "&level=" +
            orgLevel
        )
        .then(({ data: { data } }) => {
          this.report = data;
        });
    },
    getData() {
      this.loading = true
     
      this.$http.get('/actual/base/resiCategory/intelligentPredictioncategoryCountList').then(({data: {data}}) => {
        this.initCharts(data)
      })
    },
    initCharts(data) {
      let div = document.getElementById('zdgz');
      this.myChart = echarts.init(div);
     let chartData =  data.categoryList.map((item) => {
            return {
              name: resiCategoryMap[item.categoryName] || "",
              count: item.categoryCountNext,
            };
          });
      let xData = chartData.map(item=>item.name);
      let yData = chartData.map(item=>item.count)
      console.log(yData,xData);
      let color = [[
        {
          offset: 0,
          color: 'rgba(0, 84, 255, 0)' // 0% 处的颜色
        },
        {
          offset: 1,
          color: 'rgba(38, 244, 248, 1)' // 100% 处的颜色
        }
      ]]
      // let seriesArray = series.map((item, index) => {
      //   return {
      //     name: item.name,
      //     type: 'bar',
      //     barWidth: 14,
      //     itemStyle: {
      //       opacity: 1,
      //       color: new echarts.graphic.LinearGradient(
      //           0,
      //           1,
      //           0,
      //           0,
      //           color[0],
      //           false
      //       )
      //     },
      //     data: item.data,
      //   }
      // })
      let num = yData
      const max = Math.max(...num)
      let barArray = new Array(xData.length).fill((parseInt(max / 100) + 1) * 100)
      var option = {
        title: {
          show: false,
          text: '',
          x: 'center',
          top: '15px',
          textStyle: {
            color: '#333333',
            fontWeight: 500,
            fontSize: 18,
          },
        },
        tooltip: {
          trigger: 'axis',
          backgroundColor: 'rgba(13,33,71,0.5)',
          borderColor: 'rgba(143,174,252,0.6)',
          padding: 8,
          textStyle: {
            color: '#fff',
          },
          formatter: function (params) {
            var res = '<div"><p>' + params[0].name + '：'+params[0].value + '</p></div>'
            return res;
          },
        },
      
        grid: {
          top: '18%',
          left: '2%',
          right: '4%',
          bottom: '8%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            axisTick: {
              show: false,
            },
            splitLine: {
              show: false,
            },
            axisLine: {
              lineStyle: {
                color: '#323c41'
              }
            },
            axisLabel: {
              align: 'center',
              interval: 0,
              textStyle: {
                fontSize: 12,
                color: '#A3B9DA'
              }
            },
            boundaryGap: true,
            data: xData,
          }, {
            type: 'category',
            data: xData,
            axisLine: {show: false},
            axisLabel: {
              show: false,
            },
            boundaryGap: true,

          }
        ],

        yAxis: [
          {
            type: 'value',
            name: '单位：人',
            nameLocation: 'end',
            splitLine: {
              show: true,
              lineStyle: {
                color: 'rgba(4,187,255,0.18)',
                type: 'dashed'
              },
            },
            nameTextStyle: {
              color: '#A3B9DA',
              textStyle: {
                fontSize: 12
              },
              align: 'center'
            },
            axisLabel: {
              show: true,
              color: '#A3B9DA',
              textStyle: {
                fontSize: 12
              }
            },
            axisTick: {
              show: false
            }
          }
        ],
        series: [
        {
          name: "",
          type: 'bar',
          barWidth: 20,
          itemStyle: {
            opacity: 1,
            color: new echarts.graphic.LinearGradient(
                0,
                1,
                0,
                0,
                color[0],
                false
            )
          },
          data: yData,
        },
          {
            name: '',
            type: 'bar',
            barWidth: 50,
            barGap: '-60%',
            data: barArray,
            itemStyle: {
              normal: {
                color: 'rgba(22,153,152, 0.1)'
              }
            },
            zlevel: -1,
            xAxisIndex: 1,
          }
        ],
      };
      this.myChart.setOption(option);
      window.addEventListener("resize", () => this.myChart.resize());
      this.loading = false
    },
    changeDate() {},
  },
};
</script>

<style lang="scss" src="@/assets/scss/dataBoard/overview/index.scss" scoped />
<style lang="scss">
.f-hflex{
  width: 83px;
}
.f-flex{
  margin-top: 20px;
}
.f-darkGray{
  margin-top: 15px;
}
</style>
