<!-- 表格过滤组件（包括条件、排序功能） 由于组件内部的子组件暂时没有复用的场景，因此先不封装子组件，这样方便模块之间相互通讯和减少不必要层级 -->
<!--width="985px"-->
<!--:width="fromStr === 'queryReport' ? '935px' : '1100px'"-->
<template>
  <el-dialog
    class="x-table-filter-wrap np-dialog"
    append-to-body
    modal-append-to-body
    :visible.sync="dialogVisible"
    width="1100px"
    :before-close="handleBeforeClose"
    :resizable="resizable"
    @open="handleOpen">
    <div class="x-table-filter-core">
      <!--左边部分，包括条件，排序和表格设置-->
      <div class="x-table-filter-core-left">
        <div class="top-btn-wrapper">
          <div class="top-btn-wrapper-left">
            <el-button-group>
              <el-button v-for="item in activeTabOptions" :class="{active: activeTabName === item.name}"
                         :key="item.name"
                         type="primary" @click="handleTabClick(item)" v-show="item.show">{{item.label}}
              </el-button>
            </el-button-group>
          </div>
          <div class="top-btn-wrapper-right" v-if="activeTabName === activeTabOptions[0].name">
            <el-button type="primary" @click="insertCondition">插入</el-button>
            <el-button type="danger" @click="deleteCondition">删除</el-button>
            <el-button type="danger" @click="deleteAllCondition">全删</el-button>
          </div>
        </div>
        <el-tabs v-model="activeTabName">
          <el-tab-pane name="condition">
            <el-form @submit.native.prevent :model="planConditionInfoModel" ref="planConditionTableForm">
              <vxe-table
                class="meta-table-filter-table x-table"
                ref="planConditionTable"
                :data="planConditionInfoModel.planConditionList"
                border
                highlight-current-row
                height="350"
                header-align="center"
                align="left"
                style="width: 100%"
              >
                <vxe-table-column field="logicalOperator" :width="systemConfig ? 70 : 106" title="逻辑">
                  <!--<vxe-table-column field="logicalOperator" width="80" title="逻辑">-->
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item v-if="rowIndex > 0 || !systemConfig"
                                  :prop="'planConditionList.' + rowIndex + '.logicalOperator'"
                                  :rules="tableDataRules.logicalOperator">
                      <el-select v-model="row.logicalOperator" placeholder="请选择" :popper-append-to-body="false">
                        <el-option v-for="item in logicalOperatorOptions" :key="item.value" :label="item.text"
                                   :value="item.value"></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="leftBracket" :width="systemConfig ? 80 :116" title="(">
                  <!--<vxe-table-column field="leftBracket" width="100" title="(">-->
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.leftBracket'"
                                  :rules="tableDataRules.leftBracket">
                      <el-select v-model="row.leftBracket" placeholder="请选择" :popper-append-to-body="false">
                        <el-option
                          v-for="item in leftBracketOptions"
                          :key="item.value"
                          :label="item.text"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="uniqueFieldCode" v-if="systemConfig" width="160" title="条件标识">
                  <template v-slot:default="{row}">
                    <!--<el-form-item :prop="'planConditionList.' + rowIndex + '.uniqueFieldCode'"
                                  :rules="tableDataRules.fieldCode" :required="false">-->
                    <el-input
                      v-model="row.uniqueFieldCode"
                      placeholder="请输入内容"
                      clearable
                    ></el-input>
                    <!--</el-form-item>-->
                  </template>
                </vxe-table-column>
                <vxe-table-column field="fieldCode" :width="systemConfig ? 150 :186"
                                  :title="systemConfig ? '选择条件' : '条件'">
                  <!--                <vxe-table-column field="fieldCode" width="160" :title="systemConfig ? '选择条件' : '条件'">-->
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.fieldCode'"
                                  :rules="tableDataRules.fieldCode">
                      <el-select v-model="row.fieldCode" placeholder="请选择" clearable :popper-append-to-body="false"
                                 @change="handleConditionFieldCodeChange({row, rowIndex, value: $event})">
                        <el-option
                          v-for="item in conditionTableList"
                          :key="item.fieldCode"
                          :label="item.name"
                          :value="item.fieldCode"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column v-if="systemConfig" field="fieldShowName" title="条件显示名称" width="150">
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.fieldShowName'"
                                  :rules="tableDataRules.fieldShowName">
                      <el-input v-model="row.fieldShowName" placeholder="请输入内容"></el-input>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="operator" title="比较关系" :width="systemConfig ? 100 :136">
                  <!--                <vxe-table-column field="operator" title="比较关系" width="110">-->
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.operator'"
                                  :rules="tableDataRules.operator">
                      <el-select
                        v-model="row.operator"
                        :popper-append-to-body="false"
                        placeholder="请选择">
                        <el-option
                          v-for="item in operatorOptions"
                          :key="item.value"
                          :label="item.text"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="fieldValue" :title="systemConfig ? '初始值数值' : '数值'"
                                  :width="systemConfig ? 195 :235">
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.fieldValue'"
                                  :rules="tableDataRules.fieldValue">
                      <el-input
                        v-if="row.fieldInputType === 'NUMBER'"
                        v-model="row.fieldValue"
                        type="number"
                        placeholder="请输入内容"
                        clearable
                      ></el-input>
                      <el-date-picker
                        v-else-if="(/^(DATE|YEAR|MONTH|DATETIME)$/).test(row.fieldInputType)"
                        v-model="row.fieldValue"
                        :type="(row.fieldInputType || '').toLocaleLowerCase()"
                        style="width: 100%;"
                        :editable="false"
                        :clearable="true"
                        placeholder="选择日期或时间">
                      </el-date-picker>
                      <el-select
                        v-else-if="(/^(RADIO|SELECT_ONE|SELECT_MULTI|CHECKBOX)$/).test(row.fieldInputType)"
                        v-model="row.fieldValue"
                        :popper-append-to-body="false"
                        :multiple="(/^(SELECT_MULTI|CHECKBOX)$/).test(row.fieldInputType)"
                        placeholder="请选择"
                        clearable>
                        <el-option
                          v-for="item in row.options"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                      <x-meta-search-list v-else-if="(/^(POP_ONE|POP_MULTI)$/).test(row.fieldInputType)"
                                      v-model="row.fieldValue" :append-result="row.appendResult"
                                      :row-key="row.rowKey" :row-name="row.rowName" :data-code="row.dataCode"
                                      :search-option-type="row.searchOptionType"
                      ></x-meta-search-list>
                      <el-input
                        v-else
                        v-model="row.fieldValue"
                        size="mini"
                        placeholder="请输入内容"
                        clearable
                      ></el-input>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column v-if="systemConfig" field="presetValue" title="公式" width="220">
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.presetValue'">
                      <el-input
                        v-model="row.presetValue"
                        placeholder="请输入内容"
                        clearable
                      ></el-input>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <vxe-table-column field="rightBracket" title=")" :width="systemConfig ? 100 :136">
                  <!--<vxe-table-column field="rightBracket" title=")" width="100">-->
                  <template v-slot:default="{row, rowIndex}">
                    <el-form-item :prop="'planConditionList.' + rowIndex + '.rightBracket'"
                                  :rules="tableDataRules.rightBracket">
                      <el-select v-model="row.rightBracket" placeholder="请选择" :popper-append-to-body="false">
                        <el-option
                          v-for="item in rightBracketOptions"
                          :key="item.value"
                          :label="item.text"
                          :value="item.value"
                        ></el-option>
                      </el-select>
                    </el-form-item>
                  </template>
                </vxe-table-column>
                <template v-if="systemConfig">
                  <vxe-table-column field="shortcutShow" title="快捷显示" width="80" align="center">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.shortcutShow'">
                        <el-checkbox v-model="row.shortcutShow"></el-checkbox>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="showLabel" title="显示标签" width="80" align="center">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.showLabel'">
                        <el-checkbox v-model="row.showLabel"></el-checkbox>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="readOnly" title="只读" width="50" align="center">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.readOnly'">
                        <el-checkbox v-model="row.readOnly"></el-checkbox>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
