<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="addDrugLevel"-->
          <!--                     style="text-align:right"-->
          <!--          >新增药品层级-->
          <!--          </el-button>-->
          <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"
          @current-change="handleDetail"
        >
          <el-table-column label="序号" type="index"></el-table-column>
          <el-table-column label="层级标识" prop="nameCode" show-overflow-tooltip width="160">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.nameCode" style="width: 100%;margin: 4px;"
                        :disabled="true"
              ></el-input>
            </template>
          </el-table-column>
          <!--            1.主标识，2，使用单元标识，3.本体标识，4，包装标识-->
          <el-table-column label="标识类型" prop="diType" show-overflow-tooltip width="160">
            <template slot-scope="scope">
              <el-select v-model="scope.row.diType"
                         :disabled="true"
                         style="width: 90%" placeholder="选择标识类型" clearable>
                <el-option label="最小销售标识" :value="1"></el-option>
                <!--                  <el-option label="使用单元标识" :value="2"></el-option>-->
                <!--                  <el-option label="本体标识" :value="3"></el-option>-->
                <el-option label="外包装标识" :value="4"></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="包装级别" prop="packLevel" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.packLevel" style="width: 100%"
                        type="number"
                        :disabled="true"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="层级单位" prop="packUnit" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.packUnit" style="width: 100%"
                        :disabled="scope.$index !== selectedIndex"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="下级数量" prop="bhxjsl" show-overflow-tooltip width="100">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.bhxjsl" style="width: 100%"
                        type="number"
                        :disabled="scope.$index !== selectedIndex"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="下级单位" prop="xjdw" show-overflow-tooltip width="120">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.xjdw" style="width: 100%"
                        :disabled="scope.$index !== selectedIndex"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="下级标识" prop="bhxjcpbm" show-overflow-tooltip width="160">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.bhxjcpbm" style="width: 100%"
                        :disabled="scope.$index !== selectedIndex "
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column label="上级标识" prop="sjcpbm" show-overflow-tooltip width="160">
            <template slot-scope="scope">
              <el-input size="small" v-model="scope.row.sjcpbm" style="width: 100%"
                        :disabled="scope.$index !== selectedIndex"
              ></el-input>
            </template>
          </el-table-column>

          <el-table-column label="操作" width="180px" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" size="small" v-if="scope.$index == selectedIndex " @click.stop="true"
                         @click.native="levelSave(scope.row)"
              >保存
              </el-button>
              <el-button
                type="text"
                size="small"
                v-if="scope.$index != selectedIndex "
                @click.stop="true"
                @click.native="rowChange(scope.$index,scope.row)"
              >编辑
              </el-button>

              <!--:disabled=" scope.row.id != null"-->
              <!--              <el-button-->
              <!--                type="text"-->
              <!--                size="small"-->
              <!--                @click.stop="true"-->
              <!--                @click.native="deleteLevel(scope.$index, 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
                         @change="distributeLevelDiChange"
                         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
                         @change="useLevelDiChange"
                         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-row :gutter="20">
          <el-col :span="11" class="el-col">
            <el-form-item label="拆包后可用时长(小时):" prop="unpackUseTime" label-width="160px">

              <el-input v-model="editQuery.unpackUseTime" size="small" style="width: 90%"
                        clearable
                        placeholder="请输入拆包后可用时长(小时)"
              >
              </el-input>
            </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>

      <!-- <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} from '@/api/basic/product/udiRelevance'
import {updateById} from '@/api/basic/udiRelevance'
import {filterByUuid} from '@/api/basic/udiInfo'
import selectErp from "./udiInfoselectErpUdi";
import selectUdiVersion from '@/views/basic/product/UdiinfoSelectVersion'
import {getHslbs, getThrProductType} from "@/api/thrsys/thrHsfl";
import {filterClassify} from '@/api/purchase/classifyCode'
import { calculateDistCount } from '@/api/basic/product/drugUdiinfos'
import { levelByUuid } from '@/api/basic/product/udiInfo'

