<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <!-- <el-form-item label="患者id" prop="patientId">
        <el-input
          v-model="queryParams.patientId"
          placeholder="请输入患者id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="患者姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入患者姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="患者身份证号" prop="cardNo">
        <el-input
          v-model="queryParams.cardNo"
          placeholder="请输入患者身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="批次表id" prop="batchId">
        <el-input
          v-model="queryParams.batchId"
          placeholder="请输入批次表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="批次名称" prop="batchName">
        <el-input
          v-model="queryParams.batchName"
          placeholder="请输入批次名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分组id" prop="groupId">
        <el-input
          v-model="queryParams.groupId"
          placeholder="请输入分组id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分组名称" prop="groupName">
        <el-input
          v-model="queryParams.groupName"
          placeholder="请输入分组名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目id" prop="projectId">
        <el-input
          v-model="queryParams.projectId"
          placeholder="请输入项目id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目名称" prop="projectName">
        <el-input
          v-model="queryParams.projectName"
          placeholder="请输入项目名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测设备id" prop="deviceId">
        <el-input
          v-model="queryParams.deviceId"
          placeholder="请输入检测设备id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测设备名称" prop="deviceName">
        <el-input
          v-model="queryParams.deviceName"
          placeholder="请输入检测设备名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目别名" prop="projectAlias">
        <el-input
          v-model="queryParams.projectAlias"
          placeholder="请输入项目别名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="判断模式，定量：QUANTIFY，定性：QUALITATIVE" prop="judgeMode">
        <el-input
          v-model="queryParams.judgeMode"
          placeholder="请输入判断模式，定量：QUANTIFY，定性：QUALITATIVE"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="检测结果，数字或文字描述" prop="measureResult">
        <el-input
          v-model="queryParams.measureResult"
          placeholder="请输入检测结果，数字或文字描述"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目指标最大值" prop="maxValue">
        <el-input
          v-model="queryParams.maxValue"
          placeholder="请输入项目指标最大值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目指标最小值" prop="minValue">
        <el-input
          v-model="queryParams.minValue"
          placeholder="请输入项目指标最小值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项目指标默认值" prop="defaultValue">
        <el-input
          v-model="queryParams.defaultValue"
          placeholder="请输入项目指标默认值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="LIS对照" prop="lisCompare">
        <el-input
          v-model="queryParams.lisCompare"
          placeholder="请输入LIS对照"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="检测时间" prop="measureTime">
        <el-date-picker clearable
          v-model="queryParams.measureTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择检测时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="检测人姓名" prop="measureName">
        <el-input
          v-model="queryParams.measureName"
          placeholder="请输入检测人姓名，自动上传时为空，手动上传为上传人姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注信息" prop="recordRemark">
        <el-input
          v-model="queryParams.recordRemark"
          placeholder="请输入备注信息"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="合格标识，合格：QUALIFIED，不合格：NOT_QUALIFIED" prop="qualifiedSign">
        <el-input
          v-model="queryParams.qualifiedSign"
          placeholder="请输入合格标识，合格：QUALIFIED，不合格：NOT_QUALIFIED"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="检测结果附件路径" prop="measureResultPath">
        <el-input
          v-model="queryParams.measureResultPath"
          placeholder="请输入检测结果附件路径"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="计量单位" prop="unit">
        <el-input
          v-model="queryParams.unit"
          placeholder="请输入计量单位"
          clearable
          @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-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="['manage:projectresult: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="['manage:projectresult: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="['manage:projectresult:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['manage:projectresult:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectresultList" @selection-change="handleSelectionChange">
      <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="patientName" />
      <el-table-column label="患者身份证号" align="center" prop="cardNo" />
      <!-- <el-table-column label="批次表id" align="center" prop="batchId" /> -->
      <el-table-column label="批次名称" align="center" prop="batchName" />
      <!-- <el-table-column label="分组id" align="center" prop="groupId" /> -->
      <el-table-column label="分组名称" align="center" prop="groupName" />
      <!-- <el-table-column label="项目id" align="center" prop="projectId" /> -->
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <!-- <el-table-column label="检测设备id" align="center" prop="deviceId" /> -->
      <el-table-column label="检测设备名称" align="center" prop="deviceName" />
      <el-table-column label="项目别名" align="center" prop="projectAlias" />
      <el-table-column label="判断模式" align="center" prop="judgeMode" >
        <template slot-scope="scope">
          {{ scope.row.judgeMode == "QUANTIFY" ? "定量" : "" }}
          {{ scope.row.judgeMode == "QUALITATIVE" ? "定性" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="检测结果" align="center" prop="measureResult" />
      <el-table-column label="项目指标最大值" align="center" prop="maxValue" />
      <el-table-column label="项目指标最小值" align="center" prop="minValue" />
      <el-table-column label="项目指标默认值" align="center" prop="defaultValue" />
      <el-table-column label="LIS对照" align="center" prop="lisCompare" />
      <el-table-column label="检测时间" align="center" prop="measureTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.measureTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检测人姓名" align="center" prop="measureName" />
      <el-table-column label="备注信息" align="center" prop="recordRemark" />
      <el-table-column label="合格标识" align="center" prop="qualifiedSign" >
        <template slot-scope="scope">
          {{ scope.row.judgeMode == "QUALIFIED" ? "合格" : "" }}
          {{ scope.row.judgeMode == "NOT_QUALIFIED" ? "不合格" : "" }}
        </template>
      </el-table-column>
      <el-table-column label="检测结果附件路径" align="center" prop="measureResultPath" />
      <el-table-column label="计量单位" align="center" prop="unit" />
      <!-- <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['manage:projectresult:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['manage:projectresult: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="1200px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px" :inline="true">
        <el-form-item label="患者id" prop="patientId">
          <el-input v-model="form.patientId" placeholder="请输入患者id" />
        </el-form-item>
        <el-form-item label="患者姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入患者姓名" />
        </el-form-item>
        <el-form-item label="患者身份证号" prop="cardNo">
          <el-input v-model="form.cardNo" placeholder="请输入患者身份证号" />
        </el-form-item>
        <el-form-item label="批次表id" prop="batchId">
          <el-input v-model="form.batchId" placeholder="请输入批次表id" />
        </el-form-item>
        <el-form-item label="批次名称" prop="batchName">
          <el-input v-model="form.batchName" placeholder="请输入批次名称" />
        </el-form-item>
        <el-form-item label="分组id" prop="groupId">
          <el-input v-model="form.groupId" placeholder="请输入分组id" />
        </el-form-item>
        <el-form-item label="分组名称" prop="groupName">
          <el-input v-model="form.groupName" placeholder="请输入分组名称" />
        </el-form-item>
        <el-form-item label="项目id" prop="projectId">
          <el-input v-model="form.projectId" placeholder="请输入项目id" />
        </el-form-item>
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="form.projectName" placeholder="请输入项目名称" />
        </el-form-item>
        <el-form-item label="检测设备id" prop="deviceId">
          <el-input v-model="form.deviceId" placeholder="请输入检测设备id" />
        </el-form-item>
        <el-form-item label="检测设备名称" prop="deviceName">
          <el-input v-model="form.deviceName" placeholder="请输入检测设备名称" />
        </el-form-item>
        <el-form-item label="项目别名" prop="projectAlias">
          <el-input v-model="form.projectAlias" placeholder="请输入项目别名" />
        </el-form-item>
        <el-form-item label="判断模式" prop="judgeMode">
          <el-select
            v-model="form.parentId"
            placeholder="请选择"
            style="width: 208px"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <!-- <el-input v-model="form.judgeMode" placeholder="请输入判断模式，定量：QUANTIFY，定性：QUALITATIVE" /> -->
        </el-form-item>
        <el-form-item label="检测结果" prop="measureResult">
          <el-input v-model="form.measureResult" placeholder="请输入检测结果，数字或文字描述" />
        </el-form-item>
        <el-form-item label="项目指标最大值" prop="maxValue">
          <el-input v-model="form.maxValue"    :change="checkPricemax()" placeholder="请输入项目指标最大值" />
        </el-form-item>
        <el-form-item label="项目指标最小值" prop="minValue">
          <el-input v-model="form.minValue"    :change="checkPrice()" placeholder="请输入项目指标最小值" />
        </el-form-item>
        <el-form-item label="项目指标默认值" prop="defaultValue">
          <el-input v-model="form.defaultValue" placeholder="请输入项目指标默认值" />
        </el-form-item>
        <el-form-item label="LIS对照" prop="lisCompare">
          <el-input v-model="form.lisCompare" placeholder="请输入LIS对照" />
        </el-form-item>
        <el-form-item label="检测时间" prop="measureTime">
          <el-date-picker clearable
            v-model="form.measureTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择检测时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="检测人姓名，自动上传时为空，手动上传为上传人姓名" prop="measureName">
          <el-input v-model="form.measureName" placeholder="请输入检测人姓名，自动上传时为空，手动上传为上传人姓名" />
        </el-form-item>
        <el-form-item label="备注信息" prop="recordRemark">
          <el-input v-model="form.recordRemark" placeholder="请输入备注信息" />
        </el-form-item>
        <el-form-item label="合格标识" prop="qualifiedSign">
          <el-select
            v-model="form.qualifiedSign"
            placeholder="请选择"
            style="width: 208px"
          >
            <el-option
              v-for="item in option"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
          <!-- <el-input v-model="form.qualifiedSign" placeholder="请输入合格标识，合格：QUALIFIED，不合格：NOT_QUALIFIED" /> -->
        </el-form-item>
        <el-form-item label="检测结果附件路径" prop="measureResultPath">
          <el-input v-model="form.measureResultPath" placeholder="请输入检测结果附件路径" />
        </el-form-item>
        <el-form-item label="计量单位" prop="unit">
          <el-input v-model="form.unit" 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 {
  listProjectresult,
  getProjectresult,
  delProjectresult,
  addProjectresult,
  updateProjectresult,
} from "@/api/manage/projectresult";

export default {
  name: "Projectresult",
  data() {
    return {
      option: [
        // ，合格：，不合格：NOT_QUALIFIED
        {
          value: "QUALIFIED",
          label: "合格",
        },
        {
          value: "NOT_QUALIFIED",
          label: "不合格",
        },
      ],
      options: [
        {
          value: "QUANTIFY",
          label: "定量",
        },
        {
          value: "QUALITATIVE",
          label: "定性",
        },
      ],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检测项目结果表格数据
      projectresultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        patientId: null,
        patientName: null,
        cardNo: null,
        batchId: null,
        batchName: null,
        groupId: null,
        groupName: null,
        projectId: null,
        projectName: null,
        deviceId: null,
        deviceName: null,
        projectAlias: null,
        judgeMode: null,
        measureResult: null,
        maxValue: null,
        minValue: null,
        defaultValue: null,
        lisCompare: null,
        measureTime: null,
        measureName: null,
        recordRemark: null,
        qualifiedSign: null,
        measureResultPath: null,
        unit: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        patientId: [
          { required: true, message: "患者id不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**只能输入数字且有小数点最多保留两位*/
    checkPrice() {
      let checkPlan = "" + this.form.minValue;
      checkPlan = checkPlan
        .replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
        .replace(/\.{2,}/g, ".") // 只保留第一个. 清除多余的
        .replace(/^\./g, "") // 保证第一个为数字而不是.
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      if (checkPlan.indexOf(".") < 0 && checkPlan !== "") {
        // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        checkPlan = parseFloat(checkPlan) + "";
      } else if (checkPlan.indexOf(".") >= 0) {
        checkPlan = checkPlan.replace(/^()*(\d+)\.(\d\d).*$/, "$1$2.$3"); // 只能输入两个小数
      }
      this.form.minValue = checkPlan;
    },
    checkPricemax() {
      let checkPlan = "" + this.form.maxValue;
      checkPlan = checkPlan
        .replace(/[^\d.]/g, "") // 清除“数字”和“.”以外的字符
        .replace(/\.{2,}/g, ".") // 只保留第一个. 清除多余的
        .replace(/^\./g, "") // 保证第一个为数字而不是.
        .replace(".", "$#$")
        .replace(/\./g, "")
        .replace("$#$", ".");
      if (checkPlan.indexOf(".") < 0 && checkPlan !== "") {
        // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
        checkPlan = parseFloat(checkPlan) + "";
      } else if (checkPlan.indexOf(".") >= 0) {
        checkPlan = checkPlan.replace(/^()*(\d+)\.(\d\d).*$/, "$1$2.$3"); // 只能输入两个小数
      }
      this.form.maxValue = checkPlan;
    },
    /** 查询检测项目结果列表 */
    getList() {
      this.loading = true;
      listProjectresult(this.queryParams).then((response) => {
        this.projectresultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        patientId: null,
        patientName: null,
        cardNo: null,
        batchId: null,
        batchName: null,
        groupId: null,
        groupName: null,
        projectId: null,
        projectName: null,
        deviceId: null,
        deviceName: null,
        projectAlias: null,
        judgeMode: null,
        measureResult: null,
        maxValue: null,
        minValue: null,
        defaultValue: null,
        lisCompare: null,
        measureTime: null,
        measureName: null,
        recordRemark: null,
        qualifiedSign: null,
        measureResultPath: null,
        unit: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: 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;
      getProjectresult(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) {
            updateProjectresult(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProjectresult(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除检测项目结果编号为"' + ids + '"的数据项？')
        .then(function () {
          return delProjectresult(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "manage/projectresult/export",
        {
          ...this.queryParams,
        },
        `projectresult_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
