<template>
  <div class="box">
    <div>
      <div class="middlebox">
        <div class="contenttitle">
          基础资料 /
          <span class="contenttitleBold"
            >组合项目</span
          >
        </div>
        <div class="seachinput">
          <el-select
            v-model="department"
            placeholder="请选择组合项目"
            filterable
            :filter-method="remoteMethodes"
            default-first-option
            @change="quckDepartments"
            clearable
            size="small"
          >
            <el-option
              v-for="item in quckDepartment"
              :key="item.id"
              :label="item.displayName"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
      </div>
      <div style="display: flex; margin-top: 7px">
        <div
          :style="
            'width: 208px;overflow: scroll;height:' +
            (window.pageHeight < 600 ? 505 : window.pageHeight - 100) +
            'px;background-color: #fff; border-radius: 8px'
          "
        >
          <div style="margin-top: 10px">
            <el-tree
              :data="itemTypeId"
              :props="treeprops"
              @node-click="treeclick"
              node-key="id"
              ref="itemType"
              highlight-current
              auto-expand-parent
            >
              <span class="custom-tree-node" slot-scope="{ node, data }">
                <div>
                  <span class="treeicons">
                    <!-- <i
                        class="el-icon-document-remove"
                        v-if="data.parentId == null"
                      ></i> -->
                    <img
                      style="width: 20px; height: 20px; vertical-align: sub"
                      src="@/assets/images/order.png"
                      v-if="!data.parentId"
                    />
                  </span>
                  <span
                    :class="!data.parentId ? 'maxtitle' : 'mintitle'"
                    >{{ node.label }}</span
                  >
                </div>
              </span>
            </el-tree>
          </div>
        </div>
        <div style="display: block">
          <div style="margin-left: 15px; display: flex; flex-direction: column">
            <div style="display: flex; margin-bottom: 15px">
              <div
                :style="
                  'width:' +
                  (window.pageWidth - 200 - 110 - 50 - 14) +
                  'px;padding: 15px;background-color: #fff;border-radius: 8px;'
                "
              >
                <el-table
                  :data="tableData"
                  style="width: 100%"
                  row-key="id"
                  :height="
                    window.pageHeight < 600
                      ? 190
                      : Math.floor((window.pageHeight - 260) / 2)
                  "
                  class="el-table__body-wrapper tbody"
                  @row-click="rowick"
                  highlight-current-row
                  :row-style="{ height: '36px' }"
                  ref="tableData"
                >
                  <el-table-column prop="id" label="编号" width="320">
                  </el-table-column>
                  <el-table-column prop="displayName" label="名称" width="">
                  </el-table-column>
                  <el-table-column prop="price" label="价格" width="">
                  </el-table-column>
                  <el-table-column prop="creatorName" label="创建者" width="">
                  </el-table-column>
                  <el-table-column
                    prop="lastModifierName"
                    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="lastModificationTime"
                    label="修改时间"
                    width="200"
                  >
                    <template slot-scope="scope">
                      {{ scope.row.lastModificationTime | dateFormat }}
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="center">
                    <template>
                      <el-tag
                        class="move"
                        style="
                          cursor: move;
                          background-color: rgb(245, 245, 245);
                          border: none;
                        "
                        draggable="true"
                      >
                        <i
                          class="el-icon-d-caret"
                          style="
                            width: 1rem;
                            height: 1rem;
                            color: rgb(113, 113, 113);
                          "
                        ></i>
                      </el-tag>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
            <!-- table页 -->
            <div style="display: flex">
              <div
                :style="
                  'width:' +
                  (window.pageWidth - 200 - 110 - 50 - 14) +
                  'px;padding: 15px;background-color: #fff;border-radius: 8px;'
                "
              >
                <el-tabs v-model="activeName">
                  <el-tab-pane label="项目明细" name="first">
                    <div class="mainbox">
                      <div class="" :style="'width:'+Math.floor((window.pageWidth - 200 - 110 - 50 - 14-130)/2) +'px;'
                ">
                        <div>
                          <span
                            style="
                              padding: 5px;
                              font-size: 14px;
                              font-weight: 400;
                              color: #232748;
                              font-family: NotoSansSC-Regular;
                              margin-bottom: 10px;
                            "
                            >项目类别：</span
                          >
                          <el-cascader
                            v-model="values"
                            :options="itemTypeId"
                            ref="example"
                            popper-class="example"
                            @change="ischangs"
                            :props="{
                              value: 'id',
                              label: 'displayName',
                              children: 'treeChildren',
                              checkStrictly: true,
                              expandTrigger: 'hover',
                            }"
                            size="small"
                          >
                          </el-cascader>
                        </div>
                        <el-table
                          :data="leftdata"
                          :height="
                            window.pageHeight < 600
                              ? 170
                              : Math.floor((window.pageHeight - 230) / 2)
                          "
                          @row-dblclick="dbClickChoosedAsb"
                          @selection-change="handleSelectionChange"
                          @row-click="chooseAsbItem"
                          highlight-current-row
                          :row-style="{ height: '28px' }"
                        >
                          <el-table-column
                            type="index"
                            align="center"
                            label="序号"
                          />
                          <el-table-column
                            prop="displayName"
                            label="未选项目"
                          />
                        </el-table>
                      </div>
                      <div class="Selectbutton">
                        <div style="">
                          <el-button
                            @click="addAbs"
                            style="width: 100px"
                            class="commonbutton"
                            >添加<i class="el-icon-caret-right"></i>
                          </el-button>
                        </div>
                        <div style="margin-top: 18px">
                          <el-button @click="addall" class="difference"
                            >全添加<i class="el-icon-caret-right"></i
                            ><i class="el-icon-caret-right"></i
                          ></el-button>
                        </div>
                        <div style="margin-top: 18px">
                          <el-button
                            @click="delAbs"
                            style="width: 100px"
                            class="commonbutton"
                            >移除<i class="el-icon-caret-left"></i>
                          </el-button>
                        </div>
                        <div style="margin-top: 18px">
                          <el-button @click="allclear" class="difference"
                            >全移除<i class="el-icon-caret-left"></i
                            ><i class="el-icon-caret-left"></i>
                          </el-button>
                        </div>
                      </div>
                      <div class="" :style="'width:'+Math.floor((window.pageWidth - 200 - 110 - 50 - 14-130)/2) +'px;'
                ">
                        <div>
                          <span
                            style="
                              padding: 5px;
                              font-size: 14px;
                              font-weight: 400;
                              color: #232748;
                              font-family: NotoSansSC-Regular;
                              margin-bottom: 10px;
                            "
                            >搜索选择：</span
                          >
                          <el-select
                            value-key="id"
                            @change="selectitem"
                            filterable
                            v-model="flitvalues"
                            placeholder="请选择"
                            :filter-method="remoteMethods"
                            default-first-option
                            clearable
                            ref="quickAsbOCX"
                            size="small"
                          >
                            <el-option
                              v-for="item in filetelists"
                              :key="item.id"
                              :label="item.displayName"
                              :value="item"
                            >
                            </el-option>
                          </el-select>
                        </div>
                        <el-table
                          :data="rightdata"
                          :height="
                            window.pageHeight < 600
                              ? 170
                              : Math.floor((window.pageHeight - 230) / 2)
                          "
                          width="100%"
                          @row-dblclick="removeAbs"
                          @selection-change="selecteditems"
                          @row-click="removeAsbItem"
                          highlight-current-row
                          :row-style="{ height: '28px' }"
                          :summary-method="getSummaries"
                          show-summary
                          ref="table"
                        >
                          <el-table-column
                            type="index"
                            align="center"
                            label="序号"
                          />
                          <el-table-column
                            label="已选项目"
                            prop="displayName"
                          />
                        </el-table>
                      </div>
                    </div>
                  </el-tab-pane>
                  <!-- 指引单信息 -->
                  <el-tab-pane label="指引信息" name="second">
                    <div style="display: flex; width: 100%">
                      <div :style="
                  'width:' +
                  (window.pageWidth - 200 - 110 - 50 - 10-110-10) +
                  'px;'
                ">
                        <el-form
                          ref="guidanceinformation"
                          :rules="guidelinesRules"
                          :model="formdata"
                        >
                          <el-table
                            :data="formdata.guidanceinformationdata"
                            style="width: 100%"
                            highlight-current-row
                            @row-click="guiderow"
                            :row-class-name="tableRowClassName"
                            :height="
                              window.pageHeight < 600
                                ? 215
                                : Math.floor((window.pageHeight - 174) / 2)
                            "
                            ref="guidanceinformationdata"
                            class="guidelines"
                            border
                          >
                            <el-table-column label="体检中心" width="200">
                              <template slot-scope="scope">
                                <el-form-item
                                  :prop="
                                    'guidanceinformationdata.' +
                                    scope.$index +
                                    '.medicalCenterId'
                                  "
                                  :rules="guidelinesRules.medicalCenterId"
                                >
                                  <el-select
                                    v-model="scope.row.medicalCenterId"
                                  >
                                    <el-option
                                      v-for="item in organizationUnitdata"
                                      :key="item.id"
                                      :label="item.displayName"
                                      :value="item.id"
                                    />
                                  </el-select>
                                </el-form-item>
                              </template>
                            </el-table-column>
                            <el-table-column label="适用性别" width="200">
                              <template slot-scope="scope">
                                <el-form-item
                                  :prop="
                                    'guidanceinformationdata.' +
                                    scope.$index +
                                    '.forSexId'
                                  "
                                  :rules="guidelinesRules.forSexId"
                                >
                                  <el-select v-model="scope.row.forSexId">
                                    <el-option
                                      v-for="item in forsexdata"
                                      :key="item.id"
                                      :label="item.displayName"
                                      :value="item.id"
                                    />
                                  </el-select>
                                </el-form-item>
                              </template>
                            </el-table-column>
                            <el-table-column label="指引信息">
                              <template slot-scope="scope">
                                <el-form-item
                                  :prop="
                                    'guidanceinformationdata.' +
                                    scope.$index +
                                    '.guide'
                                  "
                                  :rules="guidelinesRules.guide"
                                >
                                  <el-input
                                    v-model="scope.row.guide"
                                    required
                                  />
                                </el-form-item>
                              </template>
                            </el-table-column>
                          </el-table>
                        </el-form>
                      </div>
                      <div style="margin-left: 15px">
                        <el-button
                          type=""
                          @click="createabulletbox"
                          style="margin-top: 50px;"
                          class="commonbutton"
                          >新增</el-button
                        >
                        <div style="margin-top: 10px">
                          <el-button
                            type=""
                            @click="deleteguidelines"
                            class="deleteButton"
                            >删除</el-button
                          >
                        </div>
                        <div style="margin-top: 10px;">
                          <el-button
                            type=""
                            @click="saveguidelines"
                            class="commonbutton"
                            >保存</el-button
                          >
                        </div>
                      </div>
                    </div>
                    <!-- 科室改为体检中心 -->
                  </el-tab-pane>
                </el-tabs>
              </div>
            </div>
          </div>
        </div>
        <!-- 按钮区域 -->
        <div style="margin-left: 10px">
          <el-button type="" @click="addll" class="commonbutton"
            >新增</el-button
          >
          <div style="margin-top: 10px">
            <el-button type="" @click="editpopup" class="commonbutton"
              >编辑</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button type="" @click="deleteid" class="deleteButton"
              >删除</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button type="" @click="topping" class="commonbutton"
              >置顶</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button type="" @click="setlow" class="commonbutton"
              >置底</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button
              type=""
              :disabled="isshow"
              @click="assertion"
              class="commonbutton"
              >排序</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button
              type=""
              :disabled="isshow"
              @click="cancellation"
              class="commonbutton"
              >取消</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button
              type=""
              :disabled="isdislob"
              @click="Onsubmit"
              class="commonbutton"
              >确定项目</el-button
            >
          </div>
          <div style="margin-top: 10px">
            <el-button
              type=""
              :disabled="isdislob"
              @click="projectCancellation"
              class="commonbutton"
              >取消项目</el-button
            >
          </div>
        </div>
      </div>
    </div>
    <!-- 新增或者编辑弹框 -->
    <el-dialog
      :title="title == 1 ? '新增' : '编辑'"
      :visible.sync="dialogVisible"
      width="70%"
      @close="bindidclose"
      :close-on-click-modal="false"
    >
      <el-form :model="form" :rules="rules" ref="ruleForm" label-width="100px">
        <el-row>
          <el-col :span="10">
            <el-form-item label="项目编号" prop="">
              <el-input
                v-model="form.id"
                :disabled="true"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="项目类别" prop="itemTypeId">
              <!-- <el-select v-model="form.itemTypeId" placeholder="请选择">
                    <el-option
                      v-for="item in itemTypeId"
                      :key="item.id"
                      :label="item.displayName"
                      :value="item.id"
                    >
                    </el-option>
                  </el-select> -->
              <el-cascader
                v-model="form.itemTypeId"
                :options="itemTypeId"
                popper-class="example"
                ref="itemTypeIds"
                @change="ischangsItemTypeId"
                :props="{
                  value: 'id',
                  label: 'displayName',
                  children: 'treeChildren',
                  checkStrictly: true,
                  expandTrigger: 'hover',
                }"
                size="small"
              >
              </el-cascader>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="名称" prop="displayName">
              <el-input
                v-model="form.displayName"
                ref="refinput"
                @input="($event) => changeUpdate($event, 'displayName')"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="简称" prop="">
              <el-input
                v-model="form.shortName"
                @input="($event) => changeUpdate($event, 'shortName')"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="适用性别" prop="">
              <el-select
                v-model="form.forSexId"
                placeholder="请选择"
                size="small"
                @change="quckRusetform"
              >
                <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="价格" prop="">
              <el-input
                v-model="form.price"
                type="nember"
                @input="($event) => changeUpdate($event, 'price')"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="仪器类别" prop="">
              <el-select
                v-model="form.deviceTypeId"
                placeholder="请选择"
                size="small"
                @change="quckRusetform"
              >
                <el-option
                  v-for="item in deviceTypeId"
                  :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="collectItemTypeId">
              <el-select
                v-model="form.collectItemTypeId"
                placeholder="请选择"
                size="small"
                @change="quckRusetform"
              >
                <el-option
                  v-for="item in collectItemType"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="项目结果合并" prop="" label-width="110px">
              <!-- <el-select
                    v-model="form.isItemResultMerger"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in isItemResultMerger"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isItemResultMergerBox"
                @change="changeBox('isItemResultMerger')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="餐前项目" prop="">
              <!-- <el-select v-model="form.isBeforeEat" placeholder="请选择">
                    <el-option
                      v-for="item in isBeforeEat"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isBeforeEatBox"
                @change="changeBox('isBeforeEat')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="临床意义" prop="">
              <el-input
                v-model="form.clinicalMeaning"
                type="textarea"
                :autosize="{ minRows: 2, maxRows: 2 }"
                @input="($event) => changeUpdate($event, 'clinicalMeaning')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="默认结果" prop="" class="my-el-form-item">
              <!-- <el-input v-model="form.defaultResult"></el-input> -->
              <div style="display: flex; justify-content: center">
                <el-input
                  v-model="form.defaultResult"
                  type="textarea"
                  :autosize="{ minRows: 1, maxRows: 1 }"
                  @input="($event) => changeUpdate($event, 'defaultResult')"
                />
                <el-select
                  v-model="form.defaultResult"
                  style="width: 40px"
                  class="downText"
                  @change="quckRusetform"
                >
                  <el-option
                    v-for="item in defaultResult"
                    :key="item.value"
                    :label="item.label"
                    :value="item.label"
                  >
                  </el-option>
                </el-select>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="启用诊断" prop="">
              <!-- <el-select
                    v-model="form.isDiagnosisFunction"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in isDiagnosisFunction"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isDiagnosisFunctionBox"
                @change="changeBox('isDiagnosisFunction')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="诊断函数" prop="">
              <el-input
                v-model="form.diagnosisFunction"
                :disabled="disableddiagnosisFunction"
                size="small"
              >
                <el-button
                  slot="append"
                  icon="el-icon-more"
                  v-if="form.isDiagnosisFunctionBox"
                  @click="
                    (diagnosisFunctionBox = true),
                      (diagnosisFunctionText = form.diagnosisFunction)
                  "
                  size="small"
                ></el-button>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="函数处理完毕" prop="" label-width="110px">
              <!-- <el-select
                    v-model="form.isContinueProcess"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in isContinueProcess"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isContinueProcessBox"
                @change="changeBox('isContinueProcess')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="候诊时间" prop="">
              <el-input
                v-model="form.queueTime"
                type="nember"
                @input="($event) => changeUpdate($event, 'queueTime')"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="体检报告" prop="" size="small">
              <!-- <el-select
                    v-model="form.isPictureRotate"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in isPictureRotate"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isPictureRotateBox"
                @change="changeBox('isPictureRotate')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="检查项目" prop="">
              <!-- <el-select v-model="form.isCheck" placeholder="请选择">
                    <el-option
                      v-for="item in isCheck"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isCheckBox"
                @change="changeBox('isCheck')"
              />
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="启用" prop="">
              <!-- <el-select v-model="form.isActive" placeholder="请选择">
                    <el-option
                      v-for="item in isActive"
                      :key="item.value"
                      :label="item.label"
                      :value="item.value"
                    >
                    </el-option>
                  </el-select> -->
              <el-checkbox
                v-model="form.isActiveBox"
                @change="changeBox('isActive')"
              />
            </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
                size="small"
              ></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%"
                size="small"
              ></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
                size="small"
              ></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%"
                size="small"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editcancellation" class="difference"
          >取 消</el-button
        >
        <el-button type="primary" @click="addoredit" class="commonbutton"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 指引信息新增修改弹框 -->
    <el-dialog
      :title="guidetitle == 1 ? '指引信息新增' : '指引信息修改'"
      :visible.sync="guidetitledialogVisible"
      width="50%"
    >
      <el-row>
        <el-form
          :model="guideform"
          :rules="guiderules"
          ref="ruleForms"
          label-width="100px"
          class="demo-ruleForm"
        >
          <el-col :span="12">
            <el-form-item label="体检中心" prop="medicalCenterId">
              <el-select
                v-model="guideform.medicalCenterId"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in organizationUnitdata"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="组合项目" prop="asbitemId">
              <el-select v-model="guideform.asbitemId" placeholder="请选择">
                <el-option
                  v-for="item in asbitemdata"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="12">
            <el-form-item label="适用性别" prop="forSexId">
              <el-select v-model="guideform.forSexId" placeholder="请选择">
                <el-option
                  v-for="item in forsexdata"
                  :key="item.id"
                  :label="item.displayName"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="指引内容" prop="guide">
              <el-input
                v-model="guideform.guide"
                placeholder="请输入内容"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button @click="guidetitledialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="determineguidelines">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 诊断函数弹框 -->
    <el-dialog
      title="诊断函数设置"
      :visible.sync="diagnosisFunctionBox"
      width="50%"
      :close-on-click-modal="false"
      fullscreen
    >
      <el-form label-width="110px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="诊断函数">
              <el-input
                type="textarea"
                v-model="diagnosisFunctionText"
                :autosize="{ minRows: 29, maxRows: 29 }"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button
          @click="(diagnosisFunctionBox = false), (diagnosisFunctionText = '')"
          class="difference"
          >取 消</el-button
        >
        <el-button
          type="primary"
          @click="OnsubmitDiagnosis"
          class="commonbutton"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from "vuex";
