<!-- @desc:选品组件  @auth:周兴  @time:2022/11/15 14:10 -->
<template>
  <div v-if="existsFlag">
    <Poptip ref="poptip" trigger="click" transfer :width="popWidth" @click.stop="()=>{}" @on-popper-show="onPopShow"
            placement="bottom-start" :transfer-class-name="poptipTransferClassName">
      <Input type="text" ref="input" style="width:100%;" :readonly="disabled" v-model="inputModal"
             @on-change="onChange($event)"
             @on-keydown="onkeydown($event)"
             @on-blur="handleInputBlur"
             autofocus
      />
      <!--删除按钮-->
      <Icon v-if="clearFlag&& inputModal" :class="(options && options.length > 0)?'close-class':'close-class-1' "
            type="ios-close-circle" @click.stop="clearAll"/>

      <!--查询按钮-->
      <icon v-if="searchDetailFlag" type="iconfont iconfont icon-search" class="icon-class"
            @click.stop="handleSearchClick"/>

      <!--查询商品-->
      <DkModal
        ref="modal_search"
        id="search-data-class"
        class-name="search-data-class"
        :width="modalWidth"
        :loading="loading"
        v-model="showModal"
        @modalOk="modalOk"
        @on-visible-change="onVisibleChange"
        title="请选择数据">
        <BaseIndexButtonGroup id="BaseIndexButtonGroup">
          <template #left>
            <BaseIndexButton ref="search" name="search" @click="initData()"></BaseIndexButton>
            <BaseIndexButton :finalFlag="true" ref="clear" name="clear"
                             @click="$refs['searchCond'].clearCondition()"></BaseIndexButton>
          </template>
        </BaseIndexButtonGroup>
        <SearchCond id="search-cond-div" :width="modalWidth-100" v-if="searchContent && searchContent.length > 0"
                    ref="searchCond" :col-count="colCount"
                    v-model="searchCond" :type="this.$config.pageCode.goods"
                    :setFlag="false" :searchContent="searchContent"></SearchCond>
        <div style="width: 100%;height: 2px"></div>
        <DkTabs ref="tabs" :options="multiple?tabsOptions:tabsOptionsOnly" @on-click="tabsClick"
                @on-clear="clearSelected"></DkTabs>
        <!--      商品种类列表-->
        <div :style="'height: ' + tableHeight + 'px'">
          <Split v-model="split" :min="minSplit" v-if="methodsNameLeft" v-show="tabIndex === 0">
            <!-- 列表部分左侧   左侧都默认是id和name的格式-->
            <div slot="left" class="split-pane">
              <DkTable
                ref="leftTable"
                name="table"
                :data="leftList"
                :height="tableHeight"
                :page-flag="false"
                :select-flag="false"
                :choose-flag="false"
                :show-setting-flag="false"
                @current-change="handleCurrentChange">
                <DkTableColumn :title="$t(leftColumnName)" :field="leftColumnName"
                               width="auto" :filter="false" :sortable="false" :freeze="false"></DkTableColumn>
              </DkTable>
            </div>
            <!--列表部分右侧-->
            <div slot="right" class="split-pane">
              <DkTable :primaryKey="selectKey" :primary-search-key="selectSearchKey" ref="table-select"
                       :id="'table-'+$options.name" name="table"
                       :data="rightList"
                       :height="tableHeight"
                       :clearCheckFlag="false"
                       :refreshSelect="false"
                       :tree-flag="treeFlag"
                       :otherSearchParam="otherSearchParam"
                       :lazy="treeFlag?true:false"
                       :combinedField="combinedField"
                       :data-type="this.$config.tableSelectType.goods"
                       :multiple="multiple"
                       :choose-flag="multiple"
                       :freeze="false"
                       :show-setting-flag="false"
                       @load-children="loadChildren"
                       @pageChange="pageSizeChange" @current-change="onCurrentChange"
                       @select-change="handleSelectChange"
                       :link-click-checked="true">
                <!--              <DkTableColumn type="seq" align="center" width="40" :exchangeField="exchangeField"-->
                <!--                             @on-exchange="handleExchange"></DkTableColumn>-->
                <DkTableColumn v-for="(item,index) in columnsDetail" :key="index" :field="item.field"
                               :title="item.title" :tree-node="item.treeNode"
                               :data-type="item.columnType"
                               :width="item.width"
                               :resize-flag="index === columnsDetail.length - 1"></DkTableColumn>
              </DkTable>
            </div>
          </Split>
          <!--不显示列表左侧的-->
          <div v-if="!methodsNameLeft" v-show="tabIndex === 0">
            <DkTable :primaryKey="selectKey" :primary-search-key="selectSearchKey" ref="table-select-only"
                     :id="'table-'+$options.name" name="table"
                     :data="rightList"
                     :height="tableHeight"
                     :clearCheckFlag="false"
                     :refreshSelect="false"
                     :tree-flag="treeFlag"
                     :lazy="treeFlag?true:false"
                     :combinedField="combinedField"
                     :multiple="multiple"
                     :choose-flag="multiple"
                     :freeze="false"
                     :show-setting-flag="false"
                     @pageChange="pageSizeChange" @current-change="onCurrentChange"
                     @select-change="handleSelectChange"
                     :link-click-checked="true">
              <DkTableColumn v-for="(item,index) in columnsDetail" :key="index" :field="item.field"
                             :data-type="item.columnType"
                             :width="item.width"
                             :title="item.title"></DkTableColumn>
            </DkTable>
          </div>

          <!--已选列表-->
          <div v-show="tabIndex === 1">
            <DkTable :primaryKey="selectKey" ref="table-selected" :id="'table-'+$options.name" name="table"
                     :data="selectedTable"
                     :height="tableHeight"
                     :selectFlag="false"
                     :operateFlag="true"
                     :tree-flag="treeFlag"
                     :lazy="treeFlag?true:false"
                     :children="children"
                     :page-flag="false"
                     :link-click-checked="true"
                     :show-setting-flag="false"
                     @pageChange="pageSizeChange"
                     @current-change="onCurrentChange"
                     @delRow="delItem"
            >
              <DkTableColumn v-for="(item,index) in columnsDetail" :key="index" :field="item.field"
                             :title="item.title" :tree-node="item.treeNode"
                             :resize-flag="index === columnsDetail.length - 1"></DkTableColumn>

            </DkTable>
          </div>
        </div>
      </DkModal>

      <!--    下拉菜单-->
      <div class="api" slot="content" @click.stop="()=>{}">
        <DkTable ref="select" name="table"
                 :height="200"
                 :data="selectList"
                 :filter="false"
                 :freeze="false"
                 :show-setting-flag="false"
                 :pageTotalFlag="false"
                 :choose-flag="false"
                 :link-click-checked="true"
                 :page-flag="false"
                 @cell-click="cellClick">
          <DkTableColumn v-for="(cItem,cIndex) in columns" :key="cIndex" :field="cItem.field"
                         :title="cItem.title?cItem.title:$t(cItem.field)"
                         :resize-flag="cIndex == columns.length-1"></DkTableColumn>
        </DkTable>
        <div class="look-more-class" v-if="searchDetailFlag">
          <a @click="lookMore">{{ $t('lookMore') }}</a>
        </div>
      </div>
    </Poptip>
  </div>
</template>

<script>

import {button as buttonList} from '@/locale/lang/zh-CN'

