<template>
  <div>
    <el-card class="el-card">
      <el-form v-if="queryList && queryList.length > 0 " :model="filterQuery" class="query-form"
               @submit.native.prevent
               size="mini" label-width="100px">
        <el-row style=" display:flex;  flex-wrap: wrap; ">
          <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(this)"
          >查询
          </el-button
          >
        </el-button-group>
      </div>
      <el-divider style="margin: 15px"></el-divider>
      <el-table v-loading="loading" :data="list" style="width: 100%" highlight-current-row
                border :default-sort="defaultSort"
                :row-style="{ height: '32px' }"
                @row-click="(row) => executeFuc(row,'0',tableObj.handleChangeFuc)"
                @sort-change="handleSortChange"
      >

        <!--<el-table-column label="操作" width="100" fixed="right" v-if="splitType!='search'">-->
        <!--  <template slot-scope="scope">-->
        <!--    <el-button-->
        <!--      type="text"-->
        <!--      size="small"-->
        <!--      @click.native.stop="editOrder(scope.row)"-->
        <!--    >编辑-->
        <!--    </el-button-->
        <!--    >-->
        <!--    <el-button-->
        <!--      type="text"-->
        <!--      size="small"-->
        <!--      @click.native.stop="deleteDialog(scope.row)"-->
        <!--    >删除-->
        <!--    </el-button-->
        <!--    >-->
        <!--  </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-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"
        :page.sync="filterQuery.page"
        :limit.sync="filterQuery.limit"
        @pagination="getList"
      />
    </el-card>


    <el-tabs type="border-card" style="margin: 15px">
      <el-tab-pane>
        <span slot="label">单据 {{ currentRow.billNo }}-单据详情</span>
        <el-form :inline="true" :model="bizQuery" class="query-form" size="mini">
          <el-row style=" display:flex;  flex-wrap: wrap; ">
            <template v-for="(item, index) in queryList2">
              <el-form-item v-if="item.columnType == 'input' && executeEval(row,item.expression,true)"
                            :label="item.columnDesc+`:`" :key="item.id">
                <el-input
                  v-model="bizQuery[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="bizQuery[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="bizQuery[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="bizQuery[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-form-item>
              <el-button-group>
                <el-button
                  type="primary"
                  icon="el-icon-refresh"
                  @click="onBizReset"
                >重置
                </el-button>
                <el-button type="primary" @click="onBizSubmit"
                           icon="el-icon-search"
                >查询
                </el-button>
              </el-button-group>
            </el-form-item>
          </el-row>


        </el-form>

        <el-table v-loading="bizDetailLoading" :data="codeDetailList" style="width: 100%" border
                  row-key="id" :row-style="{height:'32px'}"
        >
          <template v-for="(item, index) in tableHeader2">
            <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="bizTotal>0"-->
        <!--          :total="bizTotal"-->
        <!--          :page.sync="bizQuery.page"-->
        <!--          :limit.sync="bizQuery.limit"-->
        <!--          @pagination="getBizDetailList"-->
        <!--        />-->
      </el-tab-pane>

      <!--单据扫码明细-->
      <!--<el-tab-pane>-->
      <!--  <span slot="label">单据 {{ currentRow.billNo }}-扫码明细</span>-->
      <!--  <el-form v-if="queryList4 && queryList4.length > 0" :inline="true" :model="resultQuery" class="query-form"-->
      <!--           size="mini">-->
      <!--    &lt;!&ndash;          <el-form-item class="query-form-item" label="UDI码:">&ndash;&gt;-->
      <!--    &lt;!&ndash;            <el-input&ndash;&gt;-->
      <!--    &lt;!&ndash;              v-model="resultQuery.code"&ndash;&gt;-->
      <!--    &lt;!&ndash;              placeholder="请输入UDI码"&ndash;&gt;-->
      <!--    &lt;!&ndash;              clearable&ndash;&gt;-->
      <!--    &lt;!&ndash;            >&ndash;&gt;-->
      <!--    &lt;!&ndash;            </el-input>&ndash;&gt;-->
      <!--    &lt;!&ndash;          </el-form-item>&ndash;&gt;-->
      <!--    <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-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-row>-->

      <!--  </el-form>-->

      <!--  <el-table v-loading="resultDetailLoading" :data="resultDetailList" style="width: 100%" border-->
      <!--            row-key="id" :row-style="{height:'32px'}"-->
      <!--  >-->
      <!--    <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="getCodeDetailList"-->
      <!--  />-->
      <!--</el-tab-pane>-->
    </el-tabs>


  </div>
</template>

<script>
import {
  deleteByOrderId,
  getOrderList, submitCodes
} from "@/api/inout/order";
import addOrder from "@/views/inout/DialogCreateOrder";
import errOrder from "@/views/inout/IoCreateErrorOrder";
import {getInvListByUserOptimize} from "@/api/system/invWarehouse";
import {getLocalJoinByUserOptimize} from "@/api/basic/busType";
import {selectSysParamByKey} from "@/api/param/systemParamConfig";
import {getCorrespondence} from "@/api/basic/basicUnitMaintain";
import {
  getHead, executeFuc
} from "@/utils/customConfig";
import {convertDate} from "@/utils/date";
import {isBlank} from "@/utils/strUtil";
import {getUserBindWork} from '@/api/basic/collectPoint/userWorkplace'
import {desOrderPage, getBizDetailList, getCodeList} from '@/api/collect/IoDestroy'
import {getWorkBindBusTypes, removeBusTypeById} from '@/api/basic/workPlace/sysWorkplaceDocuments'
import {filterWorkOptimize} from '@/api/basic/workPlace/sysWorkplaceManage'

export default {
  name: "IoDestroyLog1",
  data() {
    return {
      busQuery: {
        busKey: '',
        workplaceCode: null,
        page: 1,
        limit: 100
      },
      //界面配置---------------------
      tableObj: [],
      queryList: [],
      tableHeader: [],
      fromList: [],

      tableObj2: [],
      queryList2: [],
      tableHeader2: [],
      fromList2: [],

      tableObj4: [],
      queryList4: [],
      tableHeader4: [],
      fromList4: [],
      convertDateFun: convertDate,
      defaultSort: {prop: 'createTime', order: 'desc'},
      options: {
        getInvList: [],
        getWorkPlaceList: [],
        getDeptList: [],
        getBusType: [],
        findWorkPlace: [],
      },
      //界面配置---------------------end

      total: 0,
      radioCheck: false,
      currentRow: {},
      showSearch: false,
      titleMap: {
        add: "新增单据",
        edit: "编辑单据",
      },
      title: "add",
      filterQuery: {
        busType: null,
        billNo: null,
        mainAction: null,
        action: null,
        page: 1,
        limit: 10,
        startTime: null,
        endTime: null,
        keywords: null,
      },
      fromOptions: [],
      checkStatus: {
        1: "草稿",
        2: "等待处理",
        3: "等待校验",
        4: "处理异常",
        5: "校验成功",
        6: "校验异常",
        7: "已审核",
        8: "审核拒绝",
        9: "正在处理", 10: "待审核", 11: "待配货",
      },
      curIndex: "",
      idQuery: {},
      storageList: [],
      invList: [],
      list: [],
      addOrderVisible: false,
      errOrderVisible: false,
      loading: false,
      index: null,
      formName: null,
      errorDetail: "",
      formMap: {
        add: "新增",
        edit: "编辑",
      },
      enableDept: false,
      splitBusType: "SC72197936495755",
      fromTypeMap: {
        "1": "UDIMS平台",
        "2": "网页新增",
        "3": "pda即时校验",
        "4": "pda未校验",
        "5": "pc端扫码精灵",
        "6": "流转自动补单",
        "7": "UDI供应商平台",
        "8": "平衡补录单据",
        "10": "手动补单",
        "11": "仓库盘点",
        "12": "采购计划",
        "13": "领用单据",
        "14": "第三方系统单据",
      },
      deleteData: {
        billNo: "",
        status: 10,
      },
      dialogTableVisible: false,
      formLoading: false,
      deleteLoading: false,
      busTypes: [],
      actDateRange: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      viewType: 2,
      bizQuery: {
        productName: null,
        orderIdFk: null,
        page: 1,
        limit: 10
      },
      bizTotal: 0,
      bizDetailLoading: false,
      bizDetailList: [],
      codeQuery: {
        orderIdFk: null,
        page: 1,
        limit: 10
      },
      codeTotal: 0,
      codeDetailLoading: false,
      codeDetailList: [],
      resultQuery: {
        orderId: null,
        code: null,
        page: 1,
        limit: 10
      },
      resultTotal: 0,
      resultDetailLoading: false,
      resultDetailList: [],
      stockChangeVisible: false,
      curRow: null,
      //out:预出库扫码;return:预出库退回;search:预出库单查询
      splitType: null,
    };
  },
  components: {
    addOrder, errOrder
  },
  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
      })
    },
    onReset() {
      this.filterQuery = {
        ...this.filterQuery,
        id: "",
        billNo: null,
        mainAction: null,
        action: null,
        statusType: null,
        page: 1,
        limit: 10,
        startTime: null,
        endTime: null,
        keywords: null,
        invCode: this.$store.getters.locInvCode,
      };
      this.actDateRange = [];
      this.getList();
    },
    onSubmit(_this) {
      if (_this == null)
        _this = this
      if (_this.actDateRange !== null) {
        _this.filterQuery.startTime = _this.actDateRange[0];
        _this.filterQuery.endTime = _this.actDateRange[1];
      } else {
        _this.filterQuery.startTime = null;
        _this.filterQuery.endTime = null;
      }
      _this.filterQuery.page = 1;
      _this.getList();
    },
    hideSearch() {
      this.showSearch = !this.showSearch;
      this.$nextTick(() => {
        console.log('组件已刷新');
      });
    },
    getBusType(_this) {
      let query = {
        code: this.filterQuery.invCode,
        enabled: true,
      };
      getLocalJoinByUserOptimize(query)
        .then((response) => {
          _this.options.getBusType = response.data || [];
          _this.getList();
        })
        .catch(() => {
        });
    },
    addOrders() {
      this.idQuery = {};
      this.title = "add";
      this.addOrderVisible = true;
    },

    editOrder(row) {
      this.idQuery = row;
      this.title = "edit";
      this.addOrderVisible = true;
    },

    closeDialog() {
      this.addOrderVisible = false;
      this.addHosOrderVisible = false;
      this.getList();
    },

    handleSortChange(column, prop, order) {
      if (column.order === 'descending') {
        this.filterQuery.sort = 'desc'
      } else {
        this.filterQuery.sort = 'asc'
      }
      this.filterQuery.orderBy = column.prop;
      this.getList();
    },
    //获取订单列表
    getList() {
      this.loading = true;
      desOrderPage(this.filterQuery)
        .then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            this.list = response.data.list || [];
            this.total = response.data.total || 0;
          } else {
            this.$message.error(response.message);
          }
        })
        .catch((error) => {
          this.$message.error(error.message)
          this.loading = false;
          this.list = [];
          this.total = 0;
        });
    },
    deleteOrders(data) {
      this.loading = true;
      this.deleteData.billNo = data;
      deleteByOrderId(this.deleteData)
        .then((response) => {

          if (response.code == 20000) {
            this.getList();
            this.$message({
              type: "success",
              message: "删除成功！",
            });
          } else if (response.code == 520) {
            this.$message.error("新增扫码单据列表已不存在该扫码单据！");
            this.getList();
          } else {
            this.$message.error(response.message);
            this.getList();
          }

        })
        .catch(() => {
        });
    },
    deleteDialog(row) {
      this.$confirm("此操作将永久删除该订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteOrders(row.billNo);
        })
        .catch(() => {
        });
    },


    onUpload(data) {
      this.loading = true;
      var idQuery = {
        billNo: "",
      };
      idQuery.billNo = data;
      submitCodes(idQuery)
        .then((response) => {
          this.loading = false;
          if (response.code === 20000) {
            this.$message.success("提交成功");
            this.getList();
          } else {
            this.$message.error(response.message);
          }
          this.loading = false;
        });
    },
    getInvList(_this) {
      getInvListByUserOptimize()
        .then((response) => {
          _this.options.getInvList = response.data || [];
          _this.getList();
        })
        .catch(() => {
        });
    },
    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 = [];
        });
    },

    invChange(_this) {
      _this.filterQuery.action = null;
      _this.getBusType(_this);
    },
    placeChange(_this) {
      // _this.filterQuery.workKey = _this.filterQuery.workplaceName;
      // _this.getWorkPlaceList(_this);
    },

    findMethod(query) {
      this.fromOptions = [];
      let cQuery = {
        key: query,
        corpType: 2,
        page: 1,
        limit: 10,
      };
      getCorrespondence(cQuery)
        .then((response) => {
          this.loading = false;
          this.fromOptions = response.data.list || [];
        })
        .catch(() => {
          this.loading = false;
          this.fromOptions = [];
        });
    },
    statusFilterType(status) {
      const statusMap = {
        2: "warning",
        1: "warning",
        4: "danger",
        3: "success",
      };
      return statusMap[status];
    },

    errOrderDialog() {
      this.errOrderVisible = true;
    },
    executeFuc(row, type, clickFuc, value) {
      return executeFuc(this, row, type, clickFuc, value);
    },
    executeEval(row, expression, defaultRet) {
      if (expression) {
        return eval(expression);
      }
      return defaultRet;
    },
    handleSelectionChange(_this, val) {
      _this.currentRow = val;
      _this.getOrderDetails();
    },
    getOrderDetails() {
      this.bizQuery.page = 1;
      this.codeQuery.page = 1;
      this.resultQuery.page = 1;
      this.getBizDetailList();
      // this.getCodeDetailList();
    },
    onBizReset() {
      this.bizQuery = {
        productName: null,
        orderIdFk: null,
        page: 1,
        limit: 10
      };

      if (!isBlank(this.currentRow.billNo)) {
        this.getBizDetailList();
      }
    },
    onBizSubmit() {
      this.bizQuery.page = 1;
      this.getBizDetailList();
    },
    getBizDetailList() {
      if (isBlank(this.currentRow.billNo)) {
        this.$message.error("请先选择需要查询的单据！")
        return;
      }
      this.bizDetailLoading = true;
      // this.bizQuery.page = null;
      // this.bizQuery.limit = null;
      this.bizQuery.orderIdFk = this.currentRow.billNo;
      getBizDetailList(this.bizQuery).then((res) => {
        this.bizDetailLoading = false;
        if (res.code === 20000) {
          this.codeDetailList = res.data.list || [];
          this.bizTotal = res.data.total || 0;
        } else {
          this.$message.error(res.message);
          this.codeDetailList = [];
          this.bizTotal = 0;
        }
      }).catch((error) => {
        this.bizDetailLoading = false;
        this.$message.error(error.message);
        this.bizDetailList = [];
        this.bizTotal = 0;
      })
    },
    onCodeReset() {
      this.codeQuery = {
        orderIdFk: null,
        page: 1,
        limit: 10
      };
      // this.getCodeDetailList();
    },
    onCodeSubmit() {
      this.codeQuery.page = 1;
      // this.getCodeDetailList();
    },
    getCodeDetailList() {
      if (isBlank(this.currentRow.billNo)) {
        this.$message.error("请先选择需要查询的单据！")
        return;
      }

      this.resultQuery.orderId = this.currentRow.billNo;
      this.resultDetailLoading = true;
      getCodeList(this.resultQuery).then((res) => {
        this.resultDetailLoading = false;
        if (res.code === 20000) {
          this.resultDetailList = res.data.list || [];
          this.resultTotal = res.data.total || 0;
        } else {
          this.$message.error(res.message);
          this.resultDetailList = [];
          this.resultTotal = 0;
        }
      }).catch((error) => {
        this.resultDetailLoading = false;
        this.$message.error(error.message);
        this.resultDetailList = [];
        this.resultTotal = 0;
      });
    },

  },
  mounted() {
    document.body.ondrop = function (event) {
      event.preventDefault();
      event.stopPropagation();
    };
  },
  created() {
    this.getInvList(this);
    // this.getBusType(this);
    this.findWorkPlace(this, "");
    this.getWorkBindBusTypes(this, "");


    getHead("IoDestroyLog", "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("IoDestroyLog-djxq", "1").then((re) => {
      // 处理返回的数据
      this.tableObj2 = re.data;
      this.tableHeader2 = re.data.tableList;
      this.queryList2 = re.data.queryList;
      this.fromList2 = re.data.fromList;
    });
    getHead("IoDestroyLog-smxq", "1").then((re) => {
      // 处理返回的数据
      this.tableObj4 = re.data;
      this.tableHeader4 = re.data.tableList;
      this.queryList4 = re.data.queryList;
      this.fromList4 = re.data.fromList;
    });


    selectSysParamByKey({paramKey: "muti_inv_mode"}).then((res) => {
      if (res.code === 20000) {
        if (res.data.paramValue === "0") {
          this.enableDept = true;
        }
      }
    })

  },
};
</script>

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

.query-form-item {
  margin-right: 5px;
  margin-bottom: 6px;
}

</style>

