<template>
  <div class="cmain">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent>
      <el-form-item label="患者姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入患者姓名" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list" border @selection-change="selects">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="状态" align="center" prop="hospitalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hospital_status" :value="scope.row.hospitalStatus"></dict-tag>
        </template>
      </el-table-column>
      <el-table-column label="入院时间" align="center" prop="admissionTime" />
      <el-table-column label="出院时间" align="center" prop="dischargeTime" />
      <template slot="empty">
        <el-empty></el-empty>
      </template>
    </el-table>
    <div class="mfooter">
      <el-button type="primary" @click="ok()" :disabled="rows.length == 0">选中 {{ rows.length > 0 ? rows.length + '人' : '' }}</el-button>
      <el-button @click="$layer.close(layerid)">取 消</el-button>
    </div>
  </div>
</template>

<script>
export default {
  dicts: ['hospital_status'],
  data() {
    return {
      rows: [],
      list: [],
      queryParams: {
        name: null
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/record/visit/list', data: this.queryParams }).then((response) => {
        this.list = response.data;
      });
    },
    handleQuery() {
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    selects(rows) {
      this.rows = rows;
    },
    ok() {
      this.$parent.form.patientList = this.rows;
      this.$layer.close(this.layerid);
    }
  }
};
</script>
