<template>
    <el-dialog
    title="汇总统计"
    width="800px"
    :visible.sync="visible"
    :before-close="_close"
    >
    <div>
        <el-date-picker
        style="width:150px;margin-right:10px"
        v-model="startTime"
        type="date"
        placeholder="选择日期"
        @change="handleScheduleDateChange">
        </el-date-picker>
        <el-date-picker
        style="width:150px;margin-right:10px"
        v-model="endTime"
        type="date"
        placeholder="选择日期"
        @change="handleSchedule">
        </el-date-picker>
        <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="date" label="商品类型" width="180">
               <template slot-scope="scope">
                  <span v-if="scope.row.stage == 1">{{scope.row.type_name}}</span>
                  <span v-if="scope.row.stage == 2">抗凝剂</span>
               </template>
            </el-table-column>
            <el-table-column align="center" prop="name" label="规格名称" width="180">
                <template slot-scope="scope">
                  <span v-if="scope.row.stage == 1">{{scope.row.specification_name}}</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 1">无肝素</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 2">普通肝素</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 3">低分子肝素</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 4">阿加曲班</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 5">枸橼酸钠</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 6">低分子肝素钙</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 7">低分子肝素钠</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 8">依诺肝素</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 9">达肝素</span>
                  <span v-if="scope.row.stage == 2 && scope.row.anticoagulant == 10">体外抗凝</span>
               </template>
            </el-table-column>
            <el-table-column align="center"  prop="address" label="数量">
              <template slot-scope="scope">
                  {{scope.row.count}}
               </template>
            </el-table-column>
        </el-table>
    </div>
    <!-- <div slot="footer" class="dialog-footer">
      <el-button @click="hide">取 消</el-button>
      <el-button type="primary" @click="submitAction()">保 存</el-button>
    </div> -->
  </el-dialog>
</template>



<script>
const moment = require('moment')
import { parseTime } from "@/utils";
import {getGatherList} from "@/api/consumable"
export default {
    data(){
        return{
            visible: false,
            startTime:moment(new Date()).add('year',0).format("YYYY-MM-DD"),
            endTime:moment(new Date()).add('year',0).format("YYYY-MM-DD"),
            schedulArr: [
                {value: 0, label: '全部班'},
                {value: 1, label: '上午'},
                {value: 2, label: '中午'},
                {value: 3, label: '下午'},
            ],
            schedulType: 0,
            partitionArr:[],
            partitionType: 0,
            tableData: [],
            start_time:moment(new Date()).add('year',0).format("YYYY-MM-DD"),
            end_time:moment(new Date()).add('year',0).format("YYYY-MM-DD")
        }
    },
    created(){
      //获取统计表数据
      this.getlist()
    },
    methods:{
        _close: function(done) {
            done();
        },
        show() {
            this.visible = true;
        },
        handleScheduleDateChange(){
          var startime = parseTime(this.startTime,'{y}-{m}-{d}')
          console.log("startime====",startime)
          this.start_time = startime
          this.getlist()
        },
        handleSchedule(){
          var endtime = parseTime(this.endTime,'{y}-{m}-{d}')
          this.end_time = endtime
          this.getlist()
        },
        toPrint(){
            this.$router.push({
                path: '/dialysis/allsummarydialog_print?startime='+this.start_time+"&endtime="+this.end_time + "&type=3",
                // query: { date: date }
            })
        },
        getlist(){
            const params = {
              start_time:this.start_time,
              end_time:this.end_time
            }
           console.log("params",params)
          getGatherList(params).then(response=>{
            if(response.data.state == 1){
              var arr = []
              var warehouselist = response.data.data.warehouselist
              for(let i=0;i<warehouselist.length;i++){
                 warehouselist[i].stage = 1
              }
             console.log("warehouselist",warehouselist)
              arr.push(...warehouselist)
              var consumables =  response.data.data.consumables

              var count = response.data.data.count
              for(let j=0;j<count.length;j++){
                 count[j].stage = 2
              }
             arr.push(...count)
             console.log("arr=====",arr)
             this.tableData = arr
            }
          })
        }
    }
}
</script>
