<template>
  <div>
    <el-card>
      <el-form :model="filterQuery" label-width="120px" v-show="showSearch">
        <el-row>
          <el-col :span="8">
            <el-form-item label="产品编码:">
              <el-input v-model="filterQuery.unionCode" style="width: 90%" placeholder="请输入DI/医保编码/商品条码"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="产品名称:">
              <el-input v-model="filterQuery.cpmctymc" style="width: 90%" placeholder="请输入物资名称"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="规格型号:">
              <el-input v-model="filterQuery.ggxh" style="width: 90%" placeholder="请输入规格型号" clearable="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="注册备案号:">
              <el-input v-model="filterQuery.zczbhhzbapzbh" style="width: 90%" placeholder="请输入注册备案号"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="生产企业:">
              <el-input v-model="filterQuery.ylqxzcrbarmc" style="width: 90%" placeholder="请输入生产企业/注册备案人"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="top-right-btn">
        <el-button-group style="display:flex;">
          <el-button icon="el-icon-view" type="primary" @click="hideSearch">显示/隐藏搜索栏</el-button>
          <el-button type="primary" icon="el-icon-refresh" @click="onReset">重置</el-button>
          <el-button type="primary" icon="el-icon-search" @click="search">查询</el-button>
          <el-button type="primary" icon="el-icon-bottom-right" @click="selectProduct()">选入产品</el-button>
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>
      <el-table v-loading="loading" :data="list" key="1" style="width: 100%"
                border>
        <el-table-column label="序号" type="index"></el-table-column>
        <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="ggxh" show-overflow-tooltip></el-table-column>
        <el-table-column label="医疗器械注册人" prop="ylqxzcrbarmc" show-overflow-tooltip></el-table-column>
        <el-table-column label="注册/备案号" prop="zczbhhzbapzbh" show-overflow-tooltip></el-table-column>
        <el-table-column width="120" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click.native.stop="handleModifyClick(scope.row)">编辑</el-button>
            <el-button type="text" @click.native.stop="deleteDialog(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        title="医疗器械信息-编辑"
        :visible.sync="editDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="60%"
        v-if="editDialogVisible"
      >
        <UdiBasicProductEdit
          :detailQuery="detailQuery"
          :checked="checked"
          :closeDialog="closeDialog"
        >
        </UdiBasicProductEdit>
      </el-dialog>
      <el-dialog
        title="选入医疗器械信息"
        :visible.sync="selectProductVisible"
        width="85%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="selectProductVisible"
      >
        <selectLocalUdi
          :closeDialog="closeDialog"
          filter-type="1"
          :companyId="filterQuery.companyIdFk"
        ></selectLocalUdi>
      </el-dialog>
      <pagination
        v-show="total>0"
        :total="total"
        :limit.sync="filterQuery.limit"
        :page.sync="filterQuery.page"
        @pagination="handleCurrentChange"
      ></pagination>

    </el-card>


  </div>
</template>

<script>
import selectLocalUdi from "../rel/UdiInfoSelectLocalUdi";
import UdiBasicProductEdit from "@/views/basic/product/dict/UdiBasicProductEdit";
import {deleteDict, filterList} from "@/api/basic/UdiBasic";

