<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent label-position="right">
      <el-row type="flex" justify="space-between" :gutter="20">
        <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="cardId">
            <el-input v-model="queryParams.cardId" placeholder="请输入就诊卡号" @keyup.enter.native="handleQuery" clearable
                      class="inp"/>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="患者类别" prop="patientCategory">
            <el-select v-model="queryParams.patientCategory" placeholder="请选择患者类别" clearable class="se">
              <el-option v-for="dict in dict.type.patient_category" :key="dict.value" :label="dict.label"
                         :value="dict.value"/>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col span="8">
          <el-form-item label="患者位置" prop="bed">
            <el-input v-model="queryParams.bed" placeholder="请输入患者位置" @keyup.enter.native="handleQuery" clearable
                      class="inp"/>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="主治医师" prop="physician">
            <el-input v-model="queryParams.physician" placeholder="请输入主治医师" @keyup.enter.native="handleQuery"
                      clearable class="inp"/>
          </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="主管护士代码" prop="nurseCode">
            <el-input v-model="queryParams.nurseCode" placeholder="请输入主管护士代码" @keyup.enter.native="handleQuery"
                      clearable class="inp"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col span="8">
          <el-form-item label="入院次数" prop="hospitalizedNumber">
          <el-input v-model="queryParams.hospitalizedNumber" placeholder="请输入入院次数"
                    @keyup.enter.native="handleQuery" clearable class="inp"/>
        </el-form-item>
        </el-col>
        <el-col span="8">
          <el-form-item label="出院方式" prop="dischargeMethod">
            <el-select v-model="queryParams.dischargeMethod" placeholder="请选择出院方式" clearable class="se">
              <el-option v-for="dict in dict.type.discharge_method" :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="medicalCode">
            <el-input v-model="queryParams.medicalCode" placeholder="请输入医疗机构代码" @keyup.enter.native="handleQuery"
                      clearable class="inp"/>
          </el-form-item>
        </el-col>
      </el-row>


      <el-row :gutter="20">
        <el-col span="8">
          <el-form-item label=" 在院状态" prop="hospitalStatus">
            <el-select v-model="queryParams.hospitalStatus" placeholder="请选择 在院状态" clearable class="se">
              <el-option v-for="dict in dict.type.hospital_status" :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="registrationStatus">
            <el-select v-model="queryParams.registrationStatus" placeholder="请选择门诊挂号状态" clearable class="se">
              <el-option v-for="dict in dict.type.registration_status" :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="admissionTime">
            <el-input v-model="queryParams.admissionTime" placeholder="请输入入院时间" @keyup.enter.native="handleQuery"
                      clearable class="inp"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col span="8">
          <el-form-item label="出院时间" prop="dischargeTime">
            <el-input v-model="queryParams.dischargeTime" placeholder="请输入出院时间" @keyup.enter.native="handleQuery"
                      clearable class="inp"/>
          </el-form-item>
        </el-col>


        <el-col span="8">
          <el-form-item label="患者（信息）ID" prop="msgId">
            <el-input v-model="queryParams.msgId" placeholder="请输入患者（信息）ID" @keyup.enter.native="handleQuery" clearable
                      class="inp"/>
          </el-form-item>
        </el-col>


        <el-col span="8">
          <el-form-item label="科室" prop="department">
            <el-input v-model="queryParams.department" placeholder="请输入科室" @keyup.enter.native="handleQuery" clearable
                      class="inp"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col span="24" >
          <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-col>
      </el-row>

    </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:pv1:add']">新增
      </el-button>
      <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit',ids)"
                 v-hasPermi="['work:pv1:edit']">修改
      </el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del"
                 v-hasPermi="['work:pv1: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="cardId"/>
      <el-table-column label="患者类别" align="center" prop="patientCategory">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.patient_category" :value="scope.row.patientCategory"/>
        </template>
      </el-table-column>
      <el-table-column label="患者位置" align="center" prop="bed"/>
      <el-table-column label="主治医师" align="center" prop="physician"/>
      <el-table-column label="主管护士代码" align="center" prop="nurseCode"/>
      <el-table-column label="入院次数" align="center" prop="hospitalizedNumber"/>
      <el-table-column label="收费类别" align="center" prop="feeCategory"/>
      <el-table-column label="出院方式" align="center" prop="dischargeMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.discharge_method" :value="scope.row.dischargeMethod"/>
        </template>
      </el-table-column>
      <el-table-column label="医疗机构代码" align="center" prop="medicalCode"/>
      <el-table-column label=" 在院状态" align="center" prop="hospitalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.hospital_status" :value="scope.row.hospitalStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="门诊挂号状态" align="center" prop="registrationStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.registration_status" :value="scope.row.registrationStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="入院时间" align="center" prop="admissionTime"/>
      <el-table-column label="出院时间" align="center" prop="dischargeTime"/>
      <el-table-column label="患者ID" align="center" prop="msgId"/>
      <el-table-column label="科室" align="center" prop="department"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit',scope.row)"
                     v-hasPermi="['work:pv1:edit']">修改
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)"
                     v-hasPermi="['work:pv1: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: "Pv1",
  dicts: ['hospital_status', 'discharge_method', 'patient_category', 'registration_status'],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientId: null,
        cardId: null,
        patientCategory: null,
        bed: null,
        physician: null,
        nurseCode: null,
        hospitalizedNumber: null,
        feeCategory: null,
        dischargeMethod: null,
        medicalCode: null,
        hospitalStatus: null,
        registrationStatus: null,
        admissionTime: null,
        dischargeTime: null,
        msgId: null,
        department: null,
        orderByColumn: 'id', //排序字段
        isAsc: 'desc' //排序方式
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({url: '/work/pv1/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/pv1/remove/' + (row.id || this.ids)}).then(response => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    }
  }
};
</script>
