<template>
  <!-- 配送目录记录 -->
  <div style="display: flex">
    <el-card style="width: 18%; margin-right: 18px; border-radius: 6px">
      <el-tabs v-model="activeNametree" type="card" @tab-click="tabClick" stretch>
        <!-- <el-tab-pane label="按分类" name="grp"></el-tab-pane> -->
        <el-tab-pane label="按机构" name="org"></el-tab-pane>
      </el-tabs>
      <el-tree
        :data="data"
        :props="defaultProps"
        node-key="spdId"
        @node-click="handleNodeClick"
        default-expand-all="true"
        style="margin-top: 10px"
      ></el-tree>
    </el-card>
    <div class="right-common-box">
      <el-form :model="listQuery" ref="listQuery" :inline="true" label-width="90px">
        <!-- <el-form-item size="mini" label="医保编码" prop="hiCode" class="long">
          <el-input v-model="listQuery.hiCode" placeholder="请输入医保编码"></el-input>
        </el-form-item> -->
        <el-form-item size="mini"  label="耗材信息" prop="prodName" class="long">
          <el-input v-model="listQuery.prodName" placeholder="请输入耗材名称/医保编码"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="规格" prop="spec" class="long">
          <el-input v-model="listQuery.spec" placeholder="请输入规格"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="型号" prop="mol" class="long">
          <el-input v-model="listQuery.mol" placeholder="请输入型号"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="生产企业" prop="prodEntp" class="long">
          <el-input v-model="listQuery.prodEntp" placeholder="请输入生产企业"></el-input>
        </el-form-item>
        
        <el-form-item size="mini" label="是否集采" prop="isFas" class="long">
          <el-select v-model="listQuery.isFas" placeholder="请选择是否集采" clearable>
            <el-option
              v-for="item in isFasData"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="mini" label="耗材类别" prop="mcsType" class="long">
          <el-select v-model="listQuery.mcsType" placeholder="请选择耗材类别" clearable>
            <el-option
              v-for="item in mcsTypeData"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="mini" label="生产来源" prop="prodSouc" class="long">
          <el-select v-model="listQuery.prodSouc" placeholder="请选择生产来源" clearable>
            <el-option
              v-for="item in SoucData"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item size="mini" label="材质" prop="matl" class="long">
          <el-input v-model="listQuery.matl" placeholder="请输入材质"></el-input>
        </el-form-item>
        <el-form-item size="mini" label="注册证号" prop="regcertno" class="long">
          <el-input v-model="listQuery.regcertno" placeholder="请输入注册证号"></el-input>
        </el-form-item>

        <el-form-item size="mini" label="目录来源" prop="isPub" class="long">
          <el-select v-model="listQuery.isPub" placeholder="请选择目录来源" clearable>
            <el-option
              v-for="item in isPubData"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        
        <el-form-item size="mini" label="当前状态" prop="status" class="long">
          <el-select v-model="listQuery.status" placeholder="请选择当前状态" clearable>
            <el-option
              v-for="item in statusData"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="right-button">
          <el-button type="primary" @click="getHospConsum('search')">查询</el-button>
          <el-button @click="reset('consumableData')">重置</el-button>
        </div>
      <!-- <div class="right-button" v-if="btnShow">
        <el-button type="primary" icon="el-icon-plus" @click="handleUpdate('search')"
          >挂网目录新增
        </el-button>
        <el-button type="primary" icon="el-icon-plus" @click="handleFadd('search')"
          >非挂网目录新增
        </el-button>
      </div> -->
      <el-table
        v-loading="listLoading"
        element-loading-text="加载中"
        :data="list"
        fit
        height="500"
        stripe
        border
      >
        <template slot="empty">
          <img src="@/assets/nopage.png" alt />
          <p>暂无数据</p>
        </template>
        <el-table-column fixed type="index" label="序号" width="60" />
        <el-table-column label="耗材信息" min-width="340">
          <template slot-scope="scope">
             <mcs-info :info="scope.row"></mcs-info> 
          </template>
        </el-table-column>
        <el-table-column label="医保编码" prop="hiCode" width="80" />
        <el-table-column label="规格" prop="spec" width="80" />
        <el-table-column label="型号" prop="mol" width="80" />
        <el-table-column label="材质" prop="matl" width="80" />
        <el-table-column label="是否集采" prop="isFas" width="80">
          <template #default="{ row }">
            <span v-if="row.isFas == '0'">否</span>
            <span v-if="row.isFas == '1'">是</span>
          </template>
        </el-table-column>
        <el-table-column label="采购单位" prop="purcUnt" width="80" />
        <el-table-column label="采购价" prop="purcPric" width="80" />
        <el-table-column label="驳回原因" prop="rejtRea" width="80" />
        <el-table-column label="目录来源" prop="isPub" width="80" fixed="right">
          <template #default="{ row }">
            <span v-if="row.isPub == '1'">挂网</span>
            <span v-if="row.isPub == '0'">非挂网</span>
          </template>
        </el-table-column>
        <el-table-column label="保存时间" prop="saveTime" width="140" />
        <el-table-column label="提交时间" prop="sbmtTime" width="140" />
        <el-table-column label="操作类型" prop="opeType" width="80" fixed="right">
        </el-table-column>
        <el-table-column label="当前状态" prop="status" width="80" fixed="right">
          <template #default="{ row }">
            <span v-if="row.status == 'A'">待提交</span>
            <span v-if="row.status == 'B'">待审核</span>
            <span v-if="row.status == 'C'">审核通过</span>
            <span v-if="row.status == 'R'">驳回
            </span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="160">
          <template slot-scope="scope">
            <div>
              <el-button type="text" @click="handleDui(scope.row)"  v-if="scope.row.status=='C'">详情</el-button>
              <el-button type="text" @click="handleDui(scope.row)" v-else>编辑</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <yl-pagination
        v-show="total > 0"
        :total="total"
        :page.sync="listQuery.current"
        :limit.sync="listQuery.size"
        @pagination="getHospConsum"
      />
    </div>

    <el-dialog title="调价申请" :visible.sync="dialogPrice" width="55%">
      <el-form
        ref="dataForm"
        :rules="rules"
        :model="temp"
        label-position="right"
        label-width="80px"
      >
        <el-row>
          <el-col :span="8">
            <el-form-item label="药品编码" prop="drugListId">
              <el-input v-model.trim="temp.drugListId" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="药品名称" prop="drugName">
              <el-input v-model.trim="temp.drugName" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="剂型" prop="dosformName">
              <el-input v-model.trim="temp.dosformName" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="规格" prop="specName">
              <el-input v-model.trim="temp.specName" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="包装单位" prop="pacUnt">
              <el-input v-model.trim="temp.pacUnt" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产企业" prop="prodEntp">
              <el-input v-model.trim="temp.prodEntp" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="当前价格" prop="pricInit">
              <el-input v-model.trim="temp.pricInit" readonly placeholder="请输入" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="调整价格" prop="pricCurr">
              <el-input v-model.trim="temp.pricCurr" placeholder="请输入调整后价格" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="申请原因" prop="appyRea">
            <el-input
              type="textarea"
              v-model.trim="temp.appyRea"
              placeholder="请输入调价原因"
            />
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="上传文件" prop="fileId" :rules="rules.uploadRequired">
            <yl-upload :fileId="temp.fileId" @getUpload="getUpload" urlName="acco">
              <template v-slot:dec>只能上传pdf文件</template>
            </yl-upload>
          </el-form-item>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogPrice = false">取消</el-button>
        <el-button type="primary" @click="commitData()" :loading="ccLoad">确认</el-button>
      </div>
    </el-dialog>
    <el-dialog title="选择耗材" :visible.sync="dialogAdd" width="70%">
      <template>
        <el-form :model="listQueryadd" ref="listQueryadd" :inline="true"  label-width="90px">
          <el-form-item  size="mini" label="耗材名称" prop="prodName" class="long">
            <el-input
              v-model="listQueryadd.prodName"
              placeholder="请输入耗材名称"
            ></el-input>
          </el-form-item>
          <el-form-item  size="mini" label="规格" prop="spec" class="long">
            <el-input v-model="listQueryadd.spec" placeholder="请输入耗材规格"></el-input>
          </el-form-item>
          <!-- <el-form-item label="耗材编码" prop="materialId" class="long">
            <el-input
              v-model="listQueryadd.materialId"
              placeholder="请输入耗材编码"
            ></el-input>
          </el-form-item> -->
          <el-form-item  size="mini" label="医保编码" prop="hiCode" class="long">
            <el-input
              v-model="listQueryadd.hiCode"
              placeholder="请输入医保编码"
            ></el-input>
          </el-form-item>
          <el-form-item  size="mini" label="是否集采" prop="isFas" class="long">
            <el-select
              v-model="listQueryadd.isFas"
              placeholder="请选择是否集采"
              clearable
            >
              <el-option
                v-for="item in isFasData"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item  size="mini" label="注册证号" prop="regcertno" class="long">
            <el-input
              v-model="listQueryadd.regcertno"
              placeholder="请输入注册证号"
            ></el-input>
          </el-form-item>
          <el-form-item  size="mini" label="生产企业" prop="prodEntp" class="long">
            <el-input
              v-model="listQueryadd.prodEntp"
              placeholder="请输入生产企业"
            ></el-input>
          </el-form-item>
          <el-form-item  size="mini" label="型号" prop="mol" class="long">
            <el-input
              v-model="listQueryadd.mol"
              placeholder="请输入型号"
            ></el-input>
          </el-form-item>
          <!-- <el-form-item label="对码状态" prop="stas">
          <el-select
            v-model="listQuery.stas"
            placeholder="请选择对码状态"
            clearable
          >
            <el-option
              v-for="item in crspFlgOption"
              :key="item.value"
              :label="item.name"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item> -->
          <el-form-item>
            <el-button type="primary" @click="getdialog('search')">查询</el-button>
            <el-button @click="resetdialog('consumableData')">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table
          ref="multipleTable"
          v-loading="listdialogLoading"
          element-loading-text="加载中"
          fit
          stripe
          border
          :data="consumableData"
          border
          style="width: 100%"
          row-key="id"
          height="500"
          @selection-change="handleSelectionChange"
          highlight-current-row
        >
          <el-table-column
            type="selection"
            :selectable="selected"
            :reserve-selection="true"
            width="55"
          ></el-table-column>
          <el-table-column prop="hiCode" label="医保编码"> </el-table-column>
          <el-table-column prop="prodName" label="耗材名称" width="180">
          </el-table-column>
          <el-table-column prop="pubonlnPric" label="挂网价格">
          </el-table-column>
          <el-table-column prop="isFas" label="是否集采">
            <template #default="{ row }">
              <span v-if="row.isFas == '0'">否</span>
              <span v-if="row.isFas == '1'">是</span>
            </template>
          </el-table-column>
          <el-table-column prop="fasBtch" label="集采批次"> </el-table-column>
          <!-- <el-table-column prop="splb" label="商品类别">
          </el-table-column>
          <el-table-column prop="spfl" label="商品分类">
          </el-table-column> -->
          <el-table-column prop="spec" label="规格"> </el-table-column>
          <el-table-column prop="mol" label="型号"> </el-table-column>
          <el-table-column prop="matl" label="材质"> </el-table-column>
          <el-table-column prop="pacmatl" label="包装材质"> </el-table-column>
          <el-table-column prop="prodSouc" label="生产来源">
            <template #default="{ row }">
              <span v-if="row.prodSouc == '1'">国产</span>
              <span v-if="row.prodSouc == '2'">进口</span>
            </template>
          </el-table-column>
          <el-table-column prop="regcertno" label="注册证号"> </el-table-column>
          <el-table-column prop="prodEntp" label="生产企业" width="120">
          </el-table-column>
          <el-table-column prop="agnt" label="代理企业" width="150"> </el-table-column>
        </el-table>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="handleConfirm" :loading="addLoading"
            >确认</el-button
          >
        </div>

        <!--分页-->
        <yl-pagination
          v-show="totalC > 0"
          :total="totalC"
          :page.sync="listQueryadd.current"
          :limit.sync="listQueryadd.size"
          @pagination="getdialog"
        />
      </template>
    </el-dialog>
  </div>
