<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent>
      <el-form-item label="患者ID" prop="patientId">
        <el-input v-model="queryParams.patId" placeholder="请输入患者ID"  @keyup.enter.native="handleQuery" clearable class="inp"/>
      </el-form-item>
      <el-form-item label="近亲姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入近亲姓名"  @keyup.enter.native="handleQuery" clearable class="inp"/>
      </el-form-item>
      <el-form-item label="近亲关系" prop="kinship">
        <el-select v-model="queryParams.kinship" placeholder="请选择近亲关系" clearable class="se">
          <el-option v-for="dict in dict.type.nk_kinship" :key="dict.value" :label="dict.label" :value="dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="近亲地址" prop="address">
        <el-input v-model="queryParams.address" placeholder="请输入近亲地址"  @keyup.enter.native="handleQuery" clearable class="inp"/>
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系电话"  @keyup.enter.native="handleQuery" clearable class="inp"/>
      </el-form-item>
      <el-form-item label="工作名称" prop="workName">
        <el-input v-model="queryParams.workName" placeholder="请输入工作名称"  @keyup.enter.native="handleQuery" clearable class="inp"/>
      </el-form-item>
      <el-form-item label="工作类别" prop="workCode">
        <el-input v-model="queryParams.workCode" placeholder="请输入工作类别"  @keyup.enter.native="handleQuery" clearable class="inp"/>
      </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-row :gutter="10" class="mb8">
        <el-button type="primary" icon="el-icon-plus" :disabled="ids.length > 0" @click="op('add')" v-hasPermi="['work:nk:add']">新增</el-button>
        <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit',ids)" v-hasPermi="['work:nk:edit']">修改</el-button>
        <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:nk: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="patId" />
      <el-table-column label="近亲姓名" align="center" prop="name" />
      <el-table-column label="近亲关系" align="center" prop="kinship">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.nk_kinship" :value="scope.row.kinship"/>
        </template>
      </el-table-column>
      <el-table-column label="近亲地址" align="center" prop="address" />
      <el-table-column label="联系电话" align="center" prop="phone" />
      <el-table-column label="工作名称" align="center" prop="workName" />
      <el-table-column label="工作类别" align="center" prop="workCode" />
      <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:nk:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:nk: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: "Nk",
  dicts: ['nk_kinship'],
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id:null,
        patId: null,
        name: null,
        kinship: null,
        address: null,
        phone: null,
        workName: null,
        workCode: null,
        orderByColumn:'id', //排序字段
        isAsc: 'desc' //排序方式
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/nk/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/nk/remove/' + (row.id || this.ids) }).then(response => {
                this.$modal.msgSuccess('删除成功');
                this.getList();
            });
        });
    }
  }
};
</script>
