<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent>
      <el-row>
        <el-col span="8">
          <el-form-item label="患者ID" prop="patientId">
            <el-input v-model="queryParams.patientId" placeholder="请输入患者ID"  @keyup.enter.native="handleQuery" clearable class="inp"/>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="危重级别" prop="level">
            <el-select v-model="queryParams.level" placeholder="请选择危重级别" clearable class="se">
              <el-option v-for="dict in dict.type.pv2_level" :key="dict.value" :label="dict.label" :value="dict.value"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="入区时间" prop="entryTime">
          <el-date-picker clearable v-model="queryParams.entryTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择入区时间"></el-date-picker>
        </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col span="8">
          <el-form-item label="出区时间" prop="exitTime">
            <el-date-picker clearable v-model="queryParams.exitTime" type="date" value-format="yyyy-MM-dd" placeholder="请选择出区时间"></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="出区原因" prop="reasonArea">
            <el-select v-model="queryParams.reasonArea" placeholder="请选择出区原因" clearable class="se">
              <el-option v-for="dict in dict.type.reason_area" :key="dict.value" :label="dict.label" :value="dict.value"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="婴儿信息标识" prop="babyCode">
            <el-select v-model="queryParams.babyCode" placeholder="请选择婴儿信息标识" clearable class="se">
              <el-option v-for="dict in dict.type.baby_code" :key="dict.value" :label="dict.label" :value="dict.value"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>



      <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-row :gutter="10" class="mb8">
        <el-button type="primary" icon="el-icon-plus" :disabled="ids.length > 0" @click="op('add')" v-hasPermi="['work:pv2:add']">新增</el-button>
        <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit',ids)" v-hasPermi="['work:pv2:edit']">修改</el-button>
        <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:pv2:remove']">删除{{ids.length>0?'('+ids.length+')':''}}</el-button>
    </el-row>

    <el-table :data="response.rows" border @selection-change="selects" height="calc(100vh - 270px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="患者ID" align="center" prop="patientId" />
      <el-table-column label="危重级别" align="center" prop="level">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pv2_level" :value="scope.row.level"/>
        </template>
      </el-table-column>
      <el-table-column label="入区时间" align="center" prop="entryTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.entryTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出区时间" align="center" prop="exitTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.exitTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="出区原因" align="center" prop="reasonArea">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.reason_area" :value="scope.row.reasonArea"/>
        </template>
      </el-table-column>
      <el-table-column label="婴儿信息标识" align="center" prop="babyCode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.baby_code" :value="scope.row.babyCode"/>
        </template>
      </el-table-column>
      <el-table-column label="患者ID" align="center" prop="msgId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit',scope.row)" v-hasPermi="['work:pv2:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:pv2:remove']">删除</el-button>
        </template>
      </el-table-column>
      <template slot="empty">
          <el-empty></el-empty>
      </template>
    </el-table>
    <pagination v-if="response.total>0" :total="response.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList"/>
  </div>
</template>

<script>
import edit from './edit'
export default {
  name: "Pv2",
  dicts: ['reason_area', 'baby_code', 'pv2_level'],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
                      patientId: null,
                      level: null,
                      entryTime: null,
                      exitTime: null,
                      reasonArea: null,
                      babyCode: null,
                      msgId: null,
                orderByColumn:'id', //排序字段
                isAsc: 'desc' //排序方式
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/pv2/list', data: this.queryParams }).then(response => {
            this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    selects(rows) {
      this.ids = rows.map(item => item.id)
    },
    op(tag, row) {
          if (tag == 'add') {
            this.iframe({ obj: edit, param: {}, title:'新增',width: '45%', height: '55%'});
          }
          if (tag == 'edit') {
              const id = row.id || this.ids[0];
              this.iframe({ obj: edit, param: {id: id}, title:'编辑',width: '50%', height: '50%'});
          }
    },
    del(row) {
        this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/pv2/remove/' + (row.id || this.ids) }).then(response => {
                this.$modal.msgSuccess('删除成功');
                this.getList();
            });
        });
    }
  }
};
</script>
