<template>
  <div>
    <el-card>
      <el-form v-if="queryList && queryList.length > 0 " :model="filterQuery" class="query-form"
               size="mini" label-width="100px">
        <el-row style=" display:flex;  flex-wrap: wrap; ">
          <!--          <el-col :span="20">-->
          <!--            <el-form-item prop="code" label="扫码查询:">-->
          <!--              <el-input-->
          <!--                id="inputer"-->
          <!--                @focus="getInputFocus($event)"-->
          <!--                @keypress.enter.native="enterKey($event)"-->
          <!--                ref="inputRef"-->
          <!--                style="ime-mode: disabled"-->
          <!--                type="tel"-->
          <!--                v-model="filterQuery.code"-->
          <!--              ></el-input>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <!--<el-col :span="20">-->
          <!--  <el-form-item prop="code" label="查询:">-->
          <!--    <el-input-->
          <!--      placeholder="请输入注册备案号/生产企业/供应商"-->
          <!--      clearable-->
          <!--      style="ime-mode: disabled"-->
          <!--      type="tel"-->
          <!--      v-model="filterQuery.key"-->
          <!--    ></el-input>-->
          <!--  </el-form-item>-->
          <!--</el-col>-->

          <template v-for="(item, index) in queryList">
            <div v-if="showSearch || item.isImport">
              <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`" :key="item.id">
                <el-input
                    v-model="filterQuery[item.columnName]"
                    :placeholder="item.columnDesc == '搜索' ? '产品通用名/规格/批次号' : 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 == 'select' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :label="item.columnDesc+`:`">
                <el-select v-model="filterQuery[item.columnName]"
                           :placeholder="item.columnDesc"
                           :disabled="executeEval(null,item.disabledFuc,false)"
                           clearable>
                  <el-option
                      v-for="dict in item.lableRuleObj"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                  />
                </el-select>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'selectServer' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :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)"
                    filterable
                    remote
                    :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"
                  />
                </el-select>
              </el-form-item>
              <el-form-item v-if="item.columnType == 'datePicker' && executeEval(row,item.expression,true)"
                            class="query-form-item"
                            :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)"
                            class="query-form-item"
                            :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>
            </div>
          </template>
        </el-row>
      </el-form>
      <!--      <div class="left-search" v-if="!showSearch">-->
      <!--        &lt;!&ndash; 关键字搜索 按需配置 &ndash;&gt;-->
      <!--        <el-form v-if="queryList && queryList.length > 0" :model="filterQuery" class="query-form" size="mini"-->
      <!--                 label-width="100px">-->
      <!--          <el-row style=" display:flex;  flex-wrap: wrap; ">-->
      <!--            <template v-for="(item, index) in queryList">-->
      <!--              <el-form-item-->
      <!--                  v-if="item.columnType == 'input' && executeEval(row,item.expression,true) && item.columnName == 'keywords'"-->
      <!--                  class="query-form-item"-->
      <!--                  :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>-->
      <!--            </template>-->
      <!--          </el-row>-->
      <!--        </el-form>-->
      <!--      </div>-->
      <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="onSubmit"
          >查询
          </el-button
          >
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>

      <el-table v-loading="loading" :data="list" style="width: 100%;" border highlight-current-row
                @row-click="(row) => executeFuc(row,'0',tableObj.handleChangeFuc)" ref="multipleTable"
                :default-sort="defaultSort"
                :row-style="{ height: '32px' }"
                @sort-change="handleSortChange">
        <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-for="(buttonItem, buttonIndex) in item.buttonRulObj"
                         :type="buttonItem.type"
                         :size="buttonItem.size"
                         :style="buttonItem.style"
                         :key="buttonItem"
                         v-if="executeEval(scope.row,buttonItem.hasPermi,true)"
                         :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"
                         @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"
              >{{ buttonItem.name }}
              </el-button>
            </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-card>
    <el-tabs type="border-card" style="margin: 15px">
      <el-tab-pane>
        <span slot="label"> {{ currentRow.cpmctymc }}-库存码明细</span>
        <el-form v-if="queryList4 && queryList4.length > 0" :inline="true" :model="resultQuery" class="query-form"
                 size="mini">
          <el-row style=" display:flex;  flex-wrap: wrap; ">
            <template v-for="(item, index) in queryList4">
              <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)"
                            :label="item.columnDesc+`:`" :key="item.id">
                <el-input
                    v-model="resultQuery[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 == 'select' && executeEval(row,item.expression,true)"
                            :label="item.columnDesc+`:`">
                <el-select v-model="resultQuery[item.columnName]"
                           :placeholder="item.columnDesc"
                           :disabled="executeEval(null,item.disabledFuc,false)"
                           clearable>
                  <el-option
                      v-for="dict in item.lableRuleObj"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                  />
                </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="resultQuery[item.columnName]"
                    :placeholder="item.columnDesc"
                    @change="executeFuc($event,'5',item.checkRules)"
                    :disabled="executeEval(null,item.disabledFuc,false)"
                    filterable
                    remote
                    :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"
                  />
                </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="resultQuery[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-item>
            <el-button-group>
              <el-button
                  type="primary"
                  icon="el-icon-refresh"
                  @click="onResultReset"
              >重置
              </el-button>
              <el-button type="primary" @click="onResultSubmit"
                         icon="el-icon-search"
              >查询
              </el-button
              >
            </el-button-group>
          </el-form-item>
        </el-form>

        <el-table v-loading="resultDetailLoading" :data="resultDetailList" style="width: 100%" border
                  row-key="id"
        >
          <template v-for="(item, index) in tableHeader4">
            <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-for="(buttonItem, buttonIndex) in item.buttonRulObj"
                           :type="buttonItem.type"
                           :size="buttonItem.size"
                           :style="buttonItem.style"
                           :key="buttonItem"
                           v-if="executeEval(scope.row,buttonItem.hasPermi,true)"
                           :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"
                           @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"
                >{{ buttonItem.name }}
                </el-button>
              </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="resultTotal>0"
            :total="resultTotal"
            :page.sync="resultQuery.page"
            :limit.sync="resultQuery.limit"
            @pagination="getResultDetailList"
        />
      </el-tab-pane>
      <el-tab-pane>
        <span slot="label"> {{ currentRow.cpmctymc }}-拆零明细</span>
        <el-form v-if="queryList5 && queryList5.length > 0" :inline="true" :model="resultQuery" class="query-form"
                 size="mini">
          <el-row style=" display:flex;  flex-wrap: wrap; ">
            <template v-for="(item, index) in queryList5">
              <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)"
                            :label="item.columnDesc+`:`" :key="item.id">
                <el-input
                    v-model="codeQuery[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 == 'select' && executeEval(row,item.expression,true)"
                            :label="item.columnDesc+`:`">
                <el-select v-model="codeQuery[item.columnName]"
                           :placeholder="item.columnDesc"
                           :disabled="executeEval(null,item.disabledFuc,false)"
                           clearable>
                  <el-option
                      v-for="dict in item.lableRuleObj"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                  />
                </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="codeQuery[item.columnName]"
                    :placeholder="item.columnDesc"
                    @change="executeFuc($event,'5',item.checkRules)"
                    :disabled="executeEval(null,item.disabledFuc,false)"
                    filterable
                    remote
                    :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"
                  />
                </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="codeQuery[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-item>
            <el-button-group>
              <el-button
                  type="primary"
                  icon="el-icon-refresh"
                  @click="onCodeResultReset"
              >重置
              </el-button>
              <el-button type="primary" @click="onCodeResultSubmit"
                         icon="el-icon-search"
              >查询
              </el-button
              >
            </el-button-group>
          </el-form-item>
        </el-form>

        <el-table v-loading="resultDetailLoading" :data="apartDetailList" style="width: 100%" border
                  row-key="id"
        >
          <template v-for="(item, index) in tableHeader5">
            <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-for="(buttonItem, buttonIndex) in item.buttonRulObj"
                           :type="buttonItem.type"
                           :size="buttonItem.size"
                           :style="buttonItem.style"
                           :key="buttonItem"
                           v-if="executeEval(scope.row,buttonItem.hasPermi,true)"
                           :disabled="executeEval(scope.row,buttonItem.disabledFuc,false)"
                           @click.native.stop="executeFuc(scope.row,'1',buttonItem.clickFuc)"
                >{{ buttonItem.name }}
                </el-button>
              </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="apartTotal>0"
            :total="apartTotal"
            :page.sync="codeQuery.page"
            :limit.sync="codeQuery.limit"
            @pagination="getResultDetailList"
        />
      </el-tab-pane>
    </el-tabs>

    <el-dialog
        title="添加库存预警设置"
        :visible.sync="addInvRemindSetDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="60%"
        v-if="addInvRemindSetDialogVisible"
    >
      <ioSplitFifoCodeRemindSetDialog
          :prescribeData="this.prescribeData"
          :closeDialog="this.closeRemindSetDialog"
      ></ioSplitFifoCodeRemindSetDialog>
    </el-dialog>

    <el-dialog
        title="损耗出库"
        :visible.sync="destroyOutDialogVisible"
        :close-on-click-modal="false"
        :close-on-press-escape="false"
        width="60%"
        v-if="destroyOutDialogVisible"
    >
      <destroyOutDialog
          :prescribeData="prescribeData"
          :destroyType="destroyType"
          :closeDialog="closeDialog"
      >
      </destroyOutDialog>
    </el-dialog>

  </div>
</template>

<script>
import {executeFuc, getHead} from "@/utils/customConfig";
import {convertDate} from "@/utils/date";
import {materialCodePage, materialPrescribePage, splitFifoDetail} from "@/api/inout/splitCode";
import {splitFifoPage} from "@/api/inout/splitInv";
import {getInvListByUserOptimize} from "@/api/system/invWarehouse";
import {getBasicUnitMaintainsOptimize} from '@/api/basic/basicUnitMaintain'
import {filterWorkOptimize, listPage} from '@/api/basic/workPlace/sysWorkplaceManage'
import ioSplitFifoCodeRemindSetDialog from "./ioSplitFifoCodeRemindSetDialog.vue";
import destroyOutDialog from "./destroyOutDialog.vue";
import {getWorkBindBusTypes, removeBusTypeById} from '@/api/basic/workPlace/sysWorkplaceDocuments'
import {getSplitCode} from '@/api/collect/collectOrder'


export default {
  name: "IoSplitFifoCodePanel",
  props: {
    // panelType: {
    //   type: Object,
    //   default: 1,
    //   required: true
    // },
    workPlaceCode: {
      type: Number,
      default: null,
      required: true
    },
  },
  data() {
    return {
      busQuery: {
        busKey: '',
        workplaceCode: null,
        page: 1,
        limit: 100
      },
      viewType: null,
      isLinkDisabled: false,
      //界面配置相关
      //扫码查询
      tableHeader: [],
      queryList: [],
      tableObj: [],
      fromList: [],
      tableHeader4: [],
      queryList4: [],
      fromList4: [],
      tableHeader5: [],
      queryList5: [],
      fromList5: [],
      convertDateFun: convertDate,
      //界面配置-------------end

      options: {
        getInvList: [],
        getDeptList: [],
        getBusType: [],
        findWorkPlace: [],
      },

      showSearch: false,
      filterQuery: {
        fifoSplit: null,
        workPlaceCode: null,
        code: null,
        billNo: null,
        page: 1,
        limit: 10,
        busType: null,
        // key: null
      },

      defaultSort: {prop: 'createTime', order: 'desc'},
      loading: false,
      list: [],
      total: 0,

      resultQuery: {
        billNo: null,
        code: null,
        page: 1,
        limit: 10
      },
      codeQuery: {
        code: null,
        page: 1,
        limit: 10
      },
      currentRow: {},
      resultTotal: 0,
      resultDetailLoading: false,
      resultDetailList: [],
      apartDetailList: [],//拆零明细
      apartTotal: 0,//拆零明细
      addInvRemindSetDialogVisible: false,
      destroyOutDialogVisible: false,
      prescribeData: {},
      destroyType: 1,//1 产品损耗 2.根据code损耗
    }
  },

  components: {ioSplitFifoCodeRemindSetDialog, destroyOutDialog},
  methods: {
    changePlace(_this, query) {
      _this.getWorkBindBusTypes(_this, query)
    },
    getWorkBindBusTypes(_this, query) {
      _this.busQuery.workplaceCode = query
      getWorkBindBusTypes(this.busQuery).then(res => {
        if (res.code == 20000) {
          let busTypes = res.data.list || [];
          // _this.options.getWorkPlace = res.data.list || [];
          let getWorkPlace = busTypes.map(busType => {
            return {
              code: busType.documentTypeCode,
              label: busType.busName
            };
          });
          _this.options.getBusType = getWorkPlace
          if (_this.options.getBusType.length == 1) {
            _this.filterQuery.busType = _this.options.getBusType[0].code
          } else {
            _this.filterQuery.busType = null
          }
        }
        return
      })
    },
    //界面配置相关------------
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value);
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression);
      }
      return defaultRet;
    },
    handleSortChange(column, prop, order) {
      if (column.order === 'descending') {
        this.query.sort = 'desc'
      } else {
        this.query.sort = 'asc'
      }
      this.query.orderBy = column.prop;
      this.getList();
    },
    ///界面配置相关------------end
    getInvList(_this) {
      getInvListByUserOptimize()
          .then((response) => {
            _this.options.getInvList = response.data || [];
            _this.getList();
          })
          .catch(() => {
          });
    },

    hideSearch() {
      this.showSearch = !this.showSearch;
    },
    onReset() {
      this.filterQuery = {
        fifoSplit: null,
        workPlaceCode: null,
        code: null,
        billNo: null,
        page: 1,
        limit: 10,
      };
      this.actDateRange = [];
      this.getList();
    },
    onSubmit() {
      this.filterQuery.page = 1;
      this.getList();
    },

    getList() {
      this.loading = true;
      // this.filterQuery.fifoSplit = this.panelType
      splitFifoPage(this.filterQuery).then(res => {
        this.loading = false
        let dataList = res.data.list
        dataList.forEach(item => {
          // 检查busName是否为null
          if (item.busName === null) {
            item.busName = "共享库存";
          }
        });
        this.list = dataList || []
        this.total = res.data.total || 0
      }).catch(() => {
        this.loading = false
        this.list = []
        this.total = 0
      })
    },

    detailClick(_this, row) {
      _this.resultQuery = {
        relId: row.relId,
        batchNo: row.batchNo,
        supId: row.supId,
        workPlaceCode: row.workPlaceCode,
        fifoSplit: row.fifoSplit,
        page: 1,
        limit: 10
      }
      _this.currentRow = row
      _this.getResultDetailList();
      _this.codeQuery = {
        relId: row.relId,
        batchNo: row.batchNo,
        workPlaceCode: row.workPlaceCode,
        page: 1,
        limit: 10
      }
      _this.getSplitCodeDetail();
    },

    getResultDetailList() {
      this.loading = true;
      splitFifoDetail(this.resultQuery).then(res => {
        this.loading = false
        this.resultDetailList = res.data.list || []
        this.resultTotal = res.data.total || 0
      }).catch(() => {
        this.loading = false
        this.resultDetailList = []
        this.resultTotal = 0
      })

    },
    getSplitCodeDetail() {
      getSplitCode(this.codeQuery).then(res => {
        if (res.code == 20000) {
          // this.loading = false
          this.apartDetailList = res.data.list || []
          this.apartTotal = res.data.total || 0
        }
      })
          .catch(() => {
            // this.loading = false
            this.apartDetailList = []
            this.apartTotal = res.data.total || 0
          })
    },
    onCodeResultSubmit() {
      this.codeQuery = {
        code: this.codeQuery.code,
        relId: this.currentRow.relId,
        batchNo: this.currentRow.batchNo,
        workPlaceCode: this.currentRow.workPlaceCode,
        page: 1,
        limit: 10
      }
      this.getSplitCodeDetail()
    },
    onCodeResultReset() {
      this.codeQuery = {
        relId: this.currentRow.relId,
        batchNo: this.currentRow.batchNo,
        workPlaceCode: this.currentRow.workPlaceCode,
        page: 1,
        limit: 10
      }
      this.getSplitCodeDetail()
    },

    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },


    getInputFocus(event) {
      event.currentTarget.select();
    },
    enterKey(_this, event) {
      _this.onSubmit();
    },
    findWorkPlace(_this, val) {
      let query = {
        // chargeUser: _this.$store.getters.userId,
        userIdFlag: true,
        key: val,
        page: 1,
        limit: 10,
      }
      filterWorkOptimize(query)
          .then((response) => {
            _this.loading = false;
            _this.options.findWorkPlace = response.data || [];
            if (_this.options.findWorkPlace.length == 1) {
              _this.filterQuery.workPlaceCode = _this.options.findWorkPlace[0].code;
              _this.getWorkBindBusTypes(_this, _this.filterQuery.workPlaceCode)
            }
          })
          .catch(() => {
            _this.loading = false;
            _this.options.findWorkPlace = [];
          });
    },

    invRemindSet(_this, row) {
      _this.prescribeData = row
      _this.addInvRemindSetDialogVisible = true;
    },
    closeRemindSetDialog() {
      this.prescribeData = null;
      this.addInvRemindSetDialogVisible = false;
      this.getList();
    },
    //损耗出库
    destroyOut(_this, row) {
      _this.prescribeData = row
      _this.destroyType = 1
      _this.destroyOutDialogVisible = true;
    },
    closeDialog() {
      this.destroyOutDialogVisible = false
      this.getList()
      this.detailClick(this, this.prescribeData)
    },
    destroyOutByCode(_this, row) {
      _this.prescribeData = row
      _this.destroyType = 2
      _this.destroyOutDialogVisible = true;
    }

  },
  created() {
    if (this.$route.query.workplaceId != null) {
      this.filterQuery.workPlaceCode = Number(this.$route.query.workplaceId)
      this.viewType = 1
      this.isLinkDisabled = true
    }
    this.findWorkPlace(this, "")
    // console.log(this.panelType)
    getHead("ioSplitFifoCode", "1").then((re) => {
      // 处理返回的数据
      this.tableObj = re.data;
      this.tableHeader = re.data.tableList;
      this.queryList = re.data.queryList;
      this.fromList = re.data.fromList;
      this.getList();
    });
    getHead("ioSplitFifoCode-smmx", "1").then((re) => {
      // 处理返回的数据
      this.tableObj4 = re.data;
      this.tableHeader4 = re.data.tableList;
      this.queryList4 = re.data.queryList;
      this.fromList4 = re.data.fromList;
    });
    getHead("ioSplitFifoCode-clmx", "1").then((re) => {
      // 处理返回的数据
      this.tableObj5 = re.data;
      this.tableHeader5 = re.data.tableList;
      this.queryList5 = re.data.queryList;
      this.fromList5 = re.data.fromList;
    });
    this.filterQuery.workPlaceCode = this.workPlaceCode
  }

}
</script>

<style scoped>
.query-form {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
}

.query-form-item {
  margin-right: 5px;
  margin-bottom: 6px;
}
</style>
