index.vue 11.2 KB
Newer Older
lanbaoming's avatar
lanbaoming committed
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
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="100px"
    >
      <el-form-item label="选择日期" prop="selDate">
        <el-date-picker
          v-model="queryParams.sDate"
          type="month"
          value-format="yyyy-MM"
          clearable
          placeholder="请输起始月"
        />
        <el-date-picker
          v-model="queryParams.eDate"
          type="month"
          value-format="yyyy-MM"
          clearable
          placeholder="请输截止月"
        />
      </el-form-item>
      <el-form-item label="同比年份" prop="duibiYear">
        <el-date-picker
          v-model="queryParams.duibiYear"
          type="year"
          value-format="yyyy"
          placeholder="请选择同比年份"
        />
      </el-form-item>
      <el-form-item label="部门" prop="deptid" v-show="showDept">
        <treeselect
          v-model="queryParams.deptid"
          :options="deptOptions"
          :show-count="true"
          :placeholder="$t('请选择部门')"
          :normalizer="normalizer"
        />
      </el-form-item>
      <el-form-item
        label="客户经理"
        prop="salesmanid"
        v-show="showCustomsManage"
      >
        <user-selector
          manage
          v-model="queryParams.salesmanid"
          clearable
          @change="handleQuery"
          :prepend="{ id: 0, nickname: $t('未分配客户经理') }"
        />
      </el-form-item>
      <el-form-item>
lanbaoming's avatar
lanbaoming committed
58 59 60
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">{{
          $t("搜索")
        }}</el-button>
lanbaoming's avatar
lanbaoming committed
61
        <el-button icon="el-icon-refresh" @click="resetQuery">
lanbaoming's avatar
lanbaoming committed
62
          {{ $t("重置") }}</el-button
lanbaoming's avatar
lanbaoming committed
63 64
        >
      </el-form-item>
lanbaoming's avatar
lanbaoming committed
65
      <el-form-item> </el-form-item>
lanbaoming's avatar
lanbaoming committed
66 67 68 69 70 71 72 73 74
    </el-form>
    <el-row>
      <el-form size="small" :inline="true" label-width="150px">
        <el-form-item label="">
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="hhandleQueryAnalysis"
          >
lanbaoming's avatar
lanbaoming committed
75
            {{ $t("更多") }}
lanbaoming's avatar
lanbaoming committed
76
          </el-button>
lanbaoming's avatar
lanbaoming committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        </el-form-item>
      </el-form>
    </el-row>
    <div
      ref="mainBar"
      :class="className"
      :style="{ height: height, width: width }"
    ></div>
    <!--
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />-->
  </div>
</template>
chenwei's avatar
chenwei committed
95

lanbaoming's avatar
lanbaoming committed
96 97 98 99 100 101 102 103 104 105
<script>
import UserSelector from "@/components/UserSelector";
import Treeselect from "@riophae/vue-treeselect";
//自定义目录数样式
import "@/assets/styles/vue-treeselect.css";
import { listSimpleDepts } from "@/api/system/dept";
import * as echarts from "echarts";
require("echarts/theme/macarons");
import resize from "../../dashboard/mixins/resize";
import { getReportResult } from "@/api/report/customerreport";
lanbaoming's avatar
lanbaoming committed
106 107 108 109
import {
  getCurUserPermission,
  getDeptChild,
} from "@/api/report/EcwReportPermission";
lanbaoming's avatar
lanbaoming committed
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
import { MessageBox } from "element-ui";

const CurDate = new Date();

function currentTime() {
  var date = new Date();
  var year = date.getFullYear();
  //月份从0~11,所以加一
  let month = date.getMonth() + 1;
  //如果格式是MM则需要此步骤,如果是M格式则此处注释掉
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  let strDate = year + "-" + month;
  return strDate;
}

function getLastYear() {
  //获取上一年份
  var date = new Date();
  date.setFullYear(date.getFullYear() - 1);
  let year = date.getFullYear();
  return year.toString();
}

