<template>
  <div>
    <el-form
      :model="editQuery"
      :rules="rules"
      ref="editQuery"
      border
      label-width="130px"
    >
      <el-card>
        <el-table :data="sysList" style="width: 100%;   margin-bottom: 8px" key="2" border>
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column label="第三方系统名称" prop="sysName" show-overflow-tooltip></el-table-column>
          <el-table-column label="第三方系统物资编码" prop="thirdId" show-overflow-tooltip></el-table-column>
          <el-table-column label="第三方系统物资名称" prop="thirdName" show-overflow-tooltip></el-table-column>
          <el-table-column label="第三方系统规格型号" prop="spec" show-overflow-tooltip></el-table-column>
          <el-table-column label="注册/备案号" prop="registerNo" show-overflow-tooltip></el-table-column>
          <el-table-column label="生产企业" prop="manufactory" show-overflow-tooltip></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="addSelectErp(scope.row)" :disabled="scope.row.thirdId==editQuery.nameCode">
                关联
              </el-button>
              <el-button type="text" @click.native.stop="removeErp(scope.row)"
                         :disabled="editQuery.flbm==null || scope.row.thirdId==null || scope.row.thirdId==''">解绑
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
      <el-card>
        <div style=" float: left;
                        text-align: left;
                        font-weight: bold;
                        margin-bottom: 8px">
          <span>产品标识:</span>
        </div>
        <div style=" float: right;
                        text-align: right;
                        margin-bottom: 8px;">
          <el-button type="primary" size="mini" icon="search" @click="removeDi" v-if="productType!=1"
                     style="text-align:right">解绑DI器械信息
          </el-button>
        </div>
        <el-table v-loading="loading" :data="detailList" style="width: 100%; " border key="3" highlight-current-row
                  @current-change="handleDetail">
          <el-table-column label="产品最小销售标识" prop="nameCode" show-overflow-tooltip></el-table-column>
          <el-table-column label="物资名称" prop="cpmctymc" show-overflow-tooltip></el-table-column>
          <el-table-column label="包装级别" prop="packLevel" show-overflow-tooltip></el-table-column>
          <el-table-column label="包装单位" prop="packUnit" show-overflow-tooltip></el-table-column>
          <el-table-column label="操作" width="180px">
            <template slot-scope="scope">
              <el-button type="text" @click.native.stop="singleDiEdit(scope.row)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>

        <template>
          <p class="form-title2">流通时采用的计量单位设置</p>
        </template>
        <el-row :gutter="20">
          <el-col :span="11" class="el-col">
            <el-form-item label="计量单位:" prop="distributeLevel" label-width="160px">

              <el-select v-model="editQuery.distributeLevel" size="small" style="width: 90%"
                         clearable
                         placeholder="请选择计量单位"
              >
                <el-option
                  v-for="item in levelUnitList"
                  :key="item.packLevel"
                  :value="item.packLevel"
                  :label="item.packUnit"
                >
                  <span style="float: right; color: #8492a6; font-size: 13px">单位:{{ item.packUnit }}</span>
                  <span style="float: left">层级:{{ item.packLevel }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11" class="el-col">
            <el-form-item label="允许采集的最大层级:" prop="distributeMaxLevel" label-width="160px">
              <el-select v-model="editQuery.distributeMaxLevel" size="small" style="width: 90%"
                         clearable
                         placeholder="请选择允许采集的最大层级"
              >
                <el-option
                  v-for="item in levelUnitList"
                  :key="item.packLevel"
                  :value="item.packLevel"
                  :label="item.packLevel"
                >
                  <span style="float: right; color: #8492a6; font-size: 13px">单位:{{ item.packUnit }}</span>
                  <span style="float: left">层级:{{ item.packLevel }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-divider></el-divider>
        <template>
          <p class="form-title2">使用时采用的计量单位设置</p>
        </template>
        <el-row :gutter="20">
          <el-col :span="11" class="el-col">
            <el-form-item label="计量单位:" prop="useLevel" label-width="160px">

              <el-select v-model="editQuery.useLevel" size="small" style="width: 90%"
                         clearable
                         placeholder="请选择计量单位"
              >
                <el-option
                  v-for="item in levelUnitList"
                  :key="item.packLevel"
                  :value="item.packLevel"
                  :label="item.packUnit"
                >
                  <span style="float: right; color: #8492a6; font-size: 13px">单位:{{ item.packUnit }}</span>
                  <span style="float: left">层级:{{ item.packLevel }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="11" class="el-col">
            <el-form-item label="允许采集的最大层级:" prop="useMaxLevel" label-width="160px">
              <el-select v-model="editQuery.useMaxLevel" size="small" style="width: 90%"
                         clearable
                         placeholder="请选择允许采集的最大层级"
              >
                <el-option
                  v-for="item in levelUnitList"
                  :key="item.packLevel"
                  :value="item.packLevel"
                  :label="item.packLevel"
                >
                  <span style="float: right; color: #8492a6; font-size: 13px">单位:{{ item.packUnit }}</span>
                  <span style="float: left">层级:{{ item.packLevel }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

      </el-card>
      <el-card>
        <!--<el-row type="flex" class="edit-row" style="margin-top: 20px">-->
        <!--  <el-col :span="12">-->
        <!--    <el-form-item label="收费项目编码:">-->
        <!--      <el-input-->
        <!--        style="width: 60%"-->
        <!--        size="small"-->
        <!--        placeholder="选择项目收费编码"-->
        <!--        v-model="editQuery.payFeeCode"-->
        <!--      ></el-input>-->
        <!--      <el-button type="primary" size="mini" style="margin-left: 10px" @click="selectPayFeecode">选入</el-button>-->
        <!--    </el-form-item>-->
        <!--  </el-col>-->
        <!--</el-row>-->
        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="计量单位:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.measname"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生产企业:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.manufactory"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="商品名称:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.spmc"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="产品描述:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.cpms"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="物资所属分类:">
              <treeselect
                v-model="editQuery.relCode"
                :options="fromDeptOptions"
                :normalizer="normalizer"
                :show-count="true"
                style="width: 80%;"
                placeholder="选择物资所属分类"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="医保编码:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.ybbm"
                v-debounce-input:500ms="getYbHcData"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="一级分类名称:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.catalogname1"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="二级分类名称:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.catalogname2"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="三级分类名称:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.catalogname3"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="耗材材质:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.matrial"
                disabled
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="库存积压预警数量:">
              <el-input
                style="width: 80%"
                size="small"
                type="number"
                oninput="value=value.replace(/[^\d]/g,'')"
                splaceholder="请输入内容"
                v-model="editQuery.overStockNum"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="低库存预警数量:">
              <el-input
                style="width: 80%"
                size="small"
                type="number"
                oninput="value=value.replace(/[^\d]/g,'')"
                splaceholder="请输入内容"
                v-model="editQuery.lowStockNum"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="edit-row">
          <el-col :span="12">
            <el-form-item label="近效期预警时间:">
              <el-input
                style="width: 80%"
                size="small"
                type="number"
                splaceholder="请输入内容"
                v-model="editQuery.recentDateTime"
                @change="handleChange"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预警时间单位:">
              <el-select v-model="editQuery.isDateBy" style="width: 80%" placeholder="状态" clearable>
                <el-option label="天" :value="1"></el-option>
                <el-option label="小时" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-row type="flex" class="edit-row">
          <el-col :span="12" v-if="productRemarkSet.remarkEnable1">
            <el-form-item :label="productRemarkSet.remarkTitle1+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak1"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="productRemarkSet.remarkEnable2">
            <el-form-item :label="productRemarkSet.remarkTitle2+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak2"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="edit-row">
          <el-col :span="12" v-if="productRemarkSet.remarkEnable3">
            <el-form-item :label="productRemarkSet.remarkTitle3+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak3"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="productRemarkSet.remarkEnable4">
            <el-form-item :label="productRemarkSet.remarkTitle4+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak4"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="edit-row">
          <el-col :span="12" v-if="productRemarkSet.remarkEnable5">
            <el-form-item :label="productRemarkSet.remarkTitle5+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak5"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="productRemarkSet.remarkEnable6">
            <el-form-item :label="productRemarkSet.remarkTitle6+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak6"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="edit-row">
          <el-col :span="12" v-if="productRemarkSet.remarkEnable7">
            <el-form-item :label="productRemarkSet.remarkTitle7+':'">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.basicPrductRemak7"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="productRemarkSet.remarkEnable8">
            <el-form-item :label="productRemarkSet.remarkTitle8+':'">
              <el-select
                v-model="editQuery.basicPrductRemak8"
                filterable
                remote
                clearable="true"
                reserve-keyword
                placeholder="请选择物价类别"
                :remote-method="findHsflMethod"
                :loading="loading"
                style="width: 80%"
              >
                <el-option
                  v-for="item in hsflOptions"
                  :key="item.hsbm"
                  :label="item.hsmc"
                  :value="item.hsbm"
                >
                  <span style="float: left">{{ item.hsmc }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="分类编码：" prop="require">
              <el-select
                v-model="editQuery.flbm"
                filterable
                remote
                clearable="true"
                style="width: 80%"
                reserve-keyword
                placeholder="请选择"
                :loading="loading"
                @change="classifyChange()"
              >
                <el-option
                  v-for="item in classifyList"
                  :key="item.code"
                  :label="item.name"
                  :value="item.code">
                  <span>{{ item.code }}</span>
                  <span>{{ item.name }}</span>
                </el-option>
              </el-select>


            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="包装规格:">
              <el-input
                style="width: 80%"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.bzgg"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="工位预警数量:">
              <el-input
                type="number"
                style="width: 80%"
                min="1"
                size="small"
                splaceholder="请输入内容"
                v-model="editQuery.workPlaceCount"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>


      </el-card>
      <el-collapse v-model="activeNames" style="margin-top: 12px">
        <el-collapse-item title="高级设置" name="1"
                          style="font-size: 19px;
          margin-left: 25px;
          font-weight: bold;">
          <div style="width: 96%;margin: 0 auto">
            <el-row>
              <el-col span="5">
                <span>参数</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <span>设置</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span>参数设置说明</span>
              </el-col>
            </el-row>
            <el-divider direction="horizontal"></el-divider>

            <el-row>
              <el-col span="5">
                <span class="sptext">是否需要扫码</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.requireScanCode" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="是" :value=1></el-option>
                  <el-option label="否" :value=0></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">是否需要扫码</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>

            <el-row>
              <el-col span="5">
                <span class="sptext">是否禁用</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.isDisable" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">是否禁用</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <!--            <el-row>-->
            <!--              <el-col span="5">-->
            <!--                <span class="sptext">是否寄售</span>-->
            <!--              </el-col>-->
            <!--              <el-divider direction="vertical"></el-divider>-->
            <!--              <el-col span="5">-->
            <!--                <el-select v-model="editQuery.isAdavence" style="width: 65%" placeholder="状态" clearable>-->
            <!--                  <el-option label="是" :value="true"></el-option>-->
            <!--                  <el-option label="否" :value="false"></el-option>-->
            <!--                </el-select>-->
            <!--              </el-col>-->
            <!--              <el-divider direction="vertical"></el-divider>-->
            <!--              <el-col span="13">-->
            <!--                <span class="sptext">是否寄售</span>-->
            <!--              </el-col>-->
            <!--            </el-row>-->
            <!--            <el-divider></el-divider>-->


            <el-row>
              <el-col span="5">
                <span class="sptext">采购类型</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.purType" style="width: 65%" placeholder="选择采购类型" clearable>
                  <el-option label="普通入账产品" :value="1"></el-option>
                  <el-option label="预验收产品" :value="2"></el-option>
                  <el-option label="寄售产品" :value="3"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">采购类型</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>

            <el-row>
              <el-col span="5">
                <span class="sptext">产品属性</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.attributeType" style="width: 65%" placeholder="选择产品属性" clearable>
                  <el-option label="设备" :value="1"></el-option>
                  <el-option label="耗材" :value="2"></el-option>
                  <el-option label="伴随服务费" :value="3"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">产品属性</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">耗材类别</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.hcType" style="width: 65%" placeholder="选择耗材类别" clearable>
                  <el-option label="高值耗材" :value="1"></el-option>
                  <el-option label="普通耗材" :value="2"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">产品属性</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">是否组套</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.isStack" style="width: 65%" placeholder="选择是否组套" clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">是否组套</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>

            <el-row>
              <el-col span="5">
                <span class="sptext">多次/重复使用耗材</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.useMuti" style="width: 65%" @change="setZdcfsycs" placeholder="状态"
                           clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">多次/重复使用耗材</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">最小包装可使用次数</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-input style="width: 65%" size="small" splaceholder="请输入内容" :disabled="!editQuery.useMuti"
                          type="number" v-model="editQuery.useNum"></el-input>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">最小包装可使用次数</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">启用使用单元</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.isUseDy" style="width: 65%"
                           :disabled="editQuery.useMuti==true "
                           placeholder="状态" clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">启用使用单元</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">是否可配送</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.dispatch" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">是否可配送</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">是否集采产品</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.groupBuy" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">是否集采产品</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">允许无批次</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.allowNoBatch" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="允许" :value="true"></el-option>
                  <el-option label="不允许" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">允许无批次</span>
              </el-col>
            </el-row>

            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">允许无失效日期</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>

              <el-col span="5">
                <el-select v-model="editQuery.allowNoExpire" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="允许" :value="true"></el-option>
                  <el-option label="不允许" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">允许无失效日期</span>
              </el-col>
            </el-row>

            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">允许无生产日期</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">

                <el-select v-model="editQuery.allowNoProduct" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="允许" :value="true"></el-option>
                  <el-option label="不允许" :value="false"></el-option>
                </el-select>

              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">允许无生产日期</span>
              </el-col>
            </el-row>

            <el-divider></el-divider>


            <el-row>
              <el-col span="5">
                <span class="sptext">允许无序列号</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">

                <el-select v-model="editQuery.allowNoSerial" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="允许" :value="true"></el-option>
                  <el-option label="不允许" :value="false"></el-option>
                </el-select>

              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">允许无序列号</span>
              </el-col>
            </el-row>

            <el-divider></el-divider>

            <el-row>
              <el-col span="5">
                <span class="sptext">是否必须维护资质材料</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-select v-model="editQuery.needCert" style="width: 65%" placeholder="状态" clearable>
                  <el-option label="是" :value="true"></el-option>
                  <el-option label="否" :value="false"></el-option>
                </el-select>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">是否必须维护资质材料</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>
            <!--<el-row>-->
            <!--  <el-col span="5">-->
            <!--    <span class="sptext">是否拆零</span>-->
            <!--  </el-col>-->
            <!--  <el-divider direction="vertical"></el-divider>-->
            <!--  <el-col span="5">-->
            <!--    <el-select v-model="editQuery.splitEnable" style="width: 65%" placeholder="是否拆零" clearable>-->
            <!--      <el-option label="是" :value="true"></el-option>-->
            <!--      <el-option label="否" :value="false"></el-option>-->
            <!--    </el-select>-->
            <!--  </el-col>-->
            <!--  <el-divider direction="vertical"></el-divider>-->
            <!--  <el-col span="13">-->
            <!--    <span class="sptext">是否拆零</span>-->
            <!--  </el-col>-->
            <!--</el-row>-->
            <!--<el-divider></el-divider>-->
            <!--<el-row>-->
            <!--  <el-col span="5">-->
            <!--    <span class="sptext">是否自动赋码</span>-->
            <!--  </el-col>-->
            <!--  <el-divider direction="vertical"></el-divider>-->
            <!--  <el-col span="5">-->
            <!--    <el-select v-model="editQuery.autoCode" style="width: 65%" placeholder="是否自动赋码" clearable>-->
            <!--      <el-option label="是" :value="true"></el-option>-->
            <!--      <el-option label="否" :value="false"></el-option>-->
            <!--    </el-select>-->
            <!--  </el-col>-->
            <!--  <el-divider direction="vertical"></el-divider>-->
            <!--  <el-col span="13">-->
            <!--    <span class="sptext">是否自动赋码</span>-->
            <!--  </el-col>-->
            <!--</el-row>-->
            <el-divider></el-divider>
            <el-row>
              <el-col span="5">
                <span class="sptext">使用周期</span>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="5">
                <el-input style="width: 65%" size="small" splaceholder="请输入内容" :disabled="this.useNumEnable"
                          type="number" v-model="editQuery.useExpireTime"></el-input>
              </el-col>
              <el-divider direction="vertical"></el-divider>
              <el-col span="13">
                <span class="sptext">使用周期(天)</span>
              </el-col>
            </el-row>
            <el-divider></el-divider>

          </div>
        </el-collapse-item>

        <!--        <el-collapse-item title="参数设置" name="2"-->
        <!--                          style="font-size: 19px;-->
        <!--          margin-left: 25px;-->
        <!--          font-weight: bold;">-->
        <!--          <div style="width: 96%;margin: 0 auto">-->

        <!--            <el-row :gutter="20">-->
        <!--              <el-col :span="11" class="el-col">-->
        <!--                <el-form-item label="流通计量层级标识:" prop="distributeLevelDi" label-width="160px">-->
        <!--                  <el-select v-model="editQuery.distributeLevelDi" size="small" style="width: 90%"-->
        <!--                             clearable-->
        <!--                             placeholder="请选择流通计量层级标识">-->
        <!--                    <el-option-->
        <!--                      v-for="item in detailList"-->
        <!--                      :key="item.nameCode"-->
        <!--                      :value="item.nameCode"-->
        <!--                      :label="item.nameCode">-->
        <!--                      <span style="float: left">{{ item.nameCode }}</span>-->
        <!--                      <span style="float: right; color: #8492a6; font-size: 13px">{{ item.packLevel }}</span>-->
        <!--                    </el-option>-->
        <!--                  </el-select>-->
        <!--                </el-form-item>-->
        <!--              </el-col>-->
        <!--              <el-col :span="11" class="el-col">-->
        <!--                <el-form-item label="使用计量层级标识:" prop="useLevelDi" label-width="160px">-->
        <!--                  <el-select v-model="editQuery.useLevelDi" size="small" style="width: 90%"-->
        <!--                             clearable-->
        <!--                             disabled-->
        <!--                             placeholder="请选择流通计量层级标识">-->
        <!--                    <el-option-->
        <!--                      v-for="item in detailList"-->
        <!--                      :key="item.nameCode"-->
        <!--                      :value="item.nameCode"-->
        <!--                      :label="item.nameCode">-->
        <!--                      <span style="float: left">{{ item.nameCode }}</span>-->
        <!--                      <span style="float: right; color: #8492a6; font-size: 13px">{{ item.packLevel }}</span>-->
        <!--                    </el-option>-->
        <!--                  </el-select>-->
        <!--                </el-form-item>-->
        <!--              </el-col>-->
        <!--              <el-col :span="11" class="el-col">-->
        <!--                <el-form-item label="流通计量层级单位:" prop="distributeLevelUnit" label-width="160px">-->
        <!--                  <el-input style="width: 90%" size="small" placeholder="请输入流通计量层级单位"-->
        <!--                            disabled-->
        <!--                            v-model="editQuery.distributeLevelUnit"-->
        <!--                  ></el-input>-->
        <!--                </el-form-item>-->
        <!--              </el-col>-->
        <!--              <el-col :span="11" class="el-col">-->
        <!--                <el-form-item label="使用计量层级标识:" prop="useLevelUnit" label-width="160px">-->
        <!--                  <el-input style="width: 90%" size="small" placeholder="请输入使用计量层级标识"-->
        <!--                            disabled-->
        <!--                            v-model.trim="editQuery.useLevelUnit"-->
        <!--                  ></el-input>-->
        <!--                </el-form-item>-->
        <!--              </el-col>-->
        <!--              <el-col :span="11" class="el-col">-->
        <!--                <el-form-item label="流通时含计量单元数量:" prop="distributeLevelCount" label-width="160px">-->
        <!--                  <el-input style="width: 90%" size="small" placeholder="请输入流通时包含计量单元的数量"-->
        <!--                            v-model.trim="editQuery.distributeLevelCount"-->
        <!--                  ></el-input>-->
        <!--                </el-form-item>-->
        <!--              </el-col>-->
        <!--              <el-col :span="11" class="el-col">-->
        <!--                <el-form-item label="使用时含计量单元数量:" prop="useLeverCount" label-width="160px">-->
        <!--                  <el-input style="width: 90%" size="small" placeholder="请输入使用时包含计量单元的数量"-->
        <!--                            v-model.trim="editQuery.useLeverCount"-->
        <!--                  ></el-input>-->
        <!--                </el-form-item>-->
        <!--              </el-col>-->

        <!--            </el-row>-->
        <!--          </div>-->
        <!--        </el-collapse-item>-->
      </el-collapse>
      <div style="text-align: center; margin-top: 12px">
        <el-button
          type="primary"
          size="small"
          icon="search"
          @click="onAddSubmit(false)"
          :loading="onAddLoading"
        >提交
        </el-button>
        <el-button
          size="small"
          icon="search"
          @click="cancelSubmit"
        >取消
        </el-button>
      </div>

    </el-form>

    <el-dialog
      title="耗材字典-从指定系统添加器械信息"
      :visible.sync="selectErpDialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="85%"
      append-to-body
      v-if="selectErpDialogVisible"
    >
      <selectErp
        :closeDialog="closeDialog"
        :uuid="uuid"
        :relId="relId"
        :isImport="isImport"
        :data="thisData"
        :defaultSys="defaultSys"
        @closeUdi="closeUdi"
        :supEnable="false"
      ></selectErp>
    </el-dialog>
    <el-dialog
      title="耗材字典-编辑"
      :visible.sync="editSingleDiDialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="45%"
      v-if="editSingleDiDialogVisible"
      append-to-body
    >
      <product-single-edit
        :editQuery="editSingleFormat"
      ></product-single-edit>

      <div style="text-align: center;margin-top: 12px">
        <el-button type="primary" size="small" icon="search" @click="onAddSingleSubmit(false)" :loading="addLoading"
        >提交
        </el-button>
        <el-button type="primary" size="small" icon="search" @click="cancelDialog"
        >取消
        </el-button>
      </div>
    </el-dialog>

    <el-dialog
      title="收费项目选入"
      :visible.sync="tollProjectDialogVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="70%"
      v-if="tollProjectDialogVisible"
      append-to-body
    >
      <!--<product-single-edit-->
      <!--  :editQuery="editSingleFormat"-->
      <!--&gt;</product-single-edit>-->
      <selectmedicalSuppliesDialog
        :getData="getData"
      >
      </selectmedicalSuppliesDialog>
      <!--<div style="text-align: center;margin-top: 12px">-->
      <!--  <el-button type="primary" size="small" icon="search" @click="onAddSingleSubmit(false)" :loading="addLoading"-->
      <!--  >提交-->
      <!--  </el-button>-->
      <!--  <el-button type="primary" size="small" icon="search" @click="cancelDialog"-->
      <!--  >取消-->
      <!--  </el-button>-->
      <!--</div>-->
    </el-dialog>
  </div>
</template>

<script>
import {
  getYbHcflDetail,
  disableUdi,
  removeDiRl,
  removeRl,
  thirdSysDetail,
  updatetSingleUdiInfo, updatetUdiInfos
} from "@/api/basic/product/udiRelevance";
import {isBlank} from "@/utils/strUtil";
import {filterByUuid, levelByUuid} from "@/api/basic/product/udiInfo";
import ProductSingleEdit from "@/views/basic/product/productSingleEdit";
import selectErp from "./udiInfoselectErpUdi";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import Treeselect from "@riophae/vue-treeselect";
import {getListMenu, getOneName} from '@/api/basic/basicHospType'
import {getSupComapnys} from "@/api/purchase/supCompany";
import {getHslbs} from "@/api/thrsys/thrHsfl";
import {filterClassify} from "@/api/purchase/classifyCode"
import selectmedicalSuppliesDialog from "./selectmedicalSuppliesDialog"
import {
  calculateDistCount, calculateUseCount
} from '@/api/basic/product/drugUdiinfos'

export default {
  name: "productEdit",
  props: {
    editQuery: {
      type: Object,
      required: true,
    },
    uuid: {
      type: Object,
      required: true,
    },
    relId: {
      type: Object,
      required: true,
    },
    thisData: {
      type: Object,
      required: true,
    },
    productRemarkSet: {
      type: Object,
      required: true,
    },
    relevanceEdit: {
      type: Object,
      required: true,
    },
    productType: {
      type: Object,
      required: true,
    },
    closePre: {
      type: Function,
      required: true,
    },
  },

  data() {
    return {
      loading: false,
      ybHcflDetail: {},
      isUseDyCheck: true,
      useNumEnable: true,
      sysList: [],
      detailList: [],
      fromDeptOptions: [],
      hsflOptions: [],
      defaultSys: null,
      isImport: false,
      selectErpDialogVisible: false,  //选入ERP产品
      editSingleDiDialogVisible: false,
      tollProjectDialogVisible: false,
      editSingleFormat: {
        uuid: null,
        relId: null,
        sptm: null,
        packUnit: null,
        measname: null,
        nameCode: null
      },
      classifyList: [],
      addLoading: false,
      onAddLoading: false,
      levelUnitList: [],
      maxLevel: 1,
    }
  },
  components: {
    selectErp,
    ProductSingleEdit,
    Treeselect,
    selectmedicalSuppliesDialog
  },
  created() {
    // console.log("dayinshshhs", this.editQuery)
    this.useMutiChange(true)
    this.getThirdSysDetail();
    if (this.editQuery.isDateBy == 1) {
      this.editQuery.recentDateTime = this.editQuery.recentDateTime / 24;
    }

    if (this.editQuery.distributeMaxLevel == null) {
      this.editQuery.distributeMaxLevel = 1
    }
    if (this.editQuery.useMaxLevel == null) {
      this.editQuery.useMaxLevel = 1
    }
    this.getTreeselect();
    let ttquery = {
      id: this.relevanceEdit.id
    }
    this.getDetailList(ttquery);


    if (this.editQuery.basicPrductRemak8 != null) {
      this.findHsflMethod(this.editQuery.basicPrductRemak8);
    }
    this.classifySearch("")
    this.getDiLevel()
  },
  methods: {
    distributeLevelDiChange(val) {
      const matchingItem = this.detailList.find(item => item.nameCode == val);
      if (matchingItem) {
        this.editQuery.distributeLevelUnit = matchingItem.packUnit;
        this.editQuery.distributeLevel = matchingItem.packLevel
      }
      calculateDistCount(matchingItem).then((res) => {
        this.editQuery = {
          ...this.editQuery,
          distributeLevelCount: res.data.distributeLevelCount,
        }
      })
    },
    useLevelDiChange(val) {
      const matchingItem = this.detailList.find(item => item.nameCode == val);
      if (matchingItem) {
        this.editQuery.useLevelUnit = matchingItem.packUnit;
        this.editQuery.useLevel = matchingItem.packLevel;
      }
      calculateUseCount(matchingItem).then((res) => {
        this.editQuery = {
          ...this.editQuery,
          useLeverCount: res.data.useLeverCount,
        }
      })
    },
    classifyChange() {
      this.classifyChange(this.editQuery.flbm)
      let item = this.classifyList.find(item => item.code == this.editQuery.flbm)
      if (item != null) this.editQuery.requireScanCode = item.requireScanCode;
    },
    classifySearch(key) {
      let query = {
        key: key,
      }
      filterClassify(query)
        .then(response => {
          this.loading = false;
          this.classifyList = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.classifyList = [];
        });
    },
    getYbHcData() {
      let query = {
        specificationCode: this.editQuery.ybbm
      };
      getYbHcflDetail(query).then((response) => {
        if (response.code == 20000) {
          this.ybHcflDetail = response.data
          this.editQuery.catalogname1 = this.ybHcflDetail.catalogname1
          this.editQuery.catalogname2 = this.ybHcflDetail.catalogname2
          this.editQuery.catalogname3 = this.ybHcflDetail.catalogname3
          this.editQuery.matrial = this.ybHcflDetail.matrial
          this.$forceUpdate();
        } else {
          this.editQuery.catalogname1 = ""
          this.editQuery.catalogname2 = ""
          this.editQuery.catalogname3 = ""
          this.editQuery.matrial = ""
          this.$forceUpdate();
        }
      }).catch(() => {
      })

    },
    onClose() {
      this.$emit("onClose")
    },
    diableChange() {
      let query = {
        relId: this.pId
      }
      disableUdi(query)
        .then((response) => {
          if (response.code != 20000) {
            this.editQuery.isDisable = false;
            this.$message.error(response.message);
          }

        })
        .catch(() => {
          this.loading = false;
          this.detailList = [];
        });
    },
    handleChange() {
      if (this.editQuery.recentDateTime > 30) {
        this.$message.error("近效期预警时间必须小于等于30！！！");
        this.editQuery.recentDateTime = 30;
      }
      if (this.editQuery.recentDateTime < 0) {
        this.$message.error("近效期预警时间必须大于等于0！！！");
        this.editQuery.recentDateTime = 0;
      }
    },
    addSelectErp(row) {
      this.defaultSys = row.sysId;
      this.isImport = false;
      this.selectErpDialogVisible = true;
    },
    removeDi() {
      this.$confirm("此操作将解除该绑定DI器械信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let query = {
            relId: this.editQuery.id,
          };
          removeDiRl(query)
            .then((response) => {
              if (response.code == 20000) {
                this.$message({
                  type: "success",
                  message: "解绑成功！",
                });
                this.$emit("closePre", true);
                this.cancelDialog();
              } else {
                this.$message.error(response.message);
              }
            })
            .catch(() => {
            });
        })
        .catch(() => {
        });
    },
    cancelDialog() {
      this.editSingleDiDialogVisible = false;
    },
    singleDiEdit(val) {
      let temp = val;
      this.editSingleFormat.uuid = temp.uuid;
      this.editSingleFormat.id = temp.id;
      this.editSingleFormat.sptm = temp.sptm;
      this.editSingleFormat.packUnit = temp.packUnit;
      this.editSingleFormat.measname = temp.measname;
      this.editSingleFormat.nameCode = temp.nameCode;
      this.editSingleFormat.cpmctymc = temp.cpmctymc;
      this.editSingleDiDialogVisible = true;
    },
    onAddSingleSubmit() {
      this.addLoading = true
      updatetSingleUdiInfo(this.editSingleFormat)
        .then((response) => {
          this.addLoading = false
          if (response.code == 20000) {
            let ttquery = {
              id: this.relevanceEdit.id
            }
            this.getDetailList(ttquery);
            this.editSingleDiDialogVisible = false;
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
          this.addLoading = false
          this.cancelDialog();
        });
    },

    removeErp(row) {
      this.$confirm("此操作将解除该绑定产品信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let query = {
            relId: this.relId,
            thirdSys: row.sysId
          };
          removeRl(query)
            .then((response) => {
              if (response.code == 20000) {
                this.$message({
                  type: "success",
                  message: "删除成功！",
                });
                this.getThirdSysDetail();
              } else {
                this.$message.error(response.message);
              }
            })
            .catch(() => {
            });
        })
        .catch(() => {
        });
    },
    useDyCheckChange(val) {
      this.editQuery.useNum = 0;
    },
    useDyCountChange(val) {
      if (val) {
        this.editQuery.useNum = this.editQuery.zxxsbzbhsydysl;
      } else {
        this.editQuery.useNum = 0;
      }
    },
    getThirdSysDetail() {
      let query = {
        id: this.relevanceEdit.id,
      };
      thirdSysDetail(query)
        .then((response) => {
          this.loading = false;
          this.sysList = response.data.list || [];
          this.resetThirdId();
        })
        .catch(() => {
          this.loading = false;
          this.sysList = [];
        });
    },
    resetThirdId() {
      this.sysList.forEach((item) => {
        if (item.sysId === "thirdId") {
          this.editQuery.thirdId = item.thirdId;
        } else if (item.sysId === "thirdId1") {
          this.editQuery.thirdId1 = item.thirdId;
        } else if (item.sysId === "thirdId2") {
          this.editQuery.thirdId2 = item.thirdId;
        } else if (item.sysId === "thirdId3") {
          this.editQuery.thirdId3 = item.thirdId;
        } else if (item.sysId === "thirdId4") {
          this.editQuery.thirdId4 = item.thirdId;
        }
      })
    },
    getDetailList(detailQuery) {
      this.loading = true;
      filterByUuid(detailQuery)
        .then((response) => {
          this.loading = false;
          this.detailList = response.data || [];
        })
        .catch(() => {
          this.loading = false;
          this.detailList = [];
        });
    },
    useMutiChange(val) {
      if (val) {
        this.useNumEnable = false;
        // this.editQuery.useNum = this.editQuery.zxxsbzbhsydysl;
        if (!isBlank(this.editQuery.zxxsbzbhsydysl)) {
          if (this.editQuery.zxxsbzbhsydysl > 0) {
            this.isUseDyCheck = true;
          }
        }
      } else {
        this.useNumEnable = true;
        this.editQuery.useNum = 0;
      }
    },
    closeDialog() {
      this.selectErpDialogVisible = false;
    },
    closeUdi(val) {
      this.selectErpDialogVisible = false;
      this.getThirdSysDetail();
    },
    groupBuyChange() {
      if (this.editQuery.groupBuy == true) {
        this.editQuery.dispatch = true;
      } else {
        this.editQuery.dispatch = false;
      }
    },
    getTreeselect() {
      getOneName().then(res => {
        const menu = {id: res.data.id, code: res.data.code, name: res.data.name, children: []};
        getListMenu({}).then(response => {
          this.fromDeptOptions = [];
          menu.children = this.handleTree(response.data, "code", "parentCode");
          console.log(menu)
          this.fromDeptOptions.push(menu);
        });
      })
    },
    setZdcfsycs() {
      if (this.editQuery.useMuti == false) {
        this.editQuery.useNum = 0;
      }
    },


    findHsflMethod(query) {
      this.hsflOptions = [];
      let cQuery = {
        key: query,
        page: 1,
        limit: 20
      };
      getHslbs(cQuery)
        .then((response) => {
          this.loading = false;
          this.hsflOptions = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
        });
    }
    ,

    /** 转换菜单数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.code,
        label: node.name,
        children: node.children
      };
    },

    /**
     * 选择收费项目
     */
    selectPayFeecode() {
      this.tollProjectDialogVisible = true
    },

    getData(data) {
      this.tollProjectDialogVisible = false
      this.editQuery.payFeeCode = data.medCatalogCode
    },
    onAddSubmit(relSubmit) {
      this.editQuery.relSubmit = relSubmit;
      this.editQuery.splitEnable = true;
      this.editQuery.autoCode = true;
      this.onAddLoading = true
      updatetUdiInfos(this.editQuery)
        .then((response) => {
          this.onAddLoading = false
          if (response.code == 20000) {
            this.$emit("closePre", true);
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
          this.onAddLoading = false
          this.$emit("closePre", true);
        });
    },
    cancelSubmit() {
      this.$emit("closePre", true);
    },

    getDiLevel() {
      let query = {
        id: this.relId
      }
      this.loading = true
      levelByUuid(query)
        .then((response) => {
          this.loading = false
          this.levelUnitList = response.data || []
          this.findMaxLevelObject()
        })
        .catch(() => {
          this.loading = false
          this.levelUnitList = []
        })
    },
    findMaxLevelObject() {
      this.maxLevel = 1;
      for (const obj of this.levelUnitList) {
        if (obj.packLevel > this.maxLevel) {
          this.maxLevel = Number(obj.packLevel);
        }
      }
    },
  },
  directives: {
    'debounce-input': {
      inserted(el, binding) {
        let timeout
        el.addEventListener('input', () => {
          clearTimeout(timeout)
          timeout = setTimeout(() => {
            binding.value()
          }, parseInt(binding.arg) || 300)
        })
      }
    }
  }

}
</script>

<style scoped>
.vue-treeselect--searchable:not(.vue-treeselect--disabled) .vue-treeselect__value-container {
  cursor: text;
  width: 500px;
}

.form-title2 {
  font-size: 16px;
  font-family: Noto Sans SC;
  font-weight: bold;
  color: #303133;
}

.el-divider {
  margin: 6px 0px 8px 0px;
  background: 0 0;
  border-top: 1px solid #E6EBF5;
}

.sptext {
  font-size: 13px;
  font-weight: normal;
}

</style>