export default {
  name: "UdiBasicProduct",
  data() {
    return {
      showSearch: true,
      filterQuery: {
        unionCode: null,
        udiCode: null,
        ylqxzcrbarmc: "",
        cpmctymc: "",
        nameCode: "",
        ggxh: null,
        page: 1,
        limit: 20,
        thrPiId: null,
        filterType: null,
        companyName: null,
        companyIdFk: null,
      },
      fromOptions: [],
      editQuery: null,
      detailQuery: null,
      defaultSys: null,
      isImport: false,
      isImportUdi: false,
      isUploadSmp: false,
      isSpCombine: false,
      isImportFile: false,
      uploadFileUrl: null,
      checked: false,
      list: [],
      detailList: [],
      sysList: [],
      filterList: [],
      total: 0,
      thirdNo: "",
      uuid: "111",
      originUuid: null,
      thirdId: null,
      relId: "",
      thisData: {
        nameCode: null,
        cpmctymc: null,
        ggxh: null
      },
      selectProductVisible: false,
      multipleSelection: [],
      editDialogVisible: false,       //详情
      selectUdiDialogVisible: false,  //关联选入
      selectErpDialogVisible: false,  //选入ERP产品
      selectLocalVisible: false,      //关联UDI
      selectVersionVisible: false,
      isUseDyCheck: false,
      loading: false,
      activeNames: ['1'],
      editSingleDiDialogVisible: false,
      companyTypeMap: {
        1: "生产企业",
        2: "代理商",
        3: "购买方",
      },
      editDiDialogVisible: false,
      editFormat: {},

    };
  },

  methods: {
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        lockStatus: null,
        unionCode: null,
        udiCode: null,
        ylqxzcrbarmc: "",
        cpmctymc: "",
        thrPiId: null,
        nameCode: "",
        ggxh: null,
        page: 1,
        limit: 20,
        addType: 1,
      };
      this.total = 0;
      this.list = [];
      this.getList();
    },
    search() {
      this.filterQuery.page = 1;
      this.getList();
    },
    hideSearch() {
      this.showSearch = !this.showSearch;
    },
    getList() {
      this.loading = true;
      filterList(this.filterQuery)
        .then((response) => {
          this.loading = false;
          this.list = response.data.list || [];
          this.total = response.data.total || 0;
        })
        .catch(() => {
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
    keyup_submit(event) {
      this.filterQuery.page = 1;
      this.getList();
      event.target.select();
    },
    handleDetail(row) {
      this.editQuery = row;
    },
    deleteOrders(data) {
      this.loading = true;
      let tquery = {
        uuid: data.uuid + "",
      };
      deleteDict(tquery)
        .then((response) => {
          this.loading = false;
          if (response.code == 20000) {
            this.getList();
            this.$message({
              type: "success",
              message: "删除成功！",
            });
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
        });
    },

    deleteDialog(rowId) {
      this.$confirm("此操作将永久删除该产品信息, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteOrders(rowId);
        })
        .catch(() => {
        });
    },
    selectProduct() {
      this.selectProductVisible = true;
    },

    cancelDialog() {
      this.editDiDialogVisible = false;
      this.editDialogVisible = false;
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    handleModifyClick(row) {
      this.uuid = row.uuid;
      this.isImport = false;
      this.thisData = row;
      this.editDialogVisible = true;
      this.detailQuery = row;
      this.checked = row.isUseDy == 1;
    },

    closeUdi(val) {
      this.selectUdiDialogVisible = false;
      this.selectErpDialogVisible = false;
      this.selectLocalVisible = false;
      this.editDiDialogVisible = false;
      this.getList();
    },

    selectVersion() {
      this.selectVersionVisible = true;
      this.uuid = this.editQuery.uuid;
      this.originUuid = this.editQuery.originUuid;
    },
    closeDialog() {
      this.selectErpDialogVisible = false;
      this.selectLocalVisible = false;
      this.selectVersionVisible = false;
      this.selectProductVisible = false;
      this.editDialogVisible = false;
      this.getList();
    },


    diEdit(row) {
      this.uuid = row.uuid;
      this.editFormat = JSON.parse(JSON.stringify(row));
      this.editDiDialogVisible = true;
    },

  }
  ,
  mounted() {
  }
  ,
  components: {
    selectLocalUdi,
    UdiBasicProductEdit

  }
  ,
  created() {
    this.getList();
  }
  ,
}
;
</script>
<style scoped>


.el-table .cell.el-tooltip {
  white-space: pre-wrap;
}


.itemTag {
  float: left;
  text-align: left;
  margin-top: 10px;
  width: 25%;
}

.text {
  font-size: 13px;
  font-family: "Microsoft YaHei";
}

.query-form-item {
  display: block !important;
  margin-right: 10px;
  margin-bottom: 5px;
}

.el-row {
  display: flex;
  flex-wrap: wrap;
}

.el-col {
  border-radius: 4px;
  flex-wrap: wrap;
}

.form-title {
  font-size: 16px;
  font-family: Noto Sans SC;
  font-weight: bold;
  color: #303133;
  padding-bottom: 17px;
  padding-top: 17px;
}
</style>
