<template>
  <div>
    <el-card>
      <el-form v-if="queryList && queryList.length > 0" :model="filterQuery" size="mini" label-width="120px"
               v-show="showSearch">
        <!--        <el-row>-->
        <!--          <el-col :span="6">-->
        <!--            <el-form-item label="物资编码:">-->
        <!--              <el-input v-model="filterQuery.unionCode" style="width: 90%" placeholder="请输入产品编码"-->
        <!--                        clearable="true"></el-input>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="6">-->
        <!--            <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="6">-->
        <!--            <el-form-item label="规格型号:">-->
        <!--              <el-input v-model="filterQuery.ggxh" style="width: 90%" placeholder="请输入规格型号" clearable="true"></el-input>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="6">-->
        <!--            <el-form-item label="对照条件:">-->
        <!--              <el-select v-model="filterQuery.filterType" style="width: 90%" placeholder="请选择过滤对照条件">-->
        <!--                <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-row>-->
        <!--        <el-row>-->
        <!--          <el-col :span="6">-->
        <!--            <el-form-item label="生产企业:">-->
        <!--              <el-input v-model="filterQuery.ylqxzcrbarmc" style="width: 90%" placeholder="请输入生产企业/注册备案人"-->
        <!--                        clearable="true"></el-input>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="6">-->
        <!--            <el-form-item label="第三方产品编码:">-->
        <!--              <el-input v-model="filterQuery.thrPiId" style="width: 90%" placeholder="请输入第三方产品编码"-->
        <!--                        clearable="true"></el-input>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="6">-->
        <!--            <el-form-item label="审核状态:" v-if="isSpCombine">-->
        <!--              <el-select v-model="filterQuery.lockStatus" style="width: 90%" placeholder="请选择审核状态">-->
        <!--                <el-option label="全部" value=""></el-option>-->
        <!--                <el-option label="未提交" value="1"></el-option>-->
        <!--                <el-option label="已提交" value="2"></el-option>-->
        <!--                <el-option label="已锁定" value="3"></el-option>-->
        <!--              </el-select>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <el-row style=" display:flex;  flex-wrap: wrap; ">
          <template v-for="(item, index) in queryList">
            <el-form-item
              v-if="item.columnType == 'input' && item.columnName !='queryName' && executeEval(row,item.expression,true)"
              :label="item.columnDesc+`:`" :key="item.id">
              <el-input
                v-model="filterQuery[item.columnName]"
                :placeholder="item.columnDesc"
                :disabled="executeEval(null,item.disabledFuc,false)"
                @keyup.enter.native="executeFuc($event,'5',item.clickFuc)"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item
              v-if="item.columnType == 'input' && item.columnName =='queryName' && executeEval(row,item.expression,true)"
              :label="item.columnDesc+`:`" :key="item.id">
              <el-autocomplete
                class="inline-input"
                style="width: 90%"
                v-model="queryName"
                :fetch-suggestions="queryProductName"
                placeholder="请输入内容"
                clearable
                @select="handleSelect"
                @clear="clearQueryProduct"
              ></el-autocomplete>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'select' && executeEval(row,item.expression,true)"
                          :label="item.columnDesc+`:`">
              <el-select v-model="filterQuery[item.columnName]"
                         :placeholder="item.columnDesc"
                         @change="executeFuc($event,'5',item.checkRules)"
                         :disabled="executeEval(null,item.disabledFuc,false)"
                         clearable>
                <el-option
                  v-for="dict in item.lableRuleObj"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
                <span style="float: left">{{ item.name }}</span>
                <span v-if="item.isShowXx == '1'" style="float: right; color: #8492a6; font-size: 13px">{{
                    item.code
                  }}</span>
              </el-select>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'selectServer' && executeEval(row,item.expression,true)"
                          :label="item.columnDesc+`:`">
              <el-select
                v-model="filterQuery[item.columnName]"
                :placeholder="item.columnDesc"
                :disabled="executeEval(null,item.disabledFuc,false)"
                filterable
                remote
                @change="executeFuc($event,'5',item.checkRules)"
                :remote-method="(query) => executeFuc(query,'5',item.clickFuc)"
                clearable>
                <el-option
                  v-for="item in options[item.clickFuc]"
                  :key="item.code"
                  :label="item.label"
                  :value="item.code"
                />
                <span style="float: left">{{ item.name }}</span>
                <span v-if="item.isShowXx == '1'" style="float: right; color: #8492a6; font-size: 13px">{{
                    item.code
                  }}</span>
              </el-select>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'datePicker' && executeEval(row,item.expression,true)"
                          :label="item.columnDesc+`:`">
              <el-date-picker
                :picker-options="pickerOptions"
                v-model="actDateRange"
                type="daterange"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
            <el-form-item v-if="item.columnType == 'date' && executeEval(row,item.expression,true)"
                          :label="item.columnDesc+`:`">
              <el-date-picker
                v-model="filterQuery[item.columnName]"
                :style="`width:${item.width+'px'}`"
                value-format="yyyy-MM-dd"
                :disabled="executeEval(null,item.disabledFuc,false)"
                type="date"
                :placeholder="item.columnDesc"
              ></el-date-picker>
            </el-form-item>
          </template>
        </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-upload
            :action="action"
            :headers ="headers"
            accept=".txt"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            :on-success="handleSuccess"
            :on-progress="handleProgress"
            :on-error="handleError"
            :before-upload="beforeUpload"
            :limit="1"
            :on-exceed="handleExceed"
            :file-list="fileList"
            :show-file-list="false"
            :data="extraData">
            <el-button  icon="el-icon-upload" type="primary" style="margin: 0;">药品标识上传</el-button>
          </el-upload>
        </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
                highlight-current-row>
        <!--        <el-table-column label="序号" type="index"></el-table-column>-->
        <!--        <el-table-column label="最小销售产品标识" prop="nameCode" width="140" show-overflow-tooltip></el-table-column>-->
        <!--        <el-table-column label="物资编码" prop="thirdId" 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="price" 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 label="物资分类" prop="classifyName" show-overflow-tooltip></el-table-column>-->
        <!--        <el-table-column v-if="isSpCombine" label="锁定状态" prop="lockStatus" show-overflow-tooltip>-->
        <!--          <template slot-scope="scope">-->
        <!--            {{ lockStatusMap[scope.row.lockStatus] }}-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <!--        <el-table-column width="180" label="操作" fixed="right">-->
        <!--          <template slot-scope="scope">-->
        <!--            <el-button v-if="isSpCombine" type="text" size="small"-->
        <!--                       :disabled="scope.row.originUuid!=null || scope.row.lockStatus===3"-->
        <!--                       @click.native.stop="intentSelectUdi(scope.row)">关联DI-->
        <!--            </el-button>-->
        <!--            <el-button type="text" size="small" :disabled="scope.row.lockStatus==3"-->
        <!--                       @click.native.stop="handleModifyClick(scope.row)">编辑-->
        <!--            </el-button>-->
        <!--            <el-button type="text" size="small"-->
        <!--                       @click.native.stop="handleDetailClick(scope.row)">详情-->
        <!--            </el-button>-->

        <!--            <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"-->
        <!--            >-->
        <!--                <span class="el-dropdown-link">-->
        <!--                  <i class="el-icon-d-arrow-right el-icon&#45;&#45;right"></i>更多-->
        <!--                </span>-->
        <!--              <el-dropdown-menu slot="dropdown">-->
        <!--                &lt;!&ndash;                <el-dropdown-item command="handleDetailClick" v-if=" scope.row.lockStatus!=3">详情</el-dropdown-item>&ndash;&gt;-->
        <!--                <el-dropdown-item command="sumitLockStatus" v-if="isSpCombine" :disabled="scope.row.lockStatus===3">-->
        <!--                  提交审核-->
        <!--                </el-dropdown-item>-->
        <!--                <el-dropdown-item command="splitSelectUdi" v-if="isSpCombine" type="text" size="small"-->
        <!--                                  :disabled="scope.row.thirdId===scope.row.nameCode  || scope.row.thirdId==null || scope.row.nameCode==null || scope.row.lockStatus===3">-->
        <!--                  拆分产品-->
        <!--                </el-dropdown-item>-->
        <!--                <el-dropdown-item command="deleteCompanyProductRelevance">移除</el-dropdown-item>-->
        <!--              </el-dropdown-menu>-->
        <!--            </el-dropdown>-->


        <!--            &lt;!&ndash;            <el-button v-if=" scope.row.lockStatus!=3" type="text" size="small"&ndash;&gt;-->
        <!--            &lt;!&ndash;                       @click.native.stop="handleDetailClick(scope.row)">详情&ndash;&gt;-->
        <!--            &lt;!&ndash;            </el-button>&ndash;&gt;-->
        <!--            &lt;!&ndash;            <el-button v-if="isSpCombine" type="text" size="small" :disabled="scope.row.lockStatus===3"&ndash;&gt;-->
        <!--            &lt;!&ndash;                       @click.native.stop="sumitLockStatus(scope.row)">提交审核&ndash;&gt;-->
        <!--            &lt;!&ndash;            </el-button>&ndash;&gt;-->
        <!--            &lt;!&ndash;            <el-button v-if="isSpCombine" type="text" size="small" @click.native.stop="splitSelectUdi(scope.row)"&ndash;&gt;-->
        <!--            &lt;!&ndash;                       :disabled="scope.row.thirdId===scope.row.nameCode  || scope.row.thirdId==null || scope.row.nameCode==null || scope.row.lockStatus===3">&ndash;&gt;-->
        <!--            &lt;!&ndash;              拆分产品&ndash;&gt;-->
        <!--            &lt;!&ndash;            </el-button>&ndash;&gt;-->
        <!--            &lt;!&ndash;            <el-button type="text" size="small" @click.native.stop="deleteCompanyProductRelevance(scope.row)">移除&ndash;&gt;-->
        <!--            &lt;!&ndash;            </el-button>&ndash;&gt;-->
        <!--          </template>-->
        <!--        </el-table-column>-->
        <template v-for="(item, index) in tableHeader">
          <el-table-column
            v-if="item.columnType == 'id' && executeEval(row,item.expression,true)"
            type="index" :label="item.columnDesc"></el-table-column>
          <el-table-column
            v-if="item.columnType == 'selection'"
            type="selection"
            :width="item.width"
            :selectable="(row,number) => executeFuc(row,'3',item.clickFuc)"
          ></el-table-column>

          <el-table-column
            v-if="item.columnType == 'radio' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template slot-scope="scope">
              <el-radio :label="scope.row.id" v-model="radioCheck"><span></span></el-radio>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'laber' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template slot-scope="scope">
              <span :style="{color: executeFuc(scope.row,'4',item.lableRuleObj[scope.row[item.columnName]])}">{{
                  item.lableRuleObj[scope.row[item.columnName]]
                }}</span>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'eltag' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template slot-scope="scope">
              <el-tag
                :type="executeFuc(scope.row,'4',item,item.lableRuleObj?item.lableRuleObj[scope.row[item.columnName]]:scope.row[item.columnName])">
                <span>{{
                    item.lableRuleObj ? item.lableRuleObj[scope.row[item.columnName]] : scope.row[item.columnName]
                  }}</span>
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'button' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :width="item.width"
            :key="item.columnName"
            fixed="right"
          >
            <template slot-scope="scope">
              <!--<el-button v-if="isSpCombine" type="text" size="small"-->
              <!--           :disabled="scope.row.originUuid!=null || scope.row.lockStatus===3"-->
              <!--           @click.native.stop="intentSelectUdi(scope.row)">关联DI-->
              <!--</el-button>-->
              <el-button type="text" size="small" :disabled="scope.row.lockStatus==3"
                         @click.native.stop="handleModifyClick(scope.row)">编辑
              </el-button>
              <el-button type="text" size="small"
                         @click.native.stop="handleDetailClick(scope.row)">详情
              </el-button>

              <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
              >
                      <span class="el-dropdown-link">
                        <i class="el-icon-d-arrow-right el-icon--right"></i>更多
                      </span>
                <el-dropdown-menu slot="dropdown">
                  <!--                <el-dropdown-item command="handleDetailClick" v-if=" scope.row.lockStatus!=3">详情</el-dropdown-item>-->
                  <el-dropdown-item command="sumitLockStatus" v-if="isSpCombine" :disabled="scope.row.lockStatus===3">
                    提交审核
                  </el-dropdown-item>
                  <el-dropdown-item command="splitSelectUdi" v-if="isSpCombine" type="text" size="small"
                                    :disabled="scope.row.thirdId===scope.row.nameCode  || scope.row.thirdId==null || scope.row.nameCode==null || scope.row.lockStatus===3">
                    拆分产品
                  </el-dropdown-item>
                  <el-dropdown-item command="deleteCompanyProductRelevance">移除</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
          <el-table-column
            v-if="item.columnType == 'text' && executeEval(row,item.expression,true)"
            :prop="item.columnName"
            :label="item.columnDesc"
            :sortable="item.sort"
            :width="item.width"
            :show-overflow-tooltip="item.tooltip"
            :key="item.columnName"
          >
            <template slot-scope="scope">
              <span :style="{color: executeFuc(scope.row,'4',item,scope.row[item.columnName])}">{{
                  scope.row[item.columnName]
                }}</span>
            </template>
          </el-table-column>
        </template>
      </el-table>


      <pagination
        v-show="total>0"
        :total="total"
        :limit.sync="filterQuery.limit"
        :page.sync="filterQuery.page"
        @pagination="handleCurrentChange"
      ></pagination>


      <el-dialog
        :title="titleMap[type]"
        :visible.sync="editDialogVisible"
        width="80%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="editDialogVisible"
        :before-close="refresh"
      >
        <!--:productRemarkSet="productRemarkSet"-->
        <basicProductEdit
          :closeDialog="closeDialog"
          :rowData="rowData"
          :type="type"
          :relevanceEdit="relevanceEdit"
          :uuid="uuid"
          :relId="relId"
          :thisData="thisData"
        >
        </basicProductEdit>

        <!--<selectDrugProductsEdit>-->

        <!--</selectDrugProductsEdit>-->

      </el-dialog>
      <!--<el-dialog-->
      <!--  title="药品信息详情"-->
      <!--  :visible.sync="detailDialogVisible"-->
      <!--  width="70%"-->
      <!--  :close-on-click-modal="false"-->
      <!--  :close-on-press-escape="false"-->
      <!--  v-if="detailDialogVisible"-->
      <!--&gt;-->
      <!--  <basicProductEdit-->
      <!--    :productRemarkSet="productRemarkSet"-->
      <!--    :editQuery="editQuery"-->
      <!--    :closeDialog="closeDialog"-->
      <!--    :type="type"-->
      <!--  >-->
      <!--  </basicProductEdit>-->

      <!--  &lt;!&ndash;<basicProductDetail&ndash;&gt;-->
      <!--  &lt;!&ndash;  :productRemarkSet="productRemarkSet"&ndash;&gt;-->
      <!--  &lt;!&ndash;  :editQuery="editQuery"&ndash;&gt;-->
      <!--  &lt;!&ndash;  :closeDialog="closeDialog">&ndash;&gt;-->
      <!--  &lt;!&ndash;  >&ndash;&gt;-->
      <!--  &lt;!&ndash;</basicProductDetail>&ndash;&gt;-->
      <!--</el-dialog>-->
      <el-dialog
        title="关联选入耗材信息"
        :visible.sync="selectUdiDialogVisible"
        width="85%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="selectUdiDialogVisible"
      >
        <selectUdi @closeUdi="closeUdi" :isImportUdi="isImportUdi"></selectUdi>
      </el-dialog>
      <el-dialog
        :title="selectErpTitle"
        :visible.sync="selectErpDialogVisible"
        width="85%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="selectErpDialogVisible"
      >
        <selectErp
          :closeDialog="closeDialog"
          :uuid="uuid"
          :relId="relId"
          :intentThirdId="intentThirdId"
          :isImport="isImport"
          :data="thisData"
          :defaultSys="defaultSys"
          @closeUdi="closeUdi"
          :supEnable="true"
        ></selectErp>
      </el-dialog>
      <el-dialog
        title="选入药品信息"
        :visible.sync="selectLocalVisible"
        width="85%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="selectLocalVisible"
      >
        <selectLocalUdi
          :closeDialog="closeDialog"
          :relId="relId"
          :thirdId="thirdId"
          :idSpliUdi="idSpliUdi"
          :isImportUdi="isImportUdi"
          :data="thisData"
          @closeUdi="closeUdi"
        ></selectLocalUdi>
      </el-dialog>
      <el-dialog
        title="选入药品字典信息"
        :visible.sync="selectProductVisible"
        width="85%"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        v-if="selectProductVisible"
      >
        <selectProduct
          :closeSelDialog="closeSelDialog"
          :uuid="uuid"
        ></selectProduct>
      </el-dialog>

      <el-dialog
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        title="新增配送产品"
        :visible.sync="addProductVisible"
        width="85%"
        v-if="addProductVisible"
        @close="closeAddDialog"
      >
        <ThrProductsAdd
          :closeAddDialog="closeAddDialog"
          :newType="newType"></ThrProductsAdd>
      </el-dialog>
      <el-dialog
        title="选择DI版本"
        :visible.sync="selectVersionVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="85%"
        v-if="selectVersionVisible"
      >
        <selectUdiVersion
          :closeDialog="closeDialog"
          :relId="relId"
          :uuid="uuid"
          :originUuid="originUuid"
          @closeUdi="closeUdi"
        ></selectUdiVersion>
      </el-dialog>
    </el-card>


  </div>
