<template>
  <div>
    <el-card>
      <el-form :model="filterQuery" size="mini" label-width="100px" v-if="showSearch">
        <el-row>
          <el-col :span="18">
            <el-form-item class="query-form-item" label="UDI码:">
              <el-input v-model="filterQuery.udiCode"
                        style="width: 97%"
                        placeholder="请扫描或输入UDI码"
                        clearable="true"
                        @keyup.enter.native="keyup_submit($event)"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item class="query-form-item" label="产品编码:">
              <el-input v-model="filterQuery.unionCode" placeholder="DI/医保编码/商品条码"
                        style="width: 90%"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="query-form-item" label="物资名称:">
              <el-input v-model="filterQuery.cpmctymc" placeholder="物资名称" clearable="true"
                        style="width: 90%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="query-form-item" label="规格型号:">
              <el-input v-model="filterQuery.ggxh" placeholder="规格型号" clearable="true"
                        style="width: 90%"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <el-form-item class="query-form-item" label="对照条件:">
              <el-select v-model="filterQuery.filterType" placeholder="请选择过滤对照条件"
                         style="width: 90%">
                <el-option
                  v-for="item in filterList"
                  :key="item.filterType"
                  :label="item.sysName"
                  :value="item.filterType">
                  <span style="float: left">{{ item.sysName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="query-form-item" label="注册备案人:">
              <el-input v-model="filterQuery.ylqxzcrbarmc" placeholder="生产企业/注册备案人"
                        style="width: 90%"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item class="query-form-item" label="外部产品编码:">
              <el-input v-model="filterQuery.thrPiId" placeholder="第三方产品编码"
                        style="width: 90%"
                        clearable="true"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div class="top-right-btn">
        <el-button-group>
          <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="submit">查询</el-button>
          <el-button type="primary" icon="el-icon-delect" @click="unBindProduct">解绑</el-button>
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>
      <el-table v-loading="loading" :data="list" style="width: 100%;" @selection-change="handleSelectionChange"  border key="1">
        <el-table-column type="selection" width="55" ></el-table-column>
        <el-table-column label="最小销售产品标识" prop="nameCode" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="主系统编码" prop="mainId" show-overflow-tooltip></el-table-column>
        <el-table-column label="生产企业" prop="ylqxzcrbarmc" 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="zczbhhzbapzbh" show-overflow-tooltip></el-table-column>
        <el-table-column label="器械类别" prop="qxlb" show-overflow-tooltip></el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :limit.sync="filterQuery.limit"
        :page.sync="filterQuery.page"
        @pagination="handleCurrentChange"
      ></pagination>

    </el-card>
  </div>
</template>

<script>

import {bindBasicHospProduct, saveBasicHospType,unbindBasicHospProduct,getBindList} from "@/api/basic/basicHospType";
import { sysFilter } from '@/api/basic/udiRelevance'




export default {
  props: {
    rId: {
      type: Object,
      required: true,
    },
    closeDialog: {
      type: Function,
      required: true,
    },
  },
  data() {
    return {
      filterQuery: {
        page: 1,
        limit: 20,
        addType: 1,
        thrPiId: null,
        filterType: null,
        diType: 1
      },
      productList: [],
      loading: false,
      showSearch: true,
      productType: null,
      editQuery: null,
      editFormat: {},
      pId: 0,
      productRemarkSet: {},
      list: [],
      detailList: [],
      sysList: [],
      filterList: [],
      total: 0,
      thirdNo: "",
    };
  },

  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,
        diType: 1,
        relCode:this.rId
      };
      this.getList();
    },
    submit() {
      this.loading = true;
      this.filterQuery.page = 1;
      this.getList();
    },
    getList() {
      getBindList(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;
        });
    },
    getSysFilter() {
      sysFilter()
        .then((response) => {
          this.loading = false;
          this.filterList = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.filterList = [];
        });

    },
    hideSearch() {
      this.showSearch = !this.showSearch;
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    handleSelectionChange(val) {
      this.productList = val;
    },
    unBindProduct(){
      if(this.productList.length<=0){
        this.$message.error("请先选择解绑产品！");
        return;
      }
      var ids=this.productList.map((item)=> item.id)
      var data={code:this.rId,ids:ids}
      unbindBasicHospProduct(data).then((response) => {
        if (response.code == 20000) {
          this.$message.success("解绑成功");
          this.closeDialog();
        } else {
          this.$message.error(response.message);
        }
      }).catch(() => {

      });
    },
  },
  mounted() {
  },
  components: {

  },
  created() {
    this.filterQuery.relCode=this.rId
    this.getList();
    this.getSysFilter();
  },
};
</script>
<style scoped>
.itemTag {
  float: left;
  text-align: right;
  margin-top: 5px;
  padding-right: 10px;
  width: 35%;
}

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


.edit-row {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 0px;
}

.el-row {
  display: flex;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

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

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

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