export default {
  name: 'TableSelect',
  inject: {
    dkEditTable: {
      type: Object,
      default: null
    }
  },
  props: {
    showType: {
      type: Number,
      default: 1
    },
    value: {
      type: Boolean,
      default: false
    },
    // 数据类型
    dataType: {
      type: String,
      default: null
    },
    //字段名
    field: {
      type: String,
      default: ''
    },
    text: {
      type: String,
      default: ''
    },
    //判斷字段是否顯示
    sortBoolean: {
      type: Boolean,
      default: true
    },
    //组件选项
    options: {
      type: [Array, Object],
      default: () => []
    },
    //数据源是否需要进行查询（false时，数据源需要通过options从外部传入）
    searchDataFlag: {
      type: Boolean,
      default: true
    },
    label: {
      type: String,
      default: ''
    },
    // 标题（select有用）
    title: {
      type: String,
      default: ''
    },
    //是否有点开明细按钮
    searchDetailFlag: {
      type: Boolean,
      default: true
    },
    //是否只读
    disabled: {
      type: Boolean,
      default: false
    },
    //是否多选
    multiple: {
      type: Boolean,
      default: true
    },
    // 传入的查询参数
    searchParam: {
      type: Object,
      default: null
    },
    // 切换数据的列
    exchangeField: {
      type: String,
      default: ''
    },
    // 合并处理的字段（比如组合促销的促销Id)
    combinedField: {
      type: String,
      default: ''
    },
    // 是否是树形
    treeFlag: {
      type: Boolean,
      default: false
    },
    // 选品是否包括促销
    promotionType: {
      type: Boolean,
      default: false
    },
    // 传入参数（并且会传入到列表中作为查询参数），用于查询
    otherSearchParam: {
      type: Object,
      default: null
    },
    // 传入参数（绑定在查询条件上），用于查询
    searchInitParam: {
      type: Object,
      default: null
    },
    // 是否显示清空按钮
    clearFlag: {
      type: Boolean,
      default: false,
    },
    // 查询列
    selectField: {
      type: String,
      default: null
    },
    // 选择数据后关闭窗体
    clickCloseFlag: {
      type: Boolean,
      default: true,
    },
    // 放大样式标识
    poptipTransferClassName: {
      type: String
    }
  },
  data() {
    const vm = Window.vm
    let self = this
    return {
      vm: vm,
      colCount: 4,
      modalWidth: 980,
      existsFlag: true,
      loading: false,
      leftParams: {},  // 左侧的查询条件
      optionsData: [], //存options临时文件
      selectList: [], // 下拉的数据源
      rightList: [],// 选择界面数据
      batchKeysPage: [],// 本页存Keys
      exchangeData: [], // 需要切换的数据
      showChild: false, // 切换子级界面是否显示
      focusedRow: null,
      isChange: false, //是否发生值改变
      inputModal: null,
      modal1: true,
      showModal: false,
      // 查询条件
      searchCond: {},
      searchTable: {},
      // 数据源的service
      service: {},
      // 查询方法名字
      methodsName: '',
      // 详细的查询方法
      methodsNameDetail: '',
      // 商品左侧的查询方法
      methodsNameLeft: '',
      // 切换子级的方法
      methodsNameExchange: '',
      // 左侧查询条件
      leftSearchParam: {},
      // 左侧列表数据
      leftList: [],
      // 左侧列表的id列
      leftColumnId: null,
      // 左侧列表名称
      leftColumnName: null,
      // tab页签
      tabIndex: 0,
      //列设置
      columns: [],
      //更多出来界面的列
      columnsDetail: [],
      //替换子件界面的列
      columnsExchange: [],
      // 用于更新的列
      columnsUpdate: [],
      // 选择的key
      selectKey: '',
      // 选择的label
      selectLabel: '',
      // 选择查询的Key
      selectSearchKey: '',
      // 商品类型
      skuType: '',
      //pop的宽度
      popWidth: 600,
      //查询条件
      searchContent: [],
      // 选择的数据
      selectedTable: [],
      // 选中数据的ID串
      selectedKeys: [],
      split: 0.18,
      minSplit: 0.18,
      tableHeight: 340, //modal中列表的高度
      tabsOptions: [
        {label: '选择列表', name: 'name1', index: 0},
        {label: '已选列表', name: 'name2', index: 1, clear: true},
        // { label: self.$t('staffSalesTarget'), name: 'name3' },
      ],
      //不要已选列表
      tabsOptionsOnly: [
        {label: '选择列表', name: 'name1', index: 0},
      ],
      //页数信息
      pageInfo: {
        total: 0,
        pageSize: self.$config.pageSize,
        currentPage: 1
      },
      documentKeyDownContent: Object,
      children: [],//子级（已选列表）,
      clickClearFlag: false,// 是否点击清空按钮
    }
  },
  watch: {
    showModal(n, o) {
      if (n) {
        this.$refs['searchCond']?.clearCondition()
        // 初始不加载
        // this.$nextTick(() => {
        //   this.initData()
        // })
      }
    },
    text(n, o) {
      this.inputModal = n
    },
    options(n, o) {
      this.selectList = n
      this.optionsData = n ? JSON.parse(JSON.stringify(n)) : []
      // 设置列表
      if (n && n.length > 0) {
        this.setOptionsColumn();
      }
    },
    selectedTable(n, o) {
      //监听选择的数据,改变页签的数量
      if (n && n.length) {
        this.tabsOptions[1].label = '已选列表【' + n.length + '】';
      } else {
        this.tabsOptions[1].label = '已选列表';
      }
    },
  },
  methods: {
    /**
     * @desc   : 监听全局键盘按钮按下的事件
     * @author : 周兴
     * @date   : 2022/3/4 16:57
     */
    addKeyBoardEvent() {
      let code = 0
      let self = this
      this.documentKeyDownContent = document.onkeydown
      document.onkeydown = function (e) {
        const evn = e || event
        const key = evn.keyCode || evn.which || evn.charCode
        // alt：code = 18
        if (key === 18) {
          code = 18
        }
        //只有modal弹出才能可见
        if (self.showModal) {
          // Q：code = 81 查询
          let btList = Object.values(self.$config.button);
          btList.forEach(forIt => {
            if (code === 18 && forIt.hotKey?.toLowerCase() === e.key.toLowerCase()) {
              e.returnValue = false
              if (self.$refs[forIt.name]) {
                self.$refs[forIt.name].$el.click()
              }
            }
          })
        }
      }
      // 监听全局键盘按钮松开的事件
      document.onkeyup = function (e) {
        const evn = e || event
        const key = evn.keyCode || evn.which || evn.charCode
        if (key === 18) {
          code = 0
        }
        // 一秒钟失效，避免因为按了alt+tab之后再回来，按其他什么英文字母都不好使了的问题
        setTimeout(() => {
          code = 0
        }, 1000)
      }
    },
    /**
     * @desc   : 切换子品
     * @author : 周兴
     * @date   : 2022/6/1 9:53
     */
    exchangeOk() {
      if (!this.$refs['table-exchange'].batchRows || this.$refs['table-exchange'].batchRows.length === 0
        || !this.focusedRow) {
        return;
      }
      // 关闭弹窗
      this.showChild = false;
      let row = this.$refs['table-exchange'].batchRows[0];
      // 全局中的children也要改变
      let child = this.children.filter(it => it['id'] === this.focusedRow['id'])
      // 把选择的数据进行覆盖当前列表
      this.columnsUpdate.forEach(col => {
        if (col.field !== 'parentId'
          && this.focusedRow && this.focusedRow[col.field] && row[col.field]) {
          this.focusedRow[col.field] = row[col.field];
          child[0][col.field] = row[col.field];
        }
      })
      //hasChild也需要替换
      this.focusedRow['hasChild'] = row['hasChild'] ? row['hasChild'] : 0;
      this.focusedRow['bomItems'] = row['bomItems'] ? row['bomItems'] : [];
      child['hasChild'] = row['hasChild'] ? row['hasChild'] : 0;
      child['bomItems'] = row['bomItems'] ? row['bomItems'] : [];
      // 勾选父级
      let parentRows = this.rightList.filter(it => it.id === this.focusedRow.parentId);
      if (parentRows && parentRows.length > 0) {
        this.$refs['table-select'].setCheckedRow(parentRows[0]);
      }
      //刷新已选列表
      this.$refs['table-selected'].reloadData(this.selectedTable)
    },
    /**
     * @desc   : 切换子级
     * @author : 周兴
     * @date   : 2022/6/1 8:59
     */
    handleExchange(row) {
      // 记录当前行
      this.focusedRow = row;
      // 组合才会去查
      if (row && row[this.exchangeField] && this.combinedField
        && row["promotionType"] == this.$config.promotionType.combined && row[this.combinedField]) {
        this.exchangeData = [...row[this.exchangeField]];
        //过滤掉当前数据
        this.exchangeData = this.exchangeData.filter(it => it[this.selectKey] !== row[this.selectKey])
      } else {
        // 查询子级
        this.getExchangeTable(row);
      }
      //显示可替换的界面
      this.showChild = true;
    },
    /**
     * @desc   : 查询可切换的数据
     * @author : 周兴
     * @date   : 2022/5/27 16:04
     */
    getExchangeTable(row) {
      let param = {}
      param.cpId = this.$store.state.user.cpId
      // 根据传入的数据进行检索
      param[this.exchangeField] = row[this.exchangeField]
      this.excute(this.service, this.service[this.methodsNameExchange], param).then(res => {
        if (res.code === 200) {
          this.exchangeData = res.data.list;
          //过滤掉当前数据
          this.exchangeData = this.exchangeData.filter(it => it[this.field] !== row[this.field])
          //显示可替换的界面
          this.showChild = true;
        } else {
          this.$Message.warning(res.message)
        }
      })
    },
    /**
     * @desc   : 删除一条已选列表
     * @author : 周兴
     * @date   : 2022/5/31 14:12
     */
    delItem(rowIndex) {
      let row = this.selectedTable[rowIndex]
      // 如果存在就删除
      if (row) {
        let key = row[this.selectKey];
        this.selectedKeys.splice(this.selectedKeys.indexOf(key), 1)
        this.selectedTable.splice(this.selectedTable.indexOf(row), 1)
        let tRow = this.rightList.filter(it => it[this.selectKey] === key);
        if (tRow && tRow.length > 0) {
          // 删除掉去掉的勾选
          this.$refs['table-select'].setUnCheckedRow(tRow[0]);
        } else {
          // 删除掉去掉的勾选
          if (this.batchKeysPage) {
            this.batchKeysPage.splice(this.batchKeysPage.indexOf(key), 1)
            let filterRows = this.$refs['table-select'].batchRows.filter(it => it[this.selectKey] == key)
            if (filterRows && filterRows.length > 0) {
              this.$refs['table-select'].batchRows.splice(this.$refs['table-select'].batchRows.indexOf(filterRows[0]), 1)
            }
            this.$refs['table-select'].batchKeys = this.batchKeysPage;
          }
        }
      }
    },
    /**
     * @desc   : 删除已选
     * @author : 周兴
     * @date   : 2022/5/31 15:04
     */
    clearSelected() {
      this.selectedKeys = []
      this.selectedTable = []
      this.batchKeysPage = []
      this.batchRowsPage = []
      if (this.methodsNameLeft) {
        this.$refs['table-select'].clearBatchKeys();
      } else {
        this.$refs['table-select-only'].clearBatchKeys();
      }
    },
    /**
     * @desc   : 点击查看更多
     * @author : 周兴
     * @date   : 2022/5/28 11:28
     */
    handleSearchClick() {
      this.lookMore();
    },
    /**
     * @desc   : 选择数据
     * @author : 周兴
     * @date   : 2022/5/28 11:27
     */
    modalOk() {
      let batchRows = [];
      //包括左侧
      if (this.methodsNameLeft) {
        batchRows = this.$refs['table-select'].batchRows;
      } else {
        batchRows = this.$refs['table-select-only'].batchRows;
      }
      if (batchRows) {
        // bomItems有值，但是children没有值，说明没有展开
        if (batchRows && batchRows.length > 0) {
          batchRows.forEach(it => {
            this.loadChildren(it['bomItems'], it)
          })
        }
        this.$emit('onBatchChoose', {batchRows, children: this.children, batchKeys: this.batchKeysPage})
        this.showModal = false
      }
    },
    /**
     * @desc   : 查看更多
     * @author : 周兴
     * @date   : 2022/5/28 11:28
     */
    lookMore() {
      // 关闭弹出框
      if (this.dkEditTable) {
        this.dkEditTable.closeAllPop();
      }
      this.showModal = true;
    },
    /**
     * @desc   : 光标离开事件
     * @author : 周兴
     * @date   : 2022/5/26 16:37
     */
    handleInputBlur(e) {
      // this.inputModal = null;
      this.isChange = false;
      // 点击清空不进行blur
      if (!this.clickClearFlag) {
        this.$emit('on-input-blur', e)
      }
      this.clickClearFlag = false;
    },
    /**
     * @desc   : 清空数据
     * @author : 周兴
     * @date   : 2022/9/23 17:29
     */
    clearAll() {
      this.clickClearFlag = true;
      this.inputModal = null;
      this.$emit('clear');
      // 清空后直接弹出下拉
      this.$refs.input.$el.click();
    },
    /**
     * @desc   : 选择数据
     * @author : 周兴
     * @date   : 2022/4/8 10:38
     */
    cellClick({row}) {
      this.inputModal = row[this.label ? this.label : this.field]
      this.$emit('change', row)
      this.$emit('onChoose', row)
      // 关闭弹出框
      if (this.clickCloseFlag && this.dkEditTable) {
        this.dkEditTable.closeAllPop();
      }
      // this.$refs['input'].focus()
    },
    /**
     * @desc   : 展开弹窗
     * @author : 周兴
     * @date   : 2022/4/7 19:22
     */
    onPopShow(e) {
      this.$emit('focus')
      let self = this
      // 如果值没有变化，查询数据库 TODO 这里是不是在选择的时候从本地缓存读取
      if (!self.isChange) {
        if ((!this.options || this.options.length === 0) && this.searchDataFlag) {
          // this.getDataSelect(this.inputModal)
          // 不查当前，查全部
          this.getDataSelect()
        }
      } else {
        self.isChange = false
      }
      this.$nextTick(() => {
        setTimeout(function () {
          if (self.$refs.poptip) {
            self.$refs.poptip.updatePopper()
          }
        }, 10)
        // this.$refs['table'].reloadData(this.selectList)
      })
    },
    /**
     * @desc   : 翻页查询
     * @author : 周兴
     * @date   : 2022/4/22 9:07
     */
    pageChange(pageInfo) {
      this.$refs['table-select'].pageInfo = pageInfo
      this.getDataTable()
    },
    /**
     * @desc   : 行点击相当于勾上radio
     * @author : 周兴
     * @date   : 2022/3/16 16:57
     */
    onCurrentChange({row}) {
      // this.changeRadio(row)
    },
    /**
     * @desc   : 文本框输入改变事件
     * @author : 周兴
     * @date   : 2022/3/20 14:07
     */
    onChange(e) {
      this.isChange = true
      // 转大写
      let value = e.target.value;
      // 转大写
      if (value) {
        value = value.toUpperCase();
      }
      this.inputModal = value;
      //如果没有传值才进行检索
      if (this.searchDataFlag) {
        this.getDataSelect(value) // 重新检索
      }
      this.$nextTick(() => {
        // 如果直接传入数据的
        if (!this.searchDataFlag) {
          let table = JSON.parse(JSON.stringify(this.optionsData))
          this.selectList = table.filter(it => it[this.label].includes(this.inputModal)).map(m => m)
          let self = this;
          setTimeout(function () {
            self.$refs.poptip?.updatePopper()
          }, 10)
          this.$refs['select'].$refs['table'].reloadData(this.selectList)
        }
      })
      this.$emit('change')
    },
    /**
     * @desc   : 减排事件
     * @author : 周兴
     * @date   : 2022/3/20 14:07
     */
    onkeydown(e) {
      // this.getDataSelect(e.target.value) // 重新检索
      let table = this.$refs['table']
      if(!table)return;
      let index = -1
      // console.log('keycode',e,table.getCurrentRecord())
      switch (e.code) {
        case 'ArrowDown':
          index = table.getRowIndex(table.getCurrentRecord())
          table.setCurrentRow(index === this.selectList.length - 1 ? this.selectList[0] : this.selectList[index + 1])
          break
        case 'ArrowUp':
          index = table.getRowIndex(table.getCurrentRecord())
          table.setCurrentRow(index === 0 ? this.selectList[this.selectList.length - 1] : this.selectList[index - 1])
          break
        case 'Enter':
          this.cellClick({row: table.getCurrentRecord()})
          e.stopPropagation()
          break
      }
    },
    /**
     * @desc   : modal变化事件
     * @author : 沈博
     * @date   : 2022/3/7 14:28
     */
    onVisibleChange(val) {
      //清空已选数据
      this.selectedTable = []
      this.selectedKeys = []
      this.tabIndex = 0
      if (this.methodsNameLeft) {
        this.$refs['table-select']?.clearBatchKeys();
      } else {
        this.$refs['table-select-only']?.clearBatchKeys();
      }
      this.batchKeysPage = []
      if (val) {
        this.addKeyBoardEvent() // 增加快捷键
        this.countTableHeight();//计算表格高度
        // 查询数据 如果有左侧，那么就不用查询，在切换左侧列表行时查询
        if (this.methodsNameLeft) {
          if (!this.leftList || this.leftList.length === 0) {
            this.getDataLeft();
          }
        } else {
          // this.getDataTable();
        }
      } else {
        //还原快捷键
        document.onkeydown = this.documentKeyDownContent
      }
    },
    /**
     * @desc   : 获取select数据
     * @author : 沈博
     * @date   : 2022/3/7 16:59
     */
    getDataSelect(key) {
      this.$nextTick(() => {
        let param = {}
        if (this.searchParam) {
          param = {...this.searchParam};
        }
        if (this.otherSearchParam) {
          param = Object.assign(param, this.otherSearchParam);
        }
        param.cpId = this.$store.state.user.cpId
        param.flgValid = true
        // 根据传入的数据进行检索
        param[this.selectField ? this.selectField : this.field] = key
        param.leafFlag = true
        // 下拉的不做分页
        param.pageSize = null
        param.limit = this.$config.selectLimit
        // this.$set(param, this.field, this.inputModal)
        // console.log('333',this.service,this.methodsName, param,key,this.field)
        this.excute(this.service, this.service[this.methodsName], param).then(res => {
          if (res.code === this.$config.SUCCESS_CODE) {
            this.selectList = res.data.list || res.data
          } else {
            this.$Message.warning(res.message)
          }
        })
      })
    },
    /**
     * @desc   : 翻页
     * @author : 周兴
     * @date   : 2022/3/17 14:57
     */
    pageSizeChange(pageInfo) {
      this.pageInfo = pageInfo
      this.getDataTable(this.leftParams) // 查询数据
    },
    /**
     * @desc   : 初始查询
     * @author : 周兴
     * @date   : 2022/7/9 16:59
     */
    initData() {
      this.pageInfo.currentPage = 1;
      this.leftParams = null;
      this.getDataTable();
    },
    /**
     * @desc   : 获取表格数据
     * @author : 沈博
     * @date   : 2022/3/7 16:59
     */
    getDataTable(otherParam) {
      //说明是点击查询
      if (otherParam == undefined) {
        //把左侧数据切换到第一行
        if (this.leftList && this.leftList.length > 0 && this.$refs['leftTable']) {
          this.$refs['leftTable'].$refs['table'].reloadData(this.leftList);
          this.$refs['leftTable'].$refs['table'].setCurrentRow(this.leftList[0])
        }
      }
      this.loading = true;
      let param = {}
      if (otherParam) {
        param = otherParam;
      }
      /* 沈博 2022年7月6日  外面的参数也要带到里面*/
      if (this.searchParam) {
        param = Object.assign(this.searchParam, param);
      }
      if (this.searchCond && this.searchCond._value) {
        Object.assign(param, this.searchCond._value)
        let querys = Object.keys(this.searchCond._value);
        if (querys && querys.length > 0) {
          for (let i in querys) {
            // 处理数据 把空字符串处理为undifined
            if (param[querys[i]] == '') {
              param[querys[i]] = undefined;
            }
          }
        }
      }
      // 只查询最末级节点数据
      param.leafFlag = true
      param.flgValid = true; // 只查有效的
      param.cpId = this.$store.state.user.cpId // 工厂Id
      // 部门
      if (this.otherSearchParam) {
        // 拼接参数条件实体
        this.objectMerge(param, this.otherSearchParam)
      }
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      this.excute(this.service, this.service[this.methodsNameDetail], Object.assign(param, this.searchTable)).then(res => {
        if (res.code === this.$config.SUCCESS_CODE) {
          let arr = []
          if (res.data && res.data.list) {
            arr = [...res.data.list]
          }
          if (!arr && res.data) {
            arr = [...res.data]
          }
          // arr.forEach(it => {
          //   this.$set(it, 'radioFlag', this.$refs['table-select'].batchKeys.includes(it[this.selectKey]))
          // })
          // 如果开启树形
          if (this.methodsNameLeft && this.$refs['table-select'].treeFlag) {
            arr = arr.map(it => {
              let obj = it
              //如果id不存在，那么就按照selectKey做id
              if (!it.id) {
                obj.id = it[this.selectKey]
              }
              obj.parentId = null
              return obj
            })
          }
          this.rightList = arr
          // 有左侧数据
          if (this.methodsNameLeft) {
            //单选
            if (!this.multiple) {
              //单选的设置当前行
              for (let i in arr) {
                if (this.batchKeysPage.includes(arr[i][this.selectKey])) {
                  this.$refs['table-select'].$refs['table'].setRadioRow(arr[i])
                  break;
                }
              }
            } else {
              arr.forEach(it => {
                this.$refs['table-select'].$refs['table'].setCheckboxRow(it, this.batchKeysPage.includes(it[this.selectKey]))
              })
            }
            this.$refs['table-select'].pageInfo.total = res.data.total
          } else {
            if (!this.multiple) {
              //单选的设置当前行
              for (let i in arr) {
                if (this.batchKeysPage.includes(arr[i][this.selectKey])) {
                  this.$refs['table-select-only'].$refs['table'].setRadioRow(arr[i])
                  break;
                }
              }
            } else {
              // 没有左侧
              arr.forEach(it => {
                this.$refs['table-select-only'].$refs['table'].setCheckboxRow(it, this.batchKeysPage.includes(it[this.selectKey]))
              })
            }
            this.$refs['table-select-only'].pageInfo.total = res.data.total
          }
          this.loading = false;
        } else {
          this.$Message.warning(res.message)
          this.loading = false;
        }
      })
    },
    /**
     * @desc   : 查左侧数据
     * @author : 周兴
     * @date   : 2022/5/28 14:24
     */
    getDataLeft() {
      let param = this.leftSearchParam
      param.currentPage = this.pageInfo.currentPage
      param.pageSize = this.pageInfo.pageSize
      param.cpId = this.$store.state.user.cpId

      this.excute(this.service, this.service[this.methodsNameLeft], param).then(res => {
        if (res.code === 200) {
          let result = []
          //处理数据，添加全部，并把id和name进行处理
          if (this.dataType === this.$config.tableSelectType.goods) {
            let all = {}
            all[this.leftColumnId] = null;
            all[this.leftColumnName] = this.$t('allType');
            result.push(all);
            // 如果有促销，才会加入促销的分类
            if (this.promotionType) {
              let combo = {}
              combo[this.leftColumnId] = 0;
              combo[this.leftColumnName] = this.$t('priceCombo');
              result.push(combo);
            }
            res.data.forEach(it => {
              let item = {};
              item[this.leftColumnId] = it[this.leftColumnId];
              item[this.leftColumnName] = it[this.leftColumnName];
              result.push(item);
            })
          } else if (this.dataType === this.$config.tableSelectType.promotionType) {
            let all = {}
            all[this.leftColumnId] = null;
            all[this.leftColumnName] = this.$t('allType');
            result.push(all);
            res.data.list.forEach(it => {
              let item = {};
              item[this.leftColumnId] = it[this.leftColumnId];
              item[this.leftColumnName] = it[this.leftColumnName];
              result.push(item);
            })
          } else {
            res.data.forEach(it => {
              let item = {};
              item[this.leftColumnId] = it.id;
              item[this.leftColumnName] = it.name
              result.push(item);
            })
          }
          this.leftList = result
        }
      })
    },
    /**
     * @desc   : 切换查询数据
     * @author : 周兴
     * @date   : 2022/5/28 15:25
     */
    handleCurrentChange(e) {
      let param = {}
      // 如果是SKU，那么传递参数
      if (this.dataType === this.$config.tableSelectType.goods) {
        if (e.newValue) {
          param[this.leftColumnId] = e.newValue[this.leftColumnId]
        }
      } else if (this.dataType === this.$config.tableSelectType.promotionType) {
        if (e.newValue) {
          param['parentId'] = e.newValue[this.leftColumnId]
        }
      } else {
        if (e.newValue) {
          param[this.leftColumnId] = e.newValue[this.leftColumnId]
        }
      }
      this.leftParams = param;
      // 如果界面开着才会查询
      if (this.showModal) {
        // 切换后，从第一页查询
        this.pageInfo.currentPage = 1;
        //查询数据
        this.getDataTable(this.leftParams);
      }
    },
    /**
     * @desc   : 切换tab
     * @author : 周兴
     * @date   : 2022/5/28 16:38
     */
    tabsClick(e, option) {
      this.tabIndex = option.index;
      // 如果是已选列表,需要记录查询页面的数据
      if (this.tabIndex === 1) {
      }
    },
    /**
     * @desc   : 加载子级（选择列表加载，给已选列表赋值）
     * @author : 周兴
     * @date   : 2022/6/7 11:33
     */
    loadChildren(child, row) {
      //根据父级id，先删除掉子级数据
      if (child && child.length > 0) {
        let parentId = child[0]['parentId'];
        let children = this.children.filter(it => it['parentId'] !== parentId)
        //再把输入插入进去，为了解决可能发生的替换
        child.forEach(it => {
          children.push(it);
          // 组合的数据一起删除
          if (this.combinedField + '-parentId' && row && row['id']) {
            it[this.combinedField + '-parentId'] = row['id']
          }
        })
        this.children = children;
      }
    },
    /**
     * @desc   : 勾选数据
     * @author : 周兴
     * @date   : 2022/5/28 17:00
     */
    handleSelectChange({batchRows, row, checked}) {
      if (row) {
        // 如果选了就添加到已选列表
        if (checked) {
          if (!this.selectedKeys.includes(row[this.selectKey])) {
            this.selectedKeys.push(row[this.selectKey]);
            // let children = row.children;
            this.selectedTable.push({...row});
            // this.children = children;
            // 如果有树形才加载子级
            if (this.treeFlag) {
              this.loadChildren(row.children, row)
            }
          }
        } else {
          // 如果去掉选择，那么就从已选列表中移除
          if (this.selectedKeys.includes(row[this.selectKey])) {
            this.selectedKeys.splice(this.selectedKeys.indexOf(row[this.selectKey]), 1)
            this.selectedTable.splice(this.selectedTable.indexOf(row), 1)
          }
        }
        //有左侧的
        if (this.methodsNameLeft) {
          this.batchKeysPage = [...this.$refs['table-select'].batchKeys]
        } else {
          this.batchKeysPage = [...this.$refs['table-select-only'].batchKeys]
        }
      } else {
        this.selectedKeys = []
        this.selectedTable = []
      }
    },
    /**
     * @desc   : 根据类型给属性赋值
     * @author : 周兴
     * @date   : 2022/3/16 18:12
     */
    setMagnifierProperty() {
      //供应商
      // 部门
      if (this.dataType === this.$config.tableSelectType.supplier) {
        this.service = this.$service.commonService
        this.methodsName = 'getSupplier'
        this.methodsNameDetail = 'getSupplierByPage'
        this.searchContent = [
          {
            valueFormat: {code: 'supplierName'},
            valueKind: 'STR'
          }
        ]
        this.modalWidth = 650
        this.colCount = 2
        this.selectKey = 'supplierId'
        this.selectLabel = 'supplierName'
        this.columns = [
          {field: 'supplierCode', minWidth: '40'},
          {field: 'supplierName', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'supplierCode', minWidth: '40'},
          {field: 'supplierName', minWidth: '40'},
        ]
      }
      // 部门
      else if (this.dataType === this.$config.tableSelectType.organization) {
        this.service = this.$service.commonService
        this.methodsName = 'getOrganization'
        this.methodsNameDetail = 'getOrganizationByPage'
        this.searchContent = [
          {
            valueFormat: {code: 'orgName'},
            valueKind: 'STR'
          }
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'orgId'
        this.selectLabel = 'orgName'
        this.columns = [
          {field: 'orgName', minWidth: '40'},
          {field: 'orgCode', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'orgName', minWidth: '40'},
          {field: 'orgCode', minWidth: '40'},
        ]
      }
      //用户
      else if (this.dataType === this.$config.tableSelectType.user) {
        // this.service = this.$service.userService
        // this.methodsName = 'selectByCond'
        // this.methodsNameDetail = 'selectByCond'
        this.service = this.$service.commonService
        this.methodsName = 'getUser'
        this.methodsNameDetail = 'getUserByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'userCode'},
          },
          {
            valueFormat: {code: 'userName'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'userId'
        this.selectLabel = 'userName'
        this.columns = [
          {field: 'userCodeName', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'userCodeName', minWidth: '40'},
        ]
      }
      //员工
      else if (this.dataType === this.$config.tableSelectType.staff) {
        this.service = this.$service.commonService
        this.methodsName = 'getStaff'
        this.methodsNameDetail = 'getStaffByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'staffCode'},
          },
          {
            valueFormat: {code: 'staffName'},
          },
        ]
        this.modalWidth = 700
        this.colCount = 2
        this.selectKey = 'staffId'
        this.selectLabel = 'staffName'
        this.columns = [
          {field: 'staffCodeName', width: '120', title: this.$t('staff')},
        ]
        this.columnsDetail = [
          {field: 'staffCodeName', width: '120', title: this.$t('staff')},
          {field: 'orgName', width: '150', title: this.$t('orgId')},
          {field: 'remarks', width: 'auto'},
        ]
      }
      //商品
      else if (this.dataType === this.$config.tableSelectType.goods) {
        this.service = this.$service.commonService
        this.methodsName = 'getGoods'
        this.methodsNameDetail = 'getGoodsPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'skuCode'},
          },
          {
            valueFormat: {code: 'skuName'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'skuId'
        this.selectLabel = 'skuName'
        this.columns = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceStandard', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceStandard', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
      }
      //获取商品（销售订单开单用）
      else if (this.dataType === this.$config.tableSelectType.goodsForOrder) {
        this.service = this.$service.commonService
        this.methodsName = 'getGoodsForOrder'
        this.methodsNameDetail = 'getGoodsForOrderByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'skuCode'},
          },
          {
            valueFormat: {code: 'skuName'},
          },
        ]
        this.modalWidth = 900
        this.colCount = 2
        this.selectKey = 'skuId'
        this.selectLabel = 'skuName'
        this.columns = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceStandard', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceStandard', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
      }
      //获取商品（采购订单开单用）
      else if (this.dataType === this.$config.tableSelectType.goodsForPurchase) {
        this.service = this.$service.commonService
        this.methodsName = 'getGoodsForPurchase'
        this.methodsNameDetail = 'getGoodsForPurchaseByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'skuCode'},
          },
          {
            valueFormat: {code: 'skuName'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'skuId'
        this.selectLabel = 'skuName'
        this.columns = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceStandard', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceStandard', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
      }
      //获取商品（采购退货开单用）
      else if (this.dataType === this.$config.tableSelectType.goodsForPurchaseReturn) {
        this.service = this.$service.commonService
        this.methodsName = 'getGoodsForPurchaseReturn'
        this.methodsNameDetail = 'getGoodsForPurchaseReturnByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'skuCode'},
          },
          {
            valueFormat: {code: 'skuName'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'invId'
        this.selectLabel = 'skuName'
        this.columns = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'nonStdCode', minWidth: '40'},
          {field: 'invQty', minWidth: '40'},
          {field: 'outingQty', minWidth: '40'},
          {field: 'usableQty', minWidth: '40'},
          {field: 'whName', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
          {field: 'priceInto', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'nonStdCode', minWidth: '40'},
          {field: 'invQty', minWidth: '40'},
          {field: 'outingQty', minWidth: '40'},
          {field: 'usableQty', minWidth: '40'},
          {field: 'whName', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
      }
      //获取商品（采购入库开单用）
      else if (this.dataType === this.$config.tableSelectType.goodsForInto) {
        this.service = this.$service.commonService
        this.methodsName = 'getGoodsForInto'
        this.methodsNameDetail = 'getGoodsForIntoByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'skuCode'},
          },
          {
            valueFormat: {code: 'skuName'},
          },
        ]
        this.modalWidth = 900
        this.colCount = 2
        this.selectKey = 'skuId'
        this.selectLabel = 'skuName'
        this.columns = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceInto', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'priceInto', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
      }
      //库存
      else if (this.dataType === this.$config.tableSelectType.inventory) {
        this.service = this.$service.commonService
        this.methodsName = 'getInventory'
        this.methodsNameDetail = 'getInventoryByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'skuCode'},
          },
          {
            valueFormat: {code: 'skuName'},
          },
        ]
        this.modalWidth = 1200
        this.colCount = 2
        this.selectKey = 'skuId'
        this.selectLabel = 'skuName'
        this.columns = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'nonStdCode', minWidth: '40'},
          {field: 'invQty', minWidth: '40'},
          {field: 'outingQty', minWidth: '40'},
          {field: 'usableQty', minWidth: '40'},
          {field: 'whName', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'skuCode', minWidth: '40'},
          {field: 'skuName', minWidth: '40'},
          {field: 'skuModel', minWidth: '40'},
          {field: 'nonStdCode', minWidth: '40'},
          {field: 'invQty', minWidth: '40'},
          {field: 'outingQty', minWidth: '40'},
          {field: 'usableQty', minWidth: '40'},
          {field: 'whName', minWidth: '40'},
          {field: 'skuSpec', minWidth: '40'},
          {field: 'priceInto', minWidth: '40'},
        ]
      }
      //获取资金账户
      else if (this.dataType === this.$config.tableSelectType.moneyAccount) {
        this.service = this.$service.commonService
        this.methodsName = 'getMoneyAccount'
        this.methodsNameDetail = 'getMoneyAccountByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'macCode'},
          },
          {
            valueFormat: {code: 'macName'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'macId'
        this.selectLabel = 'macName'
        this.columns = [
          {field: 'macCode', minWidth: '40'},
          {field: 'macName', minWidth: '40'},
          {field: 'balance', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'macCode', minWidth: '40'},
          {field: 'macName', minWidth: '40'},
          {field: 'balance', minWidth: '40'},
        ]
      }
      //成型模具
      else if (this.dataType === this.$config.tableSelectType.mould) {
        this.service = this.$service.commonService
        this.methodsName = 'getMouldByPage'
        this.methodsNameDetail = 'getMouldByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'uniqueCode'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'uniqueId'
        this.selectLabel = 'uniqueCode'
        this.columns = [
          {field: 'uniqueCode', minWidth: '100'},
        ]
        this.columnsDetail = [
          {field: 'uniqueCode', minWidth: '100'},
        ]
      }
      //可变更产品型号
      else if (this.dataType === this.$config.tableSelectType.product) {
        this.service = this.$service.commonService
        this.methodsName = 'getModelProduct'
        this.methodsNameDetail = 'getModelProductByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'modelCode'},
          },
          {
            valueFormat: {code: 'modelName'},
          },
        ]
        this.selectKey = 'modelId'
        this.selectLabel = 'modelName'
        this.modalWidth = 600
        this.colCount = 2
        this.columns = [
          {field: 'modelCode', width: '120'},
          {field: 'modelName', width: 'auto'},
        ]
        this.columnsDetail = [
          // {field: 'modelCode', width: '150'},
          // {field: 'modelName', width: '150'},
          {field: 'codeName', width: '150', title: this.$t('pdtModel')},
          {field: 'levelName', title: this.$t('productCategory')},
          {field: 'remarks', width: 'auto'},
        ]
      }
      //产品位置
      else if (this.dataType === this.$config.tableSelectType.productPlace) {
        this.service = this.$service.commonService
        this.methodsName = 'getProductPlace'
        this.methodsNameDetail = 'getProductPlace'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'placeCode'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'placeId'
        this.selectLabel = 'placeCode'
        this.columns = [
          {field: 'placeCode', minWidth: '100'},
          {field: 'placeName', minWidth: '100'},
        ]
        this.columnsDetail = [
          {field: 'placeCode', minWidth: '100'},
          {field: 'placeName', minWidth: '100'},
        ]
      }
      //载具
      else if (this.dataType === this.$config.tableSelectType.carrier) {
        this.service = this.$service.modelCarrierService
        this.methodsName = 'selectByCond'
        this.methodsNameDetail = 'selectByCond'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'modelCode'},
          },
          {
            valueFormat: {code: 'modelName'},
          },
        ]
        this.modalWidth = 600
        this.colCount = 2
        this.selectKey = 'modelId'
        this.selectLabel = 'modelName'
        this.columns = [
          {field: 'modelCode', width: '120'},
          {field: 'modelName', width: 'auto'},
        ]
        this.columnsDetail = [
          // {field: 'modelCode', width: '150'},
          // {field: 'modelName', width: '150'},
          {field: 'codeName', width: '150', title: this.$t('pdtModel')},
          {field: 'remarks', width: 'auto'},
        ]
      }
      //缺陷
      else if (this.dataType === this.$config.tableSelectType.defect) {
        this.service = this.$service.productDefectService
        this.methodsName = 'selectByCond'
        this.methodsNameDetail = 'selectByCond'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'defectCode'},
          },
          {
            valueFormat: {code: 'defectName'},
          },
        ]
        this.modalWidth = 600
        this.colCount = 2
        this.selectKey = 'defectId'
        this.selectLabel = 'defectName'
        this.columns = [
          // {field: 'defectCode', width: '120'},
          // {field: 'defectName', width: '120'},
          {field: 'codeName', width: '120', title: this.$t('productDefect')},
          {field: 'defectTypesName', width: 'auto'},
        ]
        this.columnsDetail = [
          // {field: 'defectCode', width: '120'},
          // {field: 'defectName', width: '120'},
          {field: 'codeName', width: '120', title: this.$t('productDefect')},
          {field: 'defectTypesName', width: '120'},
          {field: 'remarks', width: 'auto'},
        ]
      }
      //工艺工序
      else if (this.dataType === this.$config.tableSelectType.processNode) {
        this.service = this.$service.processNodeService
        this.methodsName = 'selectByCond'
        this.methodsNameDetail = 'selectByCond'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'nodeName'},
          },
          {
            valueFormat: {code: 'flowName'},
          },
        ]
        this.selectKey = 'nodeId'
        this.selectLabel = 'nodeName'
        this.modalWidth = 900
        this.colCount = 2
        this.columns = [
          {field: 'nodeName', width: 'auto'},
          {field: 'flowName', width: '120'},
          {field: 'flowKindName', title: this.$t('flowKind'), width: '120'},
          {field: 'nodeKindName', title: this.$t('nodeKind'), width: '120'},
        ]
        this.columnsDetail = [
          {field: 'nodeName', width: 'auto'},
          {field: 'flowName', width: 'auto'},
          {field: 'flowKindName', title: this.$t('flowKind'), width: 'auto'},
          {field: 'nodeKindName', title: this.$t('nodeKind'), width: 'auto'},
          {field: 'remarks', width: 'auto'},
        ]
      }
      //工种
      else if (this.dataType === this.$config.tableSelectType.job) {
        this.service = this.$service.commonService
        this.methodsName = 'getJobByPage'
        this.methodsNameDetail = 'getJobByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'jobCode'},
            itemName: 'blameJobCode',
          },
          {
            valueFormat: {code: 'jobName'},
            itemName: 'blameJobName',
          },
        ]
        this.selectKey = 'jobId'
        this.selectLabel = 'jobName'
        this.modalWidth = 550
        this.colCount = 2
        this.columns = [
          {field: 'jobCode', title: this.$t('blameJobCode'), width: 'auto'},
          {field: 'jobName', title: this.$t('blameJobName'), width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'jobCode', title: this.$t('blameJobCode'), width: 'auto'},
          {field: 'jobName', title: this.$t('blameJobName'), width: 'auto'},
        ]
      }
      //责任工号
      else if (this.dataType === this.$config.tableSelectType.blameUser) {
        this.service = this.$service.commonService
        this.methodsName = 'getUserByPage'
        this.methodsNameDetail = 'getUserByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'userCode'},
            itemName: 'blameUserCode',
          },
          {
            valueFormat: {code: 'userName'},
            itemName: 'blameUserName',
          },
        ]
        this.modalWidth = 600
        this.colCount = 2
        this.selectKey = 'userId'
        this.selectLabel = 'userName'
        this.columns = [
          {field: 'userCode', title: this.$t('blameUserCode'), width: 'auto'},
          {field: 'userName', title: this.$t('blameUserName'), width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'userCode', title: this.$t('blameUserCode'), width: 'auto'},
          {field: 'userName', title: this.$t('blameUserName'), width: 'auto'},
        ]
      }
      //物料型号
      else if (this.dataType === this.$config.tableSelectType.modelMould) {
        this.service = this.$service.commonService
        this.methodsName = 'getModelMould'
        this.methodsNameDetail = 'getModelMaterialByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'modelCode'},
          },
        ]
        this.modalWidth = 500
        this.colCount = 2
        this.selectKey = 'modelId'
        this.selectLabel = 'modelCode'
        this.columns = [
          {field: 'modelCode', minWidth: '100'},
        ]
        this.columnsDetail = [
          {field: 'modelCode', minWidth: '100'},
          {field: 'modelName', minWidth: '100'},
        ]
      }
      //产品实验单产品
      else if (this.dataType === this.$config.tableSelectType.prodExperimentProduct) {
        this.service = this.$service.commonService
        this.methodsName = 'prodExperimentProduct'
        this.methodsNameDetail = 'prodExperimentProductByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'productCode'},
          },
          {
            valueFormat: {code: 'modelCode'},
          },
          {
            itemName: {code: 'startNodeName'},
            valueFormat: {code: 'nodeName'},
          },
        ]
        this.selectKey = 'productId'
        this.selectLabel = 'productCode'
        this.modalWidth = 600
        this.colCount = 2
        this.columns = [
          {field: 'productCode', width: '120'},
          {field: 'modelCode', width: '120'},
        ]
        this.columnsDetail = [
          {field: 'productCode', width: '150'},
          {field: 'nodeName', width: '150'},
          {field: 'modelCode', width: '150'},
          {field: 'modelName', width: '150'},
        ]
      }
      //产品信息（产品实验单）
      else if (this.dataType === this.$config.tableSelectType.productNodeChange) {
        this.service = this.$service.commonService
        this.methodsName = 'getProductForChangeNoPage'
        this.methodsNameDetail = 'getProductForChange'
        this.searchContent = [
          {itemCode: 'moldLineCode'},
          {itemCode: 'moldLineName'},
          {itemCode: 'mouldUniqueCode'},
          {itemCode: 'productUniqueCode'},
          {itemCode: 'moldingUser'},
          {itemCode: 'pdtBarcode'},
          {itemCode: 'nodeName'},
        ]
        this.selectKey = 'pdtUniqueId'
        this.selectLabel = 'pdtBarcode'
        this.modalWidth = 900
        this.colCount = 4
        this.columns = [
          {field: 'pdtBarcode', width: 'auto'},
          {field: 'nodeName', width: 'auto'},
          {field: 'mouldKind', width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'pdtBarcode', width: 'auto'},
          {field: 'hisPdtCodes', width: 'auto'},
          {field: 'moldLineCode', width: 'auto'},
          {field: 'moldLineName', width: 'auto'},
          {field: 'moldingDate', width: 'auto'},
          {field: 'moldingBatch', width: 'auto'},
          {field: 'moldingUser', width: 'auto'},
          {field: 'productUniqueCode', width: 'auto'},
          {field: 'mouldUniqueCode', title: this.$t('moldingModelCode'), width: 'auto'},
          {field: 'mouldKind', width: 'auto'},
          {field: 'moldedNum', width: 'auto'},
          {field: 'manageUserName', width: 'auto'},
          {field: 'renderMTime', width: 'auto'},
          {field: 'nodeName', width: 'auto'},
        ]
      }
      //产品型号、物料型号
      else if (this.dataType === this.$config.tableSelectType.modelId) {
        this.service = this.$service.commonService
        this.methodsName = 'getModelBase'
        this.methodsNameDetail = 'getModelBaseByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'modelCode'},
          },
          {
            valueFormat: {code: 'modelName'},
          },
        ]
        this.modalWidth = 550
        this.colCount = 2
        this.selectKey = 'modelId'
        this.selectLabel = 'modelName'
        this.columns = [
          {field: 'modelName', minWidth: '40'},
          {field: 'modelCode', minWidth: '40'},
        ]
        this.columnsDetail = [
          {field: 'modelName', minWidth: '40'},
          {field: 'modelCode', minWidth: '40'},
        ]
      }
      // 物料型号
      else if (this.dataType === this.$config.tableSelectType.modelMaterial) {
        this.service = this.$service.commonService
        this.methodsName = 'getModelMaterial'
        this.methodsNameDetail = 'getModelMaterialByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'modelCode'},
          },
          {
            valueFormat: {code: 'modelName'},
          },
        ]
        this.selectKey = 'modelId'
        this.selectLabel = 'modelName'
        this.modalWidth = 600
        this.colCount = 2
        this.columns = [
          {field: 'modelCode', width: '120'},
          {field: 'modelName', width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'modelName', minWidth: '120'},
          {field: 'modelCode', minWidth: 'auto'},
        ]
      }
      // 仓库
      else if (this.dataType === this.$config.tableSelectType.warehouse) {
        this.service = this.$service.commonService
        this.methodsName = 'getWarehouse'
        this.methodsNameDetail = 'getWarehouseByPage'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'whCode'},
          },
          {
            valueFormat: {code: 'whName'},
          },
        ]
        this.selectKey = 'whId'
        this.selectLabel = 'whName'
        this.modalWidth = 600
        this.colCount = 2
        this.columns = [
          {field: 'whCode', width: 'auto'},
          {field: 'whName', width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'whCode', width: 'auto'},
          {field: 'whName', minWidth: 'auto'},
        ]
      }
      // 仓位
      else if (this.dataType === this.$config.tableSelectType.warehousePlace) {
        this.service = this.$service.commonService
        this.methodsName = 'getWarehousePlace'
        this.methodsNameDetail = 'getWarehousePlace'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'placeName'},
          },
        ]
        this.selectKey = 'placeId'
        this.selectLabel = 'placeName'
        this.modalWidth = 600
        this.colCount = 2
        this.columns = [
          {field: 'whCodeName', width: 'auto'},
          {field: 'placeName', width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'whCodeName', minWidth: 'auto'},
          {field: 'placeName', width: 'auto'},
        ]
      }
      // 工位
      else if (this.dataType === this.$config.tableSelectType.workStation) {
        this.service = this.$service.commonService
        this.methodsName = 'getWorkStation'
        this.methodsNameDetail = 'getWorkStation'
        // 查询条件
        this.searchContent = [
          {
            valueFormat: {code: 'stationName'},
          },
        ]
        this.selectKey = 'stationId'
        this.selectLabel = 'stationName'
        this.modalWidth = 600
        this.colCount = 2
        this.columns = [
          {field: 'stationCode', width: 'auto'},
          {field: 'stationName', width: 'auto'},
        ]
        this.columnsDetail = [
          {field: 'stationCode', minWidth: 'auto'},
          {field: 'stationName', width: 'auto'},
        ]
      }
    },
    /**
     * @desc   : 设置传入数据源的列
     * @author : 周兴
     * @date   : 2022/4/21 10:40
     */
    setOptionsColumn() {
      this.columns = []
      this.columns.push({field: this.label, title: this.title ? this.title : vm.$t(this.field)})
      this.selectList = this.options
      // this.optionsData = this.options ? JSON.parse(JSON.stringify(this.options)) : []
      this.popWidth = 300
    },
    /**
     * @desc   : 计算表格高度
     * @author : 周兴
     * @date   : 2022/6/8 15:23
     */
    countTableHeight() {
      this.$nextTick(()=>{
        let modalHeight = this.$refs.modal_search?.$refs.modal?.$refs.content?.clientHeight;
        let searchHeight = this.$refs.searchCond.$el.clientHeight;
        this.tableHeight = modalHeight - searchHeight - 44 - 50 - 30 - 38 - 40
      })
    },
  },
  beforeDestroy() {
    this.existsFlag = null
  },
  mounted() {
    this.$nextTick(() => {
      // 设置查询条件默认值
      if (this.searchInitParam) {
        for (let it of Object.keys(this.searchInitParam)) {
          this.$refs.searchCond.setDefault(it, this.searchInitParam[it].default, this.searchInitParam[it].valueKind)
        }
      }
    })
  },
  created() {
    //如果传递了下拉就直接用
    if (this.options && this.options.length > 0) {
      this.optionsData = this.options.copy();
      this.setOptionsColumn()
    } else {
      if (this.searchDataFlag) {
        this.setMagnifierProperty() // 根据类型给属性赋值
      } else {
        if (this.options && this.options.length > 0) {
          this.optionsData = this.options.copy();
          this.setOptionsColumn()
        }
      }
    }

    this.inputModal = this.text
  }
}
</script>

<style scoped>


/deep/ .vxe-header--column {
  padding: 0 !important;
}


/deep/ .ivu-poptip-rel {
  width: 100%;
}

.ivu-poptip-popper {
  z-index: 800 !important;
}

/deep/ .btn-div {
  background: #fff !important;
}

.icon-class {
  position: absolute;
  top: 23%;
  right: 5px;
  cursor: pointer;
  background: #fff;
}


.clear-class {
  position: absolute;
  bottom: 100px;
  left: 20px;
}

.close-class {
  cursor: pointer;
  width: 24px;
  position: absolute;
  top: 10px;
  right: 4px;
  align-items: center;
  justify-content: center;
  height: 24px;
  color: #a0a5ac;
  z-index: 99;
}

.close-class-1 {
  cursor: pointer;
  width: 24px;
  position: absolute;
  top: 10px;
  right: 16px;
  align-items: center;
  justify-content: center;
  height: 24px;
  color: #a0a5ac;
  z-index: 99;
}

/deep/ .vxe-cell {
  display: flex !important;
  align-items: center !important;
  padding-left: 10px !important;
  padding-right: 10px !important;
}

.ivu-poptip-body-content {
  overflow: hidden !important;
}


</style>
