<template>
  <div class="box">
    <div style="width: 150%">
      <el-card>
        <el-row style="margin-top: 20px; margin-left: 15px">
          <el-col :span="4">
            <el-autocomplete
              class="inline-input"
              v-model="pages.Filter"
              :fetch-suggestions="querySearch"
              placeholder="请输入内容"
              @select="handleSelect"
            >
              <template slot-scope="{ item }">
                <div
                  class="name"
                  @click="selsearch(item.id, item.medicalConclusionTypeId)"
                >
                  {{ item.displayName }}
                </div>
              </template></el-autocomplete
            >
          </el-col>
          <el-col :span="7" style="margin-left: 5%">
            <el-col :span="6" style="margin-top: 10px; margin-left: 10px"
              >类别选择</el-col
            >
            <el-select
              filterable
              v-model="Selectvalue"
              placeholder="请选择"
              @change="isselctvalue"
            >
              <el-option
                v-for="item in Selectacategory"
                :key="item.id"
                :label="item.displayName"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-col>
        </el-row>
        <div style="display: flex">
          <div style="width: 15%; margin-top: 20px">
            <el-tree
              :data="itemTypeId"
              :props="treeprops"
              @node-click="treeclick"
            ></el-tree>
          </div>
          <div style="width: 85%">
            <el-table
              :data="tableData"
              style="width: 95%; height: 500px"
              row-key="id"
              class="el-table__body-wrapper tbody"
              highlight-current-row
              @row-click="rowick"
              ref="tableData"
            >
              <el-table-column prop="id" label="编号" width="300">
              </el-table-column>
              <el-table-column prop="displayName" label="名称" width="">
              </el-table-column>
              <el-table-column prop="creatorName" label="创建者" width="">
              </el-table-column>
              <el-table-column prop="creationTime" label="创建时间" width="200">
                <template slot-scope="scope">
                  {{ scope.row.creationTime | dateFormat }}
                </template>
              </el-table-column>
              <el-table-column prop="lastModifierName" label="修改者" width="">
              </el-table-column>
              <el-table-column
                prop="lastModificationTime"
                label="修改时间"
                width="200"
              >
                <template slot-scope="scope">
                  {{ scope.row.lastModificationTime | dateFormat }}
                </template>
              </el-table-column>
              <el-table-column
                label="结果类别"
                prop="resultTemplateTypeFlag"
              ></el-table-column>
              <el-table-column label="操作">
                <template>
                  <el-tag
                    class="move"
                    style="cursor: move; margin-left: 15px"
                    draggable="true"
                  >
                    <i
                      class="el-icon-d-caret"
                      style="width: 1rem; height: 1rem"
                    ></i>
                  </el-tag>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </el-card>
    </div>
    <el-dialog
      :title="title == 1 ? '新增' : '编辑'"
      :visible.sync="dialogVisible"
      width="70%"
    >
      <el-form ref="form" :model="form" label-width="110px" :rules="rules">
        <el-row>
          <el-col :span="8">
            <el-form-item label="名称" prop="displayName">
              <el-input v-model="form.displayName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="英文缩写" prop="englishShortName">
              <el-input v-model="form.englishShortName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="项目类别" prop="itemTypeId">
              <!-- <el-cascader
                v-model="form.itemTypeId"
                :options="itemTypeId"
                :props="props"
                :show-all-levels="false"
              >
              </el-cascader> -->
              <el-select
                v-model="form.itemTypeId"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in itemTypeId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="价格" prop="price">
              <el-input v-model="form.price"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="价表项目编码" prop="priceItemId">
              <el-select
                v-model="form.priceItemId"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in priceItemId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="单位" prop="">
              <el-select
                v-model="form.unitId"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in unitId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="默认结果" prop="defaultResult">
              <!-- <el-input v-model="form.defaultResult"></el-input> -->
              <el-select
                v-model="form.defaultResult"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in defaultResult"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="参考范围类型" prop="referenceRangeTypeFlag">
              <el-select
                v-model="form.referenceRangeTypeFlag"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in referenceRangeTypeFlag"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
              <!-- <el-input v-model="form.referenceRangeTypeFlag"></el-input> -->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生成小结" prop="isProduceSummary">
              <el-input v-model="form.isProduceSummary"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="名称进入小结" prop="isNameIntoSummary">
              <el-select
                v-model="form.isNameIntoSummary"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in isNameIntoSummary"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="启用诊断函数" prop="isDiagnosisFunction">
              <el-select
                @change="enablediagnostics"
                v-model="form.isDiagnosisFunction"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in isDiagnosisFunction"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="诊断函数" prop="diagnosisFunction">
              <el-input
                v-model="form.diagnosisFunction"
                :disabled="disableddiagnosisFunction"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是计算项目" prop="isCalculationItem">
              <el-select
                v-model="form.isCalculationItem"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in isCalculationItem"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="计算函数" prop="">
              <el-input v-model="form.calculationFunction"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="继续处理" prop="isContinueProcess">
              <el-select
                v-model="form.isContinueProcess"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in isContinueProcess"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结果模板" prop="resultTemplateTypeFlag">
              <!-- <el-input v-model="form.resultTemplateTypeFlag">resulttemp</el-input> -->
              <el-select
                v-model="form.resultTemplateTypeFlag"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in resulttemp"
                  :key="item.id"
                  :label="item.result"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="输入结果校验" prop="">
              <el-input v-model="form.inputCheck"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="启用" prop="isActive">
              <el-select
                v-model="form.isActive"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option
                  v-for="item in isActive"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <!--  -->
        <el-divider></el-divider>
        <el-row>
          <el-col :span="5">
            <el-form-item label="创建者">
              <el-input v-model="form.creatorName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="创建时间" style="margin-left: -5%">
              <el-input
                :value="form.creationTime | dateFormat"
                disabled
                style="width: 90%"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="修改者" style="margin-left: -25%">
              <el-input v-model="form.creatorName" disabled></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="修改时间" style="margin-left: -5%">
              <el-input
                :value="form.lastModificationTime | dateFormat"
                disabled
                style="width: 90%"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="Onsubmit">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 按钮区域 -->
    <div style="margin-left: 10px; margin-top: 7%">
      <el-button type="primary" @click="add">新增</el-button>
      <el-button
        type="primary"
        @click="editpopup"
        style="margin-left: 0; margin-top: 10px"
        >编辑</el-button
      >
      <div style="margin-top: 10px">
        <el-button type="danger" @click="delsrts">删除</el-button>
      </div>
      <div style="margin-top: 10px">
        <el-button type="primary" @click="topping">置顶</el-button>
      </div>
      <div style="margin-top: 10px">
        <el-button type="primary" @click="toppings">置底</el-button>
      </div>
      <div style="margin-top: 10px">
        <el-button type="primary" :disabled="isshow" @click="assertion"
          >排序</el-button
        >
      </div>
      <div style="margin-top: 5px">
        <el-button type="primary" :disabled="isshow" @click="cancellation"
          >取消</el-button
        >
      </div>
      <div style="margin-top: 5px">
        <el-button
          type="primary"
          size="mini"
          @click="resulttemplate"
          style="width: 70px; height: 50px"
          >结果模板</el-button
        >
      </div>
      <div style="margin-top: 5px">
        <el-button
          type="primary"
          size="mini"
          @click="referencerange"
          style="width: 70px; height: 50px"
          >参考范围</el-button
        >
      </div>
    </div>
    <!-- 结果模板弹框 -->
    <el-dialog title="结果模板" :visible.sync="rurestdialogVisible" width="80%">
      <div style="display: flex">
        <div style="width: 95%">
          <el-table
            border=""
            :data="reusttableData"
            @row-click="reustclick"
            highlight-current-row
          >
            <el-table-column label="编号" prop="id"></el-table-column>
            <el-table-column label="项目编号" prop="itemId"></el-table-column>
            <el-table-column label="创建时间" width="200">
              <template slot-scope="scope">
                {{ scope.row.creationTime | dateFormat }}
              </template>
            </el-table-column>
            <el-table-column label="修改时间" width="200">
              <template slot-scope="scope">
                {{ scope.row.lastModificationTime | dateFormat }}
              </template>
            </el-table-column>
            <el-table-column label="结果" prop="result"></el-table-column>
            <el-table-column label="项目结果">
              <template slot-scope="scope">
                {{ scope.row.id }}
              </template>
            </el-table-column>
            <el-table-column label="诊断">
              <template> </template>
            </el-table-column>
          </el-table>
        </div>
        <div style="margin-top: 5px; margin-left: 15px">
          <el-button type="primary" @click="increase">添加1</el-button>
          <div style="margin-top: 5px">
            <el-button type="primary" @click="resultediting">编辑</el-button>
          </div>
          <div style="margin-top: 5px">
            <el-button type="primary" @click="delemtdelite">删除</el-button>
          </div>
          <!-- <div style="margin-top: 5px">
            <el-button type="primary" @click="templatecategory"
              >模板类别</el-button
            >
          </div> -->
          <div style="margin-top: 5px">
            <el-button type="primary" @click="diagnosticmatching"
              >诊断匹配</el-button
            >
          </div>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="rurestdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="rurestdialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 结果模板添加或者修改弹框 -->
    <el-dialog
      :title="ruesttiele == 1 ? '新增' : '修改'"
      :visible.sync="ruesttieledialogVisible"
      width="80%"
    >
      <el-form :model="rusetform" ref="rusetform" label-width="100px">
        <el-row>
          <!-- <el-col :span="8">
            <el-form-item label="项目">
              <el-select v-model="rusetform.itemId" placeholder="请选择">
                <el-option
                  v-for="item in itemId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="结果">
              <el-input v-model="rusetform.result"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="诊断编号">
              <el-select v-model="rusetform.diagnosisId" placeholder="请选择">
                <el-option
                  v-for="item in diagnosisId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="小结名称">
              <el-select
                v-model="rusetform.isNameIntoSummary"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in isNameIntoSummary"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进入小结">
              <el-select
                v-model="rusetform.isResultIntoSummary"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in isResultIntoSummary"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结果状态">
              <el-select
                v-model="rusetform.resultStatusId"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in resultStatusId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="ruesttieledialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="rusteronsubmit">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 参考范围弹框 -->
    <el-dialog
      title="参考范围"
      :visible.sync="referencerangedialogVisible"
      width="80%"
    >
      <el-row>
        <el-col :span="8">
          <span>参考范围类型</span>
          <el-select
            v-model="referencerangevalue"
            filterable
            placeholder="请选择"
            @change="selecttype"
          >
            <el-option
              v-for="item in referencerangedata"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <!-- //无参考范围 2223456-->
      <el-card
        v-if="referencerangevalue == 0"
        style="margin-top: 20px"
      ></el-card>
      <!-- 数字型参考范围 -->
      <div style="display: flex" v-if="referencerangevalue == 1">
        <ReferenceRange :itemId="form.id" ReferenceRangeTypeFlag="1" />
      </div>
      <!-- 字符型参考范围 -->
      <div v-if="referencerangevalue == 2">
        <div style="margin: 20px 0; display: flex">
          <div style="width: 90%">
            <el-input
              type="textarea"
              placeholder="请输入内容"
              v-model="fssubdex"
              maxlength="300"
              show-word-limit
              style="height: 50px"
            >
            </el-input>
          </div>
          <div style="width: 10%">
            <div style="margin-top: 5px">
              <el-button
                type="primary"
                size="mini"
                @click="diagnosticsettings"
                style="width: 70px; height: 50px; margin-left: 10px"
                >诊断设置</el-button
              >
            </div>
            <!-- <div style="margin-top: 10px; margin-left: 10px">
              <el-button type="primary" @click="adddiagnosis"
                >增加诊断</el-button
              >
            </div> -->
          </div>
        </div>
      </div>
      <!-- 性激素参考范围 -->
      <div v-if="referencerangevalue == 2"></div>
      <span
        slot="footer"
        class="dialog-footer"
        v-if="referencerangevalue !== '1'"
      >
        <el-button @click="referencerangedialogVisible = false"
          >取 消</el-button
        >
        <el-button type="primary" @click="determinetype">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 项目结果模板弹框 -->
    <el-dialog
      title="结果模板"
      :visible.sync="projectdialogVisible"
      width="80%"
    >
      <div style="display: flex">
        <div style="width: 95%">
          <el-table :data="projectdata">
            <el-table-column label="编号" prop="id"> </el-table-column>
            <el-table-column label="结果" prop="result"> </el-table-column>
            <el-table-column label="修改者" prop="lastModifierName">
            </el-table-column>
            <el-table-column label="修改时间" prop="lastModificationTime">
              <template slot-scope="scope">
                {{ scope.row.lastModificationTime | dateFormat }}
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 结果模板 -->
        <div style="margin-left: 10px; margin-top: 5%">
          <el-button type="primary" @click="resultaddition">添加</el-button>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="projectdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="projectdialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!--诊断匹配弹框-->
    <el-dialog
      title="诊断匹配"
      :visible.sync="diagnosdialogVisible"
      width="80%"
    >
      <div style="display: flex">
        <div style="width: 95%">
          <el-table :data="diagnosticdata">
            <el-table-column label="编号" prop="id"></el-table-column>
            <el-table-column label="名称" prop="displayName"></el-table-column>
            <el-table-column
              label="创建者"
              prop="creatorName"
            ></el-table-column>
            <el-table-column label="创建时间" prop="creationTime">
              <template slot-scope="scope">
                {{ scope.row.creationTime | dateFormat }}
              </template>
            </el-table-column>
            <el-table-column
              label="修改者"
              prop="lastModifierName"
            ></el-table-column>
            <el-table-column label="修改时间" prop="lastModificationTime">
              <template slot-scope="scope">
                {{ scope.row.lastModificationTime | dateFormat }}
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div style="margin-left: 10px; margin-top: 4%">
          <el-button type="primary" @click="adddiagnosis">增加诊断</el-button>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="diagnosdialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="diagnosdialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 增加诊断弹框 -->
    <el-dialog title="诊断编辑" :visible.sync="diagnosticediting" width="80%">
      <el-form :model="editdigoisceditingform">
        <el-row>
          <el-col :span="8">
            <el-form-item label="名称" label-width="100px">
              <el-input v-model="editdigoisceditingform.displayName"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="7" style="margin-left: 20px">
            <el-form-item label="项目类别">
              <el-cascader
                v-model="editdigoisceditingform.itemTypeId"
                :options="itemTypeId"
                :show-all-levels="false"
                :props="props"
              ></el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="建议名称" label-width="100px">
              <el-input
                v-model="editdigoisceditingform.suggestionName"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="margin-left: 4%">
            <el-form-item label="是疾病">
              <el-select
                v-model="editdigoisceditingform.isIll"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in isIll"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="总监模板">
              <el-select
                v-model="editdigoisceditingform.isSummaryTemplate"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in isSummaryTemplate"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="适用性别">
              <el-select
                v-model="editdigoisceditingform.forSexId"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in forSexId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="诊断级别">
              <el-select
                v-model="editdigoisceditingform.diagnosisLevelId"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in diagnosisLevelId"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="diagnosticediting = false">取 消</el-button>
        <el-button type="primary" @click="diagnosticsadd">确 定</el-button>
      </span>
    </el-dialog>
    <!--诊断设置弹框  -->
    <el-dialog title="诊断建议设置" :visible.sync="diagnostisbox" width="80%">
      <div style="display: flex">
        <div style="width: 95%">
          <el-card>
            <el-row>
              <el-col :span="8">
                <el-select v-model="value" placeholder="请选择">
                  <el-option
                    v-for="item in itemTypeId"
                    :key="item.id"
                    :label="item.displayName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-col>
              <el-col :span="8"> 2122 </el-col>
            </el-row>
            <!-- table部分 -->
            <el-row> </el-row>
          </el-card>
        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="diagnostisbox = false">取 消</el-button>
        <el-button type="primary" @click="diagnostisbox = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!--  -->
  </div>
