<template>
  <div class="app-container">
      <div class="app-content">

<div class="title" style="display: flex; justify-content: center; align-items: center;">问诊统计</div>


<el-form class="search-form" :inline="true" label-width="90px">
                <el-form-item   label="                     统计">
                  <el-select v-model="queryParams.type" placeholder="请选择日期">
                    <el-option
                      v-for="item in options"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>
            <el-form-item label="医生" prop="doctorId">
            <el-select v-model="queryParams.doctorId" filterable placeholder="输入名称搜索" :filter-method="doctorMethod">
              <el-option
                v-for="item in docuser"
                :key="item.name"
                :label="item.name"
                :value="item.id">
              </el-option>
            </el-select>
            </el-form-item>
                <el-form-item>
                   <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                   <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-form>
              </div>
  <div ref="chartContainer" style="width: 100%; height: 400px;"></div>
<el-button class="export" size="small"  @click="handleExport" style="float: right; margin-bottom: 15px; margin-right: 40px;" >导出</el-button>
  <div class="table-box" style="margin-left: 40px; margin-right: 40px;">
                         <el-table
                         :data="list"
                         border
                         show-summary
                         style="width: 100%;">
                         <el-table-column
                           prop="name"
                           label="医生姓名">
                         </el-table-column>
                         <el-table-column
                           prop="count"
                           label="问诊次数">
                         </el-table-column>
                         <el-table-column
                           prop="money"
                           label="金额">
                         </el-table-column>
                       </el-table>
                   </div>
   </div>

  </div>

</template>

<script>
import {listdocuser} from "@/api/his/doctorArticle";
import echarts from 'echarts'
import { orderChartData,storeOrderChart,inquiryOrderChart ,inquiryOrderChartInq,inquiryExport } from "@/api/his/index";
export default {
  data() {
    return {
  // 导出遮罩层
      exportLoading: false,
      doctorName: null,
      queryParams:{
        type: null,
        doctorId: null,
      },
       doctorName: {name:"1"},
      list:[],
      docuser:[],
      storeOPtions:[],
      chart: null,
      data: [
      ],
      options: [{
         value: '1',
         label: '今天'
       }, {
         value: '2',
         label: '昨天'
       }, {
         value: '3',
         label: '本周'
       }, {
         value: '4',
         label: '上周'
       }, {
         value: '5',
         label: '本月'
       }
       , {
         value: '6',
         label: '上月'
       },
       {
         value: '7',
         label: '本季度'
       },
       {
         value: '8',
         label: '上季度'
       }
       , {
         value: '9',
         label: '本年'
       }
       , {
         value: '10',
         label: '去年'
       }],
    };
  },
  created() {
  },
  mounted() {
    this.chart = echarts.init(this.$refs.chartContainer, 'macarons');
    this.chart.on('mouseout', this.hideTooltip);
    this.updateChart();
    this.getorderChartData();
  },

  watch: {
    data() {
      this.updateChart();
    },
  },



  methods: {
  /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
            this.exportLoading = true;
          return inquiryExport(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    doctorMethod(rows){
      this.doctorName.name=rows;
      this.getlistdocuser();
    },
    getlistdocuser(){
        listdocuser(this.doctorName).then(response => {
          this.docuser=response.rows;
      });
    },
    handleQuery(){
      inquiryOrderChart(this.queryParams).then(response => {
        this.data = response.data;

      });
      inquiryOrderChartInq(this.queryParams).then(response => {
        this.list = response.data;

      });

    },
 /** 重置按钮操作 */
    resetQuery() {
     this.queryParams={
       type: null,
       doctorId: null,
     }
     this.getorderChartData()
    },

    getorderChartData(){
      inquiryOrderChart().then(response => {
        this.data = response.data;
      });
      inquiryOrderChartInq(this.queryParams).then(response => {
        this.list = response.data;

      });
    },


    formatter(params) {
      const item = params[0];
      return  `
              <div>
                <div>日期：${item.axisValue}</div>
                <div>问诊数量：${item.value}次</div>
                <div>金额：${item.data.info}</div>
              </div>
            `;
    },

    updateChart() {
      const option = {
        xAxis: {
          type: 'category',
          data: this.data.map((item) => item.label),
        },
        yAxis: {
          type: 'value',
        },
        tooltip: {
          trigger: 'axis',
          formatter: this.formatter,
          axisPointer: {
            type: "line",
            lineStyle: {
              color: "rgba(227, 242, 252, 0.39)",
              width: 40,
              type: "solid",
            },
            z: 0,  //注意要设置层级，不然会在覆盖在柱子前面，设置为0就在柱子后面显示了。
          },
        },
        series: [
          {
            name: 'Value',
            type: 'line',
            barWidth: '40%',
            itemStyle: {
              color: '#000000',
            },
            label: {
              show: true,
              position: 'top',
            },
            data: this.data.map((item) => ({ value: item.value, info: item.info })),
          },
        ],


      };
      this.chart.setOption(option);
    },

    hideTooltip() {
      this.chart.dispatchAction({
        type: 'hideTip',
      });
    },
  },
};
</script>
<style>
.app-container{
    border: 1px solid #e6e6e6;
    padding: 12px;

    .app-content{
      background-color: white;
      .title{
        padding: 20px 30px 0px 30px;
        font-size: 18px;
        font-weight: bold;
        color: black;

      }
      .search-form{
        margin: 20px 30px 0px 30px;
      }
      .data-box{
        padding: 30px;
        background-color:  rgb(255, 255, 255);
        height: 100%;

        .echart-box{
          margin: 0 auto;
          text-align: center;
        }
        .el-select{
          margin: 5px 10px;
        }
        .table-box{
          margin-top: 15px;
          .export{
            float: right;
            margin: 10px 0px;
          }
        }
      }
    }
}
</style>
