<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>
      </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: 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"
              ></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-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.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.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-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>


    </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)"
        >提交
        </el-button>
        <el-button type="primary" size="small" icon="search" @click="cancelDialog"
        >取消
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {disableUdi, removeDiRl, removeRl, thirdSysDetail, updatetSingleUdiInfo} from "@/api/basic/product/udiRelevance";
import {isBlank} from "@/utils/strUtil";
import {filterByUuid} 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";


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,
      isUseDyCheck: true,
      useNumEnable: true,
      sysList: [],
      detailList: [],
      fromDeptOptions: [],
      hsflOptions: [],
      defaultSys: null,
      isImport: false,
      selectErpDialogVisible: false,  //选入ERP产品
      editSingleDiDialogVisible: false,
      editSingleFormat: {
        uuid: null,
        relId: null,
        sptm: null,
        packUnit: null,
        measname: null,
        nameCode: null
      },
    }
  },
  components: {
    selectErp,
    ProductSingleEdit,
    Treeselect
  },
  created() {
    this.useMutiChange(true)
    this.getThirdSysDetail();
    if (this.editQuery.isDateBy == 1) {
      this.editQuery.recentDateTime = this.editQuery.recentDateTime / 24;
    }
    this.getTreeselect();
    let ttquery = {
      id: this.relevanceEdit.id
    }
    this.getDetailList(ttquery);


    if (this.editQuery.basicPrductRemak8 != null) {
      this.findHsflMethod(this.editQuery.basicPrductRemak8);
    }
  },
  methods: {
    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() {
      updatetSingleUdiInfo(this.editSingleFormat)
        .then((response) => {
          if (response.code == 20000) {
            let ttquery = {
              id: this.relevanceEdit.id
            }
            this.getDetailList(ttquery);
            this.editSingleDiDialogVisible = false;
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
          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
      };
    },
  }
}
</script>

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

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

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

</style>