</template>

<script>
import {
  deletetUdiInfos,
  updatetUdiInfos,
  updateErpProduct,
  uploadSmp,
  thirdSysDetail,
  removeRl, sysFilterOptimize, spcombie, lockStatus, removeDiRl
} from "@/api/basic/udiRelevance";
import store from "@/store/index";
import {
  deleteCompanyProductRelevance,
  filterCompanyProductRelevance
} from "@/api/supplier/companyDrugProductRelevance";
import {finProductSet, selectSysParamByKey} from "@/api/param/systemParamConfig";
import {filterByUuid} from "@/api/basic/udiInfo";

import selectUdi from "@/views/basic/product/udiInfoRelevance.vue";
import selectErp from "@/views/basic/product/drug/udiInfoselectErpUdi";
import selectLocalUdi from "@/views/basic/product/drug/UdiInfoSelectLocalUdi";
import selectProduct from "./basicCompanyProductsImport";
import ThrProductsAdd from "@/views/supplier/company/ThrProductsAdd";
import selectUdiVersion from "@/views/basic/product/UdiinfoSelectVersion";
import basicProductEdit from "./basicCompanyproductEdit";
import basicProductDetail from "./basicCompanyproductDetail"
import selectDrugProductsEdit from "./selectDrugProductsEdit"
import {
  getHead, executeFuc
} from "@/utils/customConfig";
import {getAdminId, getToken} from '@/utils/auth';