</template>
<script>
import { yzstr } from "@/utlis/validate";
import {
  getporjectlists,
  projectlist,
  addproject,
  priceitemlist,
  posjrctid,
  projectedit,
  projectdeleft,
  projttitem,
  projectdreog,
} from "@/request/commonapi";
import { unitlist } from "@/request/systemapi";
import Sortable from "sortablejs";
import { getapi, postapi, putapi, deletapi } from "@/api/api";

import ReferenceRange from "../../components/itemSet/ReferenceRange.vue";
export default {
  components: {
    ReferenceRange,
  },

  data() {
    return {
      value: "",
      diagnostisbox: false, //诊断设置弹框的方法
      // tabelform: {
      //   ageLowerLimit: "input无法输入",
      // },
      sexname: [],
      sexid: [],
      treeprops: {
        label: "displayName",
        value: "id",
        children: "treeChildren",
      }, //左侧树形结构需要的数据
      editdigoisceditingform: {
        displayName: "",
        itemTypeId: "",
        suggestionName: "",
        isIll: "",
        isSummaryTemplate: "",
        forSexId: "",
        diagnosisLevelId: "",
      }, //诊断编辑需要绑定的对象诊断所需要的编辑
      diagnosticediting: false, //诊断编辑
      diagnosdialogVisible: false, //匹配诊断
      diagnosticdata: [], //匹配诊断
      projectdata: [], //结果模板
      projectdialogVisible: false,
      itemId: [], //项目id
      diagnosisId: [], //诊断
      rusetform: {
        itemId: "",
        result: "",
        diagnosisId: "",
        isNameIntoSummary: "",
        isResultIntoSummary: "",
        resultStatusId: "",
        simpleCode: "",
      }, //项目结果模板需要的数据
      resultStatusId: [], //结果状态
      isNameIntoSummary: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //小结名称
      isResultIntoSummary: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //进入小结

      ruesttiele: 1,
      ruesttieledialogVisible: false,
      referencerangedata: [
        {
          value: "0",
          label: "无参考范围",
        },
        {
          value: "1",
          label: "数字型参考范围",
        },
        {
          value: "2",
          label: "字符型参考范围",
        },
        {
          value: "3",
          label: "性激素参考范围",
        },
      ], //参考范围下拉框
      referencerangevalue: "0",
      referencerangedialogVisible: false, //参考范围弹框
      Selectvalue: "",
      Selectacategory: [],
      rurestdialogVisible: false,
      isshow: true,
      reusttableData: [],
      tableData: [],
      initTableData: [],
      pages: {
        Filter: "",
        Sorting: "",
        SkipCount: 0,
        MaxResultCount: 100,
      },
      title: 1,
      form: {
        displayName: "",
        englishShortName: "",
        itemTypeId: "",
        price: "",
        priceItemId: "",
        unitId: "",
        defaultResult: "",
        referenceRangeTypeFlag: "",
        isProduceSummary: "",
        isNameIntoSummary: "",
        isDiagnosisFunction: "",
        diagnosisFunction: "",
        isCalculationItem: "",
        calculationFunction: "",
        isContinueProcess: "",
        resultTemplateTypeFlag: "",
        inputCheck: "",
        isActive: "",
      },
      referenceRangeTypeFlag: [
        {
          value: "0",
          label: "无参考范围",
        },
        {
          value: "1",
          label: "数字型参考范围",
        },
        {
          value: "2",
          label: "字符型参考范围",
        },
        {
          value: "3",
          label: "性激素参考范围",
        },
      ],
      isProduceSummary: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //生成小结
      isNameIntoSummary: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //名称进入小结
      isDiagnosisFunction: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //启用诊断函数
      isCalculationItem: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //是计算项目
      isContinueProcess: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //是继续处理
      inputCheck: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //输入结果校验公式
      isActive: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //启用
      dialogVisible: false,
      rules: {
        displayName: [
          { required: true, message: "请输入名称", trigger: "blur" },
        ],
        englishShortName: [
          { required: true, message: "请输入英文缩写", trigger: "blur" },
        ],
        itemTypeId: [
          { required: true, message: "请输入项目类别", trigger: "blur" },
        ],
        price: [{ required: true, message: "请输入价格", trigger: "blur" }],
        priceItemId: [
          { required: true, message: "请输入价表项目编码", trigger: "blur" },
        ],
        unitId: [{ required: true, message: "请输入单位", trigger: "blur" }],
        defaultResult: [
          { required: true, message: "请输入默认结果", trigger: "blur" },
        ],
        referenceRangeTypeFlag: [
          { required: true, message: "请输入参考范围类别", trigger: "blur" },
        ],
        isProduceSummary: [
          { required: true, message: "请选择是生成小结", trigger: "blur" },
        ],
        isNameIntoSummary: [
          { required: true, message: "请输择称进入小结", trigger: "blur" },
        ],
        isDiagnosisFunction: [
          { required: true, message: "请选择启用诊断函数", trigger: "blur" },
        ],
        diagnosisFunction: [
          { required: true, message: "请输入诊断函数", trigger: "blur" },
        ],
        isCalculationItem: [
          { required: true, message: "请选择计算项目", trigger: "blur" },
        ],
        calculationFunction: [
          { required: true, message: "请输入计算函数", trigger: "blur" },
        ],
        isContinueProcess: [
          { required: true, message: "请选择继续处理", trigger: "blur" },
        ],
        resultTemplateTypeFlag: [
          {
            required: true,
            message: "请输入结果模板类别标志",
            trigger: "blur",
          },
        ],
        inputCheck: [
          { required: true, message: "请选择结果校验公式", trigger: "blur" },
        ],
        isActive: [{ required: true, message: "请选择启用", trigger: "blur" }],
      },
      unitId: [], //单位Id
      priceItemId: [], //价格id1
      result: [], //结果
      forSexId: [], //性别
      itemTypeId: [], //项目类别
      diagnosisLevelId: [], //诊断级别
      isIll: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //是疾病
      isSummaryTemplate: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //总监模板
      props: {
        label: "displayName",
        value: "id",
        children: "treeChildren",
      }, //左侧树形结构
      newssdate: [
        {
          id: "1",
          name: "",
        },
        {
          id: "2",
          name: "",
        },
      ],
      defaultResult: [
        {
          value: "1",
          label: "未见异常",
        },
        {
          value: "2",
          label: "正常",
        },
        {
          value: "3",
          label: "阴性",
        },
        {
          value: "4",
          label: "无",
        },
      ], //默认结果
      ssdate: [],
      fssubdex: "",
      resultitemtype: [], //项目类别
      scopediagnostic: [], //诊断范围下拉框
      reference: [], //参考范围
      resulttemp: [], // 结果模板
      disableddiagnosisFunction: false,
    };
  },
  created() {
    this.getlist();
    this.getmedicalconclusionlist();
  },
  mounted() {
    this.rowDrop();
    this.typeid();
  },
  methods: {
    //启用诊断函数
    enablediagnostics(v) {
      console.log(v);
      if (v == "N") {
        this.disableddiagnosisFunction = true;
      } else {
        this.disableddiagnosisFunction = false;
      }
    },
    //参考范围确定类型
    determinetype() {
      if (this.referencerangevalue == 2) {
        console.log(this.form.id);
        let obj = {
          itemId: this.form.id,
          referenceRangeValue: this.fssubdex,
          referenceRangeTypeFlag: this.referencerangevalue,
        };
        postapi("/api/app/reference-range/text", obj).then((res) => {
          this.$message.success("新增成功");
          this.fssubdex = res.data.referenceRangeValue;
          this.diagnosdialogVisible = false;
        });
      }
    },
    async blurInput(id, name, value) {
      var isdate = false; //是否存在
      for (var i = 0; i < this.newssdate.length; i++) {
        if (this.newssdate[i].id == id) {
          isdate = true;
          console.log("888");
          console.log(this.newssdate[i][name]);

          this.newssdate[i][name] = value;
        }
      }

      if (!isdate) {
        for (var j = 0; j < this.ssdate.length; j++) {
          if (this.ssdate[j].id == id) {
            this.newssdate.push(this.ssdate[j]);
          }
        }
      }
      //
    },
    treeclick(data) {
      getapi(`/api/app/item/in-item-type/${data.id}`).then((res) => {
        this.tableData = res.data;
        console.log(res.data, "ress");
        // this.getlist();
      });
    },
    typeid() {
      projectlist().then((res) => {
        this.itemTypeId = res.data;
      });
    },
    //诊断新增获取数据
    diagnosticsadd() {
      postapi("/api/app/diagnosis", this.editdigoisceditingform).then((res) => {
        this.$message.success("添加成功");
        this.diagnosticmatching();
      });
    },
    //增加诊断需要的Id
    diageoisaddId() {
      //项目类别id
      getapi("/api/app/item-type").then((res) => {
        this.itemTypeId = res.data.items;
      });
      //性别
      getapi("/api/app/for-sex").then((res) => {
        this.forSexId = res.data;
      });
      //诊断级别
      getapi("/api/app/diagnosis-level").then((res) => {
        this.diagnosisLevelId = res.data.items;
      });
    },
    // 增加诊断弹框
    adddiagnosis() {
      console.log(1);
      console.log("诊断的方法");
      this.diagnosticediting = true;
      this.diageoisaddId();
    },
    //诊断匹配弹框获取诊断数据
    //改成直接跳转到诊断页面
    diagnosticmatching() {
      // this.diagnosdialogVisible = true;
      // console.log(this.diagnosdialogVisible);
      // postapi("/api/app/diagnosis/getlistinfilter").then((res) => {
      //   this.diagnosticdata = res.data.items;
      //   console.log(res);
      // });
      this.$router.push({ path: "/diagnosis" });
    },
    //结果模板添加
    resultaddition() {},
    //模板类别弹框
    // templatecategory() {
    //   getapi("/api/app/item-result-template").then((res) => {
    //     this.projectdata = res.data.items;
    //     console.log(res);
    //   });
    //   this.projectdialogVisible = true;
    // },
    //项目模板置底
    bottoming() {
      if (this.rusetform.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        putapi(
          `/api/app/itemresulttemplate/updatemanysort?id=${this.rusetform.id}&SortType=2`
        ).then((res) => {
          this.$message.success("操作成功");
          this.resultlist();
        });
      }
    },
    //项目模板置顶
    toppingqq() {
      console.log(this.rusetform.id);
      if (this.rusetform.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        putapi(
          `/api/app/itemresulttemplate/updatemanysort?id=${this.rusetform.id}&SortType=1`
        ).then((res) => {
          this.$message.success("操作成功");
          this.resultlist();
        });
      }
    },
    //结果模板删除
    delemtdelite() {
      if (this.rusetform.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        deletapi(`/api/app/item-result-template/${this.rusetform.id}`).then(
          (res) => {
            this.$message.success("删除成功");
            this.resultlist();
          }
        );
      }
    },
    reustclick(row) {
      // this.rusetform = row;
      getapi(`/api/app/item-result-template/${row.id}`).then((res) => {
        this.rusetform = res.data;
      });
      console.log(row);
    },
    //项目结果模板新增弹框
    resultediting() {
      if (this.rusetform.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        this.addoredit();
        this.ruesttiele = 2;
        this.ruesttieledialogVisible = true;
      }
    },
    //结果模板新增或者修改
    rusteronsubmit() {
      if (this.ruesttiele == 1) {
        postapi(`/api/app/item-result-template`, this.rusetform).then((res) => {
          this.$message.success("新增成功");
          this.ruesttieledialogVisible = false;
          this.resultlist();
        });
      } else if (this.ruesttiele == 2) {
        putapi(
          `/api/app/item-result-template/${this.rusetform.id}`,
          this.rusetform
        ).then((res) => {
          this.$message.success("修改成功");
          this.ruesttieledialogVisible = false;
          this.resultlist();
        });
      }
    },
    //诊断设置弹框新增
    diagnosticsettings() {
      // this.diagnostisbox = true;
      // console.log("1");
      this.$router.push({ path: "/diagnosis" });
    },
    digitaladdion() {
      // this.referencerangedata.push({
      //   gender: "全部",
      //   agewise: "200",
      //   underage: "下",
      //   onreference: "0",
      //   underreference: "上",
      // });
    },
    //参考范围下拉选择
    selecttype(v) {
      console.log(v);
      this.referencerangevalue = v;
      if (v == 1) {
        getapi("/api/app/sex").then((res) => {
          console.log(res);
          this.sexid = res.data;
        });
        postapi("/api/app/diagnosis/getlistinfilter").then((res) => {
          this.scopediagnostic = res.data.items;
          console.log(res);
        });
      }
    },
    //参考范围
    referencerange() {
      console.log("我是参考范围");
      if (this.form.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        this.referencerangedialogVisible = true;
      }
    },
    //结果模板添加或者修改需要的列
    addoredit() {
      getapi("/api/app/item/in-filter").then((res) => {
        this.itemId = res.data.items;
      });
      getapi("/api/app/result-status").then((res) => {
        // this.result = res.data.items;
        this.resultStatusId = res.data.items;
      });
      postapi("/api/app/diagnosis/getlistinfilter").then((res) => {
        console.log(res);
        this.diagnosisId = res.data.items;
      });
    },
    //结果模板添加
    increase() {
      this.addoredit();
      this.ruesttiele = 1;
      this.rusetform.itemId = this.form.id;
      console.log(this.rusetform.id);
      this.ruesttieledialogVisible = true;
      // this.rusetform = {};
    },
    //获取项目类别列表
    getmedicalconclusionlist() {
      getapi("/api/app/item-type").then((res) => {
        this.Selectacategory = res.data.items;
        console.log(res);
      });
    },
    isselctvalue(v) {
      this.pages.TypeId = v;
      console.log(v);
      console.log(this.pages.TypeId);
      this.getlist();
    },
    handleSelect(item) {
      this.pages.Filter = item.displayName;
      this.item = item;
      this.formid = item.id;
      console.log(this.item);
      //console.log(item);
      //    quersmedicalid(item.id).then((res) => {
      //   console.log(res);
      //   this.form = res.data;
      // });
    },
    getlistM(rowsid) {
      getporjectlists(this.pages).then((res) => {
        console.log("数据", res);
        this.initTableData = [...res.data.items];
        this.tableData = res.data.items;
        if (rowsid != null && rowsid != "") {
          var row = this.tableData.filter((item) => item.id == rowsid);
          this.$refs.tableData.setCurrentRow(row[0]);
          getapi(`/api/app/item/${rowsid}`).then((res) => {
            this.form = res.data;
          });
        }
      });
    },
    selsearch(id, typeid) {
      this.Selectvalue = typeid;
      this.pages.TypeId = typeid;
      this.getlistM(id);
    },
    createFilter(queryString) {
      return (tableData) => {
        return (
          tableData.displayName
            .toLowerCase()
            .indexOf(queryString.toLowerCase()) != -1
        );
      };
    },
    querySearch(queryString, cb) {
      var tableData = this.tableData;
      var tableDatas = queryString
        ? tableData.filter(this.createFilter(queryString))
        : tableData;
      // 调用 callback 返回建议列表的数据
      cb(tableDatas);
    },
    resultlist() {
      getapi("/api/app/item-result-template").then((res) => {
        this.reusttableData = res.data.items;

        console.log(res);
      });
    },
    resulttemplate() {
      if (this.form.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        this.rurestdialogVisible = true;
        getapi(`/api/app/item-result-template/in-item-id/${this.form.id}`).then(
          (res) => {
            this.reusttableData = res.data;
            console.log("2222222222222222");
            console.log(res);
          }
        );
        //// 获取项目类别
        getapi("/api/app/item-type/by-code-all").then((res) => {
          this.resultitemtype = res.data;
          console.log(res);
        });
      }
    },
    //取消排序
    cancellation() {
      this.$message.info("取消操作");
      this.isshow = true;
      this.getlist();
    },
    //确定拖拽
    assertion() {
      const result = [];
      this.tableData.forEach((item, index) => {
        // index 从0开始的， displayOrder从大到小排
        console.log(item.id);
        // const currentDisplayOrder = this.tableData.length -1
        const currentDisplayOrder = this.initTableData[index].displayOrder;
        if (item.displayOrder != currentDisplayOrder) {
          // 如果它的displayOrder和它当前所在的位置不同代表挪动过位置
          result.push({ id: item.id, displayOrder: currentDisplayOrder });
        }
      });
      projectdreog({ itemList: result }).then((res) => {
        this.$message.success("操作成功");
        this.isshow = true;
        this.getlist();
      });
    },
    //初始化
    rowDrop() {
      this.$nextTick(() => {
        const tbody = document.querySelector(".el-table__body-wrapper tbody");
        const _this = this;
        Sortable.create(tbody, {
          handle: ".move",
          animation: 300,
          onEnd({ newIndex, oldIndex }) {
            _this.isshow = false;
            const currRow = _this.tableData.splice(oldIndex, 1)[0];
            _this.tableData.splice(newIndex, 0, currRow);
            _this.tableData.map((item, index) => {
              if (index == newIndex && index == oldIndex) {
                // console.log(item, "新数据");
              } else if (index == oldIndex) {
              } else if (index == newIndex) {
              }
            });
            console.log(_this.tableData.map((item) => item.displayOrder));
          },
        });
      });
    },
    //置低
    toppings() {
      if (this.form.id == undefined) {
        this.$message.success("请点击选择操作的数据");
      } else {
        projttitem(this.form.id, 2).then((res) => {
          this.$message.success("操作成功");
          this.getlist();
        });
      }
    },
    //置顶
    topping() {
      if (this.form.id == undefined) {
        this.$message.warning("请点击选择操作的数据");
      } else {
        projttitem(this.form.id, 1).then((res) => {
          this.$message.success("操作成功");
          this.getlist();
        });
      }
    },
    //删除
    delsrts() {
      if (this.form.id == undefined) {
        this.$message.warning("请选择删除的数据");
      } else {
        this.$confirm("是否确认删除,是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            projectdeleft(this.form.id).then((res) => {
              this.$message.success("删除成功");
              this.getlist();
              this.form = {};
            });
          })
          .catch(() => {});
      }
    },
    //点击列表通过id查询
    rowick(row) {
      posjrctid(row.id).then((res) => {
        console.log(res);
        this.form = res.data;
      });
      console.log(row);
    },
    //编辑弹框
    editpopup() {
      if (this.form.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        this.form.price = Number(this.form.price);
        this.addorgropdata();
        this.title = 2;
        this.dialogVisible = true;
        posjrctid(this.form.id).then((res) => {
          console.log(res);
          this.form = res.data;
        });
      }
    },
    //确定新增或者编辑
    Onsubmit() {
      this.$refs.form.validate((v) => {
        if (v) {
          if (this.title == 1) {
            this.form.price = Number(this.form.price);
            addproject(this.form).then((res) => {
              this.$message.success("新增成功222");
              this.getlist();
              this.dialogVisible = false;
            });
          } else if (this.title == 2) {
            projectedit(this.form.id, this.form).then((res) => {
              this.$message.success("修改成功");
              this.getlist();
              this.dialogVisible = false;
            });
          }
        }
      });
      //  addproject(this.form)
    },
    //新增弹框
    add() {
      this.form.price = Number(this.form.price);
      this.title = 1;
      this.dialogVisible = true;
      this.form = {};
      this.addorgropdata();
    },
    //新增或者编辑弹框需要的下拉框接口数据
    addorgropdata() {
      //获取项目id
      projectlist().then((res) => {
        this.itemTypeId = res.data;
        this.tcdate(this.itemTypeId);
      });
      //获取单位
      unitlist().then((res) => {
        this.unitId = res.data.items;
      });
      //获取价格Id
      priceitemlist().then((res) => {
        this.priceItemId = res.data.items;
      });
      //参考范围
      getapi("/api/app/reference-range").then((res) => {
        this.reference = res.data.items;
      });
      //结果模板
      getapi("/api/app/item-result-template").then((res) => {
        this.resulttemp = res.data.items;
        console.log(res, "结果模板");
      });
    },
    getlist() {
      this.getlistM();
      // getporjectlists(this.pages).then((res) => {
      //   this.initTableData = [...res.data.items];
      //   this.tableData = res.data.items;
      // });
    },
    tcdate(date) {
      for (var i = 0; i < date.length; i++) {
        if (date[i].treeChildren.length == 0) {
          date[i].treeChildren = undefined;
        } else {
          this.tcdate(date[i].treeChildren);
        }
      }
    },

    ///
  },
};
</script>
<style scoped>
.box {
  display: flex;
}
</style>
