<template>
    <el-dialog
    title="统计表"
    width="800px"
    :visible.sync="visible"
    :before-close="_close"
    >
    <div>
        <el-date-picker
        style="width:140px;margin-right:10px"
        v-model="startTime"
        type="date"
        placeholder="选择日期"
        @change="changeStartTime">
        </el-date-picker>
        <el-date-picker
        style="width:140px;margin-right:10px"
        v-model="endTime"
        type="date"
        placeholder="选择日期"
        @change="changeEndTime">
        </el-date-picker>
        <el-select style="width:140px;margin-right:10px" v-model="delive_way" placeholder="请选择">
            <el-option
            v-for="item in deliveryWay"
            :key="item.id"
            :label="item.name"
            :value="item.id">
            </el-option>
        </el-select>
        <!-- <el-button icon="el-icon-printer" type="primary" @click="toPrint">打印</el-button> -->
        
    </div>
    <div style="margin-top:10px;">
        <el-table :data="tableData" border style="width: 100%" height="300">
            <el-table-column align="center" prop="address" label="药品名称">
              <template slot-scope="scope">
                 {{scope.row.advice_name}}
              </template>
            </el-table-column>
             <el-table-column align="center" prop="address" label="药品规格">
               <template slot-scope="scope">
                  {{scope.row.advice_desc}}
               </template>
            </el-table-column>
            <el-table-column align="center" prop="name" label="数量" width="100">
                <template slot-scope="scope">
                   {{scope.row.Total}}
                </template>
            </el-table-column>
        </el-table>
    </div>
  </el-dialog>
</template>



<script>
const moment = require('moment')
import { GetAllZone } from "@/api/dialysis";
import { getDoctorAdviceCount } from "@/api/advice"
export default {
    data(){
        return{
            visible: false,
            startTime:new Date(),
            endTime:new Date(),
            schedulArr: [
                {value: 0, label: '全部班'},
                {value: 1, label: '上午'},
                {value: 2, label: '中午'},
                {value: 3, label: '下午'},
            ],
            schedulType: 0,
            partitionArr:[],
            partitionType: 0,
            deliveryWay:[],
            tableData: [],
            delive_way:""
        }
    },
    created(){
        this.getAllZone()
        this.getlist()
    },
    methods:{
        _close: function(done) {
            done();
        },
        show() {
            this.visible = true;
        },
        getAllZone: function() {
            GetAllZone().then(response => {
                if (response.data.state == 0) {
                this.$message.error(response.data.msg);
                return false;
                } else {
                this.partitionArr = response.data.data.zone;
                this.partitionArr.unshift({ id: 0, name: "全部分区" });
                var dics  =  response.data.data.dics
                var obj = {id:0,name:"全部"}
                this.deliveryWay.push(obj)
                this.deliveryWay.push(...dics)
                }
            });
        },
        toPrint(){
            this.$router.push({
                path: '/dialysis/dialysisDrugs_print',
                // query: { date: date }
            })
        },
       getlist(){

           let newTimeStart =  moment(this.startTime).format('YYYY-MM-DD')
           let newTimeEnd = moment(this.endTime).format('YYYY-MM-DD')
           var params = {
              start_time:newTimeStart,
              end_time:newTimeEnd,
              delive_way:this.delive_way,
           }
         
         getDoctorAdviceCount(params).then(response=>{
            if(response.data.state == 1){
              var list =  response.data.data.list
              console.log("list",list)
              this.tableData = list
            }
         })  
       },
      changeStartTime(val){
       var start =  moment(val).format('YYYY-MM-DD')
       this.startTime = start
       this.getlist()
      },
      changeEndTime(val){
       var end = moment(val).format('YYYY-MM-DD')
       this.endTime = end
       this.getlist()
      }
    }
}
</script>