export default {
  data() {
    return {
      showSearch: true,
      filterQuery: {
        unionCode: null,
        udiCode: null,
        ylqxzcrbarmc: "",
        cpmctymc: "",
        nameCode: "",
        ggxh: null,
        page: 1,
        limit: 20,
        addType: 1,
        thrPiId: null,
        filterType: null,
        auditStatus: null,
        productType: 2
      },
      idSpliUdi: false,
      newType: 2,
      selectProductVisible: false,
      addProductVisible: false,
      selectVersionVisible: false,
      editQuery: null,
      rowData: null,
      productRemarkSet: {},
      relevanceEdit: {
        id: null,
        thirdId: "",
        isDisable: null,
        isUseDy: false,
        isLock: null,
        isAdavence: null,
        allowNoBatch: null,
        allowNoExpire: null,
        allowNoProduct: null,
        allowNoSerial: null,
        pId: null,
      },
      pId: 0,
      tableHeader: [],
      queryList: [],
      fromList: [],

      options: {
        getSysFilter: []
      },
      productType: null,
      defaultSys: null,
      isImport: false,
      intentThirdId: null,
      isSpCombine: false,
      isImportUdi: false,
      isUploadSmp: 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
      },
      multipleSelection: [],
      editDialogVisible: false,       //编辑
      detailDialogVisible: false,//产品信息详情
      selectUdiDialogVisible: false,  //关联选入
      selectErpDialogVisible: false,  //选入ERP产品
      selectLocalVisible: false,      //关联UDI
      auditStatusMap: {
        1: '通过',
        2: '不通过',
        3: '反审',
        4: '申请反审',
        5: '拒绝反审',
      },

      selectErpTitle: "从指定系统添加耗材信息",
      lockStatusMap: {1: "未提交", 2: "已提交", 3: "已锁定"},
      isUseDyCheck: false,
      loading: false,
      activeNames: ['1'],
      type: null,
      titleMap:{
        1 : '药品信息编辑',
        2 : '药品信息详情',
      },
      headers:{
        ADMINID: getAdminId(),
        ADMINTOKEN: getToken()
      },
      extraData:{"uuid": "upload-txt"},
      uploadLoading: false,
      action: process.env.VUE_APP_BASE_API + "/udiwms/aliDrug/txtUpload",
      fileList: []
    };
  },

  methods: {
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },
    handleExceed(files, fileList) {
      this.$message.warning(`当前限制选择 5 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${ file.name }？`);
    },
    handleSuccess(res, file, fileList) {
      fileList = fileList.filter(item => item.response.code === 20000);
      this.fileList = fileList;
      if (res.code === 20000) {
        this.$message.success(res.message);
        this.fileList = []
      } else {
        this.$message.error(res.message);
      }
      this.uploadLoading.close();
    },
    beforeUpload(file) {
      const isXML = file.name.endsWith('.txt');
      const isLt5M = file.size / 1024 / 1024 < 10;
      if (!isXML) {
        this.$message.error('上传文件只能是 TXT 格式!');
      }
      if (!isLt5M) {
        this.$message.error('上传文件大小不能超过 10MB!');
      }
      return isXML && isLt5M;
    },
    handleProgress() {
      this.uploadLoading = this.$loading({
        lock: true,
        text: '文件上传中…',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.5)'
      });
    },
    handleError() {
      this.uploadLoading.close();
      this.$message.error('文件上传失败，请检查文件大小或文件格式');
    },
    hideSearch() {
      this.showSearch = !this.showSearch;
    },
    onReset() {
      this.$router.push({
        path: "",
      });
      this.filterQuery = {
        unionCode: null,
        udiCode: null,
        ylqxzcrbarmc: "",
        cpmctymc: "", thrPiId: null,
        nameCode: "",
        ggxh: null,
        page: 1,
        limit: 20,
        addType: 1,
      };
      this.getList();
    },
    refresh() {
      this.getList();
      this.editDialogVisible = false;
    },
    search() {
      this.filterQuery.page = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      this.getProductRelevanceList();
    },
    getProductRelevanceList() {
      this.loading = true;
      this.filterQuery.customerId = store.getters.customerId;
      filterCompanyProductRelevance(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();
    },
    getDetailList(detailQuery) {
      this.loading = true;
      filterByUuid(detailQuery)
        .then((response) => {
          this.isUseDyCheck = false;
          this.loading = false;
          this.detailList = response.data || [];
          this.productType = this.detailList[0].productType;
          this.detailList.forEach((item, index, array) => {
            if (item.zxxsbzbhsydysl > 1) {
              this.isUseDyCheck = true;
            }
          });
        })
        .catch(() => {
          this.loading = false;
          this.detailList = [];
        });
    },

    handleDetail(row) {
      let rlId = this.editQuery.rlId;
      this.editQuery = row;
      this.editQuery.rlId = rlId;
    },
    deleteOrders(data) {
      this.loading = true;
      let tquery = {
        id: data.id + "",
      };

      deletetUdiInfos(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(() => {
        });
    },

    intentDetail() {
      this.isImportUdi = false;
      this.selectUdiDialogVisible = true;
    },
    addSelectErp(row) {
      this.defaultSys = row.sysId;
      this.isImport = false;
      this.selectErpTitle = "从" + row.sysName + "选入耗材信息";
      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.getThirdSysDetail()();
                this.$message({
                  type: "success",
                  message: "删除成功！",
                });
              } 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.getList();
                this.cancelDialog();
              } else {
                this.$message.error(response.message);
              }
            })
            .catch(() => {
            });
        })
        .catch(() => {
        });
    },
    intentSelectErp(val) {
      this.uuid = val.uuid;
      this.relId = val.rlId;
      this.isImport = false;
      this.thisData = val;
      this.selectErpDialogVisible = true;
    },

    intentImportErp(val) {
      this.defaultSys = null;
      this.uuid = val.uuid;
      this.relId = val.rlId;
      this.isImport = true;
      this.thisData = val;
      this.intentThirdId = val.thirdId;
      this.selectErpDialogVisible = true;
    },
    uploadSMP() {
      var selectData = this.multipleSelection;
      var keys = [];
      selectData.forEach((obj) => {
        keys.push(obj.id);
      });
      var tquery = {
        keys: keys,
      };
      uploadSmp(tquery)
        .then((response) => {
          if (response.code == 20000) {
            this.$message({
              type: "success",
              message: "上传成功！",
            });
          } else {
            this.$message({
              type: "error",
              message: response.message,
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "error",
            message: "上传失败",
          });
        });
    },
    intentSelectUdi(val) {
      this.relId = val.rlId;
      this.isImportUdi = true;
      this.thisData = val;
      this.idSpliUdi = false;
      this.thirdId = val.thirdId;
      this.selectLocalVisible = true;
    },

    splitSelectUdi(val) {
      this.thirdId = val.thirdId;
      this.isImportUdi = true;
      this.thisData = val;
      this.idSpliUdi = true;
      this.selectLocalVisible = true;
    },

    intentImportUdi() {
      this.relId = null;
      this.selectLocalVisible = true;
    },
    deleteCompanyProductRelevance(row) {
      this.$confirm("是否移除?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.productLoading = true;
        let tquery = {
          id: row.id,
        };
        deleteCompanyProductRelevance(tquery)
          .then((response) => {
            this.productLoading = false;
            if (response.code === 20000) {
              this.getProductRelevanceList();
              this.$message({
                type: "success",
                message: "移除成功！",
              });
            } else {
              this.$message.error(response.message);
            }
          })
          .catch(() => {
            this.productLoading = false;
          });
      }).catch(() => {
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    closeSelDialog(val) {
      this.selectProductVisible = false;
      this.addProductVisible = false;
      this.getList();
    },
    cancelDialog() {
      this.editDialogVisible = false;
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    handleDetailClick(row) {
      this.type = 2
      this.fromName = 'edit'
      this.uuid = row.uuid;
      this.relId = row.rlId;
      this.isImport = false;
      this.thisData = row;
      this.pId = row.rlId;
      this.relevanceEdit = {
        id: row.rlId,
        isUseDy: row.isUseDy,
        isDisable: row.isDisable,
        isLock: row.isLock,
        isAdavence: row.isAdavence,
      };
      this.editFormat = JSON.parse(JSON.stringify(row));
      this.rowData = row
      this.editQuery = row;
      this.editDialogVisible = true;
    },
    sumitLockStatus(row) {
      let postQuery = {
        ids: [],
        lockStatus: 2,
      }
      postQuery.ids.push(row.rlId);
      lockStatus(postQuery)
        .then((response) => {
          if (response.code == 20000) {
            this.loading = false;
            this.$message.success(response.data);
            this.getList();
          } else {
            this.$message.error(response.message);
          }

        })
        .catch(() => {
          this.loading = false;
        });
    },
    handleModifyClick(row) {
      this.fromName = 'edit'
      this.uuid = row.uuid;
      this.relId = row.rlId;
      this.isImport = false;
      this.thisData = row;
      this.pId = row.rlId;
      this.relevanceEdit = {
        id: row.rlId,
        isUseDy: row.isUseDy,
        isDisable: row.isDisable,
        isLock: row.isLock,
        isAdavence: row.isAdavence,
      };
      this.editFormat = JSON.parse(JSON.stringify(row));
      this.rowData = row
      this.editQuery = row;
      this.type = 1
      this.editDialogVisible = true;
    },
    closeUdi(val) {
      this.selectUdiDialogVisible = false;
      this.selectErpDialogVisible = false;
      this.selectLocalVisible = false;
      this.detailDialogVisible = false;
      this.selectVersionVisible = false;
      this.getList();
      if (val) {
        this.cancelDialog();
      }
    },

    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDetailClick":
          this.handleDetailClick(row);
          break;
        case "sumitLockStatus":
          this.sumitLockStatus(row);
          break;
        case "splitSelectUdi":
          this.splitSelectUdi(row);
          break;
        case "deleteCompanyProductRelevance":
          this.deleteCompanyProductRelevance(row);
          break;
        default:
          break;
      }
    },

    getThirdSysDetail() {
      let query = {
        id: this.relevanceEdit.id,
      };

      thirdSysDetail(query)
        .then((response) => {
          this.loading = false;
          this.sysList = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.sysList = [];
        });
    },
    getSysFilter(_this) {
      sysFilterOptimize()
        .then((response) => {
          _this.loading = false;
          _this.options.getSysFilter = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.filterList = [];
        });

    },
    uploadErpProduct() {
      updateErpProduct()
        .then((response) => {
          if (response.code == 20000) {
            this.$message({
              type: "success",
              message: response.data,
            });
          } else {
            this.$message.error(response.message);
          }
        })
        .catch(() => {
        });
    },
    selectVersion() {
      this.selectVersionVisible = true;
      this.uuid = this.editQuery.uuid;
      this.originUuid = this.editQuery.originUuid;
      this.relId = this.editQuery.rlId;
    },
    closeDialog() {
      this.selectErpDialogVisible = false;
      this.selectLocalVisible = false;
      this.selectProductVisible = false;
      this.editDialogVisible = false;
      this.selectVersionVisible = false;
      this.closeUdi();
      this.getList();
    },
    onAddSubmit() {
      this.relevanceEdit.isDisable = this.editQuery.isDisable;
      this.relevanceEdit.isLock = this.editQuery.isLock;
      this.relevanceEdit.isAdavence = this.editQuery.isAdavence;
      this.relevanceEdit = this.editQuery
      this.relevanceEdit.pid = this.pId;
      if (this.checked == true) {
        this.relevanceEdit.isUseDy = 1;
      } else {
        this.relevanceEdit.isUseDy = 0;
      }
      this.relevanceEdit.id = this.editQuery.rlId,
        updatetUdiInfos(this.relevanceEdit)
          .then((response) => {
            this.loading = false;
            this.getList();
            this.cancelDialog();
          })
          .catch(() => {
            this.loading = false;
            this.cancelDialog();
          });
    },
    selectSysParam() {

      spcombie().then((response) => {
        if (response.code == 20000) {
          if (response.data.paramValue == "1") {
            this.isSpCombine = true;
          } else {
            this.isSpCombine = false;
          }
        }
      });

      let query = {
        paramKey: "smp_isUploadProuct",
      };
      selectSysParamByKey(query).then((response) => {
        if (response.code == 20000) {
          if (response.data.paramValue == "1") {
            this.isUploadSmp = true;
          }
        }
      });
      let query1 = {
        paramKey: "upload_pi_file_enabled",
      };
      selectSysParamByKey(query1).then((response) => {
        if (response.code == 20000) {
          if (response.data.paramValue == "1") {
            this.isImportFile = true;
          }
        }
      });
      let query2 = {
        paramKey: "upload_pi_file_url",
      };
      selectSysParamByKey(query2).then((response) => {
        if (response.code == 20000) {
          this.uploadFileUrl = response.data.paramValue;
        }
      });
    },
    selectProduct() {
      this.selectProductVisible = true;
    },
    closeAddDialog(val) {
      if (val) {
        this.getList();
      }
      this.addProductVisible = false;
    },

    findBasicProductSet() {
      finProductSet().then((response) => {
        if (response.code == 20000) {
          this.productRemarkSet = response.data;
        } else {
          //出错了
        }
      });
    },
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value);
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression);
      }
      return defaultRet;
    }
  }
  ,
  mounted() {
  }
  ,
  components: {
    selectUdi,
    selectErp,
    selectLocalUdi,
    selectProduct,
    ThrProductsAdd,
    selectUdiVersion,
    basicProductEdit,
    basicProductDetail,
    selectDrugProductsEdit
  }
  ,
  created() {
    this.findBasicProductSet();

    getHead("basicCompanyDRUGProducts", "1").then((re) => {
      // 处理返回的数据
      this.tableObj = re.data;
      this.tableHeader = re.data.tableList;
      this.queryList = re.data.queryList;
      this.fromList = re.data.fromList;
      this.getList();
    });
    this.selectSysParam();
    this.getSysFilter(this);
  }
  ,
}
;
</script>
<style scoped>
.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;
  margin-bottom: 6px;
}

.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;
}

.el-form-item--mini.el-form-item {
  margin-bottom: 9px;
}
</style>