</template>

<script>
import ylPagination from "@/components/yl-pagination";
import mcsInfo from "@/views/components/mcs-info.vue"
import {
  selectSplerMcsListIntf,
  selectMcsList,
  saveSplerMcs,
  PricChg,
  QueryHospList,
  QueryHospDrugList,
  QuerySplerDrugList,
  DrugMatch,
  CancMatch,
  selectSpdList,
} from "@/api/consumCataManage-sup/index";
import rulesR from "@/utils/rules";
import ylUpload from "@/components/yl-upload";
export default {
  components: {
    ylPagination,
    ylUpload,
    mcsInfo,
  },
  data() {
    return {
      activeName: "grp",
      rulesR,
      spdId: null,
      data: [],
      defaultProps: {
        children: "children",
        label: "spdName",
      },
      listQuery: {
        current: 1,
        size: 10,
        spec: "",
        // hiCode: "",
        isFas: "",
        mol: "",
        prodSouc: "",
        mcsType: "",
        matl: "",
        prodEntp: "",
        prodName: "",
        status: "",
        regcertno:"",
        isPub:"",
      },
      listLoading: false,
      list: [],
      total: 0,
      tableLoading: false,
      supLoading: false,
      tableData: [],
      // crspFlgOption: [
      //   { value: "0", name: "未对码" },
      //   { value: "1", name: "已对码" },
      // ],
      isFasData: [
        { value: "1", name: "是" },
        { value: "0", name: "否" },
      ],
      mcsTypeData: [
        { value: "0", name: "普通耗材" },
        { value: "1", name: "高值耗材" },
        { value: "2", name: "试剂" },
      ],
      SoucData: [
        { value: "1", name: "国产" },
        { value: "2", name: "进口" },
      ],
      statusData: [
        { value: "A", name: "待提交" },
        { value: "B", name: "待审核" },
        { value: "C", name: "审核通过" },
        { value: "R", name: "驳回" },
      ],
      isPubData: [
        { value: "1", name: "挂网" },
        { value: "0", name: "非挂网" },
      ],
      dialogPrice: false,
      dialogDui: false,
      ccLoad: false,
      temp: {
        drugListId: "",
        drugName: "",
        dosformName: "",
        specName: "",
        pacUnt: "",
        prodEntp: "",
        pricInit: "",
        pricCurr: "",
        appyRea: "",
        fileId: "",
      },
      rules: {
        pricCurr: [
          {
            required: true,
            message: "调整价格不能为空",
            trigger: "blur",
          },
          {
            pattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
            message: "请输入数字，最多两位小数",
            trigger: "blur",
          },
        ],
        appyRea: [
          {
            required: true,
            message: "申请原因不能为空",
            trigger: "blur",
          },
        ],
        num: [
          {
            required: true,
            message: "请输入转换比",
            trigger: "change",
          },
        ],
        uploadRequired: [{ required: true, message: "请上传文件", trigger: "change" }],
      },
      tableData: [
        {
          date: "2016-05-02",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333,
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333,
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1519 弄",
          zip: 200333,
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1516 弄",
          zip: 200333,
        },
      ],
      consumableData: [],
      form: {
        splerData: [],
      },
      // 省平台目录
      listdialogLoading: false,
      dialogAdd: false,
      listQueryadd: {
        materialId: "",
        spec: "",
        hiCode: "",
        isFas: "",
        fasBtch: "",
        mol: "",
        current: 1,
        size: 10,
      },
      totalC: false,
      addLoading: false,
      insertMcsList: [],
      // tree
      activeNametree: "org",
      btnShow: false,
      routespdId:"",
    };
  },
  methods: {
    tabClick(tab) {
      if (tab.label == "按机构") {
        this.defaultProps.label = "spdName";
      }
      // else if(tab.label == "按分类"){
      //     // this.getData4();
      //     // this.defaultProps.label = 'orgGrpName'
      //     // this.listQuery.type = 'grp';
      // }
    },
    // 上传文件
    getUpload(id) {
      this.temp.fileId = id;
      if (id) {
        this.$refs.dataForm.clearValidate("fileId");
      } else {
        this.$refs.dataForm.validateField("fileId");
      }
    },
    validateField(form, index) {
      let result = true;
      for (let item of this.$refs[form].fields) {
        if (item.prop.split(".")[1] == index) {
          this.$refs[form].validateField(item.prop, (error) => {
            if (error != "") {
              result = false;
            }
          });
        }
        if (!result) break;
      }
      return result;
    },
    // 搜索获取医院药品列表
    getHospConsum(type) {
      if (type == "search") {
        this.listQuery.current = 1;
      }
      this.listLoading = true;
      // this.spdId = this.$route.query.spdId;
      this.listQuery.spdId = this.spdId;
      selectSplerMcsListIntf(this.listQuery)
        .then((res) => {
          this.list = res.data.records;
          this.total = res.data.total;
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    // 获取新增目录弹框数据
    getdialog(type) {
      if (type == "search") {
        this.listQueryadd.current = 1;
      }
      this.listdialogLoading = true;
      // this.listQuery.spdId = this.spdId;
      selectMcsList(this.listQueryadd)
        .then((res) => {
          this.consumableData = res.data.records;
          this.totalC = res.data.total;
          this.listdialogLoading = false;
        })
        .catch((err) => {
          this.listdialogLoading = false;
        });
    },
    // 点击获取医院药品列表
    handleNodeClick(data) {
      console.log(data, "data");
      this.listLoading = true;
      this.spdId = data.spdId;
      this.listQuery.spdId = this.spdId;
      selectSplerMcsListIntf(this.listQuery)
        .then((res) => {
          this.list = res.data.records;
          this.total = res.data.total;
          this.listLoading = false;
          console.log(res, "医院目录");
          this.btnShow = true;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    // 获取医院列表
    getData(type) {
      this.data = [];
      this.listLoading = true;
      selectSpdList()
        .then((res) => {
          this.listQuery.spdId = res.data[0].spdId;
          this.data = res.data;
          console.log(this.data, "dadad");
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },

    reset(type) {
      if (type === "consumableData") {
        this.$refs.listQuery.resetFields();
        this.getHospConsum();
      } else {
        this.$refs.supQuery.resetFields();
        this.searchSup();
      }
    },
    resetdialog(type) {
      if (type === "consumableData") {
        this.$refs.listQueryadd.resetFields();
        this.getdialog();
      } else {
        this.$refs.supQuery.resetFields();
        this.searchSup();
      }
    },
    // 多选
    handleSelectionChange(e) {
      console.log(this.spdId,"sodpdp")
      this.insertMcsList = e;
      newArr = this.insertMcsList.push({spdId:this.spdId});
      // console.log(e, "ee");
    },
    // 多选后选过的禁用
    selected(row, index) {
      if (
        this.list.some((el) => {
          return el.hiCode === row.hiCode;
        })
      ) {
        return false;
      } else {
        return true;
      }
    },

    // 新增目录
    handleUpdate(type) {
      if (type == "search") {
        this.listQueryadd.current = 1;
      }
      this.dialogAdd = true;
      this.getdialog();
    },
    // 新增目录确认
    handleConfirm() {
      if (this.insertMcsList.length == 0) {
        this.$message({
          message: "请选择要添加的数据",
          type: "warning",
        });
      } else {
        this.$confirm("确认提交", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(() => {
          this.addLoading = true;
          saveSplerMcs({ insertMcsList: this.insertMcsList })
            .then((res) => {
              if (res.success === true) {
                this.addLoading = false;
                this.getHospConsum();
                this.insertMcsList = [];
                this.dialogAdd = false;
                this.$refs.multipleTable.clearSelection();
              } else {
                this.addLoading = false;
                this.$refs.multipleTable.clearSelection();
                // this.$message({
                //   message: res.message || "操作失败",
                //   type: "error",
                // });
              }
            })
            .catch(() => {
              this.addLoading = false;
              this.dialogAdd = false;
              this.$refs.multipleTable.clearSelection();
            });
        });
      }

      // saveSplerMcs
      // this.addLoading = false;
      // this.dialogAdd = false;
    },
    // 非挂网目录新增
    handleFadd() {
      this.$router.push({
        name: "catalogdetailsadd",
        query: { spdId: this.spdId },
      });
    },

    // 申请调价

    handlePrice(row) {
      this.dialogPrice = true;
      this.temp.drugListId = row.drugListId;
      this.temp.drugName = row.drugName;
      this.temp.dosformName = row.dosformName;
      this.temp.specName = row.specName;
      this.temp.pacUnt = row.pacUnt;
      this.temp.prodEntp = row.prodEntp;
      this.temp.pricInit = row.pricCurr ? row.pricCurr : 0;
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields();
      });
    },
    // 调价申请 确认
    commitData() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          this.ccLoad = true;
          let data = {
            drugListId: this.temp.drugListId,
            pricInit: this.temp.pricInit,
            pricCurr: this.temp.pricCurr,
            appyRea: this.temp.appyRea,
            spdId: this.spdId,
            fileId: this.temp.fileId,
          };
          PricChg(data)
            .then((res) => {
              if (res.success === true) {
                this.$message("调价已申请");
                this.ccLoad = false;
                this.dialogPrice = false;
                this.getHospConsum();
              }
            })
            .catch((err) => {
              this.ccLoad = false;
            });
        }
      });
    },
    // 对码弹窗获取供应商列表
    handleDui(row) {
      if (this.spdId) {
        this.routespdId = this.spdId;
      } else {
        this.routespdId = this.$route.query.spdId;
      }
      console.log(this.routespdId, "编辑");
      this.$router.push({
        name: "catalogdetails",
        query: { id: row.id, status: row.status,
          spdId: this.routespdId, isPub: row.isPub,
          opeType:row.opeType,type:"edit",
          current:this.listQuery.current,page:"2" },
      });
    },
    // 对码操作
    handleClick(item, index) {
      let DrugMatchObj = {
        spdId: this.spdId,
        drugListId: this.consumableData[0].drugListId,
        splerDrugListId: item.splerDrugListId,
        convrat: item.convrat,
      };

      if (!this.validateField("form", index)) {
        return;
      } else {
        DrugMatch(DrugMatchObj).then((res) => {
          if (res.success === true) {
            this.dialogDui = false;
            this.getHospConsum();
            this.$message({
              message: "对码成功",
              type: "success",
            });
          } else {
            this.$message.error("对码失败");
          }
        });
      }
    },
    // 取消对码
    handleCanc(row) {
      this.$confirm("此操作会取消该药品对码, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          CancMatch({ spdId: this.spdId, drugListId: row.drugListId }).then((res) => {
            if (res.success) {
              this.getHospConsum();
              this.$message({
                type: "success",
                message: "取消对码成功",
              });
            }
          });
        })
        .catch(() => {});
    },
    //搜索供应商列表
    searchSup() {
      this.supLoading = true;
      this.supQuery.spdId = this.spdId;
      QuerySplerDrugList(this.supQuery)
        .then((res) => {
          this.form.splerData = res.data.records;
          this.total = res.data.total;
          this.supLoading = false;
        })
        .catch((err) => {
          this.supLoading = false;
        });
    },
  },
  mounted() {
    this.getData();
    // this.getHospConsum();
    if (this.$route.query.spdId) {
      this.listQuery.spdId = this.$route.query.spdId;
      selectSplerMcsListIntf(this.listQuery)
        .then((res) => {
          this.list = res.data.records;
          this.total = res.data.total;
          this.listLoading = false;
          console.log(res, "医院目录");
          this.btnShow = true;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    }
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-card__body {
  padding: 12px;
}
::v-deep .el-tree-node__content {
  height: 35px;
}
::v-deep .el-input__suffix {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 15px;
}
::v-deep .long .el-form-item__content {
  width: 220px;
}
::v-deep .long .el-input__inner {
  width: 199px;
}
</style>
