<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="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入电话" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="医生名称" prop="doctorName">
        <el-input v-model="queryParams.doctorName" placeholder="请输入医生名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入用户姓名" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="销售名称" prop="qwUserName">
        <el-input v-model="queryParams.qwUserName" placeholder="请输入销售名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="医生证号" prop="doctorCertificate">
        <el-input v-model="queryParams.doctorCertificate" placeholder="请输入医生证号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="医生填写" prop="doctorStatus">
        <el-select clearable v-model="queryParams.doctorStatus">
          <el-option label="未填写" value="0"></el-option>
          <el-option label="已填写" value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="用户答复" prop="userStatus">
        <el-select clearable v-model="queryParams.userStatus">
          <el-option label="未答复" value="0"></el-option>
          <el-option label="已答复" value="1"></el-option>
        </el-select>
      </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-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['his:fsFirstDiagnosis:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['his:fsFirstDiagnosis:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['his:fsFirstDiagnosis:remove']"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" :loading="exportLoading"
          @click="handleExport" v-hasPermi="['his:fsFirstDiagnosis:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border v-loading="loading" :data="fsFirstDiagnosisList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="医生证号" align="center" prop="id" /> -->
      <el-table-column label="患者姓名" align="center" prop="patientName" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="性别" align="center" prop="gender">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.gender == 0">未知</el-tag>
          <el-tag v-if="scope.row.gender == 1">男</el-tag>
          <el-tag v-if="scope.row.gender == 2">女</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="身体状况" align="center" prop="physicalCondition" :show-overflow-tooltip="true" />
      <el-table-column label="日期" align="center" prop="dateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.dateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="初步诊断" align="center" prop="firstDiagnosis" :show-overflow-tooltip="true" />
      <el-table-column label="医生名称" align="center" prop="doctorName" />
      <el-table-column label="医生职称" align="center" prop="doctorDep" />
      <el-table-column label="医生证号" align="center" prop="doctorCertificate" />
      <el-table-column label="用户姓名" align="center" prop="userName" />
      <el-table-column label="销售名称" align="center" prop="qwUserName" />
      <el-table-column label="用户答复" align="center" prop="userStatus" width="120px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.userStatus == 0">未答复</el-tag>
          <el-tag type="success" v-if="scope.row.userStatus == 1">已答复</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="医生填写" align="center" prop="doctorStatus" width="120px">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.doctorStatus == 0">未填写</el-tag>
          <el-tag type="success" v-if="scope.row.doctorStatus == 1">已填写</el-tag>
        </template>
      </el-table-column>
      <!-- <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="handleUpdate(scope.row)"
            v-hasPermi="['his:fsFirstDiagnosis:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['his:fsFirstDiagnosis:remove']"
          >删除</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="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="患者姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入患者姓名" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="0-未知 1-男性 2-女性" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入0-未知 1-男性 2-女性" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="身体状况" prop="physicalCondition">
          <el-input v-model="form.physicalCondition" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="日期" prop="dateTime">
          <el-date-picker clearable size="small" v-model="form.dateTime" type="date" value-format="yyyy-MM-dd"
            placeholder="选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="出版诊断" prop="firstDiagnosis">
          <el-input v-model="form.firstDiagnosis" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="医生id" prop="doctoId">
          <el-input v-model="form.doctoId" placeholder="请输入医生id" />
        </el-form-item>
        <el-form-item label="医生名称" prop="doctorName">
          <el-input v-model="form.doctorName" placeholder="请输入医生名称" />
        </el-form-item>
        <el-form-item label="职称" prop="doctorDep">
          <el-input v-model="form.doctorDep" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="用户id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="医生证号" prop="doctorCertificate">
          <el-input v-model="form.doctorCertificate" placeholder="请输入医生证号" />
        </el-form-item>
      </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>
  </div>
</template>

<script>
import { listFsFirstDiagnosis, getFsFirstDiagnosis, delFsFirstDiagnosis, addFsFirstDiagnosis, updateFsFirstDiagnosis, exportFsFirstDiagnosis } from "@/api/his/fsFirstDiagnosis";

export default {
  name: "FsFirstDiagnosis",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 初诊单表格数据
      fsFirstDiagnosisList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientName: null,
        age: null,
        gender: null,
        phone: null,
        physicalCondition: null,
        dateTime: null,
        firstDiagnosis: null,
        doctoId: null,
        doctorName: null,
        doctorDep: null,
        userId: null,
        doctorCertificate: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询初诊单列表 */
    getList() {
      this.loading = true;
      listFsFirstDiagnosis(this.queryParams).then(response => {
        this.fsFirstDiagnosisList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        patientName: null,
        age: null,
        gender: null,
        phone: null,
        physicalCondition: null,
        dateTime: null,
        firstDiagnosis: null,
        doctoId: null,
        doctorName: null,
        doctorDep: null,
        createTime: null,
        updateTime: null,
        userId: null,
        doctorCertificate: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加初诊单";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getFsFirstDiagnosis(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改初诊单";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateFsFirstDiagnosis(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addFsFirstDiagnosis(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除初诊单编号为"' + ids + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function () {
        return delFsFirstDiagnosis(ids);
      }).then(() => {
        this.getList();
        this.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有初诊单数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        this.exportLoading = true;
        return exportFsFirstDiagnosis(queryParams);
      }).then(response => {
        this.download(response.msg);
        this.exportLoading = false;
      }).catch(() => { });
    }
  }
};
</script>