lanbaoming's avatar
lanbaoming committed
135
//2024-05-01合并
lanbaoming's avatar
lanbaoming committed
136
export default {
lanbaoming's avatar
lanbaoming committed
137
  name: "ReportCustomerreportIndex",
lanbaoming's avatar
lanbaoming committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
  components: {
    UserSelector,
    Treeselect,
  },
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
154
      default: "500px",
lanbaoming's avatar
lanbaoming committed
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
    },
    autoResize: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      showDept: true, //是否显示部门选择过滤条件
      showCustomsManage: true, //是否显示客户经理过滤条件
      deptOptions: undefined,
      chart: null,
      dateRangeCreateTime: [],
      queryParams: {
        sDate: CurDate.getFullYear() + "-01",
        eDate: currentTime(), //结束日期
        duibiYear: getLastYear(), //对比年份
        deptid: undefined, //部门
        salesmanid: undefined, //客户经理
lanbaoming's avatar
lanbaoming committed
182
        number: undefined, //客户编号
lanbaoming's avatar
lanbaoming committed
183 184 185 186 187
        pageNo: 1,
        pageSize: 30,
      },
      //报表权限信息
      objEcwReportPermission: {},
lanbaoming's avatar
lanbaoming committed
188
      DeptEx: { id: undefined, name: undefined, parentId: undefined },
189
      resultList: [],
lanbaoming's avatar
lanbaoming committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203
    };
  },
  watch: {},
  mounted() {
    /*
    this.$nextTick(() => {
      this.initChart();
    });*/
  },
  created() {
    //获取当前用户报表权限
    getCurUserPermission().then((response) => {
      this.objEcwReportPermission = response.data;
      if (this.objEcwReportPermission.permissionFw == 1) {
lanbaoming's avatar
lanbaoming committed
204
        //本人权限
lanbaoming's avatar
lanbaoming committed
205 206 207
        this.showCustomsManage = false;
        this.showDept = false;
        this.queryParams.salesmanid = this.objEcwReportPermission.userId;
lanbaoming's avatar
lanbaoming committed
208 209 210 211 212 213 214 215
      } else if (this.objEcwReportPermission.permissionFw == 2) {
        this.showCustomsManage = true;
        this.showDept = true;
        this.queryParams.deptid = parseInt(this.objEcwReportPermission.deptId);
      } else if (this.objEcwReportPermission.permissionFw == 3) {
        //全公司权限
        this.showCustomsManage = true;
        this.showDept = true;
lanbaoming's avatar
lanbaoming committed
216
      }
lanbaoming's avatar
lanbaoming committed
217
      this.getTreeselect();
lanbaoming's avatar
lanbaoming committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
      //获取权限后再初始化统计图表
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      var chartDom = this.$refs["mainBar"];
      this.chart = echarts.init(chartDom, "macarons");
233
      this.chart.on("click", (params) => {
lanbaoming's avatar
lanbaoming committed
234 235
        if (this.isRight() == false) return;
        let p = {};
236 237 238
        this.queryParams.salesmanid = parseInt(
          this.resultList[params.dataIndex].salesmanid
        );
lanbaoming's avatar
lanbaoming committed
239
        this.queryParams.number = this.resultList[params.dataIndex].number;
lanbaoming's avatar
lanbaoming committed
240 241 242 243 244 245
        Object.assign(p, this.queryParams);
        this.$router.push({
          path: "/report/customer_analysis",
          query: p,
        });
      });
lanbaoming's avatar
lanbaoming committed
246 247 248 249 250 251 252
      this.setOptions();
    },
    setOptions() {
      this.loading = true;
      getReportResult(this.queryParams).then((response) => {
        //全部列表数据
        this.total = response.data.total;
253 254
        this.resultList = response.data.resultList;
        let resultList2 = response.data.resultList;
lanbaoming's avatar
lanbaoming committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
        this.loading = false;
        this.chart.setOption({
          title: {
            text: "客户贡献排名",
          },
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "shadow",
            },
            // 自定义提示框内容,使用回调函数
            formatter: function (params) {
              //params 是一个数组,数组中每个元素代表一个系列的数据信息
              var result = "";
              params.forEach(function (item) {
                //var s=JSON.stringify(item);
                //alert(s);
                //在数据中查询
273 274
                let sN = item.name;
                var arr = sN.split("_");
lanbaoming's avatar
lanbaoming committed
275
                let vR = resultList2.filter((r) => r.number === arr[1]);
lanbaoming's avatar
lanbaoming committed
276
                result += "客户:" + item.name + "<br/>";
lanbaoming's avatar
lanbaoming committed
277
                result += "客户编号:" + vR[0].number + "<br/>";
278
                result += "客户经理:" + vR[0].salesman + "<br/>";
lanbaoming's avatar
lanbaoming committed
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
                result += "总V值:" + item.value + "<br/>";
                result += "海运V值:" + vR[0].sumvolume1 + "<br/>";
                result += "空运V值:" + vR[0].sumweight3 + "<br/>";
                result += "对比年份:" + vR[0].duibiYear + "<br/>";
                result += "同比:" + vR[0].allsumvolumeTbMsg + "<br/>";
                result += "环比:" + vR[0].allsumvolumeTbMsg + "<br/>";
              });
              return result;
            },
          },
          legend: {},
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true,
          },
          xAxis: {
            type: "value",
            boundaryGap: [0, 0.5],
          },
          yAxis: response.data.objyAxis,
          series: response.data.obSseries,
        });
      });
    },
