<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px" >
      <el-form-item label="患者姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="状态" clearable size="small">
             <el-option
               v-for="dict in sexOptions"
               :key="dict.dictValue"
               :label="dict.dictLabel"
               :value="dict.dictValue"
             />
           </el-select>
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" border :data="list" @selection-change="handleSelectionChange">
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="身份证号" align="center" prop="idCard" width="170px"/>
      <el-table-column label="出生年月" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="性别" align="center" prop="sex" >
        <template slot-scope="scope">
             <dict-tag :options="sexOptions" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="体重G" align="center" prop="weight" />
      <el-table-column label="手机号" align="center" prop="mobile" />
      <el-table-column label="最近一次问诊时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="150px">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleDetails(scope.row)"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleMsg(scope.row)"
          >用药提醒</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body :rules="rules">
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
    <el-drawer
      :with-header="false"
      size="75%"
      :title="show.title" :visible.sync="show.open">
      <patientDetails  ref="patientDetails"  />
    </el-drawer>
  </div>
</template>

<script>
import {getPatientList  } from "@/api/patient.js";
import patientDetails from '@/views/components/patient/patientDetails.vue';
import Editor from '@/components/Editor/wang';
export default {
  name: "patient",
  components: { patientDetails },
  data() {
    return {
      sexOptions:[],
      show:{
        title:"患者详情",
        open:false,
      },
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        
         
      }
    };
  },
  created() {
    this.getDicts("sys_patient_sex").then(response => {
      this.sexOptions = response.data;
    });
    this.getList();
  },
  methods: {
    
    handleDetails(row){
        this.show.open=true;
        setTimeout(() => {
             this.$refs.patientDetails.getDetails(row.patientId);
        }, 1);
    },
    /** 查询医生文章列表 */
    getList() {
      this.loading = true;
      getPatientList(this.queryParams).then(response => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.patientId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    }
  }
};
</script>
 