<!--                  <vxe-table-column field="required" title="必录" width="50" align="center">-->
<!--                    <template v-slot:default="{row, rowIndex}">-->
<!--                      <el-form-item :prop="'planConditionList.' + rowIndex + '.required'">-->
<!--                        <el-checkbox v-model="row.required"></el-checkbox>-->
<!--                      </el-form-item>-->
<!--                    </template>-->
<!--                  </vxe-table-column>-->
                  <vxe-table-column field="ruleIdArrayJson" title="校验规则" width="160" align="center">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.ruleIdArrayJson'">
                        <el-select v-model="row.ruleIdArrayJson" multiple :popper-append-to-body="false">
                          <el-option
                            v-for="item in formRules"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          ></el-option>
                        </el-select>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="positionRow" title="行" width="80">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.positionRow'">
                        <el-input-number v-model="row.positionRow" :precision="0" :step="1" :min="1"
                                         :max="4"></el-input-number>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="positionColumn" title="列" width="100">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.positionColumn'">
                        <el-input-number v-model="row.positionColumn" :precision="0" :step="1" :min="1"
                                         :max="4"></el-input-number>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="positionWidth" title="宽" width="100">
                    <template v-slot:default="{row, rowIndex}">
                      <el-form-item :prop="'planConditionList.' + rowIndex + '.positionWidth'">
                        <el-input-number v-model="row.positionWidth" :precision="0" :step="1" :min="1"
                                         :max="4"></el-input-number>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column field="positionHeight" title="高" width="100">
                    <template v-slot:default="{row}">
                      <el-form-item>
                        <el-input-number v-model="row.positionHeight" :precision="0" :step="1" :min="1"
                                         :max="4"></el-input-number>
                      </el-form-item>
                    </template>
                  </vxe-table-column>
                </template>
              </vxe-table>
            </el-form>
            <div class="condition-preview-wrapper">
              <el-scrollbar>
                <x-condition
                  :condition-config="conditionConfig"
                ></x-condition>
              </el-scrollbar>
            </div>
          </el-tab-pane>
          <el-tab-pane name="sort" v-if="sortConfigVisible">
            <el-row class="sort-top-wrapper">
              <el-col :span="20">
                <vxe-table
                  :data="fieldList"
                  class="x-table"
                  ref="planSortSourceTable"
                  border
                  highlight-current-row
                  height="300"
                  style="width: 100%"
                  :show-header="false"
                  align="center"
                >
                  <vxe-table-column field="name"></vxe-table-column>
                </vxe-table>
              </el-col>
              <el-col class="sort-top-col" :span="4">
                <el-button type="primary" @click="handleAdd">添加</el-button>
              </el-col>
            </el-row>
            <el-row class="sort-bottom-wrapper">
              <el-col :span="20">
                <vxe-table
                  :data="planSortList"
                  class="plan-sort-table"
                  ref="planSortTable"
                  border
                  highlight-current-row
                  height="235"
                  style="width: 100%"
                  align="center"
                >
                  <vxe-table-column field="fieldName" title="排序字段"></vxe-table-column>
                  <vxe-table-column field="orderValue" title="排序方式" width="200">
                    <template v-slot:default="{row}">
                      <el-radio v-model="row.orderValue" label="ASC">升序</el-radio>
                      <el-radio v-model="row.orderValue" label="DESC">降序</el-radio>
                    </template>
                  </vxe-table-column>
                </vxe-table>
              </el-col>
              <el-col class="sort-bottom-col" :span="4">
                <el-button type="primary" @click="handleSortUp">上移</el-button>
                <br>
                <el-button type="primary" @click="handleSortDown">下移</el-button>
                <br>
                <el-button type="danger" @click="handleDelete('planSortTable', planSortList)">删除</el-button>
                <br>
                <el-button type="danger" @click="handleSortClear">清除</el-button>
              </el-col>
            </el-row>
          </el-tab-pane>
          <el-tab-pane name="column" v-if="columnConfigVisible">
            <el-row>
              <el-col :span="20" class="table-config-left-wrapper">
                <vxe-table
                  :data="planColumnList"
                  class="plan-config-table"
                  ref="planColumnTable"
                  border
                  highlight-current-row
                  :height="systemConfig ? '300px' : '536px'"
                  style="width: 100%"
                  :mouse-config="{area: true, extension: true}"
                  :edit-config="{trigger: 'dblclick', mode: 'cell', showStatus: false, showIcon: false, autoClear: true}"
                  :keyboard-config="{isClip: true, isArrow: true, isEnter: true, isTab: true, isEdit: true}"
                  align="left">
                  <vxe-table-column type="seq" width="50"></vxe-table-column>
                  <vxe-table-column field="fieldName" title="标题" min-width="160"></vxe-table-column>
                  <vxe-table-column field="showed" title="显示" width="50" align="center">
                    <template v-slot:default="{row}">
                      <el-checkbox v-model="row.showed"></el-checkbox>
                    </template>
                  </vxe-table-column>
                  <vxe-table-column :edit-render="{name: 'ElInput'}" field="width" title="宽度" width="100">
                  </vxe-table-column>
                  <vxe-table-column :edit-render="{name: 'ElSelect', options: alignOptions, popperAppendToBody: false}" :formatter="formatAlign"
                                    field="align" title="对齐方式" width="150">
                  </vxe-table-column>
                  <vxe-table-column v-if="systemConfig" :edit-render="{name: 'ElSelect', props: {clearable: true, popperAppendToBody: false}, options: planGroupColumnList, optionProps: {label: 'fieldName', value: 'fieldCode'}}"
                                    field="parentFieldCode" title="分组父表头" width="160">
                  </vxe-table-column>
                  <vxe-table-column v-if="systemConfig && metaType === 'edit'" :edit-render="{name: 'ElSelect', props: {clearable: true, multiple: true, popperAppendToBody: false}, options: formRules, optionProps: {label: 'name', value: 'id'}}"
                                    field="ruleIdArrayJson" title="校验规则" width="160">
                  </vxe-table-column>
                  <vxe-table-column v-if="systemConfig && metaType === 'edit'" field="readOnly" title="只读" width="50" align="center">
                    <template v-slot:default="{row}">
                      <el-checkbox v-model="row.readOnly"></el-checkbox>
                    </template>
                  </vxe-table-column>
                </vxe-table>
              </el-col>
              <el-col :span="4" class="table-config-right-wrapper">
                <el-button type="primary" @click="handleColumnConfigUp">上移</el-button>
                <el-button type="primary" @click="handleColumnConfigDown">下移</el-button>
                <el-button type="primary" @click="handleColumnConfigCheckAll">全选</el-button>
                <el-button type="danger" @click="handleColumnConfigClearAll">全清</el-button>
                <el-button type="primary" @click="handleColumnConfigSetDefault">默认值</el-button>
              </el-col>
            </el-row>
            <el-row v-if="systemConfig">
              <el-col :span="20" class="table-config-left-wrapper">
                <vxe-table
                  :data="planGroupColumnList"
                  class="plan-config-table"
                  ref="planGroupColumnTable"
                  border
                  highlight-current-row
                  height="235px"
                  style="width: 100%"
                  :mouse-config="{area: true, extension: true}"
                  :edit-config="{trigger: 'dblclick', mode: 'cell', showStatus: false, showIcon: false, autoClear: true}"
                  :keyboard-config="{isClip: true, isArrow: true, isEnter: true, isTab: true, isEdit: true}"
                  align="left">
                  <vxe-table-column type="seq" width="50"></vxe-table-column>
                  <vxe-table-column :edit-render="{name: 'ElInput'}" field="fieldName"
                                    title="分组表头名称"></vxe-table-column>
                  <vxe-table-column :edit-render="{name: 'ElInput'}" field="fieldCode"
                                    title="分组表头字段"></vxe-table-column>
                  <vxe-table-column
                    :edit-render="{name: 'ElSelect', props: {clearable: true, popperAppendToBody: false}, options: planGroupColumnList, optionProps: {label: 'fieldName', value: 'fieldCode'}}"
                    field="parentFieldCode" title="分组父表头" width="180">
                  </vxe-table-column>
                </vxe-table>
              </el-col>
              <el-col :span="4" class="table-config-right-wrapper">
                <el-button type="primary" @click="handleGroupColumnConfigAdd">添加</el-button>
                <el-button type="danger" @click="handleGroupColumnConfigDelete">删除</el-button>
              </el-col>
            </el-row>
          </el-tab-pane>
        </el-tabs>
        <div class="bottom-btn-wrapper">
          <el-button type="primary" :disabled="saveDisabled" @click="handleConfirm">确定</el-button>
          <el-button type="danger" @click="handleCancel">取消</el-button>
        </div>
      </div>
      <!--左边部分，包括条件，排序和表格设置-->
      <!--右边部分，包括方案列表和对应操作按钮-->
      <div class="x-table-filter-core-right">
        <vxe-table
          ref="planListTable"
          :data="planList"
          height="535px"
          style="width: 100%"
          border
          highlight-current-row
          @current-change="handlePlanChange"
          align="left">
          <vxe-table-column field="name" title="方案列表" :formatter="formatPlanName"></vxe-table-column>
        </vxe-table>
        <div class="plan-list-btn-wrapper">
          <el-button type="primary" :disabled="saveDisabled" @click="handleSaveMetaQuery">保存</el-button>
          <el-button type="danger" @click="handleDeleteMetaQuery">删除</el-button>
        </div>
      </div>
      <!--右边部分，包括方案列表和对应操作按钮-->
    </div>
    <el-dialog width="500px" :before-close="resetMetaQuery" :visible.sync="saveDialogVisible"
               append-to-body
               modal-append-to-body
               title="提示">
      <template v-slot:default>
        <el-form @submit.native.prevent
                 label-width="90px"
                 :model="metaQuery"
                 :rules="saveMetaQueryRules"
                 class="save-dialog-body"
                 ref="saveMetaQueryForm">
          <div v-if="systemConfig">
            <el-form-item label="方案编码：" prop="queryCode">
              <el-input v-model="metaQuery.queryCode"></el-input>
            </el-form-item>
          </div>
          <div>
            <el-form-item label="方案名称：" prop="name">
              <el-input v-model="metaQuery.name"></el-input>
            </el-form-item>
          </div>
        </el-form>
      </template>
      <template v-slot:footer>
        <div>
          <el-button type="primary" @click="handleSaveConfirm">确认</el-button>
          <el-button type="danger" @click="() => {saveDialogVisible = false; resetMetaQuery();}">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </el-dialog>
