<!-- @desc:编辑表格（树形）  @auth:周兴  @time:2022/11/15 13:06 -->
<template>
  <div :style="{height: 100 + '%',width:divWidth,paddingRight:'3px'}">
    <vxe-table
      border
      size="mini"
      show-overflow
      auto-resize
      show-footer
      align="center"
      :cell-style="cellStyle"
      :footer-cell-style="footCellStyle"
      :height="height +'px'"
      :ref="name"
      :edit-rules="validRules"
      :valid-config="{showMessage:false}"
      :data="tableData"
      :show-footer="showFooter"
      :highlight-current-row="currentRow"
      :footer-method="footerMethod"
      :mouse-config="{selected: true}"
      :checkbox-config="{range: true}"
      :column-config="{resizable: true}"
      :menu-config="{body:header,header:header,visibleMethod:visibleMethod}"
      :keyboard-config="{isArrow: true, isDel: true, isEnter: true, isTab: true, isEdit: true, editMethod}"
      :edit-config="{ mode: 'row',trigger:'click',autoClear:false ,enabled:enabledEdit}"
      :tree-config="{transform: true, rowField: 'id', parentField: 'parentId',lazy: true, hasChild: 'hasChild', loadMethod: loadChildrenMethod}"
      :row-config="{isCurrent: true}"
      @contextmenu.native.prevent
      @scroll="handleScroll"
      @keydown="handleTableKeyDown"
      @cell-mouseenter="handleCellMouseEnter"
      @cell-mouseleave="handleCellMouseLeave"
      @edit-closed="editClosed"
      @current-change="currentChangeGetData"
      @menu-click="menuClick"
      @cell-menu="cellMenuClick"
    >

      <!--    </vxe-column>-->
      <div v-for="(colItem,colIndex) in columnsData" :key="colIndex">
        <!--   空白 (TODO第一列留一个余白，不然顺序就会乱，没有找到原因 周兴 2022-6-11)  -->
        <vxe-column v-if="colItem.type === 'blank'" type="blank" :field="colItem.field" :width="colItem.width"
                    :resizable="false">
        </vxe-column>
        <!--校验信息-->
        <vxe-column v-if="colItem.type === 'info'" type="info" :field="colItem.field" :width="colItem.width"
                    :resizable="false">
          <template #default="{ row,rowIndex,column }">
            <Poptip trigger="hover" transfer placement="top-start" :content="row.info" v-if="row.info">
              <Icon type="iconfont iconfont icon-question" style="cursor: pointer;font-size: 14px" color="red" ref="info-icon"/>
            </Poptip>
          </template>
        </vxe-column>
        <!--   序列   -->
        <vxe-column v-if="colItem.type === 'seq'" type="seq" :field="colItem.field" width="60" :title="vm.$t('seq')">
          <template #default="{row, seq, rowIndex}">
            <div v-if="!row._hover" :class="row.parentId === null ?'seq-class-seq':'seq-class-s'">
              {{ seq }}
            </div>
            <seq-button :delete-flag="deleteFlag  && checkDeleteButtonCanUse(row,colItem)"
                        :add-flag="addFlag"
                        v-if="row._hover"
                        @add="add(rowIndex)" @del="del(rowIndex)"/>
          </template>
        </vxe-column>

        <!--   选取类型   -->
        <vxe-column v-if="colItem.type === 'tableSelect'" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :title="colItem.title?colItem.title:$t(colItem.field)" :params="{type:'tableSelect'}"
                    :edit-render="{autofocus: '.vxe-input--inner'}" :tree-node="colItem.treeNode">
          <!--标题-->
          <template #header="{ row,column,columnIndex }">
            <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
            <Poptip trigger="hover" transfer placement="top-start" :content="colItem.tip" v-if="colItem.tip">
              <Icon type="iconfont iconfont icon-info" style="cursor: pointer;" ref="info-icon"/>
            </Poptip>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <!--显示子级-->
          <template #default="{row,column,rowIndex}">
            <div @dblclick.stop="copyValue(row,colItem,rowIndex)"
                 :class="colItem.treeNode?( row['parentId']?'child-class':'parent-class'):'edit-div-class'">
              <icon color="#19BE6B"
                    v-if="colItem.treeNode && checkExchangeIconVisible(row)"
                    :class="row['parentId']?'change-icon-class':'change-icon-child-class'"
                    @click="handleExchangeClick(row,colItem)"
                    type="iconfont iconfont icon-exchange"></icon>
              {{
                row[colItem.field]
              }}
            </div>
          </template>
          <!--编辑-->
          <template style="width:100%;" #edit="{ row,column,rowIndex }">
            <TableSelect :text="row[colItem.field]" :field="colItem.field" :dataType="colItem.dataType"
                         v-if="setCellCanTableSelect(row,colItem)"
                         :multiple="true"
                         :sortBoolean="colItem.sortBoolean"
                         :exchange-field="exchangeField"
                         :combinedField="combinedField"
                         :tree-flag="true"
                         :otherSearchParam="otherSearchParam"
                         :promotionType="colItem.promotionType"
                         @on-input-blur="handleSelectInputBlur($event,row,rowIndex,colItem,colIndex)"
                         @change="inputChange(row,rowIndex,colItem)"
                         @keydown.stop="nextInputCellByKeyDown(Object.assign($event,{column:colItem,colIndex,rowIndex,row}))"
                         @onChoose="onChoose($event,row,column,rowIndex,colIndex,colItem.fieldUpdate,colItem)"
                         @onBatchChoose="onBatchChoose($event,column,rowIndex,colIndex,colItem.fieldUpdate,colItem)"
                         :ref="colItem.field+rowIndex"></TableSelect>
            <div @dblclick.stop="copyValue(row,colItem,rowIndex)"
                 :class="colItem.treeNode?( row['parentId']?'child-class':'parent-class'):'edit-div-class'" v-else>
              <icon
                color="#19BE6B"
                v-if="colItem.treeNode && checkExchangeIconVisible(row)"
                :class="row['parentId']?'change-icon-class':'change-icon-child-class'"
                @click="handleExchangeClick(row,colItem)"
                type="iconfont iconfont icon-exchange"></icon>
              {{
                row[colItem.field]
              }}
            </div>
          </template>
        </vxe-column>

        <!--   无法修改类型 不包括开关   -->
        <vxe-column v-if="colItem.type === 'disabled' && !colItem.switch" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin" :params="colItem"
                    :title="colItem.title?colItem.title:$t(colItem.field)" :tree-node="colItem.treeNode">
          <!--标题-->
          <template #header="{ row,column,columnIndex }">
            <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #default="{ row,rowIndex,column }">
            <!--          <span class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)">{{-->
            <!--
     formatColumn({-->
            <!--                column: column,-->
            <!--                cellValue: row[colItem.field],-->
            <!--                row: row-->
            <!--              })-->
            <!--            }}</span>-->
            <div @dblclick.stop="copyValue(row,colItem,rowIndex)"
                 :class="colItem.treeNode?( row['parentId']?'child-class':'parent-class'):'edit-div-class'">
              <icon color="#19BE6B"
                    v-if="colItem.treeNode && checkExchangeIconVisible(row)"
                    :class="row['parentId']?'change-icon-class':'change-icon-child-class'"
                    @click="handleExchangeClick(row,colItem)"
                    type="iconfont iconfont icon-exchange"></icon>
              {{
                row[colItem.field]
              }}
            </div>
          </template>
        </vxe-column>

        <!--   无法修改类型 开关   -->
        <vxe-column v-if="colItem.type === 'disabled' && colItem.switch" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.width?colItem.width:vm.$config.columnWidthMin" :params="colItem"
                    :title="colItem.title?colItem.title:$t(colItem.field)">
          <!--标题-->
          <template #header="{ row,column,columnIndex }">
            <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #default="{ row,rowIndex }">
            <div class="switch-class">
              <i-switch size="small" :ref="colItem.field+'_default_'+rowIndex" v-model="row[colItem.field]"
                        :disabled="true"/>
            </div>
          </template>
        </vxe-column>

        <!--  非标淋浴房-->
        <vxe-column v-if="colItem.type === 'nonGlassFlag'" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin" :params="colItem"
                    :formatter="formatColumn"
                    :title="colItem.title?colItem.title:$t(colItem.field)" :tree-node="colItem.treeNode">
          <!--标题-->
          <template #header="{ row,column,columnIndex }">
            <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #default="{ row,rowIndex }">
            <vxe-pulldown transfer :ref="colItem.field+rowIndex" style="width:  300px;"
                          destroy-on-close>
              <template #default>
                <div style="cursor: pointer;width: 100%;height: 30px;"
                     v-if="row.nonGlassSpuItems && row.nonGlassSpuItems.length > 0"
                     @click="openNonGlassForm(Object.assign($event,{colItem,rowIndex,row}))">{{ row.nonGlassListShow }}
                </div>
              </template>
              <template #dropdown>
                <div class="non-glass-drop-down">
                  <DkForm ref="nonGlassForm" :model="row.nonGlassForm" label-position="top" inline
                          style="padding-bottom: 10px">
                    <Row v-for="(item,itIndex) in row.nonGlassSpuItems" :key="itIndex">
                      <Col span="24" style="padding-top: 5px">
                        <DkFormItem :prop="item.fieldName" style="width:98% ;" :label="item.fieldName">
                          <!--                          <selectPop v-if="item.isScope == 0" :ref="item.fieldCode + rowIndex" :multiple="false"-->
                          <!--                                     @on-change="changeNonGlass(Object.assign({value:$event, colItem ,fieldCode:item.fieldCode,rowIndex,changePrice:true}))"-->
                          <!--                                     v-model="row.nonGlassForm[item.fieldCode]"-->
                          <!--                                     :placeholder="$t('selectWords',{'search-name':$t(item.fieldName)})"-->
                          <!--                                     :options="item.options" valueKey="code"-->
                          <!--                                     labelKey="name">-->
                          <!--                          </selectPop>-->
                          <!--                          <InputPop v-else v-model="row.nonGlassForm[item.fieldCode]" :ref="item.fieldCode + rowIndex"-->
                          <!--                                    @on-change="changeNonGlass(Object.assign({value:$event,fieldCode:item.fieldCode,fieldName:item.fieldName,isScope:item.isScope,-->
                          <!--                                  colItem,rowIndex,changePrice:false}))"-->
                          <!--                                    size="small" clearable-->
                          <!--                                    :placeholder="$t('inputWords',{'search-name':$t(item.fieldName)})">-->
                          <!--                          </InputPop>-->
                        </DkFormItem>
                      </Col>
                    </Row>
                    <Row>
                      <Col span="24" style="padding-top: 5px">
                        <DkFormItem prop="specialFormula" style="width:98% ;" :label="$t('specialFormula')">
                          <!--面积公式-->
                          <InputPop v-model="row.specialFormula" :ref="'specialFormula' + rowIndex"
                                    size="small" readonly>
                          </InputPop>
                        </DkFormItem>
                      </Col>
                    </Row>
                    <Row>
                      <Col span="24" style="padding-top: 5px">
                        <DkFormItem prop="nonStandardArea" style="width:98% ;" :label="$t('skuArea')">
                          <!--面积-->
                          <InputNumberPop v-model="row.nonStandardArea" :ref="'nonStandardArea' + rowIndex"
                                          size="small" clearable :digits="6" :format-thousandth="false"
                                          @on-change="changeValueByArea(Object.assign({value:$event,row, colItem,rowIndex}))"
                                          :placeholder="$t('inputWords',{'search-name':$t('skuArea')})">
                          </InputNumberPop>
                        </DkFormItem>
                      </Col>
                    </Row>
                  </DkForm>
                </div>
              </template>
            </vxe-pulldown>
          </template>
        </vxe-column>


        <!--  选择框  -->
        <vxe-column v-if="colItem.type === 'checkbox'" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :tree-node="colItem.treeNode">
          <template #header="{ row }">
            <div class="checkbox-class">
              <vxe-checkbox :ref="colItem.field+'_header'" v-model="colItem.chooseAllFlag"
                            @change="clickAllCheckbox(colItem)"/>
            </div>
          </template>
          <template #default="{ row,rowIndex }">
            <div class="checkbox-class">
              <vxe-checkbox v-if="colItem.controlField?row[colItem.controlField]:true" size="small"
                            :ref="colItem.field+'_default_'+rowIndex"
                            :disabled="setSwitchCellDisabled(row,colItem)"
                            v-model="row[colItem.field]" @change="changeValue(colItem,rowIndex,row)"/>
            </div>
          </template>
          <template #edit="{ row,rowIndex }">
            <div class="checkbox-class">
              <vxe-checkbox v-if="colItem.controlField?row[colItem.controlField]:true" size="small"
                            :ref="colItem.field+'_default_'+rowIndex"
                            :disabled="setSwitchCellDisabled(row,colItem)"
                            v-model="row[colItem.field]" @change="changeValue(colItem,rowIndex,row)"/>
            </div>
          </template>
        </vxe-column>


        <!--   文本类型   -->
        <vxe-column v-if="colItem.type === 'text'" :field="colItem.field" :title="$t(colItem.field)"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :edit-render="{autofocus: '.vxe-input--inner'}" :tree-node="colItem.treeNode">
          <template #header="{ row }">
            <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
            <Poptip trigger="click" transfer @on-popper-hide="popperHide">
              <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
                    v-if="colItem.copyVisible"/>
              <div slot="content">
                <div style="display: flex;align-items: center;justify-content: center;">
                  <Input size="small" v-model="inputDownValue"
                         :maxlength="colItem.maxlength?colItem.maxlength:vm.$config.maxlength"
                         @keydown.13.native.stop="inputDown(colItem)"></Input>
                  <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
                </div>
              </div>
            </Poptip>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>

          <template #edit="{ row,rowIndex }">
            <vxe-input v-model="row[colItem.field]" type="text"
                       :maxlength="colItem.maxlength?colItem.maxlength:vm.$config.maxlength"
                       :ref="colItem.field+rowIndex"
                       v-if="checkInputCanVisble(row ,colItem)"
                       @dblclick.native.stop="copyValue(row,colItem,rowIndex)"
                       @change.native="changeValue(colItem,rowIndex,row)"
                       @keydown.native="nextInputCellByKeyDown(Object.assign($event,{column:colItem,colIndex,rowIndex, row}))"
            >

            </vxe-input>
            <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)" v-else>{{
                row[colItem.field]
              }}
            </div>
          </template>
        </vxe-column>

        <!--   数值   -->
        <vxe-column v-if="colItem.type === 'number'" :field="colItem.field" :title="$t(colItem.field)"
                    class-name="number-class"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :edit-render="{autofocus: '.vxe-input--inner', autoselect: true}" :formatter="formatColumn"
                    :params="colItem" :tree-node="colItem.treeNode">
          <template #header="{ row }">
            <span>{{ colItem.title ? colItem.title : $t(colItem.field) }}</span>
            <Poptip trigger="click" transfer @on-popper-show="popperShow(colIndex,'inputNumber')"
                    @on-popper-hide="popperHide">
              <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
                    v-if="colItem.copyVisible"/>
              <div slot="content">
                <!--点回车相当于点按钮填充-->
                <div style="display: flex;align-items: center;justify-content: center;">
                  <InputNumberPop size="small" v-model="inputDownValue" :ref="'pop_' + colIndex"
                                  @keydown.13.native.stop="inputDown(colItem)" :pop-visible="false"></InputNumberPop>
                  <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
                </div>
              </div>
            </Poptip>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #edit="{ row ,rowIndex}">
            <vxe-input v-model="row[colItem.field]" type="number"
                       :ref="colItem.field+rowIndex"
                       @wheel.native.prevent
                       @dblclick.native.stop="copyValue(row,colItem,rowIndex)"
                       @mousewheel.native.prevent
                       v-if="checkInputCanVisble(row,colItem)"
                       @contextmenu.native.prevent
                       @blur.native="handleBlur"
                       :controls="false"
                       @blur="changeValue(colItem,rowIndex,row)"
                       @keydown.native="controlNumber(Object.assign($event,{column:colItem,colIndex,rowIndex, row}))"
                       @keyup.native="handleKeyup(Object.assign($event,{column:colItem,colIndex,rowIndex, row}))"></vxe-input>
            <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)" v-else>{{
                row[colItem.field]
              }}
            </div>
          </template>
        </vxe-column>

        <!--   下拉   -->
        <vxe-column v-if="colItem.type === 'select'" :field="colItem.field" :title="$t(colItem.field)"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :edit-render="{autofocus: '.vxe-input--inner'}" :tree-node="colItem.treeNode">
          <template #header="{ row }">
            <span>{{ $t(colItem.title ? colItem.title : colItem.field) }}</span>
            <Poptip trigger="click" transfer @on-popper-hide="popperHide">
              <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
                    v-if="colItem.copyVisible"/>
              <div slot="content">
                <div style="display: flex;align-items: center;justify-content: center;">
                  <!--TODO暂时注释掉，以后完善-->
                  <!--                <Select size="small" v-model="inputDownValue" style="width:200px" :multiple="colItem.selectType==='M'"-->
                  <!--                        clearable>-->
                  <!--                  <Option v-for="item in typeof colItem.options === 'function'?colItem.options():colItem.options"-->
                  <!--                          :key="item[colItem.valueKey]"-->
                  <!--                          :value="item[colItem.valueKey]"-->
                  <!--                          :label="item[colItem.labelKey]">-->
                  <!--                  </Option>-->
                  <!--                </Select>-->
                  <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
                </div>
              </div>
            </Poptip>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #default="{ row }">
            <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem)">{{
                row[colItem.field + '_Name']
              }}
            </div>
          </template>

          <template #edit="{ row,column,rowIndex }" v-if="colItem.selectType === 'M'">
            <vxe-select transfer v-model="row[colItem.field]" v-show="setCellCanInput( row ,colItem)"
                        :ref="colItem.field+rowIndex"
                        @change="changeValue(colItem,rowIndex,row)" placeholder="请选择下拉"
                        multiple clearable>
              <vxe-option v-for="item in typeof colItem.options === 'function'?colItem.options():colItem.options"
                          :key="item[colItem.valueKey]"
                          :value="item[colItem.valueKey]"
                          :label="item[colItem.labelKey]"></vxe-option>
            </vxe-select>
          </template>
          <template v-else #edit="{ row,column,rowIndex }">
            <TableSelect :text="row[colItem.field + '_Name']" :field="colItem.field" :dataType="colItem.dataType"
                         :ref="column.field + rowIndex"
                         :keyValue="colItem.valueKey"
                         :label="colItem.labelKey"
                         :options="typeof colItem.options === 'function'?colItem.options():colItem.options"
                         :searchDataFlag="colItem.searchDataFlag"
                         :search-detail-flag="false"
                         :sortBoolean="colItem.sortBoolean"
                         v-if="checkInputCanVisble(row,colItem)"
                         @focus="handleSelectFocus(row,rowIndex,colItem)"
                         @change="inputChange(row,rowIndex,colItem)"
                         @keydown.stop="nextInputCellByKeyDown(Object.assign($event,{column:colItem,colIndex,rowIndex,row}))"
                         @onChoose="onChooseSelect($event,row,column,rowIndex,colIndex,colItem.fieldUpdate,colItem)"></TableSelect>
            <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem,rowIndex)" v-else>
              {{ row[colItem.field + '_Name'] }}
            </div>
          </template>

        </vxe-column>

        <!--  date   -->
        <vxe-column v-if="colItem.type === 'date'" :params="{type:'date'}" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :title="$t(colItem.field)" :edit-render="{autofocus: '.vxe-input--inner'}"
                    :tree-node="colItem.treeNode">
          <template #header="{ row }">
            <span>{{ $t(colItem.title ? colItem.title : colItem.field) }}</span>
            <Poptip trigger="click" transfer @on-popper-hide="popperHide">
              <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
                    v-if="colItem.copyVisible"/>
              <div slot="content">
                <div style="display: flex;align-items: center;justify-content: center;">
                  <DatePicker transfer v-model="inputDownValue" type="date"></DatePicker>
                  <Button type="primary" size="small" @click="inputDown(colItem)">{{ $t('filling') }}</Button>
                </div>
              </div>
            </Poptip>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #default="{ row }">
            <div class="edit-div-class" @dblclick.stop="copyValue(row,colItem)">{{
                dateFormat(row[colItem.field])
              }}
            </div>
          </template>
          <template #edit="{ row,rowIndex }">
            <DatePicker transfer :ref="colItem.field+rowIndex" v-model="row[colItem.field]" type="date"
                        @on-change="changeValue(colItem,rowIndex,row)"
                        v-show="setCellCanInput( row ,colItem)"></DatePicker>
          </template>
        </vxe-column>

        <!-- 开关 -->
        <vxe-column v-if="colItem.type === 'switch'" :params="{type:'switch'}" :field="colItem.field"
                    :width="colItem.width?colItem.width:vm.$config.columnWidth"
                    :min-width="colItem.minWidth?colItem.minWidth:vm.$config.columnWidthMin"
                    :title="$t(colItem.field)" :edit-render="{autofocus: '.vxe-input--inner'}"
                    :tree-node="colItem.treeNode">
          <template #header="{ row }">
            <span>{{ $t(colItem.title ? colItem.title : colItem.field) }}</span>
            <Poptip trigger="click" transfer @on-popper-hide="popperHide">
              <Icon type="iconfont iconfont icon-copy" style="cursor: pointer;" ref="down-input-icon"
                    v-if="colItem.copyVisible"/>
              <div slot="content">
                <div style="display: flex;align-items: center;justify-content: center;">
                  <i-switch v-model="inputDownBooleanValue"/>
                  <Button type="primary" style="margin-left:10px" size="small" @click="inputDown(colItem)">
                    {{ $t('filling') }}
                  </Button>
                </div>
              </div>
            </Poptip>
            <!--冻结/解冻列-->
            <Icon ref="freeze" :class="colItem.freezeFlag?'freezed-class':'freeze-class' "
                  v-if="freezeData && colItem.freezeFlag"
                  type="ios-lock"
                  @click="handleFreeze(colItem.field)"/>
          </template>
          <template #default="{ row,rowIndex }">
            <!--          <span>{{ row[colItem.field] ? '是' : '否' }}</span>-->
            <div class="switch-class">
              <vxe-switch v-if="colItem.controlField?row[colItem.controlField]:true" size="small"
                          :ref="colItem.field+'_default_'+rowIndex"
                          :disabled="setSwitchCellDisabled(row,colItem)"
                          v-model="row[colItem.field]" @change="changeValue(colItem,rowIndex,row)"/>
            </div>
          </template>
          <template #edit="{ row,rowIndex }">
            <!--只有设置了赠品标识的才能进行赠送-->
            <div class="switch-class">
              <vxe-switch v-if="colItem.controlField?row[colItem.controlField]:true" size="small"
                          :ref="colItem.field+rowIndex" v-model="row[colItem.field]"
                          v-show="!colItem.disabled && setCellCanInput( row ,colItem)"
                          @change="changeValue(colItem,rowIndex,row)"
                          :disabled="setSwitchCellDisabled(row,colItem)"/>
            </div>
          </template>
        </vxe-column>
      </div>

      <!--切换子品-->
      <DkModal
        width="900"
        ref="chlid_modal"
        v-model="showModal"
        @modalOk="modalOk"
        title="请选择需要替换的产品">
        <BaseIndexButtonGroup>
          <template #left>
            <BaseIndexButton ref="search" name="search" @click="searchData"></BaseIndexButton>
            <BaseIndexButton :finalFlag="true" ref="clear" name="clear" @click="clear"></BaseIndexButton>
          </template>
        </BaseIndexButtonGroup>
        <SearchCond id="search-cond-div" width="850px" v-if="searchContent && searchContent.length > 0" ref="searchCond"
                    v-model="searchCond" :setFlag="false" :searchContent="searchContent" :col-count="4"></SearchCond>

        <DkTable :primaryKey="controlId" ref="table-exchange"
                 :id="'table-'+$options.name" name="table"
                 :data="exchangeData"
                 :choose-flag="false"
                 :page-total="pageInfo.total"
                 :current-page="pageInfo.currentPage"
                 :showSettingFlag="false"
                 @pageChange="pageSizeChange"
                 size="mini">
          <DkTableColumn v-for="(item,index) in columnsDetail" :key="index" :field="item.field"
                         :title="item.title"></DkTableColumn>
        </DkTable>
      </DkModal>
    </vxe-table>
    <div class="setting-class" v-if="showSettingFlag && $refs[this.name]"
                 :style="'top:' + settingTop + ';left:' + settingLeft"
                 @click="showSetting">
    <Icon ref="setting" type="md-settings"/>
  </div>
  </div>