export default {
  name: 'productEdit',
  props: {
    editQuery: {
      type: Object,
      required: true
    },
    productRemarkSet: {
      type: Object,
      required: true
    },
    closeDialog: {
      type: Function,
      required: true
    },
  },

  data() {
    return {
      ybHcflDetail: {},
      isUseDyCheck: false,
      useNumEnable: true,
      editDialogVisible: false,
      sysList: {},
      relId: null,
      defaultSys: null,
      // detailList: {},
      isImport: null,
      thisData: {
        nameCode: null,
        cpmctymc: null,
        ggxh: null
      },
      selectVersionVisible: false,
      originUuid: null,
      uuid: null,
      editSingleFormat: {
        uuid: null,
        relId: null,
        sptm: null,
        packUnit: null,
        measname: null,
      },
      editSingleDiDialogVisible: false,
      selectErpDialogVisible: false,  //选入ERP产品
      hsflOptions: [],
      thrTypeOptions: [],
      classifyList: [],
      selectedIndex: null,
      detailList: [
        // 初始化一个空对象或包含默认值的对象
        {
          productId: null,
          nameCode: '',
          packLevel: null,
          bhxjsl: null,
          isDisabled: false,
          isUpDisabled: true,
          rowDisabled: false
        }
      ],
      levelUnitList: [],
    }
  },

  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,
        }
      })
    },
    getDiLevel() {
      let query = {
        id: this.editQuery.rlId
      }
      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);
        }
      }
    },

    classifyChange() {
      this.classifySearch(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.catalogcode = this.ybHcflDetail.catalogcode
          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.catalogcode = ""
          this.editQuery.catalogname1 = ""
          this.editQuery.catalogname2 = ""
          this.editQuery.catalogname3 = ""
          this.editQuery.matrial = ""
          this.$forceUpdate();
        }
      }).catch(() => {
      })

    },
    onClose() {
      this.$emit("onClose")
    },
    submitUpload() {
      var data = {
        id: this.editQuery.prid,
        uid: this.editQuery.rlId,
        sptm: this.editQuery.sptm,
        spmc: this.editQuery.spmc,
        measname: this.editQuery.measname,
        manufactory: this.editQuery.manufactory,
        price: this.editQuery.price,
        cpms: this.editQuery.cpms,
        ybbm: this.editQuery.ybbm,
        purType: this.editQuery.purType,
        attributeType: this.editQuery.attributeType,
        hcType: this.editQuery.hcType,
        isStack: this.editQuery.isStack,
        overStockNum: this.editQuery.overStockNum,
        lowStockNum: this.editQuery.lowStockNum,
        recentDateTime: this.editQuery.recentDateTime,
        isDateBy: this.editQuery.isDateBy,
        relSupId: this.editQuery.id,
        groupBuy: this.editQuery.groupBuy,
        basicPrductRemak1: this.editQuery.basicPrductRemak1,
        basicPrductRemak2: this.editQuery.basicPrductRemak2,
        basicPrductRemak3: this.editQuery.basicPrductRemak3,
        basicPrductRemak4: this.editQuery.basicPrductRemak4,
        basicPrductRemak5: this.editQuery.basicPrductRemak5,
        basicPrductRemak6: this.editQuery.basicPrductRemak6,
        basicPrductRemak7: this.editQuery.basicPrductRemak7,
        basicPrductRemak8: this.editQuery.basicPrductRemak8,
        catalogcode: this.editQuery.catalogcode,
        catalogname1: this.editQuery.catalogname1,
        catalogname2: this.editQuery.catalogname2,
        catalogname3: this.editQuery.catalogname3,
        matrial: this.editQuery.matrial,
      }

      updateById(data).then(res => {
        if (res.code == 20000) {
          this.closeDialog();
        } else {
          this.$message.error(response.message);
        }
      })

    },
    getThirdSysDetail() {
      let query = {
        id: this.editQuery.rlId,
      };
      thirdSysDetail(query)
        .then((response) => {
          this.loading = false;
          this.sysList = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.sysList = [];
        });
    },
    addSelectErp(row) {
      this.defaultSys = row.sysId;
      this.isImport = false;
      this.relId = this.editQuery.rlId;
      this.thisData = this.editQuery;
      this.selectErpDialogVisible = true;
    },
    removeErp(row) {
      this.$confirm("此操作将解除该绑定产品信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let query = {
            relId: this.editQuery.rlId,
            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(() => {
        });
    },
    removeDi() {
      this.$confirm("此操作将解除该绑定DI器械信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let query = {
            relId: this.editQuery.rlId,
          };
          removeDiRl(query)
            .then((response) => {
              if (response.code == 20000) {
                this.$message({
                  type: "success",
                  message: "删除成功！",
                });
                this.editDialogVisible = false;
                this.closeDialog();
              } else {
                this.$message.error(response.message);
              }
            })
            .catch(() => {
            });
        })
        .catch(() => {
        });
    },
    getDetailList(detailQuery) {
      this.loading = true;
      filterByUuid(detailQuery)
        .then((response) => {
          this.loading = false;
          this.detailList = response.data || [];
        })
        .catch(() => {
          this.loading = false;
          this.detailList = [];
        });
    },
    closeUdi2() {
      this.selectUdiDialogVisible = false;
      this.selectErpDialogVisible = false;
      this.selectLocalVisible = false;
      this.selectVersionVisible = false;
      this.getThirdSysDetail();
    },

    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;
        });
    },

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

  },
  components: {
    selectErp
  },
  created() {
    this.getDiLevel()
    this.getThirdSysDetail();
    var ttquery = {
      id: this.editQuery.rlId,
      page: 1,
      limit: 10,
    };
    this.getDetailList(ttquery);
    // if (this.editQuery.basicPrductRemak8 != null) {
    this.findHsflMethod(this.editQuery.basicPrductRemak8);
    // }
    // if (this.editQuery.basicPrductRemak7 != null) {
    this.findThrTypeMethod(this.editQuery.basicPrductRemak7);
    // }
    this.classifySearch()
    console.log("editQuery:", this.editQuery)
  }, 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>

