<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="68px">
     <el-form-item label="检查类型" prop="examTypeId">
          <el-select
            v-model="queryParams.examTypeId"
            clearable
            placeholder="请选择类型"
            @change="examTypeChange"
          >
            <el-option
              v-for="item in Examtypes"
              :key="item.typeCode"
              :label="item.typeName"
              :value="parseInt(item.typeCode)"
            />
          </el-select>
        </el-form-item>

      <el-form-item label="就诊类型" prop="visitTypeId">
         <el-select
            v-model="queryParams.visitTypeId"
            clearable
            placeholder="请选择类型"
          >
           <el-option
              v-for="item in visitType"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
             </el-select>
      </el-form-item>

      <el-form-item label="预约日期" prop="reservationDate">
       <el-date-picker v-model="queryParams.reservationDate" clearable
          placeholder="选择预约时间"
          size="small"
          type="date"
          value-format="yyyy-MM-dd">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="预约时段" prop="reservationTimeSlot">
         <el-select
            v-model="queryParams.reservationTimeSlot"
            clearable
            placeholder="请选择类型"
          >
         <el-option
              v-for="item in timeList"
              :key="item"
              :label="item"
              :value="item"
            />
             </el-select>
      </el-form-item>

      <el-form-item label="申请单状态" label-width="100px" prop="applyState">
        <el-select v-model="queryParams.applyState" clearable placeholder="请选择申请单状态" size="small">
          <el-option
            v-for="dict in applyStateOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="cyan" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">

      </el-col>
      <el-col :span="1.5">

      </el-col>
      <el-col :span="1.5">

      </el-col>
      <el-col :span="1.5">

      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="applyCountList">
      <el-table-column align="center" type="selection" width="55" />
      <el-table-column align="center" label="申请单号" prop="applyNum" />
      <el-table-column align="center" label="患者" prop="patientName" />
      <el-table-column align="center" label="检查类型" prop="examName" />
      <el-table-column align="center" label="项目" prop="outExamItemName" />
      <el-table-column align="center" label="就诊类型" prop="visitName" />
      <el-table-column :formatter="reservationDateFormat" align="center" label="预约时间段" prop="reservationTimeSlot" width="200"/>
      <el-table-column :formatter="applyStateFormat" align="center" label="申请单状态" prop="applyState" width="100" />
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

  </div>
</template>

<script>
import { listApplyCount, listApplyTime } from "@/api/resource/applyCount";
import { listApply, getApply,  } from "@/api/resource/apply";
import { listSourcePoolToManage, listSourcePool,listSourcePools, getSourcePool, delSourcePool, addSourceNum, lessSourceNum, exportSourcePool } from "@/api/resource/sourcePool";
import { listExamtype} from "@/api/basis/examtype";

export default {
  name: "ApplyCount",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预约统计表格数据
      applyCountList: [],
      // 申请单状态字典
      applyStateOptions: [],
      timeList:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
       Examtypes:[],
      visitType: [
        {"id":"1",name:"门诊"},
         {"id":"2",name:"住院"},
          {"id":"3",name:"体检"},
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientName: null,
        examTypeId: null,
        outExamItemName: null,
        visitTypeId: null,
        applyStateOptions:[],
        reservationDate: null,
        reservationTimeSlot: null,
        applyState: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
      this.getDicts("apply_status").then(response => {
      this.applyStateOptions = response.data;
    });
    listExamtype().then(response => {
        this.Examtypes = response.rows
      });
    //初始化日期时间
    var myDate = new Date();
    var year=myDate.getFullYear();
    var month=myDate.getMonth()+1
    var date=myDate.getDate();
    if(month < 10){
        month = "0"+month
    }
    if(date < 10){
        date = "0"+date
    }
    this.queryParams.reservationDate = year+"-"+month+"-"+date;
    this.getList();

  },
  methods: {
    /** 查询预约统计列表 */
    getList() {
      this.loading = true;
      listApplyCount(this.queryParams).then(response => {
        this.applyCountList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
     // 申请单状态字典翻译
    applyStateFormat(row, column) {
      return this.selectDictLabel(this.applyStateOptions, row.applyState);
    },
    reservationDateFormat(row,column){
      var reservationResult = "";
      if(row.reservationDate != null){
        if(row.reservationTimeSlot != null){
          reservationResult = row.reservationDate + ' ' + row.reservationTimeSlot;
        }else{
          reservationResult = row.reservationDate
        }
      }

      return reservationResult;
    },
    examTypeChange(val){
      listApplyTime({examTypeId:val}).then(response => {
              this.timeList = response.data;
            });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        patientName: null,
        examTypeId: null,
        outExamItemName: null,
        visitTypeId: null,
        reservationDate: null,
        reservationTimeSlot: null,
        applyState: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
          //初始化日期时间
    var myDate = new Date();
    var year=myDate.getFullYear();
    var month=myDate.getMonth()+1
    var date=myDate.getDate();
    if(month < 10){
        month = "0"+month
    }
    if(date < 10){
        date = "0"+date
    }
    this.queryParams.reservationDate = year+"-"+month+"-"+date;
     this.timeList = []
      this.handleQuery();

    },

  }
};
</script>