import Sortable from "sortablejs";
import { getapi, postapi, deletapi } from "@/api/api";
import { examinationgender, instrumentlist } from "@/request/systemapi";
import { deepCopy, objCopy } from "../../utlis/proFunc";
import {
  getporjectlists,
  groupsandlist,
  projectlist,
  invoicetypelist,
  newcombination,
  asbitemgetid,
  updateombination,
  samplesetlow,
  deletescombinationprojectid,
  combination,
} from "@/request/commonapi";
export default {
  data() {
    return {
      guiderules: {
        medicalCenterId: [
          {
            required: true,
            message: "请选择体检单位",
            trigger: "change",
          },
        ],
        asbitemId: [
          {
            required: true,
            message: "请选择组合项目",
            trigger: "change",
          },
        ],
        forSexId: [
          {
            required: true,
            message: "请选择组适用性别",
            trigger: "change",
          },
        ],
        guide: [{ required: true, message: "请输入指引内容", trigger: "blur" }],
      },
      guidetitle: 1,
      guideform: {
        medicalCenterId: "",
        asbitemId: "",
        forSexId: "",
        guide: "",
      }, //指引信息的数据对象
      organizationUnitdata: [], //体检中心
      guidetitledialogVisible: false,
      formdata: {
        guidanceinformationdata: [],
      },
      activeName: "first",
      isdislob: true,
      filetelists: [],
      flitvalues: [],
      num: 0,
      isshow: true,
      values: [],
      projectid: [],
      initprojectid: [],
      rules: {
        displayName: [
          { required: true, message: "请输入名称", trigger: "blur" },
        ],
        shortName: [{ required: true, message: "请输入简称", trigger: "blur" }],
        forSexId: [
          { required: true, message: "请选择适用性别", trigger: "blur" },
        ],
        itemTypeId: [
          { required: true, message: "请选择项目类别", trigger: "blur" },
        ],
        price: [{ required: true, message: "请输入价格", trigger: "blur" }],
        deviceTypeId: [
          { required: true, message: "请选择仪器类别", trigger: "blur" },
        ],
        invoiceItemTypeId: [
          { required: true, message: "请选择发票类别", trigger: "blur" },
        ],
        collectItemTypeId: [
          { required: true, message: "请选择汇总项目类别", trigger: "blur" },
        ],
        isItemResultMerger: [
          { required: true, message: "请选择项目结果", trigger: "blur" },
        ],
        isBeforeEat: [
          { required: true, message: "请选择餐前项目", trigger: "change" },
        ],
        clinicalMeaning: [
          { required: true, message: "请输入临床意义", trigger: "blur" },
        ],
        defaultResult: [
          { required: true, message: "请输入默认结果", trigger: "blur" },
        ],
        queueTime: [
          { required: true, message: "请输入候诊时间", trigger: "blur" },
        ],
        isDiagnosisFunction: [
          { required: true, message: "请选择启用诊断函数", trigger: "blur" },
        ],
        diagnosisFunction: [
          { required: true, message: "请输入诊断函数", trigger: "blur" },
        ],
        isContinueProcess: [
          {
            required: true,
            message: "请选择诊断函数处理完毕后继续处理",
            trigger: "blur",
          },
        ],
        isPictureRotate: [
          { required: true, message: "请选择体检报告图片旋", trigger: "blur" },
        ],
        isCheck: [
          { required: true, message: "请选择是检查项目", trigger: "blur" },
        ],
        isActive: [
          { required: true, message: "请选择是否启用", trigger: "blur" },
        ],
      }, //表单校验对象
      form: {
        displayName: "",
        shortName: "",
        forSexId: "A",
        itemTypeId: "",
        price: "0",
        deviceTypeId: null,
        invoiceItemTypeId: "",
        isItemResultMerger: "N",
        isBeforeEat: "N",
        clinicalMeaning: "",
        defaultResult: "未见异常",
        queueTime: "0",
        isDiagnosisFunction: "N",
        diagnosisFunction: "",
        isContinueProcess: "N",
        isPictureRotate: "N",
        isCheck: "N",
        isActive: "Y",
        isActiveBox: true,
        isBeforeEatBox: false,
        isCheckBox: true,
        isContinueProcessBox: false,
        isDiagnosisFunctionBox: false,
        isItemResultMergerBox: false,
        isPictureRotateBox: false,
        collectItemTypeId:""
      },
      forSexId: [], //性别
      itemTypeId: [], //项目类别
      deviceTypeId: [], //仪器类别
      invoiceItemTypeId: [], //发票类别
      isItemResultMerger: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //项目结果合并
      isBeforeEat: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //餐前项目
      isDiagnosisFunction: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //启用诊断函数
      isContinueProcess: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //诊断函数处理完毕
      isContinueProcess: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //诊断函数处理完毕后继续处理
      isPictureRotate: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //体检报告图片旋转
      isCheck: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //是检查项目
      isActive: [
        {
          value: "Y",
          label: "是",
        },
        {
          value: "N",
          label: "否",
        },
      ], //是否启用
      title: 1,
      dialogVisible: false,
      isshow: true,
      tableHeight: window.innerHeight - 180, //表格动态高度
      screenHeight: window.innerHeight, //内容区域高度
      pages: {
        Filter: "",
        SkipCount: 0,
        MaxResultCount: 100,
        Sorting: "displayOrder desc",
      },
      tableData: [],
      initTableData: [],
      leftdata: [],
      ary2: [],
      ary1: [],
      rightobj: {},
      rightdata: [],
      rightobj: {},
      nums: 0,
      itemid: "", //项目id
      curRow: {},
      asbitemdata: [], //组合项目
      forsexdata: [], //适用性别
      department: "",
      quckDepartment: [],
      treeprops: {
        label: "displayName",
        value: "id",
        children: "treeChildren",
      },
      defaultResult: [
        {
          value: "1",
          label: "未见异常",
        },
        {
          value: "2",
          label: "正常",
        },
        {
          value: "3",
          label: "阴性",
        },
        {
          value: "4",
          label: "无",
        },
        {
          value: "5",
          label: "(—)",
        },
        {
          value: "6",
          label: "­-",
        },
      ],
      diagnosisFunctionBox: false,
      diagnosisFunctionText: "",
      disableddiagnosisFunction: true,
      initfiletelists: [],
      initItemTypeId: "",
      guidelinesRules: {
        medicalCenterId: [
          { required: true, message: "请选择体检中心", trigger: "change" },
        ],
        forSexId: [
          { required: true, message: "请选择性别", trigger: "change" },
        ],
        guide: [{ required: true, message: "请输入指引信息", trigger: "blur" }],
      },
      collectItemType:[]
    };
  },
  created() {
    // this.getlist();
    this.gitprojectcategory();
  },
  mounted() {
    this.rowDrop();
    this.gitfleslist();
    this.typeid();
  },
  updated() {
  	 this.$nextTick(() => {
       	this.$refs.table.doLayout()
    	})
	},
  computed: {
    ...mapState(["window"]),
  },
  methods: {
    removeAsbItem(row) {
      this.ary2 = [row];
    },
    chooseAsbItem(row) {
      this.ary1 = [row];
    },
    changeUpdate(e, k) {
      this.$delete(this.form, k);
      this.$set(this.form, k, e);
    },
    projectCancellation() {
      if (this.form.id == undefined || this.form.id == "") {
        this.$message.warning("请选择组合项目");
        this.isdislob = true;
      } else {
        this.rowick(this.form);
        this.isdislob = true;
      }
    },
    remoteMethods(keyWords) {
      if (keyWords) {
        this.filetelists = [];
        this.initfiletelists.forEach((item) => {
          if (
            item.displayName.toLowerCase().indexOf(keyWords.toLowerCase()) >
              -1 ||
            item.simpleCode.toLowerCase().indexOf(keyWords.toLowerCase()) > -1
            // || item.shortName.toLowerCase().indexOf(keyWords.toLowerCase()) > - 1
          ) {
            this.filetelists.push(item);
          }
        });
      } else {
        this.filetelists = deepCopy(this.initfiletelists);
      }
    },
    remoteMethod(keyWords) {
      if (keyWords) {
        this.projectid = [];
        this.initprojectid.forEach((item) => {
          if (
            item.displayName.toLowerCase().indexOf(keyWords.toLowerCase()) >
              -1 ||
            item.simpleCode.toLowerCase().indexOf(keyWords.toLowerCase()) > -1
            // || item.shortName.toLowerCase().indexOf(keyWords.toLowerCase()) > - 1
          ) {
            this.projectid.push(item);
          }
        });
      } else {
        this.projectid = deepCopy(this.initprojectid);
      }
    },
    OnsubmitDiagnosis() {
      this.form.diagnosisFunction = this.diagnosisFunctionText;
      this.diagnosisFunctionText = "";
      this.diagnosisFunctionBox = false;
      //this.$message.success("设置诊断函数成功");
    },
    quckRusetform(e) {
      this.$forceUpdate();
    },
    changeBox(type) {
      //赋值
      if (this.form[type + "Box"]) {
        this.$delete(this.form, type);
        this.$set(this.form, type, "Y");
      } else {
        this.$delete(this.form, type);
        this.$set(this.form, type, "N");
      }
    },
    typeid() {
      projectlist().then((res) => {
        if (res.code != -1) {
          this.itemTypeId = res.data;
          this.itemTypeId = this.formatData(this.itemTypeId);
        }
      });
    },
    formatData(dataList) {
      for (let i = 0; i < dataList.length; i++) {
        if (dataList[i].treeChildren.length < 1) {
          dataList[i].treeChildren = undefined;
        } else {
          this.formatData(dataList[i].treeChildren);
        }
      }
      return dataList;
    },
    treeclick(data) {
      this.initItemTypeId = data.id;
      postapi("/api/app/asbitem/getasbitemlist", { itemTypeId: data.id }).then(
        (res) => {
          if (res.code != -1) {
            this.tableData = res.data;
            // this.initTableData = [...res.data];
          }
        }
      );
      this.curRow = this.$options.data().curRow;
      this.leftdata = this.$options.data().leftdata;
      this.rightdata = this.$options.data().rightdata;
      this.formdata = this.$options.data().formdata;
      this.values = this.$options.data().values;
      this.flitvalues = this.$options.data().flitvalues;
    },
    remoteMethodes(keyWords) {
      if (keyWords) {
        this.quckDepartment = [];
        this.initTableData.forEach((item) => {
          if (
            item.displayName.toLowerCase().indexOf(keyWords.toLowerCase()) >
              -1 ||
            item.simpleCode.toLowerCase().indexOf(keyWords.toLowerCase()) > -1
            // || item.shortName.toLowerCase().indexOf(keyWords.toLowerCase()) > - 1
          ) {
            this.quckDepartment.push(item);
          }
        });
      } else {
        this.quckDepartment = deepCopy(this.initTableData);
      }
    },
    quckDepartments(e) {
      if (e) {
        let currentKey = "";
        this.quckDepartment.forEach((item) => {
          if (e == item.id) {
            currentKey = item.itemTypeId;
            this.initItemTypeId = item.itemTypeId;
          }
        });
        this.$refs["itemType"].setCurrentKey(currentKey);
        let selected = this.$refs["itemType"].getCurrentNode();
        if (
          this.$refs["itemType"].getNode(selected) &&
          this.$refs["itemType"].getNode(selected).parent
        ) {
          this.expandParents(this.$refs["itemType"].getNode(selected).parent);
        }
        // getapi(`/api/app/asbitem/in-item-type/${currentKey}`)
        postapi("/api/app/asbitem/getasbitemlist", {
          itemTypeId: currentKey,
        }).then((res) => {
          if (res.code != -1) {
            this.tableData = res.data;
            this.tableData.forEach((item, index) => {
              if (e == item.id) {
                this.$refs["tableData"].setCurrentRow(item);
                this.rowick(item);
                this.tableScrollToRow(this.$refs.tableData, index);
                this.searchup(item, index)
              }
            });
          }
        });
      } else {
        this.remoteMethodes();
      }
    },
    searchup(data,index) {
      this.$nextTick(()=>{
        if(index==0){
          index=1
         }
         const targetTop = this.$refs["tableData"].$el.querySelectorAll('.el-table__body tr')[index-1].getBoundingClientRect().top
      const containerTop = this.$refs["tableData"].$el.querySelector('.el-table__body').getBoundingClientRect().top
      const scrollParent = this.$refs["tableData"].$el.querySelector('.el-table__body-wrapper')
      scrollParent.scrollTop = targetTop - containerTop
      })
    },
    expandParents(node) {
      node.expanded = true;
      if (node.parent) {
        this.expandParents(node.parent);
      }
    },
    tableScrollToRow(tableElement, rowIndex) {
      let theTableRows = tableElement.bodyWrapper.querySelectorAll(
        ".el-table__body tbody .el-table__row"
      );
      let scrollTop = 0;
      for (let i = 0; i < theTableRows.length; i++) {
        if (i === rowIndex) {
          break;
        }
        scrollTop += theTableRows[i].offsetHeight;
      }
      tableElement.bodyWrapper.scrollTop = scrollTop;
    },
    guiderow(row) {
      this.guideform = row;
    },
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex;
    },
    //指引信息删除
    deleteguidelines() {
      if (this.curRow.id == undefined || this.curRow.id == "") {
        this.$message.warning("请先选择组合项目");
      } else {
        if (
          this.guideform.asbitemId == "" ||
          this.guideform.asbitemId == undefined
        ) {
          this.$message.warning("请选择删除的数据");
        } else {
          this.$confirm("此操作确定后将永久删除该记录, 是否继续?", "提示", {
            confirmButtonText: "是",
            cancelButtonText: "否",
            type: "warning",
            cancelButtonClass:"difference",
        confirmButtonClass:"commonbutton"
          })
            .then(() => {
              this.formdata.guidanceinformationdata.splice(
                this.guideform.index,
                1
              );
            })
            .catch((err) => {
              if (err == "cancel") {
                this.$message.info("已取消删除");
              }
            });
        }
      }
    },
    //确定新增或者修改指引ruleForm
    determineguidelines() {
      this.$refs.ruleForms.validate((v) => {
        if (v) {
          postapi("/api/app/asbitem-guide", this.guideform).then((res) => {
            if (res.code != -1) {
              this.guidetitledialogVisible = false;
              this.getobtainguidance();
              //this.$message.success("创建成功");
            }
          });
        }
      });
    },
    //新增或者编辑需要的api中的id
    publicapi() {
      //获取体检中心
      getapi("/api/app/organization-units/by-code-all").then((res) => {
        if (res.code != -1) {
          this.organizationUnitdata = res.data;
        }
      });
      //获取组合项目
      // getapi("/api/app/asbitem/in-filter").then((res) => {
      //   this.asbitemdata = res.data.items;
      // });
      postapi("/api/app/asbitem/getasbitemlist").then((res) => {
        if (res.code != -1) {
          this.asbitemdata = res.data;
        }
      });
      //获取适用性别
      getapi("/api/app/for-sex").then((res) => {
        if (res.code != -1) {
          this.forsexdata = res.data;
        }
      });
    },
    //创建弹框
    createabulletbox() {
      // this.guidetitledialogVisible = true;
      // this.guideform = {};
      // this.guidetitle = 1;
      // this.publicapi();
      if (this.curRow.id == undefined || this.curRow.id == "") {
        this.$message.warning("请先选择组合项目");
      } else {
        let peisid = "";
        if (
          window.sessionStorage.getItem("peisid") === "null" ||
          window.sessionStorage.getItem("peisid") === undefined ||
          window.sessionStorage.getItem("peisid") === null
        ) {
          peisid = "";
        } else {
          peisid = window.sessionStorage.getItem("peisid");
        }
        this.formdata.guidanceinformationdata.push({
          medicalCenterId: peisid,
          asbitemId: this.curRow.id,
          forSexId: "A",
          guide: "",
        });
      }
    },
    saveguidelines() {
      this.$refs["guidanceinformation"].validate((valid, fields) => {
        if (!valid) {
          this.$message.warning(fields[Object.keys(fields)[0]][0].message);
          return false;
        }

        if (this.curRow.id == undefined || this.curRow.id == "") {
          this.$message.warning("请先选择组合项目");
        } else {
          let sampleGroupId = this.curRow.id;
          let sdate = [];
          this.formdata.guidanceinformationdata.forEach((element) => {
            sdate.push({
              medicalCenterId: element.medicalCenterId,
              forSexId: element.forSexId,
              guide: element.guide,
            });
          });
          postapi("/api/app/asbitemguide/createasbitemguidemany", {
            asbitemId: sampleGroupId,
            deatils: sdate,
          }).then((res) => {
            if (res.code != -1) {
              //this.$message.success("保存成功");
            }
          });
        }
      });
    },
    //获取指引信息guidanceinformationdata
    getobtainguidance(e) {
      if (e != undefined || e != "") {
        getapi(`/api/app/asbitemguide/getlistinasbitemid?AsbitemId=${e}`).then(
          (res) => {
            if (res.data != -1) {
              this.formdata.guidanceinformationdata = [...res.data];
            }
          }
        );
      } else {
        this.$message.warning("请先选择组合项目");
      }
    },
    //获取项目
    gitfleslist() {
      getporjectlists().then((res) => {
        if (res.code != -1) {
          this.filetelists = res.data;
          this.initfiletelists = [...res.data];
        }
      });
    },
    //搜索选择
    selectitem(v) {
      if (v) {
        if (this.curRow.id == undefined || this.curRow.id == "") {
          this.$message.warning("请先选择组合项目");
        } else {
          this.itemid = v.id;
          if (this.rightdata.length < 1) {
            this.rightdata.push({ displayName: v.displayName, id: v.id });
            this.isdislob = false;
          } else {
            for (let i = 0; i < this.rightdata.length; i++) {
              if (v.id === this.rightdata[i].id) {
                return this.$message.warning("已有该项目");
              }
            }
            this.rightdata.push({ displayName: v.displayName, id: v.id });
            this.isdislob = false;
          }
          this.$nextTick(() => {
            this.$refs["quickAsbOCX"].blur(); //total  asbItemId
            this.flitvalues = "";
            this.filetelists = deepCopy(this.initfiletelists);
            this.$refs["quickAsbOCX"].focus(); //total  asbItemId
          });
        }
      } else {
        this.remoteMethods();
      }
    },
    Onsubmit() {
      let sampleGroupId = this.form.id;
      let sdate = [];
      // let sss = { itemId: this.itemid, asbitemId: sampleGroupId };
      // sdate.push(sss);
      this.rightdata.forEach((element) => {
        sdate.push({ asbitemId: sampleGroupId, itemId: element.id });
      });
      // this.leftdata.forEach((element) => {
      //   sdate.push({ asbitemId: sampleGroupId, itemId: element.id });
      // });
      // this.leftdata.forEach((element) => {
      //   let sss = { sampleGroupId: sampleGroupId, asbitemId: element.id };
      //   sdate.push(sss);
      // });
      // sdate.push(sss);
      if (sampleGroupId == undefined || sampleGroupId == "") {
        this.$message.warning("请选择组合项目");
        this.isdislob = true;
      } else {
        postapi("/api/app/asbitemdetail/createasbitemdetailmany", {
          asbitemId: sampleGroupId,
          details: sdate,
        }).then((res) => {
          if (res.code != -1) {
            this.isdislob = true;
            //this.$message.success("确定成功！");
          }
        });
      }
      // console.log(sdate);
      // if (sampleGroupId == undefined) {
      //   this.$message.warning("请选择列表");
      // } else if (this.itemid == "") {
      //   this.$message.warning("请选择项目");
      // } else {
      //   postapi("/api/app/asbitem-detail/many", sdate).then((res) => {
      //     console.log("操作成功");
      //     this.isdislob = true;
      //   });
      // }
    },
    dbClickChoosedAsb(row, column, event) {
      let index = this.leftdata.findIndex((arr) => arr.id == row.id);
      this.leftdata.splice(index, 1);
      this.rightdata.push(row);
      this.isdislob = false;
      this.ary1 = [];
    },
    handleSelectionChange(val) {
      this.ary1 = val;
    },
    addAbs() {
      if (this.curRow.id == undefined || this.curRow.id == "") {
        this.$message.warning("请先选择组合项目");
      } else {
        if (this.ary1.length < 1) {
          this.$message.warning("请选择要添加的项目");
        } else {
          let temporaryLeft = [];
          temporaryLeft = this.leftdata.filter(
            (item) => !this.ary1.some((ele) => ele.id === item.id)
          );
          this.leftdata = [...temporaryLeft];
          this.ary1.forEach((item) => {
            this.rightdata.push(item);
          });
          this.isdislob = false;
          this.ary1 = [];
        }
      }
    },
    removeAbs(row) {
      let index = this.rightdata.findIndex((arr) => arr.id == row.id);
      this.rightdata.splice(index, 1);
      this.leftdata.push(row);
      this.isdislob = false;
      this.ary2 = [];
    },
    selecteditems(val) {
      this.ary2 = val;
    },
    delAbs() {
      if (this.curRow.id == undefined || this.curRow.id == "") {
        this.$message.warning("请先选择组合项目");
      } else {
        if (this.ary2.length < 1) {
          this.$message.warning("请选择要移除的项目");
        } else {
          let temporaryRight = [];
          temporaryRight = this.rightdata.filter(
            (item) => !this.ary2.some((ele) => ele.id === item.id)
          );
          this.rightdata = [...temporaryRight];
          this.ary2.forEach((item) => {
            this.leftdata.push(item);
          });
          this.isdislob = false;
          this.ary2 = [];
        }
      }
    },
    //右侧双击移动删除
    rightdelite(item, index) {
      this.isdislob = false;
      this.rightdata.splice(index, 1);
      this.leftdata.push(item);
      // this.updatedate();
    },
    //右侧点击选中
    rightindex(item, index) {
      this.nums = index;
      this.leftobj = item;
      // console.log(this.leftobj);
    },
    //左侧添加按钮
    addobj() {
      if (this.leftdata.length > 0) {
        this.leftdata.splice(this.num, 1);
        this.rightdata.push(this.rightobj);
        this.isdislob = false;
      }
    },
    //右移动
    removeright() {
      if (this.rightdata.length > 0) {
        this.rightdata.splice(this.num, 1);
        this.leftdata.push(this.leftobj);
        this.isdislob = false;
        // this.isdislob=false
        this.updatedate();
      }
    },
    //q全移去
    allclear() {
      if (this.curRow.id == undefined || this.curRow.id == "") {
        this.$message.warning("请先选择组合项目");
      } else {
        if (this.rightdata.length > 0) {
          this.rightdata.forEach((item) => {
            this.leftdata.push(item);
          });
          this.rightdata = [];
          this.isdislob = false;
        } else {
          this.$message.warning("没有可移除的项目");
        }
      }
    },
    //全添加
    addall() {
      if (this.curRow.id == undefined || this.curRow.id == "") {
        this.$message.warning("请先选择组合项目");
      } else {
        if (this.leftdata.length > 0) {
          this.leftdata.forEach((item) => {
            this.rightdata.push(item);
          });
          this.leftdata = [];
          this.isdislob = false;
        } else {
          this.$message.warning("没有可添加的项目");
        }
      }
    },
    //左侧双击事件
    shuanji(item, index) {
      this.leftdata.splice(index, 1);
      this.rightdata.push(item);
      this.isdislob = false;
    },
    clickPaixu(item, index) {
      this.rightobj = item;
      this.num = index;
    },
    //获取项目类别 3a0b0b10-719f-5824-6956-8cb70f204013 /api/app/item-type/by-code-all
    gitprojectcategory() {
      getapi("/api/app/item-type/by-code-all").then((res) => {
        if (res.code != -1) {
          this.projectid = res.data;
          this.initprojectid = [...res.data];
        }
      });
      postapi("/api/app/asbitem/getasbitemlist").then((res) => {
        if (res.code != -1) {
          this.initTableData = res.data;
          this.quckDepartment = [...res.data];
        }
      });
      // groupsandlist(this.pages).then((res) => {
      //   if(res.code!=-1){
      //     this.initTableData = [...res.data.items];
      //   this.quckDepartment=res.data.items;
      //   initTableData
      //   }
      // });
    },
    //ary1 需要追加的数据  ary2目标数组
    updatedate() {
      this.ary1.forEach((item) => {
        let iscz = false;
        this.ary2.forEach((item2) => {
          if (item2.id == item.id) {
            iscz = true;
          }
        });
        if (!iscz) {
          this.ary2.push(item);
          // this.allid.push({ id: item.id });
        }
      });
    },
    ischangsItemTypeId(v) {
      if (v.length > 1) {
        this.form.itemTypeId = this.form.itemTypeId.slice(-1)[0];
      } else {
        this.form.itemTypeId = this.form.itemTypeId[0];
      }
      this.$refs.itemTypeIds.toggleDropDownVisible();
    },
    //项目类别选择
    ischangs(v) {
      if (v) {
        if (this.curRow.id == undefined || this.curRow.id == "") {
          this.$message.warning("请先选择组合项目");
        } else {
          this.$refs.example.toggleDropDownVisible();
          let last = v.slice(-1)[0];
          getapi(`/api/app/item/in-item-type/${last}`).then((res) => {
            if (res.code != -1) {
              let bq = [];
              bq = res.data.filter(
                (item) => !this.rightdata.some((ele) => ele.id === item.id)
              );
              this.leftdata = [...bq];
            }
          });
        }
      } else {
        this.remoteMethod();
      }
    },
    bindidclose() {
      this.form=this.$options.data().form
    },
    rowDrop() {
      this.$nextTick(() => {
        const tbody = document.querySelector(".el-table__body-wrapper tbody");
        const _this = this;
        Sortable.create(tbody, {
          handle: ".move",
          animation: 300,
          onChoose({ oldIndex }) {
            _this.$refs["tableData"].setCurrentRow(_this.tableData[oldIndex]);
          },
          onEnd({ newIndex, oldIndex }) {
            _this.isshow = false;
            const currRow = _this.tableData.splice(oldIndex, 1)[0];
            _this.tableData.splice(newIndex, 0, currRow);
            _this.rowick(_this.tableData[newIndex]);
            _this.tableData.map((item, index) => {
              if (index == newIndex && index == oldIndex) {
              } else if (index == oldIndex) {
              } else if (index == newIndex) {
              }
            });
          },
        });
      });
    },
    //取消按钮
    cancellation() {
      postapi("/api/app/asbitem/getasbitemlist", { itemTypeId: this.initItemTypeId }).then(
        (res) => {
          if (res.code != -1) {
            this.tableData = res.data;
                  this.$message.info("操作取消");
      this.isshow = true;
          }
        }
      );
    },
    //确定排序
    assertion() {
      const result = [];
      this.tableData.forEach((item, index) => {
        // const currentDisplayOrder = this.initTableData[index].displayOrder;
        // if (item.displayOrder != currentDisplayOrder) {
          result.push({ id: item.id, displayOrder: index+1 });
        // }
      });
      combination({ itemList: result }).then((res) => {
        if (res.code != -1) {
          //this.$message.success("操作成功");
          this.isshow = true;
        }
        // this.getlist();
      });
    },
    //置底
    setlow() {
      this.form = { ...this.curRow };
      if (this.form.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        samplesetlow(this.form.id, 2).then((res) => {
          if (res.code != -1) {
            this.getItemIdList();
            //this.$message.success("操作成功");
          }
        });
      }
    },
    //置顶
    topping() {
      this.form = { ...this.curRow };
      if (this.form.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        samplesetlow(this.form.id, 1).then((res) => {
          if (res.code != -1) {
            this.getItemIdList();
            //this.$message.success("操作成功");
          }
        });
      }
    },
    //删除
    deleteid() {
      this.form = { ...this.curRow };
      if (this.form.id == undefined) {
        this.$message.warning("请选择操作的数据");
      } else {
        this.$confirm("是否确认删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          cancelButtonClass:"difference",
        confirmButtonClass:"commonbutton"
        }).then(() => {
          deletescombinationprojectid(this.form.id).then((res) => {
            if (res.code != -1) {
              this.getItemIdList();
              this.curRow = this.$options.data().curRow;
              //this.$message.success("删除成功");
            }
          });
        });
        // deletescombinationprojectid(this.form.id).then((res) => {
        //   console.log("删除成功");
        //   this.getlist();
        // });
      }
    },
    //编辑弹框
    editpopup() {
      this.form = { ...this.curRow };
      if (this.form.id == undefined) {
        this.$message.warning("请点击选择操作的数据");
      } else {
        this.form.price = Number(this.form.price);
        this.title = 2;
        this.dialogVisible = true;
        if (this.$refs.ruleForm !== undefined) {
          this.$refs.ruleForm.resetFields();
        }
        asbitemgetid(this.form.id).then((res) => {
          if (res.code != -1) {
            this.form = res.data;
            if (res.data.isItemResultMerger == "Y") {
              this.form.isItemResultMergerBox = true;
            } else {
              this.form.isItemResultMergerBox = false;
            }
            if (res.data.isBeforeEat == "Y") {
              this.form.isBeforeEatBox = true;
            } else {
              this.form.isBeforeEatBox = false;
            }
            if (res.data.isDiagnosisFunction == "Y") {
              this.form.isDiagnosisFunctionBox = true;
            } else {
              this.form.isDiagnosisFunctionBox = false;
            }
            if (res.data.isContinueProcess == "Y") {
              this.form.isContinueProcessBox = true;
            } else {
              this.form.isContinueProcessBox = false;
            }
            if (res.data.isPictureRotate == "Y") {
              this.form.isPictureRotateBox = true;
            } else {
              this.form.isPictureRotateBox = false;
            }
            if (res.data.isCheck == "Y") {
              this.form.isCheckBox = true;
            } else {
              this.form.isCheckBox = false;
            }
            if (res.data.isActive == "Y") {
              this.form.isActiveBox = true;
            } else {
              this.form.isActiveBox = false;
            }
          }
        });
        //性别
        // examinationgender().then((res) => {
        //   this.forSexId = res.data;
        // });
        //适用性别
        getapi("/api/app/for-sex").then((res) => {
          if(res.code!=-1){
            this.forSexId = res.data;
          }
        });
        //项目类别
        // projectlist().then((res) => {
        //   this.itemTypeId = res.data;
        // });
        //仪器类别
        instrumentlist().then((res) => {
          if (res.code != -1) {
            this.deviceTypeId = res.data;
          }
        });
        // //发票项目类别
        // invoicetypelist().then((res) => {
        //   if (res.code != -1) {
        //     this.invoiceItemTypeId = res.data;
        //   }
        // });
        postapi("/api/app/CollectItemType/GetList").then((res) => {
        if (res.code != -1) {
          this.collectItemType=[...res.data]
        }
      });
      }
    },
    editcancellation() {
      this.dialogVisible = false;
      // this.$refs.itemTypeIds.toggleDropDownVisible();
    },
    //确定新增或者编辑
    addoredit() {
      this.$refs.ruleForm.validate((v) => {
        if (v) {
          if (this.title == 1) {
            let obj = {
              displayName: this.form.displayName,
              shortName: this.form.shortName,
              forSexId: this.form.forSexId,
              itemTypeId: this.form.itemTypeId,
              price: Number(this.form.price),
              deviceTypeId: this.form.deviceTypeId,
              invoiceItemTypeId: this.form.invoiceItemTypeId,
              isItemResultMerger: this.form.isItemResultMerger,
              isBeforeEat: this.form.isBeforeEat,
              clinicalMeaning: this.form.clinicalMeaning,
              defaultResult: this.form.defaultResult,
              queueTime: this.form.queueTime,
              isDiagnosisFunction: this.form.isDiagnosisFunction,
              diagnosisFunction: this.form.diagnosisFunction,
              isContinueProcess: this.form.isContinueProcess,
              isPictureRotate: this.form.isPictureRotate,
              isCheck: this.form.isCheck,
              isActive: this.form.isActive,
              collectItemTypeId:this.form.collectItemTypeId
            };
            newcombination(obj).then((res) => {
              if (res.code != -1) {
                this.getItemIdList();
                this.dialogVisible = false;
                this.$nextTick(() => {
                  this.$refs["tableData"].setCurrentRow(res.data);
                  this.rowick(res.data);
                });
                //this.$message.success("新增成功");
                // this.$refs.itemTypeIds.toggleDropDownVisible();
              }
            });
          } else if (this.title == 2) {
            let obj = {
              displayName: this.form.displayName,
              shortName: this.form.shortName,
              forSexId: this.form.forSexId,
              itemTypeId: this.form.itemTypeId,
              price: Number(this.form.price),
              deviceTypeId: this.form.deviceTypeId,
              invoiceItemTypeId: this.form.invoiceItemTypeId,
              isItemResultMerger: this.form.isItemResultMerger,
              isBeforeEat: this.form.isBeforeEat,
              clinicalMeaning: this.form.clinicalMeaning,
              defaultResult: this.form.defaultResult,
              queueTime: this.form.queueTime,
              isDiagnosisFunction: this.form.isDiagnosisFunction,
              diagnosisFunction: this.form.diagnosisFunction,
              isContinueProcess: this.form.isContinueProcess,
              isPictureRotate: this.form.isPictureRotate,
              isCheck: this.form.isCheck,
              isActive: this.form.isActive,
              collectItemTypeId:this.form.collectItemTypeId
            };
            updateombination(this.form.id, obj).then((res) => {
              if (res.code != -1) {
                this.tableData.forEach((item, index) => {
                  if (res.data.id == item.id) {
                    this.$set(this.tableData, index, res.data);
                  }
                });
                this.dialogVisible = false;
                this.$nextTick(() => {
                  this.rowick(res.data);
                });
                //this.$message.success("修改成功");
                // this.$refs.itemTypeIds.toggleDropDownVisible();
              }
            });
          }
        }
      });
    },
    getItemIdList() {
      postapi("/api/app/asbitem/getasbitemlist", {
        itemTypeId: this.initItemTypeId,
      }).then((res) => {
        if (res.code != -1) {
          this.tableData = res.data;
        }
      });
    },
    //新增弹框
    addll() {
      if (this.initItemTypeId == undefined || this.initItemTypeId == "") {
        this.$message.warning("请选择项目类别");
      } else {
        this.dialogVisible = true;
        this.title = 1;
        if (this.$refs.ruleForm !== undefined) {
          this.$refs.ruleForm.resetFields();
        }
        this.form=this.$options.data().form
        this.form.itemTypeId = this.initItemTypeId;
        this.$nextTick(() => {
          this.$refs.refinput.focus();
        });
        //性别
        // examinationgender().then((res) => {
        //   if (res.code != -1) {
        //     this.forSexId = res.data;
        //   }
        // });
        getapi("/api/app/for-sex").then((res) => {
          if(res.code!=-1){
            this.forSexId = res.data;
          }
        });
        // //项目类别
        // projectlist().then((res) => {
        //   this.itemTypeId = res.data;
        // });
        //仪器类别
        instrumentlist().then((res) => {
          if (res.code != -1) {
            this.deviceTypeId = res.data;
          }
        });
        // //发票项目类别
        // invoicetypelist().then((res) => {
        //   if (res.code != -1) {
        //     this.invoiceItemTypeId = res.data;
        //   }
        // });
        postapi("/api/app/CollectItemType/GetList").then((res) => {
        if (res.code != -1) {
          this.collectItemType=[...res.data]
        }
      });
      }
    },
    rowick(row) {
      this.curRow = { ...row };
      this.form = { ...row };
      // asbitemgetid(row.id).then((res) => {
      //   this.curRow = { ...res.data };
      //   this.form = res.data;
      // });
      this.values = row.itemTypeId;
      getapi(
        `/api/app/asbitem-detail/asbitem-detail-in-item?AsbitemId=${row.id}`
      ).then((res) => {
        if (res.code != -1) {
          this.rightdata = [...res.data];
          getapi(`/api/app/item/in-item-type/${this.values}`).then((res) => {
            // this.leftdata = [...res.data];
            if (res.code != -1) {
              let bq = [];
              bq = res.data.filter(
                (item) => !this.rightdata.some((ele) => ele.id === item.id)
              );
              this.leftdata = [...bq];
            }
          });
        }
      });
      this.getobtainguidance(this.curRow.id);
      this.publicapi();
    },
    getSummaries(param){
       const { columns, data } = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '合计';
            return;
          }
         if(index === 1){
          sums[index] = data.length+'个';
            return;
         }
        });

        return sums;
    },
    getlist() {
      groupsandlist().then((res) => {
        if (res.code != -1) {
          this.initTableData = [...res.data];
          this.tableData = [...res.data];
          this.quckDepartment = [...res.data];
        }
      });
    },
  },
};
</script>
<style scoped>
@import "../../assets/css/global_button.css";
@import "../../assets/css/global_dialog.css";
@import "../../assets/css/global_table.css";
@import "../../assets/css/global_form.css";
@import "../../assets/css/global_input.css";
@import "../../assets/css/global.css";
.mainleftbox {
  flex: 1;
}
.Selectbutton {
  margin: 0 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.mainbox {
  display: flex;
  justify-content: center;
  margin-top: 5px;
}
.box {
  display: flex;
  flex-direction: column;
}
/* form表单每一项的下边距 */
:deep .el-form-item {
  margin-bottom: 14px;
}
/* 去掉input textarea的手动扩张样式 */
:deep(.el-textarea__inner) {
  resize: none;
}
/* el-dialog的头部样式 */
:deep .el-dialog__header {
  padding: 11px 20px 11px;
}
/* el-dialog的主体样式 */
:deep .el-dialog__body {
  padding: 0px 20px 0px;
}
/* el-divider样式 */
:deep .el-divider--horizontal {
  margin: 0px 0 12px;
}
/* el-dialog的底部样式 */
:deep .el-dialog__footer {
  padding: 0px 20px 14px;
}
/* 默认结果后面下拉框样式 */
:deep .downText .el-input--suffix .el-input__inner {
  width: 0;
  height: 100%;
  padding: 0 19px;
}
/* 默认结果后面下拉框图标样式 */
:deep .downText .el-input--suffix .el-input__suffix {
  right: 12px;
}
/* 默认结果后面下拉框 */
:deep .downText {
  display: flex !important;
}
/* 诊断函数后面按钮样式 */
:deep .el-input-group__append {
  padding: 0 11px;
}
/* 默认结果整体样式 */
.my-el-form-item :deep .el-form-item__content {
  line-height: 0 !important;
}
.my-el-form-item :deep .el-input__icon {
  line-height: 0 !important;
}
/* 指引信息 */
.guidelines :deep .el-form-item {
  margin-bottom: 0;
}
.seachinput {
  width: 250px;
  margin-right: 110px;
}
:deep .seachinput .el-select {
  width: 100%;
}
.layeredleftright {
  width: 95%;
  display: flex;
  flex-direction: column;
}
:deep .el-tree-node>.el-tree-node__children{
  overflow: visible;
}
</style>