</template>

<script>
import {
  getMetaQueryPlanDetail,
  getMetaQueryPlanList,
  saveOrUpdateMetaQuery,
  delMetaQueryPlan, getMetaQueryAll,
  searchMetaDataReportList
} from '../../api/metaDataApi';
import { XCondition, XDialog } from '@newpearl/ui';
import {
  InputNumber,
  Input,
  Checkbox,
  Radio,
  Button,
  ButtonGroup,
  Form,
  FormItem,
  Tabs,
  TabPane,
  Select,
  Option,
  DatePicker,
  Scrollbar,
  Row,
  Col
} from 'element-ui';
import { Table, Column } from 'vxe-table';
import { getGroupColumnsAndLeafColumns, getConditionItem, getConditionModel } from '../../util/componentUtil';
import {
  COMPARISON_OPERATOR_CONTAIN,
  COMPARISON_OPERATOR_EQUAL, COMPARISON_OPERATOR_IN,
  COMPARISON_OPERATOR_OPTIONS,
  CUSTOM_QUERY_TYPE,
  DEFAULT_QUERY_TYPE,
  FIELD_INPUT_TYPE_CHECKBOX,
  FIELD_INPUT_TYPE_DATE,
  FIELD_INPUT_TYPE_DATETIME,
  FIELD_INPUT_TYPE_NUMBER, FIELD_INPUT_TYPE_POP_MULTI, FIELD_INPUT_TYPE_POP_ONE,
  FIELD_INPUT_TYPE_RADIO, FIELD_INPUT_TYPE_SELECT_MULTI,
  FIELD_INPUT_TYPE_SELECT_ONE,
  LOGICAL_OPERATOR_AND, LOGICAL_OPERATOR_OPTIONS,
  SET_REPORT, SYSTEM_QUERY_TYPE, FIELD_INPUT_TYPE_MONTH, FIELD_INPUT_TYPE_YEAR,
  ALIGN_LEFT, ALIGN_OPTIONS, QUERY_REPORT, META_TYPE_QUERY, META_TYPE_EDIT
} from '../x-meta-query/meta-query-constant';
import { convertCondition, getMetaData, getUniqueField, sortPlanList } from '../../util/metaQueryUtil';
import { getOptionsByCode } from '../../util/dictUtil';
import * as appUtils from '../../util/appUtils';
import {MULTIPLE_SELECT, SINGLE_SELECT} from '../../mixins/search-dialog-mixin';
// import { DialogDrag } from '@newpearl/ui/lib/directive/draggable';
// import { DialogResize } from '@newpearl/ui/lib/directive/resizable';
const DEFAULT_SHOW = true;
const DEFAULT_ALIGN = ALIGN_LEFT.value;
const DEFAULT_WIDTH = 300;
// 表单校验规则缓存
let formRulesCache = [];
export default {
  name: 'XTableFilter',
  // directives: {
  //   DialogDrag,
  //   DialogResize
  // },
  components: {
    ElDialog: XDialog.ElDialog,
    [XCondition.name]: XCondition,
    [Table.name]: Table,
    [Column.name]: Column,
    [Button.name]: Button,
    [ButtonGroup.name]: ButtonGroup,
    [Form.name]: Form,
    [FormItem.name]: FormItem,
    [Tabs.name]: Tabs,
    [TabPane.name]: TabPane,
    [Select.name]: Select,
    [Option.name]: Option,
    [DatePicker.name]: DatePicker,
    [Scrollbar.name]: Scrollbar,
    [Row.name]: Row,
    [Col.name]: Col,
    [Radio.name]: Radio,
    [Checkbox.name]: Checkbox,
    [Input.name]: Input,
    [InputNumber.name]: InputNumber
  },
  inheritAttrs: false,
  props: {
    /**
     * 页面的所有筛选条件，包括配置的条件和表格自带的过滤
     */
    tempConditionConfig: Object,
    /**
     * 页面表格自带的排序
     */
    // tempSortList: Array,
    /**
     * 获取列表中字段，由于vxe-grid自带隐藏和显示字段功能，所以通过函数来实时获取
     */
    getTempColumnList: Function,
    fromStr: {
      type: String,
      // queryReport 用于用户使用报表时查询, setReport 用于产品或开发添加新报表
      default: QUERY_REPORT
    },
    fieldList: {
      type: Array,
      default() {
        return [];
      }
    },
    dataCode: String,
    queryCode: String,
    sortConfigVisible: {
      type: Boolean,
      default: true
    },
    columnConfigVisible: {
      type: Boolean,
      default: true
    },
    resizable: {
      type: [Boolean, Object],
      default: false
    },
    metaType: {
      type: String,
      default: META_TYPE_QUERY.value
    }
  },
  data() {
    return {
      // 改属性是控制保存按钮是否disabled，打开本弹窗，如果查询第一个方案的失败，但是用户还是点击保存，就有可能导致conditions和sorts丢失，lists初始的情况
      // 如果是切换方案时查询失败，继续点击保存，就会导致上一个方案的详情覆盖下一个方案的详情，参考后端代码
      /*
      * if (lists != null && lists.size() > 0) {
            lists.stream().forEach(item -> {
                item.setDataCode(dataCode);
                item.setQueryCode(queryCode);// 这里会将上一个方案的详情，变成下一个方案的详情
                item.setCreateTime(metaquery.getCreateTime());
                item.setModifyTime(metaquery.getModifyTime());

            });
            metaQueryListDao.deleteMetaQueryListByCode(dataCode, queryCode); // 这里会将下一个方案原来的详情删除掉
            this.metaQueryListDao.saveAll(lists);
        } else {
            this.metaQueryListDao.deleteMetaQueryListByCode(dataCode, queryCode);
        }
      * */
      saveDisabled: true,
      combineConditionList: [],
      dialogVisible: false,
      planList: [], // 方案列表
      planConditionInfoModel: {
        planConditionList: [] // 查询条件信息
      },
      conditionConfig: {
        labelWidth: '100px',
        model: {},
        list: []
      },
      planSortList: [], // 排序信息
      planColumnList: [], // 表格信息
      planGroupColumnList: [], // 父表头信息
      activeTabName: 'condition',
      logicalOperatorOptions: LOGICAL_OPERATOR_OPTIONS,
      leftBracketOptions: [
        { text: ' ', value: 'ZERO_BRACKET' },
        { text: '(', value: 'ONE_BRACKET' },
        { text: '((', value: 'TWO_BRACKET' },
        { text: '(((', value: 'THREE_BRACKET' },
        { text: '((((', value: 'FOUR_BRACKET' }
      ],
      rightBracketOptions: [
        { text: ' ', value: 'ZERO_BRACKET' },
        { text: ')', value: 'ONE_BRACKET' },
        { text: '))', value: 'TWO_BRACKET' },
        { text: ')))', value: 'THREE_BRACKET' },
        { text: '))))', value: 'FOUR_BRACKET' }
      ],
      operatorOptions: COMPARISON_OPERATOR_OPTIONS,
      tableDataRules: {
        logicalOperator: { required: true, message: '必填字段', trigger: 'blur' },
        leftBracket: { required: true, message: '必填字段', trigger: 'blur' },
        fieldCode: { required: true, message: '必填字段', trigger: 'blur' },
        fieldShowName: { required: true, message: '必填字段', trigger: 'blur' },
        operator: { required: true, message: '必填字段', trigger: 'blur' },
        // fieldValue: { required: true, message: '必填字段', trigger: 'blur'},
        rightBracket: { required: true, message: '必填字段', trigger: 'blur' },
        uniqueFieldCode: { required: false, message: '唯一标识只能使用数字、字母', pattern: /^[a-zA-Z0-9]+$/, trigger: 'blur' }
      },
      alignOptions: JSON.parse(JSON.stringify(ALIGN_OPTIONS)),
      // 基础查询方案，用户自定义的查询方案是基于基础查询方案
      baseMetaQuery: null,
      // 保存弹窗
      saveDialogVisible: false,
      metaQuery: {
        queryCode: '',
        name: '',
        queryType: ''
      },
      saveMetaQueryRules: {
        queryCode: { required: true, message: '编码只能使用数字、字母和横线', pattern: /^[a-zA-Z0-9-]+$/, trigger: 'blur' },
        name: {
          required: true,
          message: '名称只能含有汉字、数字、字母、下划线',
          pattern: /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/,
          trigger: 'blur'
        }
      },
      formRules: []
    };
  },
  methods: {
    handleGroupColumnConfigAdd() {
      this.planGroupColumnList.push({
        fieldName: '',
        fieldCode: '',
        parentFieldCode: ''
      });
    },
    handleGroupColumnConfigDelete() {
      const row = this.$refs.planGroupColumnTable.getCurrentRecord();
      if (!row) {
        return;
      }
      const fieldCode = row.fieldCode;
      if (!fieldCode) {
        this.handleDelete('planGroupColumnTable', this.planGroupColumnList);
        return;
      }
      // 判断分组表头是否被使用
      for (const item of this.planColumnList) {
        if (item.parentFieldCode === fieldCode) {
          this.$notify.error('该分组表头已被' + item.fieldName + '使用');
          return;
        }
      }
      for (const item of this.planGroupColumnList) {
        if (item.parentFieldCode === fieldCode) {
          this.$notify.error('该分组表头已被' + item.fieldName + '使用');
          return;
        }
      }
      this.handleDelete('planGroupColumnTable', this.planGroupColumnList);
    },
    resetMetaQuery(done) {
      this.metaQuery.queryCode = '';
      this.metaQuery.name = '';
      delete this.metaQuery.queryType;
      delete this.metaQuery.baseId;
      done && done();
    },
    handleSaveConfirm() {
      this.$refs.saveMetaQueryForm.validate((flag, object) => {
        if (!flag) {
          if (object) {
            for (const key in object) {
              const item = object[key];
              if (!Array.isArray(item) || item.length < 1) {
                continue;
              }
              this.$notify.error(item[0].message);
            }
          }
          return;
        }
        // 判断名称是否有重复
        for (const item of this.planList) {
          if (item.name === this.metaQuery.name) {
            this.$notify.error('方案名称重复');
            return;
          }
        }
        if (!this.metaQuery.queryType) {
          this.metaQuery.queryType = this.systemConfig ? DEFAULT_QUERY_TYPE : CUSTOM_QUERY_TYPE;
        }
        this.metaQuery.dataCode = this.dataCode;
        this.saveMetaQuery(this.metaQuery);
      });
    },
    formatAlign({ cellValue }) {
      for (const item of this.alignOptions) {
        if (item.value === cellValue) {
          return item.label;
        }
      }
      return cellValue;
    },
    createConditionItem() {
      return {
        leftBracket: this.leftBracketOptions[0].value,
        rightBracket: this.rightBracketOptions[0].value,
        operator: COMPARISON_OPERATOR_EQUAL.value,
        // 用户插入的查询条件不显示
        shortcutShow: this.systemConfig,
        uniqueFieldCode: '',
        fieldCode: '',
        fieldShowName: '',
        fieldInputType: '',
        enumCode: '',
        fieldValue: '',
        presetValue: '',
        showLabel: true,
        readOnly: false,
        required: false,
        ruleIdArrayJson: [],
        positionRow: 1,
        positionColumn: 1,
        positionWidth: 1,
        positionHeight: 1,
        options: []
      };
    },
    formatPlanName({ cellValue, row }) {
      const queryType = row.queryType;
      if (queryType === CUSTOM_QUERY_TYPE) {
        return cellValue;
      }
      if (queryType === SYSTEM_QUERY_TYPE) {
        return cellValue + '(系统)';
      }
      return cellValue + '(默认)';
    },
    /**
     * @desc 切换查询条件
     * @param row 当前行
     * @param value 新选中的字段
     */
    handleConditionFieldCodeChange({ row, rowIndex, value }) {
      for (const item of this.conditionTableList) {
        if (item.fieldCode !== value) {
          continue;
        }
        const fieldInputType = item.fieldInputType;
        row.fieldShowName = item.name;
        row.fieldInputType = fieldInputType;
        row.enumCode = item.enumCode;
        row.dataCode = item.refDataCode;
        row.rowKey = item.refFieldCode;
        row.rowName = item.refFieldName;
        row.fieldValue = '';
        // uniqueFieldCode默认等于fieldCode, 用户可以修改
        // row.uniqueFieldCode = item.fieldCode;
        row.uniqueField = getUniqueField(item.fieldCode);
        if (this.systemConfig) {
          row.required = item.required;
        }
        switch (fieldInputType) {
          case FIELD_INPUT_TYPE_NUMBER.value:
          case FIELD_INPUT_TYPE_RADIO.value:
          case FIELD_INPUT_TYPE_SELECT_ONE.value:
            row.operator = COMPARISON_OPERATOR_EQUAL.value;
            row.fieldValue = '';
            break;
          case FIELD_INPUT_TYPE_POP_ONE.value:
          case FIELD_INPUT_TYPE_DATE.value:
          case FIELD_INPUT_TYPE_DATETIME.value:
          case FIELD_INPUT_TYPE_YEAR.value:
          case FIELD_INPUT_TYPE_MONTH.value:
            row.operator = COMPARISON_OPERATOR_EQUAL.value;
            row.fieldValue = null;
            if (fieldInputType === FIELD_INPUT_TYPE_POP_ONE.value) {
              row.searchOptionType = SINGLE_SELECT;
            }
            break;
          case FIELD_INPUT_TYPE_SELECT_MULTI.value:
          case FIELD_INPUT_TYPE_CHECKBOX.value:
          case FIELD_INPUT_TYPE_POP_MULTI.value:
            row.operator = COMPARISON_OPERATOR_IN.value;
            row.fieldValue = [];
            if (fieldInputType === FIELD_INPUT_TYPE_POP_MULTI.value) {
              row.searchOptionType = MULTIPLE_SELECT;
              row.appendResult = true;
            }
            break;
          default:
            row.operator = COMPARISON_OPERATOR_CONTAIN.value;
            row.fieldValue = '';
            break;
        }
        if (item.fieldInputType !== FIELD_INPUT_TYPE_SELECT_ONE.value && item.fieldInputType !== FIELD_INPUT_TYPE_SELECT_MULTI.value) {
          row.options = [];
          continue;
        }
        if (item.enumCode) {
          if (!Array.isArray(row.options)) {
            row.options = [];
          }
          getOptionsByCode(item.enumCode, (dict) => {
            if (dict instanceof Error) {
              this.$notify.error(dict.message);
              return;
            }
            const options = [];
            let field;
            for (const fieldItem of this.fieldList) {
              if (fieldItem.fieldCode === item.fieldCode) {
                field = fieldItem;
                break;
              }
            }
            if (!field) {
              throw new RuleError('没有对应的字段');
            }
            for (const item of dict) {
              options.push({label: item.name, value: item.dictKey});
            }
            row.options = options;
            this.$set(this.planConditionInfoModel.planConditionList, rowIndex, row);
          });
        }
        if (item.refDataCode) {
          if (!Array.isArray(row.options)) {
            row.options = [];
          }
          getMetaData({
            dataCode: item.refDataCode,
            rowKey: item.refFieldCode,
            rowName: item.refFieldName
          }).then((data) => {
            if (data instanceof Error) {
              this.$notify.error(data.message);
              return;
            }
            row.options = data;
            this.$set(this.planConditionInfoModel.planConditionList, rowIndex, row);
            // console.log(row.optionList);
          });
        }
      }
    },
    handleUp(refName, list) {
      const row = this.$refs[refName].getCurrentRecord();
      const index = list.indexOf(row);
      if (index < 1) {
        return;
      }
      list.splice(index, 1);
      list.splice(index - 1, 0, row);
    },
    handleDown(refName, list) {
      const row = this.$refs[refName].getCurrentRecord();
      const index = list.indexOf(row);
      if (index === list.length - 1) {
        return;
      }
      list.splice(index, 1);
      list.splice(index + 1, 0, row);
    },
    handleColumnConfigUp() {
      this.handleUp('planColumnTable', this.planColumnList);
    },
    handleColumnConfigDown() {
      this.handleDown('planColumnTable', this.planColumnList);
    },
    handleColumnConfigCheckAll() {
      for (const item of this.planColumnList) {
        if (!item.showed) {
          this.$set(item, 'showed', true);
        }
      }
    },
    handleColumnConfigClearAll() {
      for (const item of this.planColumnList) {
        if (item.showed) {
          this.$set(item, 'showed', false);
        }
      }
    },
    handleColumnConfigSetDefault() {
      for (const item of this.planColumnList) {
        this.$set(item, 'showed', DEFAULT_SHOW);
        this.$set(item, 'align', DEFAULT_ALIGN);
        this.$set(item, 'width', DEFAULT_WIDTH);
      }
    },
    handleTabClick(item) {
      const name = item.name;
      this.activeTabName = name;
      // 因为切换tab之后表格是不是马上渲染，需要放在下一个微任务重新计算表格
      this.$nextTick(() => {
        const activeTabOptions = this.activeTabOptions;
        if (this.metaType === META_TYPE_EDIT.value) {
          if (name === activeTabOptions[0].name) {
            this.$refs.planConditionTable.recalculate(true);
            return;
          }
          if (name === activeTabOptions[1].name) {
            this.$refs.planColumnTable.recalculate(true);
            if (this.$refs.planGroupColumnTable) {
              this.$refs.planGroupColumnTable.recalculate(true);
            }
          }
          return;
        }
        if (name === activeTabOptions[0].name) {
          this.$refs.planConditionTable.recalculate(true);
          return;
        }
        if (name === activeTabOptions[1].name) {
          this.$refs.planSortSourceTable.recalculate(true);
          this.$refs.planSortTable.recalculate(true);
          return;
        }
        if (name === activeTabOptions[2].name) {
          this.$refs.planColumnTable.recalculate(true);
          if (this.$refs.planGroupColumnTable) {
            this.$refs.planGroupColumnTable.recalculate(true);
          }
        }
      });
    },
    handleAdd() {
      const row = this.$refs.planSortSourceTable.getCurrentRecord();
      if (!row) {
        this.$notify.error('请选择需要排序的字段');
        return;
      }
      const planSortList = this.planSortList;
      for (const item of planSortList) {
        if (item.fieldCode === row.fieldCode) {
          this.$notify.error(row.name + '已添加排序');
          return;
        }
      }
      planSortList.push({
        fieldName: row.name,
        fieldCode: row.fieldCode,
        orderValue: 'ASC'
      });
    },
    handleSortUp() {
      this.handleUp('planSortTable', this.planSortList);
    },
    handleSortDown() {
      this.handleDown('planSortTable', this.planSortList);
    },
    handleDelete(refName, list) {
      list.splice(list.indexOf(this.$refs[refName].getCurrentRecord()), 1);
    },
    handleSortClear() {
      this.planSortList = [];
    },
    tranSelectVal(fieldValue, fieldInputType) {
      if (/^(SELECT_MULTI|CHECKBOX)$/.test(fieldInputType)) {
        return fieldValue ? fieldValue.split(',') : [];
      } else {
        return fieldValue;
      }
    },
    handleOpen() {
      // openDialogFlag用于记录当前状态是不是用户打开table-filter，如果用户点击保存，这个状态会设置为false
      // 因为用户点击保存之后，会重新查询方案，此时不能与外部传入的条件合并，否则会导致删除预设值之后，点击保存，预设值又会重新出现
      this.openDialogFlag = true;
      this.saveDisabled = true;
      if (!Array.isArray(formRulesCache) || formRulesCache.length < 1) {
        searchMetaDataReportList({jsonStr: JSON.stringify({dataCode: 'formRule', page: 1, pageSize: 65535})}, {originResponse: false}).then((res) => {
          if (!res.isSuccess()) {
            return Promise.reject(new RequestError(res.msg));
          }
          this.formRules = formRulesCache = res.data.pager.list;
        });
      } else {
        this.formRules = formRulesCache;
      }
      this.handleTabClick(this.activeTabOptions[0]);
      this.getPlanList().then(() => {
        if (!Array.isArray(this.planList) || this.planList.length < 1) {
          // 没有任何查询方案时需要初始化表格设置的信息
          this.planColumnList = this.getDefaultPlanColumnList();
          this.saveDisabled = false;
          return;
        }
        setTimeout(() => {
          // 如果父组件传入的queryCode,就使用父组件的queryCode,否则使用第一个元素的queryCode
          let row = null;
          if (this.queryCode) {
            for (const item of this.planList) {
              if (item.queryCode === this.queryCode) {
                row = item;
                break;
              }
            }
          } else if (this.planList.length > 0) {
            row = this.planList[0];
          }
          if (row) {
            this.$refs.planListTable.setCurrentRow(row);
            this.getPlanDetail(row.queryCode);
          }
        });
      });
    },
    handlePlanChange({ row }) {
      this.getPlanDetail(row.queryCode);
    },
    getPlanList() {
      let promise;
      if (this.systemConfig) {
        promise = getMetaQueryPlanList(this.dataCode, {queryTypeArray: [SYSTEM_QUERY_TYPE, DEFAULT_QUERY_TYPE], metaType: this.metaType});
      } else {
        promise = getMetaQueryPlanList(this.dataCode, {queryTypeArray: [SYSTEM_QUERY_TYPE, DEFAULT_QUERY_TYPE, CUSTOM_QUERY_TYPE], metaType: this.metaType});
      }
      return promise.then((response) => {
        const res = response.data;
        if (!res.isSuccess()) {
          this.$notify.error(res.msg);
          return Promise.reject(new RequestError(res.msg));
        }
        const planList = res.data || [];
        // 对方案列表进行排序，
        sortPlanList(planList);
        this.planList = planList;
      });
    },
    /**
     * @desc 查询配置详情
     * @param queryCode
     * @param dataCode
     */
    async getPlanDetail(queryCode) {
      this.saveDisabled = true;
      this.baseMetaQuery = null;
      const response = await getMetaQueryPlanDetail({ queryCode, dataCode: this.dataCode });
      const res = response.data;
      if (!res.isSuccess()) {
        this.$notify.error(res.msg);
        return;
      }
      const data = res.data || {};
      let planSortList = data.sorts || [];
      // this.planSortListBackup = JSON.stringify(planSortList);
      // 如果有缓存，就从缓存中取
      if (this.openDialogFlag && this.queryCode === queryCode && this.planSortListBackup) {
        planSortList = JSON.parse(this.planSortListBackup);
      }
      // 经区志亮和廖仲华沟通后，sort和column都不再与外部查询相互映射
      /* // 如果当前查询的queryCode和外部传入的queryCode一直，且外部传入了tempSortList，就需要和planSortList合并
      // 外部的排序优先配置的排序
      if (this.queryCode === queryCode && Array.isArray(this.tempSortList)) {
        const list = [];
        for (const item of this.tempSortList) {
          for (let i = 0; i < planSortList.length; i++) {
            if (item.fieldCode === planSortList[i].fieldCode) {
              planSortList.splice(i, 1);
            }
          }
          list.push({
            fieldName: item.fieldName,
            fieldCode: item.fieldCode,
            orderValue: item.orderValue
          });
        }
        list.push(...planSortList);
        planSortList = list;
      } */
      this.planSortList = planSortList;
      let { leafColumns: planColumnList, groupColumns: planGroupColumnList } = getGroupColumnsAndLeafColumns({ columns: data.lists || [] });
      // 设置默认的宽度和对齐方式
      // 将planColumnList转成对象，方便查询
      // 如果planColumnList是空的，就直接将fieldList转成planColumnList
      if (planColumnList.length < 1) {
        planColumnList = this.getDefaultPlanColumnList();
      }
      for (const item of planColumnList) {
        if (appUtils.isString(item.ruleIdArrayJson) && item.ruleIdArrayJson) {
          item.ruleIdArrayJson = JSON.parse(item.ruleIdArrayJson);
        }
        if (item.align === undefined || item.align === null || item.align === '') {
          item.align = DEFAULT_ALIGN;
        }
      }
      if (this.openDialogFlag && this.queryCode === queryCode && this.planColumnListBackup) {
        planColumnList = JSON.parse(this.planColumnListBackup);
      }
      if (this.openDialogFlag && this.queryCode === queryCode && this.planGroupColumnListBackup) {
        planGroupColumnList = JSON.parse(this.planGroupColumnListBackup);
      }
      // 经区志亮和廖仲华沟通后，sort和column都不再与外部查询相互映射
      /* // 如果当前查询的queryCode和外部传入的queryCode一致
      if (this.queryCode === queryCode && this.getTempColumnList) {
        const {visibleColumn, fullColumn} = this.getTempColumnList();
        // 根据visibleColumn来控制planColumnList的显示
        if (Array.isArray(visibleColumn)) {
          const columnObject = {};
          for (const item of visibleColumn) {
            columnObject[item.property] = item;
          }
          for (const item of planColumnList) {
            const column = columnObject[item.fieldCode];
            if (column) {
              item.showed = true;
            } else {
              item.showed = false;
            }
          }
        }
        // 根据fullColumn的顺序来调整planColumnList的顺序
        if (Array.isArray(fullColumn)) {
          const planColumnObject = {};
          for (const item of planColumnList) {
            planColumnObject[item.fieldCode] = item;
          }
          planColumnList = [];
          for (const column of fullColumn) {
            const item = planColumnObject[column.property];
            if (item) {
              item.width = column.renderWidth || column.resizeWidth || column.width;
              planColumnList.push(item);
            }
          }
        }
      } */
      this.planColumnList = planColumnList;
      this.planGroupColumnList = planGroupColumnList;
      let planConditionList = data.conditions || [];
      for (const item of planConditionList) {
        const field = this.fieldMap[item.fieldCode];
        if (!field) {
          throw new RuleError(item.fieldCode + '不在字段列表中');
        }
        item.dataCode = field.refDataCode;
        item.rowKey = field.refFieldCode;
        item.rowName = field.refFieldName || field.refFieldCode;
        if (item.ruleIdArrayJson) {
          item.ruleIdArrayJson = JSON.parse(item.ruleIdArrayJson);
        }
        const fieldInputType = item.fieldInputType;
        const fieldValue = item.fieldValue;
        if (!appUtils.isEmpty(item.fieldValue) && (FIELD_INPUT_TYPE_DATE.value === fieldInputType || FIELD_INPUT_TYPE_DATETIME.value === fieldInputType ||
          FIELD_INPUT_TYPE_YEAR.value === fieldInputType || FIELD_INPUT_TYPE_MONTH.value === fieldInputType)) {
          item.fieldValue = appUtils.toDate(fieldValue);
          continue;
        }
        if (FIELD_INPUT_TYPE_POP_MULTI.value === fieldInputType || FIELD_INPUT_TYPE_SELECT_MULTI.value === fieldInputType || FIELD_INPUT_TYPE_CHECKBOX.value === fieldInputType) {
          if (item.fieldValue) {
            item.fieldValue = JSON.parse(fieldValue);
          } else {
            item.fieldValue = [];
          }
        }
        if (FIELD_INPUT_TYPE_POP_ONE.value === fieldInputType) {
          if (item.fieldValue) {
            item.fieldValue = JSON.parse(fieldValue);
          } else {
            item.fieldValue = null;
          }
        }
        if (FIELD_INPUT_TYPE_POP_ONE.value === fieldInputType || FIELD_INPUT_TYPE_POP_MULTI.value === fieldInputType) {
          item.appendResult = true;
          item.searchOptionType = FIELD_INPUT_TYPE_POP_ONE.value === item.fieldInputType ? SINGLE_SELECT : MULTIPLE_SELECT;
        }
        if (FIELD_INPUT_TYPE_SELECT_MULTI.value === fieldInputType || FIELD_INPUT_TYPE_SELECT_ONE.value === fieldInputType) {
          if (item.enumCode) {
            item.options = [];
            let field;
            for (const fieldItem of this.fieldList) {
              if (fieldItem.fieldCode === item.fieldCode) {
                field = fieldItem;
                break;
              }
            }
            if (!field) {
              throw new RuleError('没有对应的字段');
            }
            getOptionsByCode(item.enumCode, (dict) => {
              const options = [];
              for (const item of dict) {
                options.push({label: item.name, value: item.dictKey});
              }
              item.options = options;
            });
          }
          if (item.dataCode) {
            try {
              item.options = await getMetaData({
                dataCode: item.dataCode,
                rowKey: item.rowKey,
                rowName: item.rowName
              });
            } catch (error) {
              item.options = [];
              throw error;
            }
          }
        }
      }
      // 默认或系统方案在用户模式下不显示，需要将后台查询的条件置空
      if (!this.systemConfig && data.metaQuery.queryType !== CUSTOM_QUERY_TYPE) {
        planConditionList = [];
      }
      // 如果当前queryCode和外部传入的queryCode一致，且外部传入了条件列表,需要将外部条件的值映射到当前弹框查询条件
      planConditionList = this.combineFieldValue({ queryCode, list: planConditionList, flag: true });
      this.planConditionInfoModel.planConditionList = planConditionList;
      // 如果该方案还有baseId,就需要将基础方案查询出来
      // 如果没有baseId,该方案是基础方案
      if (!data.metaQuery.baseId) {
        res.data.conditions = this.combineFieldValue({ queryCode, list: res.data.conditions, flag: false });
        this.baseMetaQuery = data;
        this.saveDisabled = false;
        return;
      }
      getMetaQueryAll(data.metaQuery.baseId).then((response) => {
        const res = response.data;
        if (!res.isSuccess()) {
          this.$notify.error(res.msg);
          return;
        }
        res.data.conditions = this.combineFieldValue({ queryCode, list: res.data.conditions, flag: false });
        this.baseMetaQuery = res.data;
        this.saveDisabled = false;
      });
    },
    /**
     * @desc 合并查询条件
     * @param {object} queryCode查询方案的编码，list: 通过接口获取的查询条件列表，flag: 用户配置条件为true, 系统默认条件为false
     */
    combineFieldValue({ queryCode, list, flag }) {
      if (this.openDialogFlag && this.queryCode === queryCode && this.tempConditionConfig && this.tempConditionConfig.model) {
        const model = this.tempConditionConfig.model;
        if (!model) {
          return;
        }
        // 如果flag为true,就要使用planConditionListBackup,这种场景是针对用户打开高级查询的弹窗，配置了一些选项，然后点击确定
        // 当用户第二次进入高级查询的弹窗，需要还原原来配置，而不是显示从服务查询得到的配置
        if (flag && this.planConditionListBackup) {
          list = JSON.parse(this.planConditionListBackup);
        }
        for (const item of list) {
          const condition = getConditionItem({ list: this.tempConditionConfig.list, field: item.uniqueField });
          const fieldValue = model[item.uniqueField];
          if (condition) {
            item.operator = condition.operator;
            item.useValue = condition.useValue;
            // 打开table-filter之前用户可能已经在meta-query中进行过操作，因此要操作值记录起来
            if (condition.useValue) {
              item.value = fieldValue;
              if (fieldValue !== undefined) {
                if (fieldValue instanceof Date) {
                  item.fieldValue = new Date(fieldValue.getTime());
                } else if (fieldValue instanceof Object) {
                  item.fieldValue = JSON.parse(JSON.stringify(fieldValue));
                } else {
                  item.fieldValue = fieldValue;
                }
              }
              continue;
            }
          }
          // 如果使用了公式，就不能对fieldValue赋值
          if (appUtils.isNotEmpty(item.presetValue)) {
            continue;
          }
          if (fieldValue !== undefined) {
            if (fieldValue instanceof Date) {
              item.fieldValue = new Date(fieldValue.getTime());
            } else if (fieldValue instanceof Object) {
              item.fieldValue = JSON.parse(JSON.stringify(fieldValue));
            } else {
              item.fieldValue = fieldValue;
            }
          }
        }
      }
      return list;
    },
    /**
     * @desc 获取默认的表格设置信息
     * @return {array}
     */
    getDefaultPlanColumnList() {
      const list = [];
      for (let i = 0; i < this.fieldList.length; i++) {
        const item = this.fieldList[i];
        list.push({
          fieldName: item.name,
          fieldCode: item.fieldCode,
          showed: DEFAULT_SHOW,
          width: DEFAULT_WIDTH,
          align: DEFAULT_ALIGN,
          orderValue: i,
          parentFieldCode: '',
          ruleIdArrayJson: [],
          realOnly: false,
          dataCode: this.dataCode
        });
      }
      return list;
    },
    async handleBeforeClose(done) {
      this.clearPlanInfo();
      return true;
      // done();
    },
    show() {
      this.dialogVisible = true;
    },
    async validate() {
      const codeReg = /^[a-zA-Z]+[a-zA-Z0-9]*$/;
      try {
        await this.$refs.planConditionTableForm.validate();
        if (!Array.isArray(this.planConditionInfoModel.planConditionList)) {
          this.planConditionInfoModel.planConditionList = [];
        }
        let leftStr = '';
        let rightStr = '';
        for (const item of this.planConditionInfoModel.planConditionList) {
          for (const leftBracket of this.leftBracketOptions) {
            if (leftBracket.value === item.leftBracket) {
              leftStr += leftBracket.text;
              break;
            }
          }
          for (const rightBracket of this.rightBracketOptions) {
            if (rightBracket.value === item.rightBracket) {
              rightStr += rightBracket.text;
              break;
            }
          }
        }
        leftStr = leftStr.replace(/\s/g, '');
        rightStr = rightStr.replace(/\s/g, '');
        if (leftStr.length !== rightStr.length) {
          throw new RuleError('左右括号不匹配');
        }
        // 判断uniqueFieldCode是否重复
        const obj = {};
        for (const item of this.planConditionInfoModel.planConditionList) {
          if (!item.uniqueFieldCode) {
            continue;
          }
          // 输入空格也要处理并重新校验
          item.uniqueFieldCode = item.uniqueFieldCode.trim();
          if (!item.uniqueFieldCode) {
            continue;
          }
          if (obj[item.uniqueFieldCode]) {
            throw new RuleError('条件标识重复');
          }
          if (!codeReg.test(item.uniqueFieldCode)) {
            throw new RuleError('条件标识只能使用字母开头的字母和数字组合');
          }
          obj[item.uniqueFieldCode] = item;
        }
        // 如果两个条件的fieldCode相同，且两个条件都没有配置uniqueFieldCode，就要提示用户
        /* const conditionObject = {};
        for (const item of this.planConditionInfoModel.planConditionList) {
          const fieldCode = item.fieldCode;
          if (!conditionObject[fieldCode]) {
            conditionObject[fieldCode] = item;
            continue;
          }
          const sameFiledCodeItem = conditionObject[fieldCode];
          if (!sameFiledCodeItem.uniqueFieldCode || !item.uniqueFieldCode) {
            throw new RuleError('相同字段条件必须输入条件标识');
          }
        } */
      } catch (error) {
        this.handleTabClick(this.activeTabOptions[0]);
        throw error;
      }
      const tabIndex = this.metaType === META_TYPE_EDIT.value ? 1 : 2;
      for (const item of this.planGroupColumnList) {
        if (!item.fieldCode) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw new RuleError('分组表头字段不能为空');
        }
        item.fieldCode = item.fieldCode.trim();
        if (!item.fieldCode) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw new RuleError('分组表头字段不能为空');
        }
        if (!codeReg.test(item.fieldCode)) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw new RuleError('分组表头字段只能使用字母开头的字母和数字组合');
        }
        if (!item.fieldName) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw new RuleError('分组表头名称不能为空');
        }
        item.fieldName = item.fieldName.trim();
        if (!item.fieldName) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw new RuleError('分组表头名称不能为空');
        }
      }
      // 判断分组表头是否有被使用,没有被使用的分组表头会导致getColumns这个方法报错
      for (const { fieldCode } of this.planGroupColumnList) {
        let flag = false;
        // 检查该分组表头是否有被其它分组表头用作分组父表头
        for (const item of this.planGroupColumnList) {
          if (fieldCode === item.parentFieldCode) {
            flag = true;
            break;
          }
        }
        if (flag) {
          continue;
        }
        // 检查该分组表头是否有被其它普通表头用作分组父表头
        for (const item of this.planColumnList) {
          if (fieldCode === item.parentFieldCode) {
            flag = true;
            break;
          }
        }
        if (!flag) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw new RuleError(fieldCode + '没有使用，请删除');
        }
      }

      // 检查分组表头是否有循环引用
      for (const item of this.planGroupColumnList) {
        const list = [item];
        try {
          this.validateCircularReference(list);
        } catch (e) {
          this.handleTabClick(this.activeTabOptions[tabIndex]);
          throw e;
        }
      }

      if (!Array.isArray(this.planColumnList) || this.planColumnList.length < 1) {
        this.handleTabClick(this.activeTabOptions[tabIndex]);
        throw new RuleError('表格设置没有字段');
      }
      // for (const item of this.planColumnList) {
      //   if (item.showed) {
      //     return;
      //   }
      // }
      // this.handleTabClick(this.activeTabOptions[tabIndex]);
      // throw new RuleError('表格设置没有可显示字段');
    },
    /**
     * @desc 校验分组表头循环引用
     */
    validateCircularReference(list) {
      const lastItem = list[list.length - 1];
      // 特殊情况是自己分组父表头是自己
      if (lastItem.fieldCode === lastItem.parentFieldCode) {
        throw new RuleError(lastItem.fieldCode + '存在循环引用');
      }
      // 用于记录是list中是否放入新元素，如果没有，表示没有循环应用的可能
      let flag = false;
      for (const column of this.planGroupColumnList) {
        if (lastItem === column) {
          continue;
        }
        // 如果lastItem的分组父表头存在，就将分组父表头放入list中
        if (lastItem.parentFieldCode === column.fieldCode) {
          flag = true;
          list.push(column);
          break;
        }
      }
      if (!flag) {
        return;
      }
      // 判断list的第一个元素和其它元素是否一样，如果是一样就出现了循环引用
      const firstItem = list[0];
      for (let i = 1; i < list.length; i++) {
        if (firstItem === list[i]) {
          throw new RuleError(firstItem.fieldCode + '存在循环引用');
        }
      }
      // 递归到上一层分组表头
      this.validateCircularReference(list);
    },
    /**
     * 设置planColumnList的顺序，该顺序用于控制最终列表显示的列的顺序
     */
    setPlanColumnListOrder() {
      for (let i = 0; i < this.planColumnList.length; i++) {
        this.planColumnList[i].orderValue = i;
      }
    },
    /**
     * 设置planGroupColumnList的顺序
     */
    setPlanGroupColumnListOrder() {
      for (let i = 0; i < this.planGroupColumnList.length; i++) {
        this.planGroupColumnList[i].orderValue = 0 - i - 1;
      }
    },
    handleSaveMetaQuery() {
      this.validate().then(() => {
        /*
          1.判断systeConfig是否为true,如果为true，第一次创建是默认方案，第二次创建是系统方案,或者覆盖这两种方案
            systemConfig为false，只能创建或者覆盖自定义方案
           */
        // systemConfig为true可以覆盖任意方案，否则只能覆盖自己创建方案
        // if (!this.systemConfig && (plan.queryType === DEFAULT_QUERY_TYPE || plan.queryType === SYSTEM_QUERY_TYPE)) { // 用户查询报表不能修改默认方案
        //   this.$notify.error('默认方案和系统方案不能修改');
        //   return;
        // }
        // 判断如果同时使用公式和初始值，就提示用户只能选一个
        for (const item of this.planConditionInfoModel.planConditionList) {
          if (item.fieldValue && appUtils.isNotEmpty(item.presetValue)) {
            this.$notify.error(item.fieldShowName + '不能同时用使用公式和数值');
            return;
          }
        }
        this.setPlanColumnListOrder();
        this.setPlanGroupColumnListOrder();
        // 判断是否有选中方案
        const row = this.$refs.planListTable.getCurrentRecord();
        if (row) {
          // 系统设置模式模式下
          if (this.systemConfig) {
            this.$confirm('确认要覆盖此方案?', '提示').then(() => {
              // 覆盖原来的方案
              this.saveMetaQuery(row);
            }).catch((error) => {
              // 另存为需要将queryType改为系统
              this.metaQuery.queryType = SYSTEM_QUERY_TYPE;
              this.metaQuery.queryCode = appUtils.uuid();
              this.saveDialogVisible = true;
              // this.saveSameTypeMetaQuery({queryType: SYSTEM_QUERY_TYPE});
              if (error === 'cancel') {
                return;
              }
              throw error;
            });
          } else {
            // 用户模式下,如果基于系统配置项，直接创建新的配置项，同时增加baseId
            if (row.queryType !== CUSTOM_QUERY_TYPE) {
              this.metaQuery.baseId = row.id;
              this.saveDialogVisible = true;
              this.metaQuery.queryCode = appUtils.uuid();
              /* this.showSavePrompt().then(({ value }) => {
                // 判断新输入新方案名是否和已有的方案名一样，如果一样提示覆盖
                for (const item of this.planList) {
                  if (item.name === value) {
                    // 系统方案不能覆盖
                    if (item.queryType !== CUSTOM_QUERY_TYPE) {
                      this.$notify.error('无法覆盖默认或系统方案');
                      return;
                    }
                    this.$confirm('当前方案名称已存在，是否覆盖？').then(() => {
                      this.saveMetaQuery(item);
                    }).catch(() => {
                      this.saveMetaQuery({baseId, name: value, dataCode: this.dataCode, queryType: CUSTOM_QUERY_TYPE});
                    });
                    return;
                  }
                }
                this.saveMetaQuery({baseId, name: value, dataCode: this.dataCode, queryType: CUSTOM_QUERY_TYPE});
              }); */
            } else {
              this.$confirm('确认要覆盖此方案?', '提示').then(() => {
                // 覆盖原来的方案
                this.saveMetaQuery(row);
              }).catch((error) => {
                this.metaQuery.queryType = CUSTOM_QUERY_TYPE;
                this.saveDialogVisible = true;
                this.metaQuery.queryCode = appUtils.uuid();
                if (row.baseId) {
                  this.metaQuery.baseId = row.baseId;
                }
                // this.saveSameTypeMetaQuery({queryType: CUSTOM_QUERY_TYPE});
                if (error === 'cancel') {
                  return;
                }
                throw error;
              });
            }
          }
          return;
        }
        // 当前没有方案列表，需要创建
        if (!Array.isArray(this.planList) || this.planList.length < 1) {
          if (!this.systemConfig) {
            this.$notify.error('用户查询方案需要基于默认或者系统的查询方案');
            return;
          }
          // 保存新方案
          this.metaQuery.queryCode = appUtils.uuid();
          this.saveDialogVisible = true;
          // this.showSavePrompt().then(({ value }) => {
          //   this.saveMetaQuery({name: value, dataCode: this.dataCode, queryType: this.systemConfig ? DEFAULT_QUERY_TYPE : CUSTOM_QUERY_TYPE });
          // });
        }
      }).catch((error) => {
        if (appUtils.isBoolean(error)) {
          return;
        }
        if (error instanceof RuleError) {
          this.$notify.error(error.message);
          return;
        }
        throw error;
      });
    },
    /**
     * 保存相同类型的方案，在系统模式下新增或者修改系统方案，在用户模式下新增或修改用户方案
     * @param name
     * @param queryType
     */
    saveSameTypeMetaQuery({ queryType }) {
      // 保存新方案
      this.saveDialogVisible = true;
      this.metaQuery.queryType = queryType;
      /* this.showSavePrompt().then(({ value }) => {
        // 判断新输入新方案名是否和已有的方案名一样，如果一样提示覆盖
        for (const item of this.planList) {
          if (item.name === value) {
            this.$confirm('当前方案名称已存在，是否覆盖？').then(() => {
              this.saveMetaQuery(item);
            }).catch(() => {
              this.saveMetaQuery({name: value, dataCode, queryType});
            });
            return;
          }
        }
        this.saveMetaQuery({name: value, dataCode, queryType});
      }); */
    },
    showSavePrompt() {
      return this.$prompt('请输入名称', '请输入新方案名称', {
        inputPattern: /^[a-zA-Z0-9_\u4e00-\u9fa5]+$/,
        inputErrorMessage: '名称只能含有汉字、数字、字母、下划线'
      });
    },
    saveMetaQuery(metaQuery) {
      metaQuery.dataCode = this.dataCode;
      // 如果没有metaType，就将当前弹窗的metaType赋值给metaQuery
      if (!metaQuery.metaType) {
        metaQuery.metaType = this.metaType;
      }
      // 新增查询方案，需要将id去掉
      const conditions = JSON.parse(JSON.stringify(this.planConditionInfoModel.planConditionList));
      const sorts = JSON.parse(JSON.stringify(this.planSortList));
      const lists = JSON.parse(JSON.stringify(this.planColumnList));
      const groupLists = JSON.parse(JSON.stringify(this.planGroupColumnList));
      for (const item of groupLists) {
        lists.unshift(item);
      }
      // 如果是新增的，就需要将原来的id清掉
      if (!metaQuery.id) {
        for (const item of conditions) {
          delete item.id;
        }
        for (const item of sorts) {
          delete item.id;
        }
        for (const item of lists) {
          delete item.id;
        }
      }
      for (const item of conditions) {
        // 删除options，减少传输数据
        Reflect.deleteProperty(item, 'options');
        if (Array.isArray(item.ruleIdArrayJson)) {
          item.ruleIdArrayJson = JSON.stringify(item.ruleIdArrayJson);
        }
        switch (item.fieldInputType) {
          // 对于多选的情况，fieldValue有可能变成一个数组，需要转成json
          case FIELD_INPUT_TYPE_SELECT_MULTI.value:
          case FIELD_INPUT_TYPE_CHECKBOX.value:
          case FIELD_INPUT_TYPE_POP_MULTI.value:
            if (!Array.isArray(item.fieldValue)) {
              item.fieldValue = [];
            }
            item.fieldValue = JSON.stringify(item.fieldValue);
            break;
          case FIELD_INPUT_TYPE_POP_ONE.value:
            // pop_one弹窗单选，需要将fieldValue转成数组
            if (item.fieldValue instanceof Object) {
              item.fieldValue = JSON.stringify(item.fieldValue);
            } else {
              delete item.fieldValue;
            }
            break;
          case FIELD_INPUT_TYPE_DATE.value:
          case FIELD_INPUT_TYPE_DATETIME.value:
          case FIELD_INPUT_TYPE_MONTH.value:
          case FIELD_INPUT_TYPE_YEAR.value: {
            if (!item.fieldValue) {
              break;
            }
            if (item.fieldValue instanceof Date) {
              item.fieldValue = item.fieldValue.getTime();
              break;
            }
            const date = appUtils.toDate(item.fieldValue);
            if (!date) {
              break;
            }
            item.fieldValue = date.getTime();
            break;
          }
          default:
            break;
        }
      }
      for (const item of lists) {
        if (Array.isArray(item.ruleIdArrayJson)) {
          item.ruleIdArrayJson = JSON.stringify(item.ruleIdArrayJson);
        }
      }
      saveOrUpdateMetaQuery({
        metaQuery,
        conditions,
        sorts,
        lists
      }).then(({ data }) => {
        if (!data.isSuccess()) {
          this.$notify.error(data.msg);
          return;
        }
        this.$notify.success(data.msg);
        // 关闭弹窗
        this.saveDialogVisible = false;
        this.openDialogFlag = false;
        this.resetMetaQuery();
        this.getPlanList().then(() => {
          this.setCurrentPlan(metaQuery.name);
        });
      });
    },
    setCurrentPlan(name) {
      // 下一个宏任务执行选中操作
      setTimeout(() => {
        if (!Array.isArray(this.planList) || this.planList.length < 1) {
          return;
        }
        if (!name) {
          this.$refs.planListTable.setCurrentRow(this.planList[0]);
          this.handlePlanChange({ row: this.planList[0] });
        } else {
          for (const item of this.planList) {
            if (item.name === name) {
              this.$refs.planListTable.setCurrentRow(item);
              this.handlePlanChange({ row: item });
              break;
            }
          }
        }
      }, 0);
    },
    handleDeleteMetaQuery() {
      const row = this.$refs.planListTable.getCurrentRecord();
      if (!row) {
        return;
      }
      if (row.queryType !== CUSTOM_QUERY_TYPE && !this.systemConfig) {
        this.$notify.error('不能删除默认或系统方案');
        return;
      }
      this.$confirm(`确定要删除方案：${row.name}？`).then(() => {
        delMetaQueryPlan({ queryCode: row.queryCode, dataCode: this.dataCode }).then(({ data }) => {
          if (!data.isSuccess()) {
            this.$notify.error(data.msg);
            return;
          }
          this.$notify.success(data.msg);
          this.clearPlanInfo();
          this.saveDisabled = true;
          this.getPlanList().then(() => {
            if (!Array.isArray(this.planList) || this.planList.length < 1) {
              this.saveDisabled = false;
              // 没有任何查询方案时需要初始化表格设置的信息
              this.planColumnList = this.getDefaultPlanColumnList();
              return;
            }
            this.setCurrentPlan();
          });
        });
      });
    },
    clearPlanInfo() {
      this.planList = [];
      this.baseMetaQuery = null;
      this.planConditionInfoModel.planConditionList = [];
      this.planSortList = [];
      this.planColumnList = [];
      this.planGroupColumnList = [];
    },
    insertCondition() {
      const itemInfo = this.createConditionItem();
      // 系统模式下，第一个是逻辑运算符是空，用户自定义方案基于默认或系统方案，第一个逻辑运算是and
      if (this.planConditionInfoModel.planConditionList.length === 0 && this.systemConfig) {
        itemInfo.logicalOperator = '';
      } else {
        itemInfo.logicalOperator = LOGICAL_OPERATOR_AND.value;
      }
      // this.planConditionInfoModel.planConditionList.push(itemInfo);
      const row = this.$refs.planConditionTable.getCurrentRecord();
      const list = this.planConditionInfoModel.planConditionList;
      if (row) {
        list.splice(list.indexOf(row) + 1, 0, itemInfo);
      } else {
        list.push(itemInfo);
      }
    },
    deleteCondition() {
      const row = this.$refs.planConditionTable.getCurrentRecord();
      if (!row) {
        return;
      }
      const list = this.planConditionInfoModel.planConditionList;
      list.splice(list.indexOf(row), 1);
    },
    deleteAllCondition() {
      this.planConditionInfoModel.planConditionList = [];
    },
    handleConfirm() {
      const row = this.$refs.planListTable.getCurrentRecord();
      if (!row) {
        this.$notify.error('未选中方案');
        return;
      }
      this.validate().then(() => {
        // 判断如果同时使用公式和初始值，就提示用户只能选一个
        for (const item of this.planConditionInfoModel.planConditionList) {
          if (item.fieldValue && appUtils.isNotEmpty(item.presetValue)) {
            this.$notify.error(item.fieldShowName + '不能同时用使用公式和数值');
            return;
          }
        }
        this.setPlanColumnListOrder();
        this.setPlanGroupColumnListOrder();
        // 将this.planConditionInfoModel.planConditionList缓存起来
        if (!this.systemConfig) {
          this.planConditionListBackup = JSON.stringify(this.planConditionInfoModel.planConditionList);
          this.planSortListBackup = JSON.stringify(this.planSortList);
          this.planGroupColumnListBackup = JSON.stringify(this.planGroupColumnList);
          this.planColumnListBackup = JSON.stringify(this.planColumnList);
        }
        this.$emit('confirm', {
          data: {
            conditions: this.getCombineConditionList(),
            sorts: this.planSortList,
            lists: this.planColumnList,
            groupLists: this.planGroupColumnList
          },
          queryCode: row.queryCode,
          metaQueryList: JSON.parse(JSON.stringify(this.planList))
        });
        this.clearPlanInfo();
        this.dialogVisible = false;
      });
    },
    handleCancel() {
      this.clearPlanInfo();
      this.dialogVisible = false;
    },
    // 查询条件的合并数组，用户自定义的查询条件会包含默认或者系统的查询条件和本身的查询条件
    getCombineConditionList() {
      const list = [];
      if (!this.systemConfig && this.baseMetaQuery && Array.isArray(this.baseMetaQuery.conditions)) {
        for (const item of this.baseMetaQuery.conditions) {
          list.push(item);
        }
      }
      if (Array.isArray(this.planConditionInfoModel.planConditionList)) {
        for (const item of this.planConditionInfoModel.planConditionList) {
          list.push(item);
        }
      }
      this.combineConditionList = list;
      return list;
    }
  },
  watch: {
    combineConditionList: {
      async handler(conditions) {
        const conditionList = await convertCondition({
          conditions,
          fields: this.fieldList,
          event: {
            handleItemChange: ({ item, value }) => {
              // 先处理基础方案
              if (this.baseMetaQuery && Array.isArray(this.baseMetaQuery.conditions)) {
                for (const condition of this.baseMetaQuery.conditions) {
                  if (condition.uniqueField === item.field) {
                    condition.fieldValue = value;
                    condition.useValue = true;
                    return;
                  }
                }
              }
              if (Array.isArray(this.planConditionInfoModel.planConditionList)) {
                for (const condition of this.planConditionInfoModel.planConditionList) {
                  if (condition.uniqueField === item.field) {
                    condition.fieldValue = value;
                    condition.useValue = true;
                    return;
                  }
                }
              }
            }
          }
        });
        this.conditionConfig.model = getConditionModel({ list: conditionList });
        this.conditionConfig.list = conditionList;
      }
    },
    baseMetaQuery() {
      this.getCombineConditionList();
    },
    'planConditionInfoModel.planConditionList': {
      handler() {
        this.getCombineConditionList();
      },
      deep: true
    }
  },
  computed: {
    activeTabOptions() {
      if (this.metaType === META_TYPE_EDIT.value) {
        return [
          { name: 'condition', label: '表头', show: true },
          { name: 'column', label: '表格设置', show: this.columnConfigVisible }
        ];
      }
      return [
        { name: 'condition', label: '条件', show: true },
        { name: 'sort', label: '排序', show: this.sortConfigVisible },
        { name: 'column', label: '表格设置', show: this.columnConfigVisible }
      ];
    },
    conditionTableList() {
      // 1. 必须在metaDataEdit中设置了是否参与查询
      const list = [];
      for (const item of this.fieldList) {
        if (!item.canQuery) {
          continue;
        }
        list.push(item);
      }
      return list;
    },
    systemConfig() {
      return this.fromStr === SET_REPORT;
    },
    fieldMap() {
      const fieldMap = {};
      for (const item of this.fieldList) {
        fieldMap[item.fieldCode] = item;
      }
      return fieldMap;
    }
  }
};
</script>