</template>

<script>

import XEUtils from 'xe-utils'
import SeqButton from '_c/sub/seq-button'
import TableSelect from '_c/business/table-select'

export default {
  name: 'EditTreeTable',
  components: {SeqButton, TableSelect},
  props: {
    data: {
      type: Array,
      default: () => {
      }
    },
    columns: {
      type: Array,
      default: () => []
    },
    // table的高度
    height: {
      type: [String, Number],
      default: 300
    },
    initCount: {
      type: Number,
      default: 10
    },
    enabledRepeat: {
      type: Boolean,
      default: false
    },
    enabledRepeatId: {
      type: [String, Array],
      default: ''
    },
    //该行数据有值其他可输入单元格才能进行
    controlId: {
      type: String,
      default: ''
    },
    // 新增标识是否可见
    addFlag: {
      type: Boolean,
      default: true
    },
    //删除按钮
    deleteFlag: {
      type: Boolean,
      default: true
    },
    //操作标识是否可见
    operateFlag: {
      type: Boolean,
      default: true
    },
    // 是否显示新行
    newRowFlag: {
      type: Boolean,
      default: true
    },
    //光标是否进入新增行
    focusFlag: {
      type: Boolean,
      default: false
    },
    //合计行
    showFooter: {
      type: Boolean,
      default: false
    },
    //表格名字
    name: {
      type: String,
      default: 'xTable'
    },
    //高亮显示
    currentRow: {
      type: Boolean,
      default: false
    },
    //必须输入
    requiredColumn: {
      type: Array,
      default: () => []
    },
    // 切换数据的列
    exchangeField: {
      type: String,
      default: ''
    },
    // 传入参数
    otherSearchParam: {
      type: Object,
      default: null
    },
    // 合并处理的字段（比如组合促销的促销Id)
    combinedField: {
      type: String,
      default: ''
    },
    //主键Id
    majorField: {
      type: String,
      default: ''
    },
    //跟单标识
    followFlag: {
      type: Boolean,
      default: false
    },
    //是否只读
    readonly: {
      type: Boolean,
      default: false
    },
    // 金额名称
    amountName: {
      type: String,
      default: 'itemAmount'
    },
    // 列表的宽度
    divWidth: {
      type: String,
      default: '100%'
    },
    // 是否显示设置按钮
    showSettingFlag: {
      type: Boolean,
      default: true
    },
    // 是否开启冻结
    freeze: {
      type: Boolean,
      default: true,
    },
    // 鼠标移入进行编辑的标识
    mouseEnterEditFlag: {
      type: Boolean,
      default: true,
    },
    //绑定条码标识
    bindBarCodeFlag: {
      type: Boolean,
      default: false,
    },
    // 查询条件（传入）
    searchInfo: {
      type: Object
    },
  },
  data() {
    const vm = window.vm
    return {
      vm: vm,
      whName: '',
      rowIndex: -1,
      colIndex: -1,
      header: {
        options: [
          [
            {code: 'rowPosition', name: vm.$t('rowPosition'), disabled: false, visible: true},
            {code: 'colPosition', name: vm.$t('colPosition'), disabled: false, visible: true},
            {code: 'clearFreeze', name: vm.$t('clearFreeze'), disabled: false, visible: false},
            {code: 'selfAdaptionOne', name: '当前列自适应', disabled: false, visible: true},
            {code: 'selfAdaption', name: '全部列自适应', disabled: false, visible: true},
          ]
        ]
      },
      freezeData: false, // 是否开启冻结
      enabledEdit: true, //是否启用编辑模式
      modal1: true,
      filterWrapper: true,
      inputDownValue: null,
      inputDownBooleanValue: false,
      tableData: [],
      tableDataChange: [],  //改变集合
      exchangeData: [],    //可替换的集合
      isScroll: false,
      validRules: {},    //校验的规则
      // 数据源的service
      service: {},
      methodsName: '',     // 查询子级的方法
      methodsNameExchange: '',//查询可以切换的方法
      columnsData: [],   //记录列
      columnsDetail: [],// 切换列表
      columnsUpdate: [], // 需要更新的列
      showModal: false,
      focusedRow: null,    // 当前行
      children: [],       // 记录子级
      chooseDataChange: false,//是否是选择数据进行的改变
      deleteData: [],     //删除的数据
      expandRows: [],      // 记录展开的行
      nonGlassForm: {},    // 非标玻璃的form表单
      settingLeft: null,          // 设置图标居左的位置
      settingTop: null,           // 设置图标居上的位置
      pageInfo: {
        total: 0,
        pageSize: this.$config.pageSize,
        currentPage: 1
      },
      // 查询条件
      searchCond: {
        _value: {}
      },
      searchContent: [],
      // 外部传入的查询条件
      otherCondition: {
        type: Object,
        default: null
      },
      //绑定条码添加标识
      bindBarCodeAddFlag: false,
      //绑定条码替换标识
      bindBarCodeReplaceFlag: false,
    }
  },
  watch: {
    readonly(n, o) {
      if (n) {
        this.enabledEdit = false
      }
    },
    newRowFlag(n, o) {
      if (n) {
        this.add()
      }
    },
    data(n, o) {
      if (n) {
        //赋值上所需要id ,parentId
        let data = n.map(it => {
          let obj = it
          // 如果后台有id，直接用，没有就用controlId
          if (!it.id) {
            obj.id = it[this.controlId]
          }
          obj.parentId = null
          return obj
        })
        // 编辑
        if (data && data.length > 0) {
          this.tableData = JSON.parse(JSON.stringify(data))
          this.handleSelectData()
          this.loadChildrenInit(this.tableData) // 处理子级数据
        } else {
          this.tableData = []
          this.tableDataChange = []
          if (this.newRowFlag) {
            //新建时增加行
            this.add()
          }
        }
      }
    }
  },
  methods: {
    /**
     * @desc   : 用传入的参数给值赋值
     * @author : 周兴
     * @date   : 2023/2/21 10:27
     */
    setSearchInfo(searchInfo) {
      if (searchInfo) {
        this.objectMerge(this.searchCond._value, searchInfo);
      }
    },
    /**
     * @desc   : 清空事件
     * @author : 周兴
     * @date   : 2022/3/4 8:19
     */
    clear() {
      this.searchList = {}
      this.searchCond._value = {}
      if (this.$refs.searchCond) {
        this.$refs.searchCond.clearCondition();
      }
      this.searchData() // 重新查询
    },
    /**
     * @desc   : 查询，从第一页开始
     * @author : 周兴
     * @date   : 2023/2/24 10:45
     */
    searchData() {
      this.pageInfo.currentPage = 1;
      this.getDataTable();
    },
    pageSizeChange(pageInfo) {
      this.pageInfo = pageInfo
      this.getDataTable() // 查询数据
    },
    /**
     * @desc   : 单元格样式
     * @author : 周兴
     * @date   : 2022/8/23 17:23
     */
    cellStyle({row, rowIndex, column}) {
      //序号居中
      if (column.type === 'seq' || column.field === 'seq' || column.type === 'checkbox' || column.type === 'date'
        || column.type === 'switch' || (column.params && column.params.type === 'disabled' && column.params.switch)) {
        return {textAlign: 'center'}
      } else if (column.type === 'number' || (column.params && column.params.type === 'disabled' && column.params.number)) {
        return {textAlign: 'right'}
      } else {
        return {textAlign: 'left'}
      }
    },
    /**
     * @desc   : 底部单元格样式
     * @author : 周兴
     * @date   : 2022/8/23 17:33
     */
    footCellStyle({row, rowIndex, column}) {
      if (column.params && column.params.type === 'number') {
        return {textAlign: 'right', background: '#FFF8E1'}
      } else {
        return {textAlign: 'left', background: '#FFF8E1'}
      }
    },
    /**
     * @desc   : 点击右键
     * @author : 周兴
     * @date   : 2022/12/19 11:12
     */
    cellMenuClick(e) {
      this.$refs[this.name].$el.click() //关闭表头的pop
    },
    /**
     * @desc   : 右键菜单
     * @author : 沈博
     * @date   : 2022/3/13 10:55
     */
    visibleMethod(e) {
      // 表格可以冻结
      if (this.freeze) {
        this.header.options[0].update({code: 'freeze', visible: true}, 'code', 'visible')
      }
      return true
    },
    /**
     * @desc   : 点击右键按钮
     * @author : 周兴
     * @date   : 2022/3/30 17:24
     */
    menuClick(e) {
      if (e.menu.code == 'selfAdaption') {
        this.autoWidthHandle()
      } else if (e.menu.code == 'selfAdaptionOne') {
        this.autoWidthHandle(e)
      } else if (e.menu.code == 'export') {
        this.export(e.column.property)
      } else if (e.menu.code == 'rowPosition') {   // 行定位
        this.showRowPosition(e)
      } else if (e.menu.code == 'colPosition') {   // 列定位
        this.showColPosition(e)
      } else if (e.menu.code == 'colFreeze') { // 列冻结
        this.handleFreeze(e)
      } else if (e.menu.code == 'clearFreeze') {  // 解除冻结
        this.unFreeze(e)
      }
    },
    /**
     * @desc   : 显示行定位定位框
     * @author : 周兴
     * @date   : 2022/11/30 13:00
     */
    showRowPosition(e) {
      let event = e.$event
      this.$Position({left: event.clientX, top: event.clientY},
        {
          ok: (searchText) => {
            this.rowPositioning(this.$refs[this.name], this.tableData, searchText)
          },
        })
    },
    /**
     * @desc   : 显示列定位定位框
     * @author : 周兴
     * @date   : 2022/11/30 13:00
     */
    showColPosition(e) {
      let event = e.$event
      this.$Position({left: event.clientX, top: event.clientY},
        {
          ok: (searchText) => {
            this.handleColPosition(searchText)   // 执行列定位方法
          },
        })
    },
    /**
     *   @author : 寇珊珊
     *   @date   : 2022/3/23 16:29
     *   @desc   : 自适应全部列宽
     */
    autoWidthHandle(e) {
      if (this.tableData && this.tableData.length > 0) {
        let data = this.tableData.copy()
        if (e) {
          if (e.column) {
            // 当前列的自适应
            let columnValues = data.map(it => it[e.column.field])
            // 树形需要把子级也要插入到数据中
            if (this.children && this.children.length > 0) {
              this.children.forEach(it => {
                columnValues.pushNoRepeat(it[e.column.field])
              })
            }
            columnValues.push(e.column.title + '占位占位')  // 把每列的表头也加进去算
            let width = this.getMaxLength(columnValues) + 10 // 每列内容最大的宽度 + 表格的内间距(依据实际情况而定)
            // this.$set(e.column, 'width', width)
            // 取这个宽度和最小宽度的最大值
            let minWidth = (e.column.minWidth + '')?.replace('px', '').toNum(0)
            this.$set(e.column, 'width', [width, minWidth].max())
          }
        } else {
          // 全部可见列的自适应
          let columns = this.$refs[this.name].getColumns()
          columns.forEach(col => {
            if (col.type !== 'seq' && col.type !== 'radio' && col.type !== 'checkbox'
              && col.type !== 'switch' && col.type !== 'operate' && col.type !== 'info'
              && col.type !== 'blank') {
              let columnValues = data.map(it => it[col.field])
              // 树形需要把子级也要插入到数据中
              if (this.children && this.children.length > 0) {
                this.children.forEach(it => {
                  columnValues.pushNoRepeat(it[col.field])
                })
              }
              columnValues.push(col.title + '占位占位')  // 把每列的表头也加进去算
              let width = this.getMaxLength(columnValues) + 10 // 每列内容最大的宽度 + 表格的内间距(依据实际情况而定)
              // this.$set(col, 'width', width)
              // 取这个宽度和最小宽度的最大值
              let minWidth = (col.minWidth + '')?.replace('px', '').toNum(0)
              this.$set(col, 'width', [width, minWidth].max())
            }
          })
        }
        this.$nextTick(() => {
          this.$refs[this.name].resetColumn({resizable: true})
          this.$refs[this.name].recalculate()
        })
      }
    },
    /**
     * @desc   : 解除冻结
     * @author : 周兴
     * @date   : 2022/12/1 13:30
     */
    unFreeze() {
      const tableColumns = this.$refs[this.name].getTableColumn()
      if (tableColumns && tableColumns.visibleColumn) {
        tableColumns.visibleColumn.forEach(it => {
          if (it.type != 'seq' && it.type != 'radio' && it.type != 'checkbox') {
            it.fixed = ''
          }
        })
        this.columnsData.forEach(it => {
          it.freezeFlag = false
        })
        // 清空冻结不可见
        // this.header.options[0].update({code: 'clearFreeze', visible: false}, 'code', 'visible');
        let filters = this.header.options[0].filter(it => it.code === 'freeze')
        if (filters && filters.length > 0) {
          filters[0].children.update({code: 'clearFreeze', visible: false}, 'code', 'visible')
        }
        this.$refs[this.name].refreshColumn()
      }
    },
    /**
     * @desc   : 冻结列
     * @author : 周兴
     * @date   : 2022/11/30 17:28
     */
    handleFreeze(e) {
      let field = e.column.field
      const tableColumns = this.$refs[this.name].getTableColumn()
      if (tableColumns && tableColumns.visibleColumn) {
        let columnIndex = 0
        tableColumns.visibleColumn.forEach((it, index) => {
          it.fixed = ''
          if (it.field === field) {
            columnIndex = index
          }
        })
        // 冻结该列之前的列，包括这列
        for (let i = 0; i <= columnIndex; i++) {
          tableColumns.visibleColumn[i].fixed = 'left'
        }
        // 先把所有的冻结标识都去掉
        this.columnsData.forEach(it => {
          it.freezeFlag = false
        })
        // 找到当前列，给其赋值冻结标识
        let colItems = this.columnsData.filter(it => it.field === field)
        if (colItems && colItems.length > 0) {
          colItems[0].freezeFlag = true
        }
        // 清空冻结可见
        // this.header.options[0].update({code: 'clearFreeze', visible: true}, 'code', 'visible');
        let filters = this.header.options[0].filter(it => it.code === 'freeze')
        if (filters && filters.length > 0) {
          filters[0].children.update({code: 'clearFreeze', visible: true}, 'code', 'visible')
        }
        this.$refs[this.name].refreshColumn()
      }
    },
    /**
     * @desc   : 表格设置
     * @author : 周兴
     * @date   : 2022/12/1 15:11
     */
    showSetting(e) {
      const tableColumns = this.$refs[this.name].getTableColumn()
      if (tableColumns) {
        let columns = tableColumns.fullColumn
        columns = columns.filter(it => it.type != 'seq' && it.type != 'blank' && it.type != 'info')
        this.$TableFilter({tableData: columns},
          {
            ok: (val) => {
              this.unFreeze()
              // 去掉选择的标题
              let filterRows = val.filter(it => it.type == 'checkbox' || it.type == 'radio')
              if (filterRows && filterRows.length > 0) {
                filterRows.forEach(it => {
                  it.title = ''
                })
              }
              // 加入序号
              val.splice(0, 0, tableColumns.fullColumn[0])
              // 加入校验信息
              val.splice(1, 0, tableColumns.fullColumn[1])
              // 加入blank
              val.push(tableColumns.fullColumn[tableColumns.fullColumn.length - 1])
              // 加载列
              this.$refs[this.name].loadColumn(val)
            },
          })
      }
    },
    /**
     * @desc   : 打开非标选择窗口
     * @author : 周兴
     * @date   : 2022/8/25 10:48
     */
    openNonGlassForm(e) {
      setTimeout(() => {
        if (this.$refs[e.colItem.field + e.rowIndex] && this.$refs[e.colItem.field + e.rowIndex].length > 0) {
          this.$refs[e.colItem.field + e.rowIndex][0].togglePanel()
        }
      }, 30)
    },
    /**
     * @desc   : 修改面积后联动计算
     * @author : 周兴
     * @date   : 2022/9/28 17:09
     */
    changeValueByArea(e) {
      // 计算
      this.calc('priceSale', e.rowIndex)
      // 根据单价进行计算
      this.$nextTick(() => {
        this.$emit('changeValue', {field: 'priceSale', row: e.row, rowIndex: e.rowIndex})
      })
    },
    /**
     * @desc   : 改变非标参数选项
     * @author : 周兴
     * @date   : 2022/8/25 10:52
     */
    changeNonGlass(e) {
      let rowIndex = e.rowIndex
      if (this.tableData && rowIndex >= 0 && this.tableData[e.rowIndex]) {
        let row = this.tableData[e.rowIndex]
        let nonGlassSpuItems = row.nonGlassSpuItems
        let keys = Object.keys(row.nonGlassForm)
        let texts = []
        let texts_no_input = [] // 不包括文本输入，用于获取标价
        let nonGlassList = []
        for (let i in keys) {
          let item = nonGlassSpuItems.filter(it => it.fieldCode == keys[i])
          if (!item || item.length == 0) {
            continue
          }
          let text = ''
          if (item[0].options && item[0].options.length > 0) {
            // 说明是下拉
            let filterRows = item[0].options.filter(it => it.code == row.nonGlassForm[keys[i]])
            if (filterRows && filterRows.length > 0) {
              text = item[0].fieldName + '：' + filterRows[0].name
              texts_no_input.push(text)
              nonGlassList.push({
                fieldId: item[0].fieldId, fieldCode: item[0].fieldCode,
                fieldName: item[0].fieldName, optionCode: filterRows[0].code,
                optionName: filterRows[0].name
              })
            }
          } else {
            if (e.fieldCode == keys[i]) {
              if (e.value) {
                nonGlassList.push({
                  fieldId: item[0].fieldId, fieldCode: item[0].fieldCode,
                  fieldName: item[0].fieldName, optionCode: e.value, optionName: e.value
                })
                row.nonGlassForm[keys[i]] = e.value
                text = item[0].fieldName + '：' + e.value
              }
            } else {
              if (row.nonGlassForm[keys[i]]) {
                nonGlassList.push({
                  fieldId: item[0].fieldId,
                  fieldCode: item[0].fieldCode,
                  fieldName: item[0].fieldName,
                  optionCode: row.nonGlassForm[keys[i]],
                  optionName: row.nonGlassForm[keys[i]]
                })
                text = item[0].fieldName + '：' + row.nonGlassForm[keys[i]]
              }
            }
          }
          if (text) {
            texts.push(text)
          }
          row[e.colItem.field] = texts.join('，')
          row[e.colItem.field + '_no_input'] = texts_no_input.join('，')
          row.nonGlassList = nonGlassList
        }
        // 增加面积公式
        if (row.specialFormula) {
          row.nonGlassList.push({
            fieldId: -1, fieldCode: 'specialFormula',
            fieldName: '面积公式'
          })
        }
        // 增加面积
        row.nonGlassList.push({
          fieldId: -2, fieldCode: 'nonStandardArea',
          fieldName: '面积'
        })
        if (e.changePrice) {
          // 获取非标的价格
          this.getNonGlassPrice(row, rowIndex)
        }
        // 输入长度计算面积
        if (e.isScope == 1) {
          // 计算面积
          this.calcNonGlassArea(row, rowIndex)
        }
        //把改变的行加入到tableDataChange中（子级的改变不做记录）
        if (!row.parentId) {
          let rows = this.tableDataChange.filter(it => it['id'] === row['id'])
          //说明已经存在
          if (rows && rows.length > 0) {
            this.tableDataChange = this.tableDataChange.filter(it => it['id'] !== row['id']).map(it => it)
          }
          this.tableDataChange.push(row)
        }
      }
    },
    /**
     * @desc   : 计算面积
     * @author : 周兴
     * @date   : 2022/9/28 13:15
     */
    calcNonGlassArea(row, rowIndex) {
      let area = 1
      // 根据面积公式计算面积
      if (row.specialFormula) {
        let nonGlassList = row.nonGlassList
        if (nonGlassList && nonGlassList.length > 0) {
          let specialFormula = row.specialFormula
          nonGlassList.forEach(it => {
            specialFormula = specialFormula.replace(it.fieldName, (parseFloat(it.optionCode) / 1000).toString())
          })
          try {
            area = eval(specialFormula)
            area = area.toFixed(6)
          } catch (err) {
            area = 1
          }
        }
      }
      row.nonStandardArea = area
      // 计算
      this.calc('priceSale', rowIndex)
      // 根据单价进行计算
      this.$nextTick(() => {
        this.$emit('changeValue', {field: 'priceSale', row: row, rowIndex: rowIndex})
      })
    },
    /**
     * @desc   : 获取非标淋浴房的标价
     * @author : 周兴
     * @date   : 2022/8/25 13:53
     */
    getNonGlassPrice(row, rowIndex) {
      let nonGlassShow = row['nonGlassListShow_no_input'] ? row['nonGlassListShow_no_input'] : ''
      let nonGlassPriceItems = JSON.parse(JSON.stringify(row['nonGlassPriceItems']))
      // 根据逗号进行分割
      if (nonGlassPriceItems && nonGlassPriceItems.length > 0) {
        let nonGlassShows = nonGlassShow.split('，')
        nonGlassShows.forEach(nonRow => {
          nonGlassPriceItems = nonGlassPriceItems.filter(it => it.nonGlassListShowArr.length == nonGlassShows.length
            && it.nonGlassListShowArr.includes(nonRow))
        })
        if (nonGlassPriceItems && nonGlassPriceItems.length > 0) {
          row.priceSale = nonGlassPriceItems[0].itemPrice
          row.priceStandard = nonGlassPriceItems[0].itemPrice
          row.discountStandard = 100
        } else {
          // 查询是否有空项目的，默认空项目的标价
          if (row['nonGlassPriceItems'] && row['nonGlassPriceItems'].length > 0) {
            let filterRows = row['nonGlassPriceItems'].filter(it => !it.nonGlassListShow)
            if (filterRows && filterRows.length > 0) {
              row.priceSale = filterRows[0].itemPrice
              row.priceStandard = filterRows[0].itemPrice
              row.discountStandard = 100
            } else {
              row.priceStandard = 0
              row.discountStandard = 0
              row.priceSale = 0
            }
          } else {
            row.priceStandard = 0
            row.discountStandard = 0
            row.priceSale = 0
          }
        }
      }
      this.calc('priceSale', rowIndex)
      // 根据单价进行计算
      this.$nextTick(() => {
        this.$emit('changeValue', {field: 'priceSale', row: row, rowIndex: rowIndex})
      })
    },
    /**
     * @desc   : 下拉聚焦事件
     * @author : 周兴
     * @date   : 2022/4/22 9:10
     */
    handleSelectFocus(row, rowIndex, colItem) {
      this.$emit('on-select-focus', colItem.field, row, rowIndex)
    },
    /**
     *   @desc   : 初始时加载子级数据
     *   @date   : 2023/4/20 13:30
     *   @author : 寇珊珊
     */
    loadChildrenInit(data, columns = []) {
      if (data && data.length > 0) {
        data.forEach(row => {
          if (row.bomItems && row.bomItems.length > 0) {
            row.bomItems.forEach(item => {
              let filters = this.children.filter(it => it.id == item.id)
              if (filters && filters.length === 0) {
                this.children.push(item)
              } else {
                columns.forEach(c => {
                  filters[0][c] = item[c]
                })
              }
            })
          }
        })
      }
    },
    /**
     * @desc   : 给下拉数据源增加Name列
     * @author : 周兴
     * @date   : 2022/4/22 9:02
     */
    handleSelectData() {
      let options = []
      //记录下拉的列
      this.columns.forEach(col => {
        if (col.type === 'select') {
          if (this.tableData && this.tableData.length > 0) {
            //获取下拉数据源
            if (typeof col.options === 'function') {
              options = col.options()
            }
            this.tableData.forEach(row => {
              if (row[col.field]) {
                let selectVal = options.filter(it => row[col.field] === it[col.valueKey])[0]
                if (selectVal) {
                  row[col.field + '_Name'] = selectVal[col.labelKey]
                }
              }
            })
          }
        }
      })
    },
    /**
     * @desc   : 点击表格的keydown自动进入第一个单元格
     * @author : 周兴
     * @date   : 2022/4/19 13:17
     */
    handleTableKeyDown(e) {
      if (e.$event.key === 'Enter') {
        this.$refs[this.name].setActiveCell(this.tableData[0], this.columns[0].field)
        this.handleFocus(this.columns[0], 0)
      }
    },
    /**
     * @desc   : 增加当前行hover
     * @author : 周兴
     * @date   : 2023/5/17 16:39
     */
    addHover(rowIndex){
      if (this.readonly) {
        return;
      }
      if (this.operateFlag) {
        // 如果行不变，不用执行
        if (rowIndex != this.rowIndex) {
          if (this.tableData && this.tableData.length > 0) {
            this.tableData.forEach(it => {
              this.$set(it, '_hover', false)
            })
          }
        }
        setTimeout(() => {
          if (rowIndex >= 0 && this.tableData[rowIndex]) {
            this.$set(this.tableData[rowIndex], '_hover', true)
          }
        }, 30)
      }
    },
    /**
     * @desc   : 鼠标移入增加新增和删除按钮
     * @author : 周兴
     * @date   : 2022/4/19 10:56
     */
    handleCellMouseEnter(e) {
      // if (this.readonly) {
      //   return
      // }
      // if (this.operateFlag) {
      //   // 如果行不变，不用执行
      //   if (e && (e.rowIndex != this.rowIndex)) {
      //     if (this.tableData && this.tableData.length > 0) {
      //       this.tableData.forEach(it => {
      //         this.$set(it, '_hover', false)
      //       })
      //     }
      //     setTimeout(() => {
      //       if (e.rowIndex >= 0 && this.tableData[e.rowIndex]) {
      //         this.$set(this.tableData[e.rowIndex], '_hover', true)
      //       }
      //     }, 300)
      //   }
      // }
      // // 鼠标移入后，当前行变为编辑状态
      // if (e && e.row) {
      //   this.colIndex = e.columnIndex
      //   // 鼠标移入自动进行行切换
      //   if (this.mouseEnterEditFlag) {
      //     // this.$refs[this.name].setActiveRow(e.row)
      //     // // console.log('ttt',e.row,e.rowIndex,this.currentRowIndex)
      //     // this.$refs[this.name].setCurrentRow(e.row)
      //     // if(this.rowIndex !== e.rowIndex){
      //     //   this.currentChangeGetData({ oldRowIndex:this.rowIndex,rowIndex:e.rowIndex })
      //     // }
      //   }
      //   this.rowIndex = e.rowIndex
      // }
    },
    /**
     * @desc   : 鼠标移出删除新增和删除按钮
     * @author : 周兴
     * @date   : 2022/4/19 10:56
     */
    handleCellMouseLeave(e) {
      // if (this.operateFlag) {
      //   setTimeout(() => {
      //     if (e && e.rowIndex != this.rowIndex) {
      //       if (e.rowIndex >= 0 && this.tableData[e.rowIndex]) {
      //         this.$set(this.tableData[e.rowIndex], '_hover', false)
      //       }
      //     }
      //   }, 300)
      // }
    },
    /**
     * @desc   : desc
     * @author : 周兴
     * @date   : 2022/6/16 10:45
     */
    calcColumns(rowIndex) {
      this.columns.forEach(it => {
        //数值
        if (it.type === 'number' || it.number) {
          this.calc(it.field, rowIndex, true)               //计算
        }
      })
    },
    /**
     * @desc   : 开关控制（子级）
     * @author : 周兴
     * @date   : 2022/9/1 9:09
     */
    switchValueChild(colItem, rowIndex, row, autoFlag) {
      let children = this.children.filter(it => it.id === row.id)
      if (children && children.length > 0) {
        let child = children[0]
        // 如果开关开启，那么相关列修改为0
        if (child[colItem.field] != null) {
          // 只有设置了switchField才能进行修改相关金额
          if (colItem.switchField && colItem.field === 'flgGift') {
            if (child[colItem.switchField] && child[colItem.switchField] != 0) {
              // 先记录原始的数据
              this.setSwitchValue(true, row, colItem)
              if (!autoFlag) {
                this.setSwitchValue(true, child, colItem)
              }
            } else {
              // 先记录原始的数据
              this.setSwitchValue(false, row, colItem)
              if (!autoFlag) {
                this.setSwitchValue(false, child, colItem)
              }
            }
            //计算父级
            let pRows = this.tableData.filter(it => it.id === row.parentId)
            let pRowIndex = this.tableData.findIndex(it => it.id === row.parentId)
            if (pRows && pRows.length > 0) {
              let pRow = pRows[0]
              let childs = this.children.filter(cRow => cRow.parentId === pRow.id && cRow.hasChild == 0)
              if (childs && childs.length > 0) {
                let amount = 0
                childs.forEach(c => {
                  if (c.hasChild == 0 && c[this.amountName]) {
                    amount += Number(c[this.amountName])
                  }
                })
                // console.log('ter3', amount,colItem, parseFloat(amount.toFixed(2)))
                pRow[this.amountName] = parseFloat(amount.toFixed(2))
              }
              // 计算金额相关的其他列
              this.calc(this.amountName, pRowIndex, false, true)
            }
          } else {
            this.$set(child, colItem.field, row[colItem.field])
          }
        }
      }
    },
    /**
     * @desc   : desc
     * @author : 周兴
     * @date   : 2022/9/1 19:20
     */
    setSwitchValue(flag, row, colItem) {
      if (flag) {
        this.$set(row, colItem.switchField + '_switch', row[colItem.switchField])
        this.$set(row, this.amountName + '_switch', row[this.amountName])
        this.$set(row, 'discountStandard_switch', row.discountStandard)
        this.$set(row, 'discountPromotion_switch', row.discountPromotion)
        this.$set(row, colItem.switchField, 0)
        this.$set(row, this.amountName, 0)
        this.$set(row, 'discountStandard', 0)
        this.$set(row, 'discountPromotion', 0)
      } else {
        this.$set(row, colItem.switchField, row[colItem.switchField + '_switch'])
        this.$set(row, this.amountName, row[this.amountName + '_switch'])
        this.$set(row, 'discountStandard', row['discountStandard_switch'])
        this.$set(row, 'discountPromotion', row['discountPromotion_switch'])
      }
    },
    /**
     * @desc   : 开关控制
     * @author : 周兴
     * @date   : 2022/6/23 9:09
     */
    switchValue(colItem, rowIndex, row) {
      // if (colItem.switchField) {
      if (colItem.type === 'switch') {
        // 如果这行有子级，那么子级的也要处理
        let children = this.children.filter(it => it.parentId === row.id)
        if (children && children.length > 0) {
          children.forEach(it => {
            it[colItem.field] = row[colItem.field]
          })
        }
        // 如果开关开启，那么相关列修改为0
        if (colItem.switchField && row[colItem.field] != null) {
          if (this.tableData[rowIndex][colItem.switchField]) {
            // 先记录原始的数据
            this.$set(this.tableData[rowIndex], colItem.switchField + '_switch', this.tableData[rowIndex][colItem.switchField])
            this.tableData[rowIndex][colItem.switchField] = 0
          } else {
            // 先记录原始的数据
            this.$set(this.tableData[rowIndex], colItem.switchField, this.tableData[rowIndex][colItem.switchField + '_switch'])
          }
          // 重新计算
          this.calc(colItem.switchField, rowIndex)
        }
      } else {
        let flag = false
        // 控制开关列
        if (row[colItem.field] && row[colItem.field] != 0) {
          flag = false
          this.tableData[rowIndex][colItem.switchField] = false
        } else {
          flag = true
          this.tableData[rowIndex][colItem.switchField] = true
        }
        // 如果这行有子级，那么子级的也要处理
        let children = this.children.filter(it => it.parentId === row.id)
        if (children && children.length > 0) {
          children.forEach(it => {
            it[colItem.switchField] = flag
          })
        }
      }
      // }
    },
    /**
     * @desc   : 重新加载树形
     * @author : 周兴
     * @date   : 2023/4/25 10:02
     */
    reloadTreeTable(data) {
      let expandRows = this.$refs[this.name].getTreeExpandRecords()
      let filters = []
      let flag = true;
      expandRows.forEach(it => {
        filters = data.filter(t => t['_X_ID'] == it['_X_ID'])
        // console.log('filters',filters,filters[0].children)
        if (filters && filters.length > 0 && (!filters[0].children || filters[0].children.length === 0)) {
          flag = false;
        }
      })
      if (flag) {
        this.$refs[this.name].reloadData(data)
        this.restoreTreeTableStatus(expandRows) // 恢复刷新前的节点展开状态
      }
    },
    /**
     * @desc   : 值改变
     * @author : 周兴
     * @date   : 2022/4/10 14:21
     */
    changeValue(colItem, rowIndex, row, autoFlag) {
      let field = colItem.field
      //数值
      if (colItem.type === 'number') {
        // 如果是这里必须是负数，需要自动转为负数
        if (colItem.negative && parseFloat(row[field]) > 0) {
          this.tableData[rowIndex][field] = -1 * parseFloat(row[field])
        }
        this.calc(field, rowIndex)           //计算
      } else {
        // 如果子级的数据需要跟父级一致，但是必须子级是空时
        this.setChildEqual(row, colItem, field)
      }
      //开关
      if (!row.parentId) {
        // 父级
        this.switchValue(colItem, rowIndex, row)
      } else {
        // 子级
        this.switchValueChild(colItem, rowIndex, row, autoFlag)
      }
      // 有联动，数据改变需要清空对应的列数据
      this.columns.forEach(it => {
        if (it.controlIds && it.controlIds.length > 0) {
          //说明这列管控其他列
          if (it.controlIds.includes(field)) {
            row[it.field] = null
          }
        }
      })
      //把改变的行加入到tableDataChange中（子级的改变不做记录）
      if (!row.parentId) {
        let rows = this.tableDataChange.filter(it => it['id'] === row['id'])
        //说明已经存在
        if (rows && rows.length > 0) {
          this.tableDataChange = this.tableDataChange.filter(it => it['id'] !== row['id']).map(it => it)
        }
        this.tableDataChange.push(row)
      } else {
        let rows = this.tableDataChange.filter(it => it['id'] === row.parentId)
        let tRows = this.tableData.filter(it => it['id'] === row.parentId)
        if (tRows && tRows.length > 0) {
          //说明已经存在
          if (rows && rows.length > 0) {
            this.tableDataChange = this.tableDataChange.filter(it => it['id'] !== row.parentId).map(it => it)
          }
          this.tableDataChange.push(tRows[0])
        }
      }
      this.$emit('changeValue', {field, row, rowIndex})
      // 父级改动才会变
      if (!row.parentId) {
        this.$nextTick(() => {
          // 重新加载树形表格
          this.reloadTreeTable(this.tableData)
        })
      } else {
        setTimeout(() => {
          // 更新合计行
          this.$refs[this.name].updateFooter()
        }, 100)
      }
    },
    /**
     * @desc   : 改变值，子级不会变，就需要reload列表，然后恢复子级的状态
     * @author : 周兴
     * @date   : 2022/7/30 10:43
     */
    restoreTreeTableStatus(expandRows) {
      setTimeout(() => {
        if (expandRows && expandRows.length > 0) {
          expandRows.forEach(it => {
            this.$refs[this.name]?.toggleTreeExpand(it)
          })
        }
        // 更新合计行
        this.$refs[this.name].updateFooter()
      }, 300)
    },
    /**
     * @desc   : 设置子级数据
     * @author : 周兴
     * @date   : 2022/7/22 15:23
     */
    setChildEqual(row, colItem, field) {
      if (colItem.equal) {
        // 查看是否有子级
        let children = this.children.filter(it => it['parentId'] === row['id'])
        if (children && children.length > 0) {
          children.forEach(it => {
            this.$set(it, field, row[field])
            // 如果是下拉还需赋名称
            if (colItem.type === 'select') {
              this.$set(it, field + '_Name', row[field + '_Name'])
            }
          })
          row.children = children
        }
      }
    },
    /**
     * @desc   : 控制下拉选择是否出现
     * @author : 周兴
     * @date   : 2022/6/6 14:39
     */
    setCellCanTableSelect(row, column) {
      //如果这列是否禁用的，就不能选择
      if (column.disabled) {
        return false
      }
      //如果功能是跟单，并且主键有值那么就不允许
      if (this.followFlag && this.majorField && row[this.majorField]) {
        return false
      }
      let flag = true
      // 子级不允许选择
      if (row['parentId']) {
        flag = false
      } else {
        // 组合类不允许选择
        if (this.combinedField && row[this.combinedField]) {
          flag = false
        }
      }
      if (flag) {
        flag = this.setCellCanInput(row, column)
      }
      return flag
    },
    /**
     * @desc   : 控制删除按钮是否可以用
     * @author : 周兴
     * @date   : 2022/11/28 10:43
     */
    checkDeleteButtonCanUse(row, column) {
      let flag = true
      // 如果是跟单，并且主键有值
      if (this.followFlag && this.majorField && row[this.majorField] && !column.followNoControl) {
        flag = false
      }
      return flag
    },
    /**
     * @desc   : 判断输入框是否显示
     * @author : 周兴
     * @date   : 2022/6/24 14:37
     */
    checkInputCanVisble(row, column) {
      let flag = true
      // 如果是跟单，并且主键有值
      if (this.followFlag && this.majorField && row[this.majorField] && !column.followNoControl) {
        flag = false
      }
      // 数值列子级不允许显示
      if (column.type === 'number' && row['parentId']) {
        flag = false
      }
      // 下拉列子级不允许显示
      if (column.type === 'select' && row['parentId']) {
        flag = false
      }
      if (column.type === 'text' && !column.childCanInput && row['parentId']) {
        flag = false
      }
      if (flag) {
        flag = this.setCellCanInput(row, column)
        if (flag) {
          // 按照行进行控制列
          if (row['readOnly']) {
            let readOnly = row['readOnly']
            if (readOnly.indexOf(column.field) >= 0) {
              flag = false
            }
          }
        }
      }
      return flag
    },
    /**
     * @desc   : 设置单元格是否可以输入
     * @author : 周兴
     * @date   : 2022/4/7 15:20
     */
    setCellCanInput(row, column) {
      let flag = false
      if (this.controlId) {
        //看这列是否需要进行管控
        if (column.controlId && this.controlId === column.controlId) {
          flag = true
        } else {
          //如果该行controlId有值，不管控
          if (row[this.controlId] || (this.combinedField && row[this.combinedField])) {
            flag = true
          } else {
            //子级的文本不用控制
            if (column.type === 'text' && row.parentId) {
              flag = true
            }
            // 组合的子级，赠品标识不控制
            if (this.combinedField && (column.field == 'flgGift' || column.field == 'flgAllowSpecsUndefine')) {
              flag = true
            }
          }
        }
      } else {
        flag = true
        // 如果列设置了管控
        if (column.controlIds && column.controlIds.length > 0) {
          for (let i in column.controlIds) {
            //如果有任意一个没有数据，那么就不允许
            if (!row[column.controlIds[i]]) {
              flag = false
              break
            }
          }
        }
      }
      return flag
    },
    /**
     * @desc   : 设置是否只读
     * @author : 周兴
     * @date   : 2022/4/11 14:22
     */
    setSwitchCellDisabled(row, column) {
      // 只有用户设置了赠品才能进行赠送  组合中不能点（跟小程序一致）
      if (column.type == 'switch' && column.field == 'flgGift' && (!row.cpFlgGift || row.parentId)) {
        return true
      }
      // 只有用户设置了开启坑距是否可待定
      if (column.type == 'switch' && column.field == 'flgAllowSpecsUndefine' && !row.flgAllowSpecsUndefine) {
        return true
      }
      if (column.type === 'switch' && !column.childCanInput && row['parentId']) {
        return true
      }
      if (column.type === 'checkbox' && !column.childCanInput && row['parentId']) {
        return true
      }
      if(row.disabled){
        return true
      }
      return false
    },
    /**
     * @desc   : TODO
     * @author : 周兴
     * @date   : 2022/4/6 10:27
     */
    inputMouseDown(e) {
      // console.log('e')
      e.preventDefault()
    },
    blurInput(e) {
      // console.log('blur', e)
    },
    /**
     * @desc   : 失去焦点
     * @author : 周兴
     * @date   : 2022/5/27 15:23
     */
    handleBlur() {
      //失去焦点后，就清除激活状态
      this.$refs[this.name].clearActived()
    },
    /**
     * @desc   : 删除行时调用，删除子级
     * @author : 周兴
     * @date   : 2022/6/10 15:13
     */
    deleteChildren(rows) {
      if (Array.isArray(rows)) {
        rows.forEach(row => {
          // 根据id删除
          this.children = this.children.filter(it => it['parentId'] !== row['id'])
          this.tableDataChange = this.tableDataChange.filter(it => it['id'] !== row['id'])
        })
      } else {
        // 根据id删除
        this.children = this.children.filter(it => it['parentId'] !== rows['id'])
        this.tableDataChange = this.tableDataChange.filter(it => it['id'] !== rows['id'])
      }
    },
    /**
     * @desc   : 懒加载
     * @author : 周兴
     * @date   : 2022/5/26 11:43
     */
    loadChildrenMethod({row}) {
      return new Promise(resolve => {
        // 如果有combinedField 判断这列
        if (!row) {
          return
        }
        // let children = null
        // if (row.bomItems && row.bomItems.length > 0) {
        //   children = row.bomItems
        //   if (this.children.length == 0) {
        //     this.children = children
        //   } else {
        //     for (let i of row.bomItems) {
        //       let filters = this.children.filter(it => it.id == i.id)
        //       if (filters && filters.length > 0) {
        //         //重新赋值绑定条码
        //         for (let item of  row.bomItems) {
        //           for (let it of this.children) {
        //             if (it.id == item.id) {
        //               it.productUniqueCode = item.productUniqueCode
        //               break
        //             }
        //           }
        //         }
        //       }else{
        //         this.children.push(i)
        //       }
        //     }
        //   }
        // }
        let children = typeof this.children === 'function' ? this.children() : this.children
        //如果有值直接显示
        if (children && children.length > 0) {
          // 根据id进行过滤 增加 hasChild的判断，因为bom那条数据hasChild不是0
          let childs = this.children.filter(it => it.parentId === row.id && it.hasChild == 0)
          resolve(childs)
        }
      })
    },

    /**
     * @desc   : 获取子级数据
     * @author : 周兴
     * @date   : 2022/5/27 10:51
     */
    getChildData(row) {
      return new Promise(resolve => {
        if (!this.controlId || !row || !row[this.controlId]) {
          return
        }
        let param = {}
        param.cpId = this.$store.state.user.cpId
        param.orgId = this.orgId
        // 根据传入的数据进行检索
        param[this.controlId] = row[this.controlId]
        this.service[this.methodsName](param).then(res => {
          if (res.code === 200) {
            resolve(res.data)
          } else {
            this.$Message.warning(res.message)
          }
        })
      })
    },
    /**
     * @desc   : 控制跳转到下一个输入格
     * @author : 周兴
     * @date   : 2022/4/9 13:40
     */
    nextInputCellByKeyDown(e) {
      this.isScroll = true
      //如果点击回车需要进入下一个可输入单元格
      if (e.keyCode === 13) {
        //回车的时候阻止冒泡事件
        e.stopPropagation()
        //如果是点击过去的，就不用再走一次
        if (e.type === 'keyup') return
        //跳转到下一个可输入单元格
        this.nextInputCell(e.row, e.rowIndex, e.colIndex, e.column.field, e.column)
      }
    },
    /**
     * @desc   : 控制数值的输入
     * @author : 周兴
     * @date   : 2022/4/5 22:28
     */
    controlNumber(e) {
      //回车的时候阻止冒泡事件 上下箭事件
      if (e.keyCode === 13) {
        e.stopPropagation()
      }
      //控制跳转到下一个输入格
      this.nextInputCellByKeyDown(e)
      //backspace,delete,enter，左右不控制
      if (e.keyCode === 8 || e.keyCode === 46 || e.keyCode === 37
        || e.keyCode === 39 || e.keyCode === 13) {
        return
      }
      // 获取小数位数
      let digits = 0
      if (e.column.digits) {
        digits = e.column.digits
      } else {
        //如果没有设置小数位数，那么就读取商品中的计量单位
        if (e.row.decimalPlaces) {
          digits = e.row.decimalPlaces
        }
      }
      //ctrl+v,ctrl+c不控制
      if ((e.key === 'v' || e.key === 'c') && e.ctrlKey) {
        return
      }
      //查看是否有选中数据，再输入的情况
      let selectedLength = e.target.selectionEnd - e.target.selectionStart
      if (selectedLength > 0) {
        return
      }
      let num = e.target.value + '' + e.key
      //说明是插入到字符串中的
      if (e.target.selectionEnd < e.target.value.length) {
        num = this.$libaray.insertStr(e.target.value, e.target.selectionEnd, e.key)
      }
      //判断是否包括负数
      let negativeFlag = e.column.negative ? true : false
      if (!this.$libaray.getRegex(digits, negativeFlag).test(num)) {
        e.preventDefault()
      } else {
        //如果有最大值，需要判断不要超过最大值
        let max = e.column.max ? e.column.max : this.$config.maxNumber
        if (num >= parseFloat(max)) {
          e.preventDefault()
        }
      }
    },
    /**
     * @desc   : 控制数值的输入
     * @author : 周兴
     * @date   : 2022/4/5 22:28
     */
    handleKeyup(e) {
      // 获取小数位数
      let digits = 0
      if (e.column.digits) {
        digits = e.column.digits
      } else {
        //如果没有设置小数位数，那么就读取商品中的计量单位
        if (e.row.decimalPlaces) {
          digits = e.row.decimalPlaces
        }
      }
      //复制时调用改变事件
      if (e.key === 'v' && e.ctrlKey) {
        this.changeValueByCtrlV(e, digits)
      }
    },
    /**
     * @desc   : 值改变
     * @author : 周兴
     * @date   : 2022/4/10 14:21
     */
    changeValueByCtrlV(e, digits) {
      let value = e.target.value
      if (Number.isNaN(Number(value))) {
        e.target.value = null
        this.tableData[e.rowIndex][e.column.field] = null
      } else {
        //正则表达式去控制输入
        if (!this.$libaray.getRegex(digits).test(value)) {
          value = XEUtils.toFixed(XEUtils.round(value, digits), digits)
        }
        //判断是否超过最大值，如果超过最大值，就取最大值
        let max = e.column.max ? e.column.max : this.$config.maxNumber
        if (parseFloat(value) >= max) {
          //获取最大值
          let maxValue = this.$libaray.getMaxValue(max, digits)
          e.target.value = maxValue
          this.tableData[e.rowIndex][e.column.field] = maxValue
        } else {
          e.target.value = value
          this.tableData[e.rowIndex][e.column.field] = value
        }
      }
    },
    /**
     * @desc   : 格式化列
     * @author : 周兴
     * @date   : 2022/4/4 13:40
     */
    formatColumn({column, cellValue, row}) {
      //默认显示空值
      if (cellValue === undefined || !column.params) {
        return cellValue
      }
      let param = column.params
      // 只有数值类型，或者是diable类型中数值的需要进行处理
      if (param.type === 'number' || param.number) {
        //获取小数位数
        let digits = 0
        if (param.digits) {
          digits = param.digits
        } else {
          //如果没有设置小数位数，那么就读取商品中的计量单位
          if (row.decimalPlaces) {
            digits = row.decimalPlaces
          }
        }
        // 数值列开启千分位过滤 (默认开启千分位)
        if (param.formatThousandth == undefined || param.formatThousandth) {
          if (cellValue != null) {
            //开启千分位
            return XEUtils.commafy(Number(cellValue), {digits})
          }
        } else {
          if (cellValue != null) {
            //没有开启千分位
            return XEUtils.toFixed(XEUtils.round(cellValue, digits), digits)
          }
        }
      } else {
        // 如果不是数值，就直接返回
        return cellValue
      }
    }
    ,
    /**
     * @desc   : 合计行运算
     * @author : 周兴
     * @date   : 2022/3/31 11:28
     */
    footerMethod({data}) {
      //如果不开启合计行，那么就不走该方法
      if (!this.showFooter) return
      let total = this.$t('totalSum')
      const sums = []
      if (sums.indexOf(total) < 0) {
        sums.push(total)
      }
      let sumCell = null
      setTimeout(() => {
        for (let column of this.columns) {
          sumCell = null
          if ((column.type === vm.$config.columnType.number
            || column.number) && column.sum) {
            let digits = 0
            //小数位数
            if (column.digits) {
              digits = column.digits
            }
            data.forEach(item => {
              // 如果有子级，那么就统计子级的
              if (item.bomItems && item.bomItems.length > 0) {
                // 查看节点是否展开
                if (!this.$refs[this.name].isTreeExpandByRow(item)) {
                  item.bomItems.forEach(it => {
                    if (it.hasChild == 0) {
                      sumCell += Number(it[column.field] == undefined ? 0 : it[column.field])
                    }
                  })
                }
              } else {
                sumCell += Number(item[column.field] == undefined ? 0 : item[column.field])
              }
            })
            //格式化金额开启(默认开启)
            if (column.formatThousandth == undefined || column.formatThousandth) {
              sumCell = XEUtils.commafy(Number(sumCell), {digits})
            }
          }
          sums.push(sumCell)
        }
      }, 100)
      return [sums]
    }
    ,
    /**
     * @desc   : poper隐藏事件
     * @author : 沈博
     * @date   : 2022/3/13 10:10
     */
    popperHide() {
      this.inputDownValue = null
    },
    /**
     * @desc   : poper显示事件 TODO
     * @author : 周兴
     * @date   : 2022/4/11 11:37
     */
    popperShow(colIndex, type) {
      this.$nextTick(() => {
        if (!type) {
          this.$refs['pop_' + colIndex][0].$refs.input.focus()
        } else {
          this.$refs['pop_' + colIndex][0].$refs.inputNumber.focus()
        }
      })
    },
    /**
     * @desc   : 获取删除的数据
     * @author : 周兴
     * @date   : 2022/6/18 16:32
     */
    getDeleteData() {
      let table = [...this.deleteData]
      return table
    },
    /**
     * @desc   : 获取数据
     * @author : 周兴
     * @date   : 2022/4/10 11:38
     */
    getTableData() {
      let table = [...this.tableData]
      return table
    },
    /**
     * @desc   : 获取过滤掉主键数据没有选择的信息
     * @author : 周兴
     * @date   : 2022/4/10 11:39
     */
    getTableDataFilter() {
      let table = [...this.tableData]
      if (this.controlId) {
        // 如果没有组合，按照controlId
        if (!this.combinedField) {
          table = table.filter(it => it[this.controlId])
        } else {
          table = table.filter(it => it[this.controlId] || it[this.combinedField])
          // console.log('t3444',table,this.controlId,this.combinedField)
          // 加上子级数据
          if (table && table.length > 0 && this.children && this.children.length > 0) {
            table.forEach(row => {
              let filterChilds = this.children.filter(it => it['parentId'] === row['id'])
              row['bomItems'] = filterChilds
            })
          }
        }
      }
      return table
    },
    /**
     * @desc   : 获取改变的数据
     * @author : 周兴
     * @date   : 2022/4/10 11:38
     */
    getTableChangeData() {
      let table = [...this.tableDataChange]
      if (table && table.length > 0 && this.children && this.children.length > 0) {
        table.forEach(row => {
          let filterChilds = this.children.filter(it => it['parentId'] === row['id'])
          row['bomItems'] = filterChilds
        })
      }
      return table
    },
    /**
     * @desc   : 清空数据
     * @author : 周兴
     * @date   : 2022/4/21 17:24
     */
    clearTable() {
      this.children = []
      this.tableData = []
      this.tableDataChange = []
      // 新增一行
      this.add()
    },
    /**
     * @desc   : 清除掉变化数据
     * @author : 周兴
     * @date   : 2022/4/21 17:24
     */
    clearTableChangeData() {
      this.tableDataChange = []
    },
    /**
     * @desc   : 文本输入后执行的事件
     * @author : 周兴
     * @date   : 2022/4/6 13:52
     */
    editClosed(e) {
      this.$emit('editClosed', e, this.tableData)
    },
    /**
     * @desc   : 点击行执行事件
     * @author : 于继渤
     * @date   : 2022/4/21 13:43
     */
    currentChangeGetData(e) {
      e.oldRowIndex = this.currentRowIndex;
      this.$emit('current-change', e, this.tableData);
      this.currentRowIndex = e.rowIndex;
      // 给当前行增加hover
      this.addHover(this.currentRowIndex);
    },
    /**
     * @desc   : 根据field获取
     * @author : 周兴
     * @date   : 2022/6/16 8:44
     */
    getColumnByField(field) {
      for (let i = 0; i < this.columns.length; i++) {
        if (this.columns[i].field === field) {
          return this.columns[i]
        }
      }
    },
    /**
     * @desc   : 根据field获取
     * @author : 周兴
     * @date   : 2022/6/16 8:44
     */
    getColumnIndexByField(columns, field) {
      for (let i = 0; i < columns.length; i++) {
        if (columns[i].property === field) {
          return i
        }
      }
    },
    /**
     * @desc   : 跳转到下一个可输入单元格
     * @author : 周兴
     * @date   : 2022/4/7 15:36
     */
    nextInputCell(row, rowIndex, columnIndex, field, colItem) {
      //如果下拉选择数据没有选择，点回车光标不离开 用columnIndex去查不对，因为位置可能会移动，并且column的列也可能跟列表的顺序不一致
      let filterColumn = this.getColumnByField(field)
      if (filterColumn && filterColumn.controlId && row[field] === null) {
        this.$refs[this.name].setActiveCell(this.tableData[rowIndex], field)
        this.handleFocus(filterColumn, rowIndex)
        return
      }
      let visibleColumns = this.$refs[this.name].getTableColumn().visibleColumn
      this.isScroll = true
      let currentColumnIndex = columnIndex
      //如果是最后一列那么跳转到下一行
      if (field === visibleColumns[visibleColumns.length - 1].property) {
        rowIndex = parseInt(rowIndex) + 1
        columnIndex = 0
      } else {
        // 根据field后去列的顺序
        columnIndex = this.getColumnIndexByField(visibleColumns, field) + 1
      }
      //设置单元格激活状态
      for (let i = rowIndex; i < this.tableData.length; i++) {
        for (let j = columnIndex; j < visibleColumns.length; j++) {
          filterColumn = this.getColumnByField(visibleColumns[j].property)
          //列只读以及行单元格只读
          if (filterColumn && filterColumn.type !== 'disabled' && filterColumn.type !== 'switch') {
            // 不能从同一个controlId的列跳转到下一列
            if (filterColumn.controlId && colItem.controlId
              && filterColumn.controlId === colItem.controlId) {
              continue
            } else {
              this.$refs[this.name].setActiveRow(this.tableData[i])
              this.$refs[this.name].setCurrentRow(this.tableData[i])
              this.$refs[this.name].setActiveCell(this.tableData[i], visibleColumns[j].property)
              // 焦点落在各控件上
              this.handleFocus(filterColumn, i)
            }
            // 如果是第一列，需要设置滚动，不然不会回到第一个列的位置
            if (j === 0) {
              this.$refs[this.name].scrollTo(0, 0)
            }
            // 延迟更新不然就会让 滚动先执行
            setTimeout(() => {
              this.isScroll = false
            }, 500)
            return
          }
        }
      }
      this.isScroll = false
    },
    /**
     * @desc   : 单元格编辑结束后，光标停留在对应的位置
     * @author : 周兴
     * @date   : 2022/4/10 14:02
     */
    handleFocus(column, rowIndex) {
      setTimeout(() => {
        if (column.type) {
          switch (column.type) {
            case 'date':
              this.$refs[column.field + rowIndex][0].focus()
              this.$refs[column.field + rowIndex][0].$refs['input'].focus()
              break
            case 'switch':
              this.$refs[column.field + rowIndex][0].$el.focus()
              break
            // case 'select':
            //   console.log('res',column.field + rowIndex)
            //   // this.$refs[column.field + rowIndex][0].focus()
            //   this.$refs[column.field + rowIndex][0].isActivated = true
            //   this.$refs[column.field + rowIndex][0].$refs.input.focus()
            //   break;
            case 'tableSelect':
            case 'select':
              if (this.$refs[column.field + rowIndex] && this.$refs[column.field + rowIndex].length > 0) {
                this.$refs[column.field + rowIndex][0].$refs['input'].$el.click()
                this.$refs[column.field + rowIndex][0].$refs['input'].focus()
                this.$refs[column.field + rowIndex][0].$refs['table'].focus()
              }
              break
          }
        }
      }, 200)
    },
    /**
     * @desc   : 计算
     * @author : 周兴
     * @date   : 2022/4/6 13:59
     */
    calc(field, rowIndex, formulaLateFlag, isNoCalcChildFlag) {
      //获取当前列的名
      let currentColumn = this.columns.filter(col => col.field === field)
      if (!currentColumn) return
      let row = this.tableData[rowIndex]
      // 根据公式进行计算
      this.calcItemPublic(field, rowIndex, formulaLateFlag, currentColumn[0], row)
      if (!isNoCalcChildFlag) {
        // 给子级分配
        this.shareToChildrenData(row, currentColumn[0]).then(res => {
          // 更新合计行
          this.$refs[this.name].updateFooter()
        })
      }
    },
    /**
     * @desc   : 计算
     * @author : 周兴
     * @date   : 2022/6/28 16:54
     */
    calcItemPublic(field, rowIndex, formulaLateFlag, currentColumn, row, pRow, lastFlag, firstFlag) {
      if (!currentColumn) return
      let formula = currentColumn.formula
      //如果没有公式就推出
      if (!formula || !Object.keys(formula)) {
        return
      }
      let keys = Object.keys(formula)
      for (let i in keys) {
        if (formulaLateFlag && currentColumn.formulaLate) {
          continue
        }
        // 按照公式进行计算
        this.calcItem(formula, keys[i], row, field, pRow, lastFlag, firstFlag, rowIndex)
      }
    },
    /**
     * @desc   : 计算明细
     * @author : 周兴
     * @date   : 2022/6/16 10:34
     */
    calcItem(formula, key, row, field, pRow, lastFlag, firstFlag, rowIndex) {
      //获取需要计算的列
      let countColumn = this.columns.filter(col => col.field === key)
      if (!countColumn) return
      let values = formula[key]
      if (values && values.length > 0) {
        let formu = values[0]
        for (let i = 1; i < values.length; i++) {
          if (row[values[i]]) {
            formu = formu.replace(values[i], row[values[i]])
          } else {
            // 如果不是非标，面积要进行替换为1
            if (values[i] == 'nonStandardArea') {
              formu = formu.replace('nonStandardArea', 1)
            } else {
              formu = formu.replace(values[i], 0)
            }
            // formu = formu.replace(values[i], 0);
          }
        }
        try {
          // 获取小数位数
          let digits = 0
          if (countColumn[0].digits) {
            digits = countColumn[0].digits
          }
          //用eval进行计算
          let tValue = eval(formu)
          //说明除数为0，那么金额清空
          if ('Infinity' == tValue || '-Infinity' == tValue || isNaN(tValue)) {
            // row[field] = null;
            this.$set(row, key, 0)
          } else {
            // 如果是需要计算最后一行，需要进行减的，可以进行
            if (countColumn[0].supply && pRow) {
              let tempAmount = 0
              if (firstFlag) {
                this.$set(pRow, countColumn[0].field + '_temp', 0)
              }
              // 说明是最后一行
              if (lastFlag) {
                let lastValue = parseFloat(pRow[countColumn[0].field]) - parseFloat(pRow[countColumn[0].field + '_temp'])
                this.$set(row, key, XEUtils.toFixed(XEUtils.round(lastValue, digits), digits))
                // 由于金额重算需要重新计算价格
                this.calcItemPublic(countColumn[0].field, rowIndex, false, countColumn[0], row)
              } else {
                if (!pRow[countColumn[0].field + '_temp']) {
                  tempAmount = parseFloat(XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
                } else {
                  tempAmount = parseFloat(pRow[countColumn[0].field + '_temp']) + parseFloat(XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
                }
                // 记录临时数据，用于计算最后一行
                this.$set(pRow, countColumn[0].field + '_temp', tempAmount)
                this.$set(row, key, XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
              }
            } else {
              //对计算出来的数据进行处理
              this.$set(row, key, XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
            }
          }
        } catch (err) {
          this.$set(row, key, 0)
          // row[key] = 0
        }
      }
    },
    /**
     * @desc   : 分摊到子级
     * @author : 周兴
     * @date   : 2022/5/26 17:06
     */
    shareToChildrenData(row, col, digits) {
      return new Promise(resolve => {
        //开启分摊再进行分摊到子级
        if (col && this.children) {
          if (!digits) {
            digits = col.digits ? col.digits : 0
          }
          //获取当前列的名
          let currentColumn = this.columns.filter(c => c.field === col.field)
          let amount = 0
          let children = this.children.filter(it => it['parentId'] === row['id'] && it['hasChild'] == 0)
          children.forEach((it, index) => {
            // 如果按照表中有的列，比如数量
            if (col.shareField && it[col.shareField] && col.shareField != 'percent' && col.shareField != 'amount') {
              this.$set(it, col.field, XEUtils.toFixed(XEUtils.round(it[col.shareField] * row[col.field], digits), digits))
              // it[col.field] = XEUtils.toFixed(XEUtils.round(it[col.shareField] * row[col.field], digits), digits);
            }
            // 需要赋值给_X_ID,不然就会子级就报重复主键
            it['_X_ID'] = it.id
            // 如果子级跟父级一样，那么就会按照父级更新
            if (col.equal) {
              this.$set(it, col.field, row[col.field])
            }
            // setTimeout(() => {
            // 根据金额进行计算
            if (col.shareField) {
              // 如果这个属性为true,最后一行为剩余数
              if (!col.supply || col.supply && index < children.length - 1) {
                // 根据比率进行计算
                this.calcPercent(col, row, it, digits)
                // 根据金额进行计算
                this.calcAmount(col, row, it, digits)
                amount = amount + parseFloat(it[col.field])
              } else {
                // 最后一行为减法
                // it[col.field] = XEUtils.toFixed(XEUtils.round(row[col.field] - amount, digits), digits);
                this.$set(it, col.field, XEUtils.toFixed(XEUtils.round(row[col.field] - amount, digits), digits))
              }
            }
            setTimeout(() => {
              // 在对子级进行公式的计算
              this.calcItemPublic(col.field, index, false, currentColumn[0], it, row,
                index == children.length - 1 ? true : false, index == 0 ? true : false)
            }, 300)
            // }, 300)
          })
          this.$set(row, 'children', children)
          // row.children = children;
        }
        resolve()
      })
    },
    /**
     * @desc   : 分摊到子级
     * @author : 周兴
     * @date   : 2022/5/26 17:06
     */
    shareFromParentData(row, child) {
      // console.log('rowds', row, child)
      //展开子级，从父级分摊
      if (row && child) {
        let amount = 0
        child.forEach((it, index) => {
          // it.parentId = row['id']
          this.columns.forEach(col => {
            let digits = col.digits ? col.digits : 0
            //如果开启分摊
            if (col.shareField && row[col.field]) {
              // 根据列相乘，比如像数量
              if (it[col.shareField]) {
                it[col.field] = XEUtils.toFixed(XEUtils.round(it[col.shareField] * row[col.field], digits), digits)
              }
              //根据比率进行计算
              this.calcPercent(col, row, it, digits)

              // 根据金额进行计算
              if (col.shareField && col.shareField === 'amount' && col.amount) {
                // 如果这个属性为true,最后一行为剩余数
                if (!col.supply || col.supply && index < child.length - 1) {
                  this.calcAmount(col, row, it, digits)
                  amount = amount + parseFloat(it[col.field])
                } else {
                  // 最后一行为减法
                  // it[col.field] = XEUtils.toFixed(XEUtils.round(row[col.field] - amount, digits), digits);
                  this.$set(it, col.field, XEUtils.toFixed(XEUtils.round(row[col.field] - amount, digits), digits))
                }
              }
            }
          })
        })
      }
      return child
    },
    /**
     * @desc   : 根据子级计算父级数据之后
     * @author : 周兴
     * @date   : 2022/6/6 16:49
     */
    calcSumTotal(col, pRow, child, digits) {
      let sumTotal = col.sumTotal
      if (sumTotal && sumTotal.length > 0) {
        let total = 0
        let formu = ''
        child.forEach(it => {
          formu = sumTotal[0]
          for (let i = 1; i < sumTotal.length; i++) {
            // 说明是子级的
            if (sumTotal[i].includes('child')) {
              let childField = sumTotal[i].replace('[child]', '')
              if (it[childField]) {
                formu = formu.replace(sumTotal[i], it[childField])
              } else {
                formu = formu.replace(sumTotal[i], 0)
              }
            }
          }
          try {
            //用eval进行计算
            let tValue = eval(formu)
            //说明除数为0，那么金额清空
            if ('Infinity' != tValue) {
              //对计算出来的数据进行处理
              total = total + tValue
            }
          } catch (err) {
          }
        })
        // 给父级赋值
        // pRow[col.field] = XEUtils.toFixed(XEUtils.round(total, digits), digits);
        this.$set(pRow, col.field, XEUtils.toFixed(XEUtils.round(total, digits), digits))
      }
    },
    /**
     * @desc   : 计算比率
     * @author : 周兴
     * @date   : 2022/6/2 14:08
     */
    calcPercent(col, pRow, cRow, digits) {
      if (col.shareField && col.shareField === 'percent' && col.percent) {
        let percent = col.percent
        if (percent && percent.length > 0) {
          let formu = percent[0]
          for (let i = 1; i < percent.length; i++) {
            // 说明是子级的
            if (percent[i].includes('child')) {
              let childField = percent[i].replace('[child]', '')
              if (cRow[childField]) {
                formu = formu.replace(percent[i], cRow[childField])
              } else {
                formu = formu.replace(percent[i], 0)
              }
            } else {
              // 说明是父级列的
              if (pRow[percent[i]]) {
                formu = formu.replace(percent[i], pRow[percent[i]])
              } else {
                formu = formu.replace(percent[i], 0)
              }
            }
          }
          try {
            //用eval进行计算
            let tValue = eval(formu)
            //说明除数为0，那么金额清空
            if ('Infinity' == tValue) {
              // cRow[col.field] = null;
              this.$set(cRow, col.field, null)
            } else {
              //对计算出来的数据进行处理
              this.$set(cRow, col.field, XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
              // cRow[col.field] = XEUtils.toFixed(XEUtils.round(tValue, digits), digits);
            }

          } catch (err) {
            // cRow[col.field] = 0;
            this.$set(cRow, col.field, 0)
          }
        }
      }
    },
    /**
     * @desc   : 计算金额列
     * @author : 周兴
     * @date   : 2022/6/2 15:08
     */
    calcAmount(col, pRow, cRow, digits) {
      if (col.shareField && col.shareField === 'amount' && col.amount) {
        let amount = col.amount
        if (amount && amount.length > 0) {
          let formu = amount[0]
          for (let i = 1; i < amount.length; i++) {
            // 说明是子级的
            if (amount[i].includes('child')) {
              let childField = amount[i].replace('[child]', '')
              // console.log('ddd', formu, cRow[childField], childField, cRow)
              if (cRow[childField]) {
                formu = formu.replace(amount[i], cRow[childField])
              } else {
                formu = formu.replace(amount[i], 0)
              }
            } else {
              // 说明是父级列的
              if (pRow[amount[i]]) {
                formu = formu.replace(amount[i], pRow[amount[i]])
              } else {
                formu = formu.replace(amount[i], 0)
              }
            }
          }
          try {
            //用eval进行计算
            let tValue = eval(formu)
            //说明除数为0，那么金额清空
            if ('Infinity' == tValue) {
              this.$set(cRow, col.field, null)
              // cRow[col.field] = null;
            } else {
              //对计算出来的数据进行处理
              // cRow[col.field] = XEUtils.toFixed(XEUtils.round(tValue, digits), digits);
              this.$set(cRow, col.field, XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
            }
          } catch (err) {
            this.$set(cRow, col.field, 0)
            // cRow[col.field] = 0;
          }
        }
      }
    },
    /**
     * @desc   : 表格向下{{ $t('filling') }}
     * @author : 沈博
     * @date   : 2022/3/13 9:56
     */
    inputDown(column) {
      let field = column.field
      //获取当前列的名
      let currentColumn = this.columns.filter(col => col.field === field)
      if (!currentColumn) return
      // console.log('d', currentColumn, column.type)
      // 数值
      if (column.type === 'number') {
        let formula = currentColumn[0].formula
        //如果没有公式就推出
        if (formula && Object.keys(formula)) {
          let key = Object.keys(formula)[0]
          //获取需要计算的列
          let countColumn = this.columns.filter(col => col.field === key)
          if (countColumn) {
            let values = formula[key]
            if (values && values.length > 0) {
              let formu = values[0]
              //给你当前单元格赋值
              this.tableData.forEach(it => {
                // 如果有controlId，那么只能赋值有值的行
                if (this.controlId && it[this.controlId]) {
                  formu = values[0]
                  for (let i = 1; i < values.length; i++) {
                    if (it[values[i]]) {
                      formu = formu.replace(values[i], it[values[i]])
                    } else {
                      formu = formu.replace(values[i], 0)
                    }
                  }
                  try {
                    // 获取小数位数
                    let digits = 0
                    if (countColumn[0].digits) {
                      digits = countColumn[0].digits
                    } else {
                      //如果没有设置小数位数，那么就读取商品中的计量单位
                      if (it.decimalPlaces) {
                        digits = it.decimalPlaces
                      }
                    }
                    //用eval进行计算
                    let tValue = eval(formu)
                    //说明除数为0，那么金额清空
                    if ('Infinity' == tValue) {
                      this.$set(it, field, null)
                    } else {
                      //对计算出来的数据进行处理
                      this.$set(it, key, XEUtils.toFixed(XEUtils.round(tValue, digits), digits))
                    }
                  } catch (err) {
                    this.$set(it, key, 0)
                  }
                }
              })
            }
          }
        } else {
          //给你当前单元格赋值
          // 获取小数位数
          let digits = 0
          if (currentColumn[0].digits) {
            digits = currentColumn[0].digits
          }
          this.tableData.forEach(it => {
            // 如果有controlId，那么只能赋值有值的行
            if ((this.controlId && it[this.controlId]) || !this.controlId) {
              //如果没有设置小数位数，那么就读取商品中的计量单位
              if (digits === 0) {
                digits = it.decimalPlaces
              }
              this.$set(it, field, XEUtils.toFixed(XEUtils.round(this.inputDownValue, digits), digits))
            }
          })
        }
      } else if (column.type === 'text') {
        //文本
        this.tableData.forEach(it => {
          // 如果有controlId，那么只能赋值有值的行
          if ((this.controlId && it[this.controlId]) || !this.controlId) {
            this.$set(it, field, this.inputDownValue)
          }
        })
      } else if (column.type === 'switch') {
        this.tableData.forEach(it => {
          // 如果有controlId，那么只能赋值有值的行
          if ((this.controlId && it[this.controlId]) || !this.controlId) {
            this.$set(it, field, this.inputDownBooleanValue)
          }
        })
      }
      this.$refs['down-input-icon'][0].$el.click()
    }
    ,
    /**
     * @desc   : 新增一行
     * @author : 周兴
     * @date   : 2022/4/7 14:36
     */
    add(rowIndex, currentRowFlag) {
      // console.log('rowi', rowIndex)
      let obj = {}
      this.columns.forEach(it => {
        //开关时，默认是true,如果要是false需要在列中给其传值
        if (it.type === 'switch') {
          this.$set(obj, it.field, it.value === undefined || it.value === null ? true : it.value)
        } else {
          // 如果是显示顺序需要自增
          if (it.field === 'displayNo') {
            let arr = this.tableData.map(m => m[it.field])
            let cMax = Math.max.apply(null, arr)
            if (cMax && cMax != '-Infinity') {
              this.$set(obj, it.field, cMax + 1)
            } else {
              this.$set(obj, it.field, 1)
            }
          } else {
            //读取列的默认值，如果有设置，那么需要设置上
            if (it.value && it.value != null) {
              this.$set(obj, it.field, it.value)
            } else {
              this.$set(obj, it.field, null)
            }
          }
        }
      })
      // 给id和parentId赋值
      this.$set(obj, 'id', 10000 + (rowIndex == undefined ? 0 : rowIndex + 1))
      this.$set(obj, 'parentId', null)
      //说明是手动新增的
      let curorRowIndex = 0
      if (rowIndex || rowIndex === 0) {
        //如果是组合，那么就按照parentId一致来，不能插入到中间
        if (this.combinedField && this.tableData[rowIndex] && this.tableData[rowIndex][this.combinedField + '-parentId']) {
          let parentId = this.tableData[rowIndex][this.combinedField + '-parentId']
          let span = 0
          for (let i = rowIndex + 1; i < this.tableData.length; i++) {
            if (parentId !== this.tableData[i][this.combinedField + '-parentId']) {
              break
            } else {
              span = span + 1
            }
          }
          rowIndex = rowIndex + span
          //在当前行增加
          if (currentRowFlag) {
            this.tableData.splice(rowIndex, 0, obj)
            curorRowIndex = rowIndex
          } else {
            this.tableData.splice(rowIndex + 1, 0, obj)
            curorRowIndex = rowIndex + 1
          }
        } else {
          //在当前行增加
          if (currentRowFlag) {
            this.tableData.splice(rowIndex, 0, obj)
            curorRowIndex = rowIndex
          } else {
            this.tableData.splice(rowIndex + 1, 0, obj)
            curorRowIndex = rowIndex + 1
          }
        }
      } else {
        this.tableData.push(obj)
        curorRowIndex = 0
      }
      //设置光标位置
      if (this.focusFlag) {
        this.$nextTick(() => {
          for (let j in this.columns) {
            if (this.columns[j].type !== 'disabled' && this.columns[j].type !== 'switch' &&
              (!this.tableData[curorRowIndex].readOnly || this.tableData[curorRowIndex].readOnly.indexOf(this.columns[j].field) < 0)) {
              this.$refs[this.name].setActiveCell(this.tableData[curorRowIndex], this.columns[j].field)
              this.handleFocus(this.columns[j], curorRowIndex)
              break
            }
          }
        })
      }
    },
    /**
     * @desc   : 删除一行
     * @author : 周兴
     * @date   : 2022/4/11 9:13
     */
    del(rowIndex) {
      let row = {...this.tableData[rowIndex]}
      // 记录删除的数据
      if (this.majorField && row[this.majorField]) {
        this.deleteData.push(row)
      }
      this.tableData = [...this.tableData.filter((it, index) => {
        return index !== rowIndex
      })]
      //删除变化数据表
      this.tableDataChange = this.tableDataChange.filter(it => it.id !== row.id)
      //删除子级
      this.deleteChildren([row])
      //如果删完了，那么就要新增新行
      if (!this.tableData || this.tableData.length === 0) {
        this.add(0)
      }
      this.$refs[this.name].reloadData(this.tableData)
      this.$emit('delRow', row)
      this.$emit('changeValue', {field: null, row, rowIndex})
    },
    /**
     * @desc   : TableSelect输入框离开焦点事件
     * @author : 周兴
     * @date   : 2022/5/26 16:40
     */
    handleSelectInputBlur(e, row, rowIndex, colItem, colIndex) {
      // 把值恢复回去
      if (this.$refs[colItem.field + rowIndex] && row[colItem.field]) {
        this.$refs[colItem.field + rowIndex][0].$refs.input.$refs.input.value = row[colItem.field]
      }
    },
    /**
     * @desc   : desc
     * @author : 周兴
     * @date   : 2022/4/10 14:22
     */
    inputChange(row, rowIndex, colItem) {
      // 更新需要更新的列
      this.columns.forEach((it, index) => {
        //如果这里是controlId
        if (this.controlId) {
          if (colItem.type === 'tableSelect') {
            if (colItem.controlId && it.field == colItem.field && this.controlId === colItem.controlId) {
              this.tableData[rowIndex][it.field] = null
            }
          }
        } else {
          //说明这列受管控
          if (it.controlIds && it.controlIds.length > 0 && it.controlIds.includes(colItem.field)) {
            this.tableData[rowIndex][it.field] = null
            if (this.tableData[rowIndex][it.field + '_Name']) {
              this.tableData[rowIndex][it.field + '_Name'] = null
            }
          }
        }
      })
      this.$emit('changeValue', {field: colItem.field, row, rowIndex})
    },
    /**
     * @desc   : 批量选择数据
     * @author : 周兴
     * @date   : 2022/5/26 16:54
     */
    onBatchChoose(e, column, rowIndex, colIndex, fieldUpdate, colItem) {
      let {batchRows, batchKeys, children} = e
      // 把子级赋值给全局
      if (children && children.length > 0) {
        children.forEach(it => {
          let filterRows = this.children.filter(row => row.id == it.id)
          if (!filterRows || filterRows.length == 0) {
            if (it.bomItems && it.bomItems.length > 0) {
              it.hasChild = 1
            }
            this.children.push(it)
          }
        })
        // 处理子级
        this.setNowChildrenData()
      }
      if (batchRows && batchRows.length > 0) {
        let deleteCurrentFlag = false
        let index = 0
        let filterCombinedData = []
        let filterCombinedKeys = []
        let child = []
        // 如果是商品，需要判断类型是否是组合促销
        if (colItem.dataType === this.$config.tableSelectType.goods && this.combinedField) {
          batchRows.forEach(it => {
            if (it.promotionType === this.$config.promotionType.combined && this.combinedField) {
              let rows = children.filter(c => c['parentId'] === it['id'])
              if (!rows || rows.length === 0) {
                // 把没有子级的传进去，如果有的话，就不用查后台了
                filterCombinedData.push(it)
                filterCombinedKeys.push(it[this.combinedField])
              }
            }
          })
        }
        // 获取根据商品获取价格
        this.getCombinedPriceByKeys(filterCombinedKeys, colItem, filterCombinedData).then(res => {
          //如果返回的数据有值，就替换
          if (res && res.length > 0) {
            // 先删除原数据中组合的数据
            res.forEach(it => {
              //删除子级
              this.deleteChildren(batchRows.filter(row => row[this.combinedField] === it[this.combinedField]))
              //过滤数据
              batchRows = batchRows.filter((row, index) => row[this.combinedField] !== it[this.combinedField])
              batchRows.splice(index, 0, it)
            })
          }
          for (let i = 0; i < batchRows.length; i++) {
            // 对子级的处理(组合才会处理），其他都在选择界面查出来了 要判断controlId为空，因为有可能会有bom会有单品促销
            if (this.combinedField && batchRows[i][this.combinedField] && !batchRows[i][this.controlId]) {
              let newChildren = []
              let bomItems = batchRows[i]['bomItems']
              if (bomItems && bomItems.length > 0) {
                // 如果有bomItems说明有子级
                batchRows[i]['hasChild'] = 1
                bomItems.forEach(child => {
                  child.parentId = batchRows[i]['id']
                  newChildren.push(child)
                })
              }
              //如果子级有children直接升级，并且把当前数据删除掉，直接显示子级
              this.setChildrenData(batchRows[i], newChildren)
            }
            // 只有控制主键的列才会这么操作
            if (colItem.controlId) {
              // 判断是否重复
              let isRepeat = this.checkRepeat(batchRows[i], batchRows[i], rowIndex, colItem, false)
              // 如果重复就不进行后续
              if (isRepeat) {
                //只要重复就不允许删除当前行了
                deleteCurrentFlag = true
                index = index + 1
                continue
              }
              // 如果第一行是新行，那么就要把deleteCurrentFlag设置为true,不然第二行就要删除掉之前的数据
              if (i === 0 && this.controlId && !this.tableData[rowIndex][this.controlId]) {
                deleteCurrentFlag = true
              }
              //如果当前行有值，先删除当前行 (当前行只能删除一次)
              if (!deleteCurrentFlag && this.controlId && this.tableData[rowIndex][this.controlId]) {
                //删除子级
                this.deleteChildren(this.tableData[rowIndex])
                //需要删除的数据
                if (this.majorField && this.tableData[rowIndex][this.majorField]) {
                  this.deleteData.push(this.tableData[rowIndex])
                }
                //过滤掉当前行数据
                this.tableData = [...this.tableData.filter((it, index) => {
                  return index !== rowIndex
                })]
                deleteCurrentFlag = true
              }
              this.add(rowIndex + index, true)
              // 设置需要更新的数据
              this.setTableData(batchRows[i], batchRows[i], rowIndex + index, colItem, fieldUpdate)
              // 计算公式
              this.calcColumns(rowIndex + index)
              index = index + 1
            }
          }

          // 跳转到第一行的可输入单元格
          this.nextInputCell(batchRows[0], rowIndex, colIndex, colItem.field, colItem)
        })
      }
      // 设置赠品标识
      this.setFlgGift().then(res => {
        //选择数据之后公布事件
        this.$emit('on-choose', batchRows)
      })
      // 给子级下拉赋值
      this.setChildrenSelect()
    },
    /**
     * @desc   : 设置赠品标识
     * @author : 周兴
     * @date   : 2022/9/14 17:53
     */
    setFlgGift() {
      return new Promise(resolve => {
        setTimeout(() => {
          resolve()
        }, 600)
      })
    },
    /**
     * @desc   : 点击表头的checkbox全选/全不选
     * @author : 周兴
     * @date   : 2023/5/9 13:30
     */
    clickAllCheckbox(colItem) {
      if (this.tableData && this.tableData.length > 0) {
        this.tableData.forEach(it => {
          it[colItem.field] = colItem.chooseAllFlag
          // 子级
          if (it.children && it.children.length > 0) {
            it.children.forEach(cIt => {
              cIt[colItem.field] = colItem.chooseAllFlag
            })
          }
          // 所有子级
          if(this.children && this.children.length > 0){
            this.children.forEach(cIt => {
              cIt[colItem.field] = colItem.chooseAllFlag
            })
          }
        })
      }
    },
    /**
     * @desc   : 处理已经存在children中字段，把子级升级
     * @author : 周兴
     * @date   : 2022/7/25 11:00
     */
    setNowChildrenData() {
      if (this.children && this.children.length > 0) {
        let bomItems = []
        for (let i in this.children) {
          //组合的替换不在这里，在选择界面
          if (this.combinedField && this.children[i][this.combinedField]) {
            this.children[i][this.exchangeField] = null
          }
          if (this.children[i]['bomItems'] && this.children[i]['bomItems'].length > 0) {
            this.children[i]['bomItems'].forEach(item => {
              item['cIndex'] = i
              item['parentId'] = this.children[i]['parentId']
              bomItems.push(item)
            })
          }
        }
        if (bomItems && bomItems.length > 0) {
          for (let i in bomItems) {
            this.children.splice(bomItems[i]['cIndex'] + i, 0, bomItems[i])
          }
          //删除掉组合中的bom 不删除 只是不显示
          // this.children = this.children.filter(it => it['hasChild'] === 0 )
        }
      }
    },
    /**
     * @desc   : 处理子级的数据，把子级的子级升级，并且把子级去掉
     * @author : 周兴
     * @date   : 2022/6/9 11:49
     */
    setChildrenData(row, children) {
      let bomItems = []
      // 只有组合的这种情况要考虑这么处理
      // if (this.combinedField && row[this.combinedField]) {
      // 先把子级的bomItems记录下来
      for (let i in children) {
        //组合的替换不在这里，在选择界面
        if (this.combinedField && children[i][this.combinedField]) {
          children[i][this.exchangeField] = null
        }
        if (row['id'] === children[i]['parentId']
          && children[i]['bomItems'] && children[i]['bomItems'].length > 0) {
          children[i]['bomItems'].forEach(item => {
            item['cIndex'] = i
            item['parentId'] = row['id']
            //组合时只用 TODO 业务变更，暂时留着
            if (row[this.combinedField]) {
              item[this.combinedField + '-parentId'] = row['id']
            }
            bomItems.push(item)
          })
        }
      }
      //插入到children中
      if (bomItems && bomItems.length > 0) {
        for (let i in bomItems) {
          children.splice(bomItems[i]['cIndex'] + i, 0, bomItems[i])
        }
        //删除掉组合中的bom 保留BOM那条数据，只是不显示出来
        // children = children.filter(it => it['hasChild'] === 0 )
      }
      children.forEach(it => {
        let filterRows = this.children.filter(row => row.id == it.id)
        if (!filterRows || filterRows.length == 0) {
          this.children.push(it)
        }
      })
      // }
      //计算子级
      this.shareToParentData(row).then(res => {
        // 再根据父级计算子级其他数据
        this.shareFromParentData(row, this.children)
      })
    },
    /**
     * @desc   : 设置子级下拉数据
     * @author : 周兴
     * @date   : 2022/9/21 9:09
     */
    setChildrenSelect() {
      setTimeout(() => {
        let colItems = this.columnsData.filter(it => it.defaultName)
        if (colItems && colItems.length > 0 && this.children && this.children.length > 0) {
          let keyArr = colItems.map(it => it.valueKey).union(colItems.map(it => it[it.valueKey + '_Name']))
          let valueArr = colItems.map(it => it.defaultValue).union(colItems.map(it => it.defaultName))
          this.children.fillArray(keyArr, valueArr)
        }
      }, 300)
    },
    /**
     * @desc   : 获取组合促销的价格和明细
     * @author : 周兴
     * @date   : 2022/5/31 15:55
     */
    getCombinedPriceByKeys(keys, colItem, batchRows) {
      return new Promise(resolve => {
        // 如果不查数据库，直接放会
        if (!keys || keys.length === 0) {
          resolve()
        }
        if (colItem.dataType === this.$config.tableSelectType.goods) {
          // 判断是否有子级，如果有子级就用选择页面的，如果没有再查
          let batchKeys = [...keys]
          batchRows.forEach(row => {
            if (row.children && row.children.length > 0) {
              batchKeys.splice(row[this.controlId], 1)
            }
          })
          // 如果有batchKeys才会到数据库中检索
          if (batchKeys && batchKeys.length > 0 && this.combinedField) {
            let param = {}
            param.cpId = this.$store.state.user.cpId
            param.orgId = this.orgId
            param[this.combinedField] = batchKeys
            param['searchType'] = 2  // 非查询
            this.excute(this.service, this.service[this.methodsName], param).then(res => {
              if (res.code === 200) {
                let data = res.data.list
                //需要把父级的id更新到子级的parentId上
                if (data && this.combinedField) {
                  batchRows.forEach(it => {
                    // 不用combinedField ，怕有多条组合促销的情况
                    let filterRows = data.filter(row => row[this.combinedField] === it[this.combinedField])
                    it['bomItems'] = filterRows
                  })
                }
                //设置子级数据
                resolve(batchRows)
              } else {
                this.$Message.warning(res.message)
              }
            })
          } else {
            resolve(batchRows)
          }
        }
      })
    }
    ,
    /**
     * @desc   : 增加新行（【批量选择数据后增加】）
     * @author : 周兴
     * @date   : 2022/5/27 9:13
     */
    addNewRow(rowIndex) {
      if (!this.tableData[rowIndex]) {
        this.add(rowIndex)
      } else {
        // 如果多行增加时，这行有值，需要增加
        if (this.controlId && this.tableData[rowIndex][this.controlId]) {
          this.add(rowIndex)
        } else {
          if (this.combinedField && this.tableData[rowIndex][this.combinedField]) {
            this.add(rowIndex)
          }
        }
      }
    }
    ,
    /**
     * @desc   : 判断是否重复
     * @author : 周兴
     * @date   : 2022/5/27 8:46
     */
    checkRepeat(eRow, row, rowIndex, colItem, showMessage) {
      //如果需要进行唯一性判断
      if (this.enabledRepeat && this.enabledRepeatId) {
        //不是数组
        if (!Array.isArray(this.enabledRepeatId)) {
          //判断是否有重复的数据
          let tmpRows = this.tableData.filter(it => it[this.enabledRepeatId] == eRow[this.enabledRepeatId])
          if (tmpRows && tmpRows.length > 0) {
            //判断是否是同一行的
            if (row['id'] != tmpRows[0]['id']) {
              //提示信息重复
              if (showMessage) {
                this.$Message.warning(vm.$t('W_018'))
              }
              return true
            }
          }
        } else {
          let data = [...this.tableData]
          let currentRow = data[rowIndex]
          for (let col in this.enabledRepeatId) {
            data = this.filterData(data, eRow, this.enabledRepeatId[col], currentRow, colItem)
            // 说明没有重复
            if (!data || data.length === 0) {
              break
            }
          }
          if (data && data.length > 0) {
            //提示信息重复
            if (showMessage) {
              this.$Message.warning(vm.$t('W_018'))
            }
            return true
          }
        }
      }
      return false
    }
    ,
    /**
     * @desc   : 选择数据（私有方法）
     * @author : 周兴
     * @date   : 2022/5/26 16:39
     */
    chooseData(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem, showMessage) {
      return new Promise(resolve => {
        let eRow = e == null ? row : e
        let deleteCurrentFlag = false
        let index = 0
        let filterCombinedData = []
        let filterCombinedKeys = []
        let child = []
        let batchRows = []
        // 如果是商品，需要判断类型是否是组合促销
        if (colItem.dataType === this.$config.tableSelectType.goods && this.combinedField) {
          // 组合
          if (eRow.promotionType === this.$config.promotionType.combined) {
            // 把没有子级的传进去，如果有的话，就不用查后台了
            filterCombinedData.push(eRow)
            filterCombinedKeys.push(eRow[this.combinedField])
          }
        }
        // 获取根据商品获取价格
        this.getCombinedPriceByKeys(filterCombinedKeys, colItem, filterCombinedData).then(res => {
          let childs = []
          // 如果没有组合 那么就直接查当前行
          if (!filterCombinedKeys || filterCombinedKeys.length === 0) {
            batchRows.push(eRow)
          } else {
            showMessage = false
          }
          //如果返回的数据有值，就替换
          if (res && res.length > 0) {
            // 先删除原数据中组合的数据 需要用this.combinedField + '-parentId'，不然就会把已经选择的组合也删除掉
            res.forEach(it => {
              //删除子级
              this.deleteChildren(batchRows.filter(row => row[this.combinedField] === it[this.combinedField]))
              //过滤数据
              batchRows = batchRows.filter((row, index) => row[this.combinedField] !== it[this.combinedField])
              batchRows.splice(index, 0, it)
            })
          }
          let children = []
          for (let i = 0; i < batchRows.length; i++) {
            // 对子级的处理(组合才会处理），其他都在选择界面查出来了
            let bomItems = batchRows[i]['bomItems']
            if (bomItems && bomItems.length > 0) {
              // 如果有bomItems说明有子级
              batchRows[i]['hasChild'] = 1
              bomItems.forEach(child => {
                child.parentId = batchRows[i]['id']
                children.push(child)
              })
            }
            // }
            //如果子级有children直接升级，并且把当前数据删除掉，直接显示子级
            this.setChildrenData(batchRows[i], children)
            // 判断是否重复
            let isRepeat = this.checkRepeat(batchRows[i], batchRows[i], rowIndex, colItem, showMessage)
            // 如果重复就不进行后续
            if (isRepeat) {
              //只要重复就不允许删除当前行了
              deleteCurrentFlag = true
              index = index + 1
              continue
            }
            // 如果第一行是新行，那么就要把deleteCurrentFlag设置为true,不然第二行就要删除掉之前的数据
            if (i === 0 && this.controlId && !this.tableData[rowIndex][this.controlId]) {
              deleteCurrentFlag = true
            }
            //如果当前行有值，先删除当前行 (当前行只能删除一次)
            if (!deleteCurrentFlag && this.controlId && this.tableData[rowIndex][this.controlId]) {
              //删除子级
              this.deleteChildren(this.tableData[rowIndex])
              //需要删除的数据
              if (this.majorField && this.tableData[rowIndex][this.majorField]) {
                this.deleteData.push(this.tableData[rowIndex])
              }
              //过滤掉当前行数据
              this.tableData = [...this.tableData.filter((it, index) => {
                return index !== rowIndex
              })]
              deleteCurrentFlag = true
            }
            // 插入到当前行
            this.add(rowIndex + index, true)
            // 设置需要更新的数据
            this.setTableData(batchRows[i], batchRows[i], rowIndex + index, colItem, fieldUpdate)
            // 计算公式
            this.calcColumns(rowIndex + index)
            index = index + 1
          }
          // 跳转到第一行的可输入单元格
          this.nextInputCell(batchRows[0], rowIndex, columnIndex, colItem.field, colItem)
          resolve()
        })
      })
    }
    ,
    /**
     * @desc   : 设置需要更新的数据
     * @author : 周兴
     * @date   : 2022/5/27 8:48
     */
    setTableData(eRow, row, rowIndex, colItem, fieldUpdate) {
      // console.log('fieldUpdate',fieldUpdate)
      // 更新需要更新的列
      if (fieldUpdate) {
        let nonGlassPriceItemsFilterRow = null
        fieldUpdate.forEach(it => {
          this.tableData[rowIndex][it.updateField] = eRow[it.valueFiled]
          // 如果这个数值没有，并且有默认值，那么就赋值上默认值
          if (!eRow[it.valueFiled] && it.defaultValue) {
            this.tableData[rowIndex][it.updateField] = it.defaultValue
          }
          // 如果是赠品标识，默认要勾上赠品标识
          if (it.valueFiled === 'cpFlgGift' && eRow[it.valueFiled]) {
            this.tableData[rowIndex]['flgGift'] = true
            this.tableData[rowIndex].priceSale = 0
            this.switchValue(colItem, rowIndex, row)
          }
          // 如果是非标淋浴房，需要取标价的默认值
          if (it.updateField === 'nonGlassListShow') {
            if (row.nonGlassSpuItems && row.nonGlassSpuItems.length > 0) {
              row.nonGlassSpuItems.forEach(it => {
                if (!this.tableData[rowIndex].nonGlassForm) {
                  this.tableData[rowIndex].nonGlassForm = {}
                }
                this.tableData[rowIndex].nonGlassForm[it.fieldCode] = null
              })
            }
            if (row.nonGlassPriceItems && row.nonGlassPriceItems.length > 0) {
              let nonGlassFiters = row.nonGlassPriceItems.filter(it => it.flgDefItem)
              if (nonGlassFiters && nonGlassFiters.length > 0) {
                nonGlassPriceItemsFilterRow = nonGlassFiters[0]
                this.tableData[rowIndex][it.updateField] = nonGlassPriceItemsFilterRow['nonGlassListShow']
                if (nonGlassPriceItemsFilterRow.nonGlassList && nonGlassPriceItemsFilterRow.nonGlassList.length > 0) {
                  nonGlassPriceItemsFilterRow.nonGlassList.forEach(fRow => {
                    this.tableData[rowIndex].nonGlassForm[fRow.fieldCode] = fRow.optionCode
                  })
                }
                // 设置非标参数
                this.tableData[rowIndex].nonGlassList = nonGlassPriceItemsFilterRow.nonGlassList
                this.tableData[rowIndex].nonStandardArea = 1
              }
            }
          }
          // 下拉默认值的处理
          if (it.default) {
            // 获取相关列
            this.getColItem(it.valueFiled).then(col => {
              if (col) {
                let defaults = typeof col.default === 'function' ? col.default() : col.default
                if (defaults) {
                  if (!col.defaultName) {
                    // 如果下拉有默认值需要获取名称
                    let options = typeof col.options === 'function' ? col.options() : col.options
                    let rows = options.filter(it => it[col.valueKey] == defaults)
                    if (rows && rows.length > 0) {
                      col.defaultName = rows[0][col.labelKey]
                      col.defaultValue = defaults
                      col[col.valueKey + '_Name'] = col.valueKey + '_Name'
                    }
                  }
                  this.tableData[rowIndex][col.valueKey + '_Name'] = col.defaultName
                  this.tableData[rowIndex][col.valueKey] = defaults
                }
              }
            })
          }
        })
        // 如果非标价格有值，需要赋值
        if (nonGlassPriceItemsFilterRow) {
          this.tableData[rowIndex].priceSale = nonGlassPriceItemsFilterRow.itemPrice
          this.tableData[rowIndex].priceStandard = nonGlassPriceItemsFilterRow.itemPrice
        }
        // 给hasChild赋值
        this.tableData[rowIndex]['hasChild'] = eRow['hasChild'] ? eRow['hasChild'] : 0
        // // 组合的数据一起删除
        // if (this.combinedField + '-parentId' && eRow[this.combinedField + '-parentId']) {
        //   this.tableData[rowIndex][this.combinedField + '-parentId'] = eRow[this.combinedField + '-parentId']
        // }
        // 替换列的添加
        if (this.exchangeField && eRow[this.exchangeField]) {
          this.tableData[rowIndex][this.exchangeField] = eRow[this.exchangeField]
        }
      }
      //说明是下拉，需要赋值
      if (colItem.valueKey) {
        //先把labelKey赋值给field,方便显示
        if (eRow[colItem.valueKey]) {
          this.tableData[rowIndex][colItem.field] = eRow[colItem.valueKey].toString()
          this.tableData[rowIndex][colItem.field + '_Name'] = eRow[colItem.labelKey]
        }
      }
      if (eRow['id']) {
        // 给id赋值
        this.tableData[rowIndex]['id'] = eRow['id']
        //把改变的行加入到tableDataChange中
        let rows = this.tableDataChange.filter(it => it['id'] === row['id'])
        //说明已经存在
        if (rows && rows.length > 0) {
          this.tableDataChange = this.tableDataChange.filter(it => it['id'] !== row['id']).map(it => it)
        }
        this.tableDataChange.push(this.tableData[rowIndex])
      }
    },
    /**
     * @desc   : 获取列
     * @author : 周兴
     * @date   : 2022/9/19 13:17
     */
    getColItem(field) {
      return new Promise(resolve => {
        this.columns.forEach(it => {
          if (it.field === field) {
            resolve(it)
          }
        })
        resolve(null)
      })
    },
    /**
     * @desc   : 选择数据
     * @author : 周兴
     * @date   : 2022/4/7 16:02
     */
    onChoose(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem) {
      this.chooseData(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem, true).then(res => {
        // 设置赠品标识
        this.setFlgGift().then(t => {
          // 选择数据之后公布事件
          this.$emit('on-choose')
        })
        // 设置下拉默认值
        this.setChildrenSelect()
      })
      this.$refs[this.name].clearActived()
    }
    ,
    /**
     * @desc   : 选择数据
     * @author : 周兴
     * @date   : 2022/4/7 16:02
     */
    onChooseSelect(e, row, column, rowIndex, columnIndex, fieldUpdate, colItem) {
      let eRow = e == null ? row : e
      // 判断是否重复
      this.checkRepeat(eRow, row, rowIndex, colItem, true)
      // 设置需要更新的数据
      this.setTableData(eRow, row, rowIndex, colItem, fieldUpdate)

      this.$emit('chooseData', row, rowIndex)
      setTimeout(() => {
        this.$refs[this.name].clearActived()
        // 跳转到下一个可输入单元格
        this.nextInputCell(row, rowIndex, columnIndex, colItem.field)
        // 如果子级的数据需要跟父级一致，但是必须子级是空时
        this.setChildEqual(row, colItem, colItem.field)
        if (!row.parentId) {
          this.expandRows = this.$refs[this.name].getTreeExpandRecords()
          this.$refs[this.name].reloadData(this.tableData)
          this.restoreTreeTableStatus() // 恢复刷新前的节点展开状态
        }
      }, 300)
    },
    /**
     *   @desc   : 重新加载数据
     *   @date   : 2023/4/20 14:02
     *   @author : 寇珊珊
     */
    reloadData(data) {
      this.$refs[this.name].reloadData(data)
    },
    /**
     * @desc   : 过滤数据
     * @author : 周兴
     * @date   : 2022/5/13 16:27
     */
    filterData(data, eRow, col, currentRow, column) {
      //说明是当前列，当前列从下拉中取值
      if (column.field === col) {
        if (column.valueKey) {
          return data.filter(it => it[col] == eRow[column.valueKey])
        }
      } else {
        if (currentRow && currentRow[col]) {
          return data.filter(it => it[col] == currentRow[col] && it['id'] != currentRow['id'])
        }
      }
      return null
    }
    ,
    /**
     * @desc   : 校验数据
     * @author : 周兴
     * @date   : 2022/4/7 16:02
     */
    validCheck() {
      return new Promise((resolve, reject) => {
        const $table = this.$refs[this.name]
        $table.fullValidate(true).then(() => {
          resolve(true)
        }).catch(errMap => {
          resolve(false)
        })
      })
    }
    ,
    /**
     * @desc   : 日期格式
     * @author : 周兴
     * @date   : 2022/4/24 17:13
     */
    dateFormat(val) {
      if (!val) {
        return ''
      }
      return val.format('yyyy-MM-dd')
    }
    ,
    /**
     * @desc   : 单元格编辑结束后，光标停留在对应的位置
     * @author : 周兴
     * @date   : 2022/4/10 14:02
     */
    editMethod(e) {
    }
    ,
    /**
     * @desc   : 滚动就隐藏pop
     * @author : 周兴
     * @date   : 2022/4/19 9:21
     */
    handleScroll(e) {
      //只有人为滚动时才处理
      if (!this.isScroll) {
        this.$refs[this.name].clearActived() //关闭下拉的pop
        this.$refs[this.name].$el.click() //关闭表头的pop
      }
    }
    ,
    /**
     * @desc   : 根据requiredColumn进行validRules设置
     * @author : 周兴
     * @date   : 2022/4/25 15:13
     */
    setRequiredColumn() {
      if (this.requiredColumn && this.requiredColumn.length > 0) {
        let validRules = {}
        this.requiredColumn.forEach(col => {
          let tempCol = this.columns.filter(it => it.field === col)
          if (tempCol) {
            validRules[col] = [{
              required: true,
              // message: vm.$t('inputWords', {'search-name': tempCol[0].title ? tempCol[0].title : vm.$t(tempCol[0].field)})
            }]
          }
        })
        this.validRules = validRules
      }
    }
    ,
    /**
     * @desc   : 查询可替换的数据
     * @author : 周兴
     * @date   : 2022/3/7 14:28
     */
    handleExchangeClick(row, colItem) {
      this.showModal = true
      // 记录当前行
      this.focusedRow = row
      if (this.exchangeField == 'pdtModelId') {
        // 绑定条码 不管有值没值都是可以查询数据的
        //查询可替换商品
        // this.getDataTable(row)
        this.bindBarCodeReplaceFlag = true
      }
      // 说明已经有值，直接替换，不用查询数据库 只包括父级
      else if (this.exchangeField && row[this.exchangeField] && (!row['parentId'] || !row['bomSkuId'])) {
        this.exchangeData = [...row[this.exchangeField]]
        //过滤掉当前数据
        this.exchangeData = this.exchangeData.filter(it => it[this.controlId] !== row[this.controlId])
        this.exchangeData.forEach(it => {
          it['hasChild'] = 0
        })
        //显示可替换的界面
        this.showModal = true
      } else {
        // 查询可替换商品
        // this.getDataTable(row)
      }
    },
    /**
     * @desc   : 查询可切换的数据
     * @author : 周兴
     * @date   : 2022/5/27 16:04
     */
    getDataTable(row) {
      //显示可替换的界面
      this.$nextTick(() => {
        let param = {...this.$refs['table-exchange'].pageInfo}
        param.currentPage = this.pageInfo.currentPage ? this.pageInfo.currentPage : 1
        param.pageSize = this.pageInfo.pageSize
        param.ftyId = this.$store.state.user.ftyId
        // 根据传入的数据进行检索
        if (!row) {
          row = this.focusedRow
        }
        param[this.exchangeField] = row[this.exchangeField]
        if (this.bindBarCodeFlag) {
          //添加子集
          if (row.hasChild == 1) {
            //成型线Id
            param.moldlineId = row.bomItems[0]['moldlineId']
            //产品id集合
            param.modelIdList = row.bomItems.map(it => it.mouldId).unique()
            this.bindBarCodeAddFlag = true
          }
          //替换子集
          else {
            //todo  zdl 2023年6月1日11:40:02   分组 组内不区分粘贴模式
            // param.pdtGlueKind = row['pdtGlueKind']
            //todo 查出所有数据 zdl 2023年4月25日09:01:27
            // param.moldlineId = row['moldlineId']
            //todo 暂时注掉 2023年4月25日08:46:09  zdl
            // param.moldlineItemNoList =  this.children.map(it=>it.moldlineItemNo).unique()
            //赋值查询类型
            this.columns[0].dataType = this.$config.tableSelectType.product
          }
        }
        // 拼接外部传入的其他参数otherCondition
        if (this.otherCondition) {
          param = Object.assign(param, this.otherCondition)
        }
        if (this.searchCond) {
          param = Object.assign(param, this.searchCond._value)
        }
        this.excute(this.service, this.service[this.methodsNameExchange], param).then(res => {
          if (res.code === this.$config.SUCCESS_CODE) {
            let arr = []
            if (res.data && res.data.list && res.data.list.length > 0) {
              arr = [...res.data.list]
            }
            if ((!arr || arr.length === 0) && res.data && res.data.length > 0) {
              arr = [...res.data]
            }
            this.exchangeData = arr
            //过滤掉当前数据  不是绑定条码需要(这里保留的是原来的逻辑)
            if (!this.bindBarCodeFlag) {
              this.exchangeData = this.exchangeData.filter(it => it[this.controlId] !== row[this.controlId])
            }
            this.$refs['table-exchange'].pageInfo.total = res.data.total
            //显示可替换的界面
            // this.showModal = true
          } else {
            this.$Message.warning(res.message)
          }
        })
      })
    },
    /**
     * @desc   : 判断交换图标是否可见
     * @author : 周兴
     * @date   : 2022/5/28 7:54
     */
    checkExchangeIconVisible(row) {
      //当前行替换标识不存在或者是true的情况 替换标识可见
      if (!this.readonly && row && row[this.exchangeField]
        && row['parentId'] && (row['exchangeFlag'] == undefined || row['exchangeFlag'])) {
        return true
      }
      return false
    },
    /**
     * @desc   : 选择数据之后
     * @author : 周兴
     * @date   : 2022/5/27 16:49
     */
    modalOk() {
      // 如果没有选择数据返回
      if (!this.$refs['table-exchange'].batchRows || this.$refs['table-exchange'].batchRows.length === 0
        || !this.focusedRow) {
        return
      }
      let row = this.$refs['table-exchange'].batchRows[0]
      //如果是绑定条码
      if (this.bindBarCodeFlag) {
        //判断页面中是否已有选择数据
        //没有重复数据
        if (this.children.filter(it => it.pdtModelId == row.pdtModelId && it.moldingBatch == row.moldingBatch
          && it.moldingDate == row.moldingDate &&
          it.moldlineId == row.moldlineId && it.moldlineItemNo == row.moldlineItemNo).length == 0) {
          //添加绑定条码
          if (this.bindBarCodeAddFlag) {
            this.addDetailByBindBarCode(row)
            this.bindBarCodeAddFlag = false
          }
          //替换绑定条码
          else {
            this.checkDetailByBindBarCode(row)
            this.bindBarCodeReplaceFlag = false
          }
          this.showModal = false
        }
        //有重复数据
        else {
          this.$Message.warning(this.$t('W_141'))
          return
        }
      } else {
        // 判断替品是否有标价
        if (!row.priceStandard && row.priceStandard != 0) {
          this.$Message.warning(this.$t('W_069', {'param': this.$t('priceStandard')}))
          return
        }
        // 关闭弹窗
        this.showModal = false
        // 全局中的children也要改变
        let child = this.children.filter(it => it['id'] === this.focusedRow['id'])
        // 把选择的数据进行覆盖当前列表
        this.columnsUpdate.forEach(col => {
          if (col.field !== 'id' && 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.tableData.filter(it => it['id'] === this.focusedRow['parentId'])
        if (parentRows && parentRows.length > 0) {
          // 先计算父级
          this.shareToParentData(parentRows[0]).then(res => {
            // 再根据父级计算子级其他数据
            this.shareFromParentData(parentRows[0], parentRows[0].children)
          })
        }
      }
      // 清空查询条件
      this.$refs['searchCond'].clearCondition();
    },
    /**
     *   @desc   : 替换明细--当前绑定条码用
     *   @date   : 2023/4/24 14:40
     *   @author : 寇珊珊
     */
    checkDetailByBindBarCode(row) {
      for (let i in this.children) {
        //找到明细中需要替换的数据
        if (this.children[i].id == this.focusedRow.id) {
          row.parentId = this.children[i].parentId
          row.hasChild = this.children[i].hasChild
          row.id = this.children[i].id
          row.readOnlyUniqueCode = this.children[i].readOnlyUniqueCode
          this.children[i] = row
          this.children.moldingItemId = this.children[i].itemId
          break
        }
      }
      this.$emit('check-detail-by-bind-bar-code', this.focusedRow, row)
    },
    /**
     *   @desc   : 添加明细--当前绑定条码用
     *   @date   : 2023/4/27 14:37
     *   @author : 寇珊珊
     */
    addDetailByBindBarCode(row) {
      this.$emit('add-detail-by-bind-bar-code', row)
    },
    /**
     * @desc   : 计算父级数据
     * @author : 周兴
     * @date   : 2022/6/6 16:41
     */
    shareToParentData(row) {
      return new Promise(resolve => {
        let child = this.children.filter(it => it['parentId'] === row['id'] && it['hasChild'] == 0)
        this.columns.forEach(col => {
          if (col.shareField && col.shareField === 'sumTotal'
            && col.sumTotal && child && child.length > 0) {
            this.calcSumTotal(col, row, child, col.digits ? col.digits : 0)
          }
          resolve()
        })
      })
    },
    /**
     * @desc   : 复制单元格
     * @author : 周兴
     * @date   : 2022/6/9 9:31
     */
    copyValue(row, colItem) {
      let field = colItem.field
      if (row && row[field]) {
        this.$message.success(vm.$t('copySuccess') + '：' + row[field])
        //创建一个input框
        const input = document.createElement('input')
        //将指定的DOM节点添加到body的末尾
        document.body.appendChild(input)
        //设置input框的value值为直播地址
        input.setAttribute('value', row[field])
        //选取文本域中的内容
        input.select()
        //copy的意思是拷贝当前选中内容到剪贴板
        //document.execCommand（）方法操纵可编辑内容区域的元素
        //返回值为一个Boolean，如果是 false 则表示操作不被支持或未被启用
        if (document.execCommand('copy')) {
          document.execCommand('copy')
        }
        //删除这个节点
        document.body.removeChild(input)
      }
    },
    /**
     * @desc   : 初始化列
     * @author : 周兴
     * @date   : 2022/6/11 10:42
     */
    initColumn() {
      let columns = [...this.columns]
      //如果列中没有序号要加上
      let filterColumns = columns.filter(it => it.field === 'seq')
      if (!filterColumns || filterColumns.length === 0) {
        columns.splice(0, 0, {type: 'seq', field: 'seq', fixed: 'left'})
        columns.splice(1, 0, {type: 'info', field: 'info', fixed: 'left', width: '15'})
        columns.splice(0, 0, {type: 'blank', field: 'blank', width: '1'})
      }
      this.columnsData = columns
    },
    /**
     * @desc   : 固定列
     * @author : 周兴
     * @date   : 2022/6/8 20:29
     */
    toggleFixedColumn() {
      const xTable = this.$refs[this.name]
      const tableColumns = xTable.getTableColumn()
      if (tableColumns && tableColumns.visibleColumn
        && tableColumns.visibleColumn.length > 0) {
        let refreshFlag = false
        let field = null
        for (let i in this.columnsData) {
          // 查看是否有列设置了固定
          if (this.columnsData[i].fixed) {
            field = this.columnsData[i].field
            let col = tableColumns.visibleColumn.filter(it => it.field === this.columnsData[i].field)
            if (col && col.length > 0) {
              col[0].fixed = this.columnsData[i].fixed
              refreshFlag = true
            }
          }
        }
        if (field) {
          // 找到当前列，给其赋值冻结标识
          let colItems = this.columnsData.filter(it => it.field === field)
          if (colItems && colItems.length > 0) {
            colItems[0].freezeFlag = true
          }
        }
        if (refreshFlag) {
          // 清空冻结可见
          this.header.options[0].update({code: 'clearFreeze', visible: true}, 'code', 'visible')
          // 刷新列
          xTable.refreshColumn()
        }
      }
    },
    /**
     * @desc   : 查询子级的方法
     * @author : 周兴
     * @date   : 2022/5/27 10:48
     */
    setLoadChildInit() {
      this.columns.forEach(col => {
        //必须是属性节点的列才会设置
        if (col.treeNode && col.dataType === this.$config.tableSelectType.goods) {
          //设置后台接口服务
          this.methodsName = 'getCombinedSkuById'
          // this.methodsName = 'getGoodsChild';
          this.methodsNameExchange = 'getGoodsReplace'
          this.service = this.$service.commonService
          this.columnsUpdate.push(
            {field: 'skuModel'},
            {field: 'skuCode'},
            {field: 'skuId'},
            {field: 'skuName'},
            {field: 'itemPrice'},
            {field: 'skuSpecs'},//商品规格
            {field: 'skuUnit'},//计量单位
            {field: 'flgEstimate'},//计量标识
            {field: 'salesMode'},//流通方式
            {field: 'goodsCategoryName'},//商品种类
            {field: 'goodsVarietyName'},//商品品种
            {field: 'skuSeries'},//商品系列
            {field: 'skuBrand'},//商品品牌
            {field: 'skuLength'},
            {field: 'skuWidth'},
            {field: 'skuHeight'},
            {field: 'skuVolume'},
            {field: 'skuArea'},
            {field: 'skuType'},
            {field: 'standardId'},
            {field: 'standardItemId'},
            {field: 'priceStandard'},
            {field: 'orderItemQuantity'},
            {field: 'combinedPackageId'},
            {field: 'combinedPackageName'},
            {field: 'promotionId'},
            {field: 'promotionItemId'},
            {field: 'pricePromotion'},
            {field: 'priceSale'},
            {field: 'promotionTypeName'},
            {field: 'promotionName'},
          )
          this.columnsDetail.push(
            {field: 'skuModel', type: 'disabled', minWidth: '40', treeNode: true, title: this.$t('skuModel')},
            {field: 'skuName', type: 'disabled', minWidth: '40', title: this.$t('skuName')},
            {field: 'skuTypeName', type: 'disabled', minWidth: '40', title: this.$t('skuTypeName')},
            {
              field: 'priceStandard',
              type: 'disabled',
              minWidth: '40',
              digits: 2,
              columnType: this.$config.columnType.number,
              title: this.$t('priceStandard')
            },
            {field: 'goodsVarietyName', type: 'disabled', minWidth: '40', title: this.$t('goodsVarietyName')},
            {field: 'goodsCategoryName', type: 'disabled', minWidth: '40', title: this.$t('skuCategory')},
            // {field: 'skuSpecs', type: 'disabled', minWidth: '40', title: this.$t('skuSpecs')},
          )
        }
        //绑定条码- 替换产品
        else if (col.treeNode && col.dataType === this.$config.tableSelectType.product) {
          //设置后台接口服务
          this.methodsName = 'selectProductByBindBarcode'
          this.methodsNameExchange = 'selectProductByBindBarcode'
          this.service = this.$service.moldingRecordItemService
          this.searchContent = [
            //成型批次
            {itemCode: 'moldingBatch'},
            //成型日期
            {
              itemCode: 'moldingDate',
              valueFormat: {code: 'moldingDate'},
              valueKind: 'DATE_RANGE',
            },
            //分组名称
            {itemCode: 'groupName'},
            //成型线编码
            {
              itemCode: 'uniqueCode',
              itemName: 'moldlineCode'
            },
            //产品型号
            {
              itemCode: 'modelId',
              itemName: 'appModelProduct',
              valueFormat: {code: 'pdtModelId'},
              valueKind: this.$config.docUserInput.sSearch,
              magnifierType: this.$config.MagnifierType.modelMould,
            },
            //模具型号
            {
              itemCode: 'mouldId',
              itemName: 'modelName',
              valueFormat: {code: 'mouldId'},
              valueKind: this.$config.docUserInput.sSearch,
              magnifierType: this.$config.MagnifierType.product,
            },
          ]
          //替换的列
          this.columnsUpdate.push(
            {field: 'moldlineItemNo', title: this.$t('bondingNo')}, // 粘接序号
            {field: 'moldlineItemCode', title: this.$t('repPdtModelName')},//可变更产品名称
            {field: 'repPdtModelName'},//可变更产品名称
            {field: 'uniqueCode', title: this.$t('moldlineCode')},//成型线编码
            {field: 'moldlineName'},//成型线名称
            {field: 'manageUserName'},//成型班长
            {field: 'moldingUserName'},//成型工号
            {field: 'modelCode', title: this.$t('productCode')},//产品编码
            {field: 'modelName', title: this.$t('productName')},//产品名称
            {field: 'mouldCode', title: this.$t('moldingModelCode')},//模具编号
            {field: 'moldlineItemKindName', title: this.$t('mouldKindName')},//模具状态
            {field: 'moldingBatch'},//成型批次
            {field: 'flgMolding'},//成型标识
            {field: 'unmoldedReasonName'},//未成型原因
            {field: 'logoName'},//产品商标
            {field: 'colourName'},//釉色
            {field: 'flgScrap'},//损坯标识
            {field: 'scrapReasonName'},//损坯原因
          )
          //弹窗的列
          this.columnsDetail.push(
            // 成型批次
            {field: 'moldingBatch', type: 'disabled', width: 'auto'},
            // 成型日期
            {field: 'moldingDate', type: 'disabled', width: 'auto'},
            // 分组序号
            {field: 'groupNo', title: this.$t('groupNo'), treeNode: true, type: 'disabled', width: 'auto'},
            // 分组名称
            {field: 'groupName', title: this.$t('groupName'), type: 'disabled', width: 'auto'},
            // 成型线编码
            {field: 'uniqueCode', title: this.$t('moldlineCode'), type: 'disabled', width: 'auto'},
            // 成型线名称
            {field: 'moldlineName', type: 'disabled', width: 'auto'},
            // 产品编码
            {field: 'modelCode', title: this.$t('productCode'), type: 'disabled', width: 'auto'},
            // 产品名称
            {field: 'modelName', title: this.$t('productName'), type: 'disabled', width: 'auto'},
            // 模具状态
            {field: 'moldlineItemKindName', title: this.$t('mouldKindName'), type: 'disabled', width: 'auto'},
          )
        }
        //绑定条码- 添加产品
        else if (col.treeNode && col.dataType === this.$config.tableSelectType.addProduct) {
          //设置后台接口服务
          this.methodsName = 'selectProductCanBindBarcode'
          this.methodsNameExchange = 'selectProductCanBindBarcode'
          this.service = this.$service.moldingRecordItemService
          this.searchContent = [
            //成型批次
            {itemCode: 'moldingBatch'},
            //成型日期
            {
              itemCode: 'moldingDate',
              valueFormat: {code: 'moldingDate'},
              valueKind: 'DATE_RANGE',
            },
            //分组名称
            {itemCode: 'groupName'},
            //成型线编码
            {
              itemCode: 'uniqueCode',
              itemName: 'moldlineCode'
            },
          ]
          //替换的列
          this.columnsUpdate.push(
            {field: 'moldlineItemNo', title: this.$t('bondingNo')}, // 粘接序号
            {field: 'moldlineItemCode', title: this.$t('repPdtModelName')},//可变更产品名称
            {field: 'repPdtModelName'},//可变更产品名称
            {field: 'uniqueCode', title: this.$t('moldlineCode')},//成型线编码
            {field: 'moldlineName'},//成型线名称
            {field: 'manageUserName'},//成型班长
            {field: 'moldingUserName'},//成型工号
            {field: 'modelCode', title: this.$t('productCode')},//产品编码
            {field: 'modelName', title: this.$t('productName')},//产品名称
            {field: 'mouldCode', title: this.$t('moldingModelCode')},//模具编号
            {field: 'moldlineItemKindName', title: this.$t('mouldKindName')},//模具状态
            {field: 'moldingBatch'},//成型批次
            {field: 'flgMolding'},//成型标识
            {field: 'unmoldedReasonName'},//未成型原因
            {field: 'logoName'},//产品商标
            {field: 'colourName'},//釉色
            {field: 'flgScrap'},//损坯标识
            {field: 'scrapReasonName'},//损坯原因
          )
          //弹窗的列
          this.columnsDetail.push(
            // 成型批次
            {field: 'moldingBatch', type: 'disabled', width: 'auto'},
            // 成型日期
            {field: 'moldingDate', type: 'disabled', width: 'auto'},
            // 分组序号
            {field: 'groupNo', title: this.$t('groupNo'), treeNode: true, type: 'disabled', width: 'auto'},
            // 分组名称
            {field: 'groupName', title: this.$t('groupName'), type: 'disabled', width: 'auto'},
            // 成型线编码
            {field: 'uniqueCode', title: this.$t('moldlineCode'), type: 'disabled', width: 'auto'},
            // 成型线名称
            {field: 'moldlineName', type: 'disabled', width: 'auto'},
            // 产品编码
            {field: 'modelCode', title: this.$t('productCode'), type: 'disabled', width: 'auto'},
            // 产品名称
            {field: 'modelName', title: this.$t('productName'), type: 'disabled', width: 'auto'},
            // 模具状态
            {field: 'moldlineItemKindName', title: this.$t('mouldKindName'), type: 'disabled', width: 'auto'},
          )
        }
      })
    },
    /**
     * @desc   : 改变设置的位置
     * @author : 周兴
     * @date   : 2023/1/29 16:55
     */
    changeSettingLocation() {
      let self = this
      setTimeout(() => {
        self.settingLeft = self.$refs[self.name] ? (self.$refs[self.name].$el.offsetWidth + self.$refs[self.name].$el.offsetLeft - 26) + 'px' : 0// 设置图标居左的位置
        self.settingTop = self.$refs[self.name] ? (self.$refs[self.name].$el.offsetTop + 1) + 'px' : 0           // 设置图标居上的位置
      }, 100)
    },
  }
  ,
  mounted() {
    let self = this
    setTimeout(() => {
      self.toggleFixedColumn()
    }, 300)

    //监听窗口变化
    window.addEventListener('resize', function (e) {
      setTimeout(() => {
        self.settingLeft = self.$refs[self.name] ? (self.$refs[self.name].$el.offsetWidth + self.$refs[self.name].$el.offsetLeft - 26) + 'px' : 0// 设置图标居左的位置
        self.settingTop = self.$refs[self.name] ? (self.$refs[self.name].$el.offsetTop + 1) + 'px' : 0           // 设置图标居上的位置
      }, 300)
    })
    self.changeSettingLocation()
  }
  ,
  created() {
    //初始化列
    this.initColumn()
    //设置新行
    if (!this.data || this.data.length === 0) {
      let data = this.data ? this.data : []
      //赋值上所需要id ,parentId
      this.tableData = data.map(it => {
        let obj = it
        obj.id = it[this.controlId]
        obj.parentId = null
        return obj
      })
      this.tableDataChange = []
      if (this.newRowFlag) {
        //新建时增加行
        this.add()
      }
      setTimeout(() => {
        this.$refs[this.name].setActiveRow(this.tableData[0])
      }, 300)
    }
    // 设置必须输入项
    this.setRequiredColumn()
    // 设置查询子级的相关基础数据
    this.setLoadChildInit()
    // 根据列表是否只读，判断是否开启编辑模式
    if (this.readonly) {
      this.enabledEdit = false
    }
    this.freezeData = this.freeze
  }
}
</script>

<style scoped>
/deep/ .vxe-cell {
  display: flex;
  align-items: center;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/deep/ .vxe-cell--label {
  padding-left: 10px !important;
  padding-right: 10px !important;
}

.edit-div-class {
  padding-left: 10px !important;
  padding-right: 10px !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  white-space: nowrap !important;
}


/deep/ .vxe-input {
  width: 100%;
  border: 1px solid #dcdee2;
  border-radius: 2px;
}

/deep/ .vxe-input :hover {
  /*border: 1px solid #57a3f3 !important;*/
  /*border-radius: 2px;*/
}

/deep/ .vxe-input > input:focus {
  box-shadow: 0 0 0 2px rgba(45, 140, 240, 0.2);
}

/deep/ .col--valid-error .vxe-input > input {
  border-color: red !important;
}


/deep/ .vxe-cell--title {
  line-height: 0;
}


/*
 * @desc   : TODO 不好使
 * @author : 周兴
 * @date   : 2022/4/5 16:35
 */
.number-class .vxe-cell {
  justify-content: right !important;
}


/deep/ .vxe-input--number-prev-icon {
  display: none;
}

/deep/ .vxe-input--number-next-icon {
  display: none;
}

/deep/ .vxe-input .vxe-input--extra-suffix {
  display: none;
}

.seq-class-s {
  margin-left: 20px !important;
}

.seq-class-seq {
  margin-left: 10px !important;
}

.seq-class-t {
  margin-left: 0px !important;
}

.change-icon-class {
  position: absolute;
  top: 8px;
  left: 8px;
  cursor: pointer;
}

.change-icon-child-class {
  position: absolute;
  top: 8px;
  left: -8px;
  cursor: pointer;
}

/**
 * @desc   : 展开子级的图标
 * @author : 周兴
 * @date   : 2022/6/7 17:22
 */
/deep/ .vxe-tree--btn-wrapper {
  left: 6px;
}

/**
 * @desc   : 树形列父级的样式
 * @author : 周兴
 * @date   : 2022/6/7 17:22
 */
.parent-class {
  padding-left: 28px !important;
}

/**
 * @desc   : 树形列子级的样式
 * @author : 周兴
 * @date   : 2022/6/7 17:22
 */
.child-class {
  padding-left: 35px !important;
}

/deep/ .vxe-cell--tree-node {
  width: 100%;
}

/deep/ .vxe-cell--tree-node > .vxe-tree-cell {
  padding-left: 0 !important;
}

.non-glass-drop-down {
  width: 300px;
  background-color: #fff;
  box-shadow: 0 0 6px 2px rgba(0, 0, 0, 0.1);
}

.setting-class {
  position: absolute;
  z-index: 300;
  width: 25px;
  height: 28px;
  background: #F8F8F9;
  justify-content: center;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.freeze-class {
  margin-top: 4px;
  margin-left: 5px;
  cursor: pointer;
  font-size: 14px;
  color: #c0c4cc;
}

.freezed-class {
  margin-top: 4px;
  margin-left: 5px;
  cursor: pointer;
  font-size: 14px;
}

/deep/ .vxe-switch.size--mini {
  font-size: 10px !important;
}

.switch-class {
  height: calc(100% - 3px) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.checkbox-class {
  height: 100% !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.checkbox-class label {
  margin-bottom: 0 !important;
}

</style>