lanbaoming's avatar
lanbaoming committed
305

lanbaoming's avatar
lanbaoming committed
306
    hhandleQueryAnalysis() {
lanbaoming's avatar
lanbaoming committed
307 308 309 310 311 312 313
      if (this.isRight() == false) return;
      let p = {};
      Object.assign(p, this.queryParams);
      this.$router.push({
        path: "/report/customer_analysis",
        query: p,
      });
lanbaoming's avatar
lanbaoming committed
314
    },
lanbaoming's avatar
lanbaoming committed
315
    isRight() {
lanbaoming's avatar
lanbaoming committed
316 317 318
      //校验查询参数 lanbm 2024-04-07 add
      if (this.queryParams.sDate == undefined) {
        MessageBox("请输入起始月份。");
lanbaoming's avatar
lanbaoming committed
319
        return false;
lanbaoming's avatar
lanbaoming committed
320 321 322
      }
      if (this.queryParams.eDate == undefined) {
        MessageBox("请输入截止月份。");
lanbaoming's avatar
lanbaoming committed
323
        return false;
lanbaoming's avatar
lanbaoming committed
324 325 326
      }
      if (this.queryParams.duibiYear == undefined) {
        MessageBox("请输入对比年份。");
lanbaoming's avatar
lanbaoming committed
327
        return false;
lanbaoming's avatar
lanbaoming committed
328 329 330 331
      } else {
        let y = parseInt(this.queryParams.duibiYear);
        if (y < 2023) {
          MessageBox("对比年份只能选2023年和2023年之后的年份。");
lanbaoming's avatar
lanbaoming committed
332
          return false;
lanbaoming's avatar
lanbaoming committed
333 334 335 336 337
        }
        var date = new Date();
        var year = date.getFullYear();
        if (y > year) {
          MessageBox("对比年份只能选当前年份之前的年份。");
lanbaoming's avatar
lanbaoming committed
338
          return false;
lanbaoming's avatar
lanbaoming committed
339
        }
lanbaoming's avatar
lanbaoming committed
340
      }
lanbaoming's avatar
lanbaoming committed
341 342 343 344
      return true;
    },
    handleQuery() {
      if (this.isRight() == false) return;
lanbaoming's avatar
lanbaoming committed
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
      //查询统计结果
      this.initChart();
    },
    getList() {
      //this.initChart();
    },
    resetQuery() {
      this.queryParams = {
        sDate: undefined, //开始日期
        eDate: undefined, //结束日期
        duibiYear: undefined, //对比年份
        deptid: undefined, //部门
        salesmanid: undefined, //客户经理
        pageNo: 1,
        pageSize: 30,
      };
    },
    handleAdd() {},
    handleExport() {},
    /** 查询部门下拉树结构 + 岗位下拉 */
    getTreeselect() {
lanbaoming's avatar
lanbaoming committed
366 367 368 369 370 371 372 373 374 375 376 377 378 379
      if (this.objEcwReportPermission.permissionFw == 3) {
        listSimpleDepts().then((response) => {
          // 处理deptOptions 参数
          this.deptOptions = [];
          this.deptOptions.push(...this.handleTree(response.data, "id"));
        });
      } else if (this.objEcwReportPermission.permissionFw == 2) {
        this.DeptEx.id = this.objEcwReportPermission.deptId;
        getDeptChild(this.DeptEx).then((response) => {
          // 处理deptOptions 参数
          this.deptOptions = [];
          this.deptOptions.push(...this.handleTree(response.data, "id"));
        });
      }
lanbaoming's avatar
lanbaoming committed
380 381 382 383 384 385 386 387 388 389 390 391
    },
    //格式化部门的下拉框
    normalizer(node) {
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      };
    },
  },
};
</script>