<!--
 * @Description : 产品目录清单 -- 新增SPU -- tabs Sku
 * @Author      : jinxin
 * @Date        : 2022-10-17 13:59:48
-->

<template>
  <div class="table">
    <vxe-table ref="getDom" class="my-table" border resizable height="600" :scroll-x="{enabled: false}"
      :row-config="{isHover: true}" :scroll-y="{enabled: false}" :data="data.list" :edit-rules="validRules"
      @checkbox-change="getSelectRow" @checkbox-all="getSelectRow"
      :edit-config="{trigger: 'click', mode: 'cell',showStatus: true}" :row-class-name="rowClassName"
      :column-config="{resizable:true}">
      <div v-for="(item,index) in data.listHeader" :key="index + data.headerIndex">
        <vxe-column v-if="item.type == 'checkbox'" :type="item.type" :fixed="item.fixed" :align="item.align"
          :width="item.width"></vxe-column>
        <vxe-colgroup v-if="item.type == 'group'" :fixed="item.fixed" :align="item.align" :title="item.title">
          <div v-for="(itemChild,indexChild) in item.children" :key="indexChild + data.headerIndex">
            <vxe-column v-if="itemChild.type == 'col'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align"></vxe-column>
            <vxe-column v-if="itemChild.type == 'sel'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align" :edit-render="{name:'select'}">
              <template #default="scope">
                <span>{{ getShowMh(scope.row[itemChild.field],itemChild.list[scope.$rowIndex],scope.$rowIndex) }}</span>
              </template>
              <template #edit="scope">
                <el-select v-model="scope.row[itemChild.field]" filterable remote reserve-keyword clearable
                  @focus="getlist(scope.row[itemChild.field],scope.$rowIndex,scope,'focus')"
                  :remote-method="(query)=>{getlist(query,scope.$rowIndex,scope,'other')}"
                  :popper-append-to-body="false" placeholder="可搜索">
                  <el-option v-for="(it,index) in itemChild.list[scope.$rowIndex]" :key="index" :label="it.value"
                    :value="it.id"></el-option>
                </el-select>
              </template>
            </vxe-column>
            <vxe-column v-if="itemChild.type == 'ipt'" :field="itemChild.field" :title="itemChild.title" show-overflow
              :width="itemChild.width" :align="itemChild.align" :edit-render="{autofocus:'.el-input__inner'}">
              <template #edit="scope">
                <el-input v-model.trim="scope.row[itemChild.field]" type="text" maxlength="200"
                  placeholder=" 可输入"></el-input>
              </template>
            </vxe-column>
            <vxe-column v-if="itemChild.type == 'ipt_num'" :field="itemChild.field" :title="itemChild.title"
              show-overflow :width="itemChild.width" :align="itemChild.align"
              :edit-render="{autofocus:'.el-input__inner'}">
              <template #edit="scope">
                <el-input v-model.trim="scope.row[itemChild.field]" type="text" maxlength="200"
                  @input="countCom(scope.row[itemChild.field],itemChild.field,scope.$rowIndex)"
                  @blur="countBlur(scope.row[itemChild.field],itemChild.field,scope.$rowIndex)"
                  placeholder=" 可输入"></el-input>
              </template>
            </vxe-column>
            <vxe-column v-if="itemChild.type == 'date'" :field="itemChild.field" :title="itemChild.title" show-overflow
              :width="itemChild.width" :align="itemChild.align" :edit-render="{autofocus:'.el-input'}">
              <template #edit="scope">
                <el-date-picker @change="countBlur(scope.row[itemChild.field],itemChild.field,scope.$rowIndex)"
                  v-model="scope.row[itemChild.field]" type="date" value-format="YYYY-MM-DD" placeholder="请选择日期"
                  :default-value="new Date()" />
              </template>
            </vxe-column>
          </div>
        </vxe-colgroup>
        <vxe-colgroup v-if="item.type == 'group-allow'" v-allow="'NewCost.NewCostFinance'" :fixed="item.fixed"
          :align="item.align" :title="item.title">
          <div v-for="(itemChild,indexChild) in item.children" :key="indexChild + data.headerIndex">
            <vxe-column v-if="itemChild.type == 'col'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align"></vxe-column>
            <vxe-column v-if="itemChild.type == 'sel'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align" :edit-render="{name:'select'}">
              <template #default="scope">
                <span>{{ getShowMh(scope.row[itemChild.field],itemChild.list[scope.$rowIndex],scope.$rowIndex) }}</span>
              </template>
              <template #edit="scope">
                <el-select v-model="scope.row[itemChild.field]" filterable remote reserve-keyword
                  :remote-method="(query)=>{getlist(query,scope.$rowIndex,scope,'other')}"
                  :popper-append-to-body="false" placeholder="可搜索">
                  <el-option v-for="(it,index) in itemChild.list[scope.$rowIndex]" :key="index" :label="it.value"
                    :value="it.id"></el-option>
                </el-select>
              </template>
            </vxe-column>
          </div>
        </vxe-colgroup>
        <vxe-colgroup v-if="item.type == 'group_1'" :fixed="item.fixed" :align="item.align" :title="item.title">
          <div v-for="(itemChild,indexChild) in item.children" :key="indexChild + data.headerIndex">
            <vxe-column v-if="itemChild.type == 'col'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align"></vxe-column>

            <vxe-column v-if="itemChild.type == 'img'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align">
              <template #default="scope">
                <img :src="scope.row.cover ? scope.row.cover : defaulImg" class="avatar"
                  @error="e => {e.target.src = defaulImg}" />
              </template>
            </vxe-column>

          </div>
        </vxe-colgroup>
        <vxe-colgroup v-if="item.type == 'group_2'" :fixed="item.fixed" :align="item.align" :title="item.title">
          <div v-for="(itemChild,indexChild) in item.children" :key="indexChild + data.headerIndex">
            <vxe-column v-if="itemChild.type == 'col'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align"></vxe-column>
            <vxe-column v-if="itemChild.type == 'sel'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align" :edit-render="{name:'select'}">
              <template #default="scope">
                <span>{{ getShowMh(scope.row[itemChild.field],itemChild.list[scope.$rowIndex],scope.$rowIndex) }}</span>
              </template>
              <template #edit="scope">
                <el-select v-model="scope.row[itemChild.field]" filterable remote reserve-keyword
                  :remote-method="(query)=>{getlist(query,scope.$rowIndex,scope,'other')}"
                  :popper-append-to-body="false" placeholder="可搜索">
                  <el-option v-for="(it,index) in itemChild.list[scope.$rowIndex]" :key="index" :label="it.value"
                    :value="it.id"></el-option>
                </el-select>
              </template>
            </vxe-column>
          </div>
        </vxe-colgroup>
        <vxe-colgroup v-if="item.type == 'group_3'" :fixed="item.fixed" :align="item.align" :title="item.title">
          <div v-for="(itemChild,indexChild) in item.children" :key="indexChild + data.headerIndex">
            <vxe-column v-if="itemChild.type == 'col'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align"></vxe-column>
            <vxe-column v-if="itemChild.type == 'selout_2'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align" :edit-render="{}">
              <template #default="{ row }">
                <span>{{ getShowName(row[itemChild.field],itemChild.list) }}</span>
              </template>
              <template #edit="{ row }">
                <vxe-select :disabled="data.isDisabled" v-model="row[itemChild.field]" transfer clearable>
                  <vxe-option v-for="it in itemChild.list" :key="it.id" :value="it.id" :label="it.name"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column v-if="itemChild.type == 'selout_3'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align" :edit-render="{}">
              <template #default="{ row }">
                <span>{{ getShowName(row[itemChild.field],itemChild.list) }}</span>
              </template>
              <template #edit="{ row }">
                <vxe-select :disabled="data.isDisabled" v-model="row[itemChild.field]" transfer clearable>
                  <vxe-option v-for="it in itemChild.list" :key="it.id" :value="it.id" :label="it.name"></vxe-option>
                </vxe-select>
              </template>
            </vxe-column>
            <vxe-column v-if="itemChild.type == 'ipt'" :field="itemChild.field" :title="itemChild.title" show-overflow
              :width="itemChild.width" :align="itemChild.align" :edit-render="{autofocus:'.el-input__inner'}">
              <template #edit="scope">
                <el-input :disabled="data.isDisabled" v-model.trim="scope.row[itemChild.field]" type="text"
                  maxlength="200" placeholder=" 可输入"></el-input>
              </template>
            </vxe-column>
            <vxe-column v-if="itemChild.type == 'ipt_num'" :field="itemChild.field" :title="itemChild.title"
              show-overflow :width="itemChild.width" :align="itemChild.align"
              :edit-render="{autofocus:'.el-input__inner'}">
              <template #edit="scope">
                <el-input :disabled="data.isDisabled" v-model.trim="scope.row[itemChild.field]" type="text"
                  maxlength="200" @input="countComOther(scope.row[itemChild.field],itemChild.field,scope.$rowIndex)"
                  @blur="countBlurOther(scope.row[itemChild.field],itemChild.field,scope.$rowIndex)"
                  placeholder=" 可输入"></el-input>
              </template>
            </vxe-column>

            <vxe-column v-if="itemChild.type == 'sel'" :field="itemChild.field" :title="itemChild.title"
              :width="itemChild.width" :align="itemChild.align" :edit-render="{name:'select'}">
              <template #default="scope">
                <span>{{ getShowMh(scope.row[itemChild.field],itemChild.list[scope.$rowIndex],scope.$rowIndex) }}</span>
              </template>
              <template #edit="scope">
                <el-select :disabled="data.isDisabled" v-model="scope.row[itemChild.field]" filterable remote
                  reserve-keyword :remote-method="(query)=>{getlist(query,scope.$rowIndex,scope,'other')}"
                  :popper-append-to-body="false" placeholder="可搜索">
                  <el-option v-for="(it,index) in itemChild.list[scope.$rowIndex]" :key="index" :label="it.value"
                    :value="it.id"></el-option>
                </el-select>
              </template>
            </vxe-column>
          </div>
        </vxe-colgroup>
        <vxe-column v-if="item.type == 'col'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align"></vxe-column>
        <vxe-column v-if="item.type == 'col_1'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align"></vxe-column>
        <vxe-column v-if="item.type == 'colfd'" :fixed="item.fixed" :field="item.field" :title="item.title"
          :width="item.width" :align="item.align"></vxe-column>
        <vxe-column v-if="item.type == 'colfdedit'" :fixed="item.fixed" :field="item.field" :title="item.title"
          show-overflow :width="item.width" :align="item.align" :edit-render="{autofocus:'.vxe-input--inner'}">
          <template #edit="scope">
            <vxe-input v-model.trim="scope.row[item.field]" type="text"
              :disabled="data.isDisabled || data.list[scope.$rowIndex].FNumber != '' ? true : false"
              @blur="clearNull(scope.row[item.field],scope.$rowIndex,item.field)" @change="getDom.updateStatus(scope)">
            </vxe-input>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'colfdedit_69'" :fixed="item.fixed" :field="item.field" :title="item.title"
          show-overflow :width="item.width" :align="item.align" :edit-render="{autofocus:'.vxe-input--inner'}">
          <template #edit="scope">
            <vxe-input v-model.trim="scope.row[item.field]" type="text"
              @blur="clearNull(scope.row[item.field],scope.$rowIndex,item.field)" @change="getDom.updateStatus(scope)">
            </vxe-input>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'colfdedit-allow'" v-allow="'NewCost.NewCostFinance'" :field="item.field"
          :title="item.title" :width="item.width" :align="item.align"></vxe-column>
        <!-- <vxe-column v-if="item.type == 'colfdedit-allow'" v-allow="'NewCost.NewCostFinance'" :fixed="item.fixed"
          :field="item.field" :title="item.title" :width="item.width" :align="item.align"
          :edit-render="{autofocus:'.vxe-input--inner'}">
          <template #edit="{ row }">
            <vxe-input :disabled="data.isDisabled" v-model="row[item.field]" type="text"></vxe-input>
          </template>
        </vxe-column> -->
        <vxe-column v-if="item.type == 'colfdedit-allow-price'" v-allow="'NewCost.NewCostFinance'" :fixed="item.fixed"
          :field="item.field" :title="item.title" :width="item.width" :align="item.align"
          :edit-render="{autofocus:'.vxe-input--inner'}">
          <template #edit="scope">
            <!-- <vxe-input v-model="scope.row[item.field]" type="text" :disabled="item.dislist[scope.$rowIndex]" -->
            <vxe-input v-model="scope.row[item.field]" type="text" :disabled="data.isDisabled"
              @change="getDom.updateStatus(scope)"></vxe-input>
          </template>
        </vxe-column>

        <vxe-column v-if="item.type == 'cboxq'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align" :edit-render="{}">
          <template #default="{ row }">
            <span>{{ getShowbox(row[item.field]) }}</span>
          </template>
          <template #edit="{ row }">
            <vxe-checkbox :disabled="data.isDisabled" v-model="row[item.field]" content=""></vxe-checkbox>
          </template>
        </vxe-column>
        <vxe-column v-if=" item.type == 'cboxq_1'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align" :edit-render="{}">
          <template #default="{ row }">
            <span>{{ getShowbox(row[item.field]) }}</span>
          </template>
          <template #edit="{ row }">
            <vxe-checkbox :disabled="data.isDisabled" v-model="row[item.field]" content=""></vxe-checkbox>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'switch'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align" :edit-render="{}">
          <template #default="{ row }">
            <span>{{ getShowSwitch(row[item.field]) }}</span>
          </template>
          <template #edit="scope">
            <vxe-switch v-model="scope.row[item.field]" open-label="开" close-label="关" :open-value='1' :close-value='0'
              :disabled="data.isDisabled" class="my-switch2"></vxe-switch>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'selout'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align" :edit-render="{}">
          <template #default="{ row }">
            <span>{{ getShowName(row[item.field],item.list) }}</span>
          </template>
          <template #edit="{ row }">
            <vxe-select :disabled="data.isDisabled" v-model="row[item.field]" transfer
              @change="changeMethods(row,row[item.field],item.field)">
              <vxe-option v-for="it in item.list" :key="it.id" :value="it.id" :label="it.name"></vxe-option>
            </vxe-select>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'selout_1'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align" :edit-render="{}">
          <template #default="{ row }">
            <span>{{ getShowName(row[item.field],item.list) }}</span>
          </template>
          <template #edit="{ row }">
            <vxe-select :disabled="data.isDisabled" v-model="row[item.field]" transfer clearable>
              <vxe-option v-for="it in item.list" :key="it.id" :value="it.id" :label="it.name"></vxe-option>
            </vxe-select>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'selmhout'" :field="item.field" :title="item.title" :width="item.width"
          show-overflow :align="item.align" :edit-render="{}">
          <template #default="scope">
            <span>{{ getShowMhName(scope.row[item.field],item.list[scope.$rowIndex],scope.$rowIndex) }}</span>
          </template>
          <template #edit="scope">
            <!-- <el-select v-model="scope.row[item.field]" filterable remote clearable :disabled="item.dislist[scope.$rowIndex]" -->
            <el-select :disabled="data.isDisabled" v-model="scope.row[item.field]" filterable remote clearable
              reserve-keyword :remote-method="(query)=>{getComList(query,scope.$rowIndex,scope)}"
              :popper-append-to-body="false" placeholder="可搜索">
              <el-option v-for="(it,index) in item.list[scope.$rowIndex]" :key="index" :label="it.name" :value="it.id">
              </el-option>
            </el-select>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'selmhout-allow'" v-allow="'NewCost.NewCostFinance'" :field="item.field"
          show-overflow :title="item.title" :width="item.width" :align="item.align" :edit-render="{}">
          <template #default="scope">
            <span>{{ getShowMhName(scope.row[item.field],item.list[scope.$rowIndex],scope.$rowIndex) }}</span>
          </template>
          <template #edit="scope">
            <!-- <el-select v-model="scope.row[item.field]" filterable remote clearable :disabled="item.dislist[scope.$rowIndex]" -->
            <el-select :disabled="data.isDisabled" v-model="scope.row[item.field]" filterable remote clearable
              reserve-keyword :remote-method="(query)=>{getComList(query,scope.$rowIndex,scope)}"
              :popper-append-to-body="false" placeholder="可搜索">
              <el-option v-for="(it,index) in item.list[scope.$rowIndex]" :key="index" :label="it.name" :value="it.id">
              </el-option>
            </el-select>
          </template>
        </vxe-column>
        <vxe-column v-if="item.type == 'imgupload'" :field="item.field" :title="item.title" :width="item.width"
          :align="item.align">
          <template #default="{ row }">
            <el-upload :action="data.upLoadUrl" :with-credentials="true" :on-success="function (res, file, file_list) {
                                return handleSuccess(res, file, file_list, row)
                            }" :show-file-list="false" name="file" :limit="1" :data="data.upLoadQuery"
              accept=".png, .jpg" :on-change="handleChange">
              <img v-if="row.image" :src="data.cdn + row.image" class="avatar"
                @mousemove="entryCellShowImg($event, row)" @mouseout="leaveCellBlurImg(row)" />
              <el-icon v-else class="el-icon-plus"></el-icon>
              <view v-show="row.showImg" class="img-show position-f" v-if="data.showImgUrl" :style="data.top">
                <img :src="data.cdn +  data.showImgUrl" />
              </view>
            </el-upload>
          </template>
        </vxe-column>
      </div>
    </vxe-table>
    <!-- 批量修改 -->
    <BatchEdit v-model:isBatchEditShow="data.isBatchEditShow" v-model:attrlist="data.muleditAttrCom"
      v-model:cusTitle="data.cusTitle" @getBatchEditObj="getBatchEditObj"></BatchEdit>
  </div>
</template>
<script>
import { defineComponent, reactive, getCurrentInstance, ref, onMounted, watch, onActivated, nextTick } from "vue";
import { useStore } from 'vuex'
import { useRouter } from 'vue-router'
import { VXETable } from 'vxe-table'
import defaulImg from '@/assets/defaulImg.jpg'
import BatchEdit from '@/views/components/BatchEdit/BatchEdit.vue'
import { Decimal } from 'decimal.js'
export default defineComponent({
  name: 'SkuVxeTable',
  props: {
    clickEvent: String,
    notice: Number,
    transmitData: Object,
    editId: String
  },
  emits: ['update:clickEvent', 'transmitTableDate'],
  components: {
    BatchEdit,
  },
  setup (props, context) {
    // 生命周期
    onMounted(() => {
      nextTick(() => {
        getReqData()
        data.listHeader = [

          { type: 'checkbox', fixed: 'left', align: 'center', width: '36' },
          { type: 'colfd', fixed: 'left', field: 'index', title: '序号', width: '50', align: 'center' },
          { type: 'imgupload', fixed: 'left', field: 'image', title: '图片', width: '65', align: 'center' },
          { type: 'colfdedit', fixed: 'left', field: 'sku', title: '规格型号（sku）', width: '280', align: 'left', edit: true },
          {
            type: 'group', align: 'center', title: '属性信息', children: [
              { type: 'ipt', field: 'attribute_id_1', title: '材质', width: '120', list: data.czlist },
              { type: 'sel', field: 'attribute_id_2', title: '协议', width: '120', list: data.xylist },
              { type: 'sel', field: 'attribute_id_3', title: '速率', width: '120', list: data.sllist },
              { type: 'sel', field: 'attribute_id_4', title: '包装', width: '120', list: data.bzlist },
              { type: 'sel', field: 'attribute_id_5', title: '安规', width: '120', list: data.aglist },
              { type: 'ipt', field: 'attribute_id_6', title: '接口', width: '120', list: data.jklist },
              { type: 'ipt', field: 'attribute_id_7', title: '尺码/数量/长度', width: '120', list: data.cclist },
              { type: 'sel', field: 'attribute_id_8', title: '颜色', width: '120', list: data.yslist },
              { type: 'ipt', field: 'attribute_id_9', title: '功能/版本/容量', width: '120', list: data.gnlist },
              { type: 'ipt', field: 'attribute_id_10', title: '输出接口', width: '120', list: data.sclist },
            ]
          },
          { type: 'cboxq', field: 'fast', title: '是否211型号', width: '140', align: 'center' },
          { type: 'cboxq_1', field: 'is_war_for_price', title: '是否价格战产品', width: '140', align: 'center' },
          { type: 'selout', field: 'form_buy', title: '物料属性', width: '120', align: 'left', list: data.mtlist },
          { type: 'selout_1', field: 'supply_chain', title: '供应链', width: '100', align: 'left', list: data.splist },
          { type: 'colfdedit_69', field: 'FBARCODE', title: '69码', width: '100', align: 'left', edit: true },
          { type: 'selmhout-allow', field: 'supplier', title: '默认供应商', width: '140', align: 'left', list: data.dsplist },
          { type: 'colfdedit-allow-price', field: 'purchase_price', title: '采购价格', width: '120', align: 'left', edit: true },
          { type: 'selmhout', field: 'FUseOrgId', title: '默认供应组织', width: '140', align: 'left', list: data.dspzlist },
          // { type: 'selmhout-allow', field: 'supplier', title: '默认供应商', width: '140', align: 'left', list: data.dsplist, dislist: data.supplierdislist },
          // { type: 'colfdedit-allow-price', field: 'purchase_price', title: '采购价格', width: '120', align: 'left', edit: true, dislist: data.pricedislist },
          // { type: 'selmhout', field: 'FUseOrgId', title: '默认供应组织', width: '140', align: 'left', list: data.dspzlist, dislist: data.orgdislist },
          { type: 'switch', field: 'status', title: 'SKU状态', width: '120', align: 'center' },
          { type: 'col', field: 'F_PAEZ_Combo2', title: '促销类型', width: '120', align: 'left' },
          {
            type: 'group', align: 'center', title: '价格信息', children: [
              { type: 'col', field: 'factory_price', title: '出厂价（TCO成本）', width: '130' },
              { type: 'col', field: 'agent_price', title: '代理价(￥)', width: '80' },
              { type: 'ipt_num', field: 'agent_special_offer', title: '代理特价(￥)', width: '110' },
              { type: 'col', field: 'agency_price_diff', title: '代理价差额(￥)', width: '110' },
              { type: 'col', field: 'partner_gross_margin', title: '渠道毛利率', width: '80' },
              { type: 'col', field: 'retail_price', title: '零售指导价(￥)', width: '110' },
              { type: 'ipt_num', field: 'retail_special_offer', title: '零售特价(￥)', width: '110' },
              { type: 'col', field: 'retail_price_diff', title: '零售价差额(￥)', width: '110' },
              { type: 'col', field: 'b2c_gross_margin', title: 'B2C毛利率', width: '80' },
              { type: 'col', field: 'dealer_gross_margin', title: '经销商毛利率', width: '100' },
              { type: 'col', field: 'minimum_activity_price', title: '最低活动价', width: '80' },
              { type: 'col', field: 'overseas_retail_price', title: '海外零售指导价($)', width: '130' },
              { type: 'col', field: 'overseas_minimum_activity_price', title: '海外零售最低活动价($)', width: '150' },
              { type: 'date', field: 'discount_begin_time', title: '特价开始时间', width: '180' },
              { type: 'date', field: 'discount_end_time', title: '特价结束时间', width: '180' },
            ]
          },
          { type: 'colfdedit-allow', field: 'material_total_price', title: '物料成本价', width: '120', align: 'center', },
          {
            type: 'group-allow', align: 'center', title: '成本构成', children: [
              { type: 'col', field: 'clinker_cost', title: '结构本体', width: '80' },
              { type: 'col', field: 'metal_cost', title: '电子', width: '80' },
              { type: 'col', field: 'electron_cost', title: '电源', width: '80' },
              { type: 'col', field: 'wire_cost', title: '线材', width: '80' },
              { type: 'col', field: 'accessories_cost', title: '配料/配件', width: '100' },
              { type: 'col', field: 'packing_cost', title: '包材', width: '80' },
              { type: 'col', field: 'process_cost', title: '加工费', width: '80' },
              { type: 'col', field: 'other_cost', title: '硬盘/运费其他', width: '120' },
            ]
          },
          { type: 'col', field: 'moq', title: 'MOQ', width: '100', align: 'center' },
          {
            type: 'group', align: 'center', title: 'sku尺寸重量信息mm/g', children: [
              { type: 'col', field: 'FLENGTH', title: '长', width: '80', align: 'center' },
              { type: 'col', field: 'FWIDTH', title: '宽', width: '80', align: 'center' },
              { type: 'col', field: 'FHEIGHT', title: '高', width: '80', align: 'center' },
              { type: 'col', field: 'FNETWEIGHT', title: '重量', width: '80', align: 'center' },
            ]
          },
          {
            type: 'group_1', align: 'center', title: '包装信息mm/g', children: [
              { type: 'col', field: 'packing', title: '包装方式', width: '80', align: 'center' },
              { type: 'col', field: 'FPACKAGE1', title: '包装版本名称', width: '80', align: 'center' },
              { type: 'col', field: 'FLENGTHP1', title: '包装长', width: '80', align: 'center' },
              { type: 'col', field: 'FWIDTHP1', title: '包装宽', width: '80', align: 'center' },
              { type: 'col', field: 'FHEIGHTP1', title: '包装高', width: '80', align: 'center' },
              { type: 'col', field: 'FNETWEIGHTP1', title: '包装重量', width: '80', align: 'center' },
              { type: 'col', field: 'FQtyC1', title: '数量', width: '80', align: 'center' },
              { type: 'img', field: 'package_img', title: '包装图', width: '80', align: 'center' },
            ]
          },
          {
            type: 'group_2', align: 'center', title: '装箱信息(mm/Kg)', children: [
              { type: 'col', field: 'FLENGTHC1', title: '装箱长', width: '80', align: 'center' },
              { type: 'col', field: 'FWIDTHC1', title: '装箱宽', width: '80', align: 'center' },
              { type: 'col', field: 'FHEIGHTC1', title: '装箱高', width: '80', align: 'center' },
              { type: 'col', field: 'FNETWEIGHTC1', title: '装箱净重', width: '80', align: 'center' },
              { type: 'col', field: 'FGROSSWEIGHTC1', title: '装箱毛重', width: '80', align: 'center' },
            ]
          },
          {
            type: 'group_3', align: 'center', title: '报关信息', children: [
              { type: 'ipt', field: 'customs_cn', title: '中文报关名', width: '110', align: 'center' },
              { type: 'ipt', field: 'customs_en', title: '英文报关名', width: '110', align: 'center' },
              { type: 'ipt_num', field: 'import_unit_price', title: '进口申报单价', width: '110', align: 'center' },
              { type: 'ipt_num', field: 'customs_unit_price', title: ' 出口报关单价', width: '120', align: 'center' }
              ,
              { type: 'ipt', field: 'customs_code', title: '海关HS编码', width: '100', align: 'center' },
              { type: 'selout_2', field: 'special_attr', title: '特殊属性', width: '120', align: 'center', list: data.speList },
              // { type: 'selout_3', field: 'supplier_invoicing_unit', title: '报关/开票单位', width: '140', align: 'center', list: data.supList },
              { type: 'ipt', field: 'use_type', title: '用途', width: '80', align: 'center' },
              { type: 'ipt', field: 'inland_delivered', title: '境内货源地', width: '100', align: 'center' },
            ]
          },
          { type: 'col', field: 'erp_create_time', title: '首批入库时间', width: '130', align: 'center' },
          { type: 'col_1', field: 'update_time', title: '上次更新时间', width: '130', align: 'center' },
        ]
        data.listHeader.reverse()
        data.listHeader.forEach(el => {
          if (el.children) {
            el.children.reverse()
          }
        });
      })
      // console.log('route -->',route.currentRoute.value.meta.permission)
      // 语言为英文 禁用 属性信息之外的所有字段
      data.isDisabled = store.state.user.language.id == 1 ? false : true
      // console.log('data.isDisabled -> 是否禁用',data.isDisabled)
    })
    onActivated(() => {
      data.headerIndex = data.headerIndex + 1
    })
    // 获取实例
    const { proxy } = getCurrentInstance()
    // 创建实例
    let store = useStore()
    let getDom = ref(null)
    let route = useRouter()
    // 变量
    let data = reactive({
      isDisabled: false,
      cdn: store.state.user.cdn,
      listHeader: [],
      cusTitle: '批量编辑',
      list: [
        {
          index: 1,
          sku: '',
          F_PAEZ_Combo2: '',
          fast: 0,
          is_war_for_price: 0,
          form_buy: null,
          supply_chain: '',
          FBARCODE: '',
          supplier: '',
          FUseOrgId: '',
          purchase_price: null,
          cover: '',
          image: '',
          status: 1,
          attribute_id_1: '',
          attribute_id_2: '',
          attribute_id_3: '',
          attribute_id_4: '',
          attribute_id_5: '',
          attribute_id_6: '',
          attribute_id_7: '',
          attribute_id_8: '',
          attribute_id_9: '',
          attribute_id_10: '',
          discount_begin_time: '',
          discount_end_time: '',
          FNumber: '',
          agent_special_offer: '',
          retail_special_offer: '',
          factory_price: '',
          retail_price: '',
          minimum_activity_price: '',
          overseas_retail_price: '',
          overseas_minimum_activity_price: '',
          customs_cn: '',
          customs_en: '',
          import_unit_price: '',
          customs_unit_price: '',
          customs_code: '',
          special_attr: null,
          // supplier_invoicing_unit: null,
          use_type: '',
          inland_delivered: ''
        }
      ],
      outList: [
        {
          sku: [{
            sku: '',
            F_PAEZ_Combo2: '',
            fast: null,
            is_war_for_price: null,
            form_buy: null,
            supply_chain: '',
            FBARCODE: '',
            supplier: '',
            FUseOrgId: '',
            purchase_price: null,
            FNumber: '',
            discount_begin_time: '',
            discount_end_time: '',
            agent_special_offer: '',
            retail_special_offer: '',
            factory_price: '',
            retail_price: '',
            minimum_activity_price: '',
            overseas_retail_price: '',
            overseas_minimum_activity_price: '',

            customs_cn: '',
            customs_en: '',
            import_unit_price: '',
            customs_unit_price: '',
            customs_code: '',
            special_attr: null,
            // supplier_invoicing_unit: null,
            use_type: '',
            inland_delivered: ''
          }],
          sku_params: [{
            cover: '',
            image: '',
            status: 1,
            attribute_id_1: '',
            attribute_id_2: '',
            attribute_id_3: '',
            attribute_id_4: '',
            attribute_id_5: '',
            attribute_id_6: '',
            attribute_id_7: '',
            attribute_id_8: '',
            attribute_id_9: '',
            attribute_id_10: '',
            // customs_cn: '',
            // customs_en: '',
            // import_unit_price: '',
            // customs_unit_price: '',
            // customs_code: '',
            // special_attr: null,
            // supplier_invoicing_unit: null,
            // use_type: '',
            // inland_delivered: ''
          }],
        }
      ],
      selectList: [],
      page: 1,
      size: 10,
      isBatchEditShow: false,
      czlist: [[]],
      xylist: [[]],
      sllist: [[]],
      bzlist: [[]],
      aglist: [[]],
      jklist: [[]],
      cclist: [[]],
      yslist: [[]],
      gnlist: [[]],
      sclist: [[]],
      mtlist: [{ id: 1, name: '自制' }, { id: 2, name: '委外' }, { id: 3, name: '外购' }],
      splist: [{ id: 1, name: '深圳' }, { id: 2, name: '东莞' }, { id: 3, name: '长沙' }],
      speList: [{ id: 1, name: '含电' }, { id: 2, name: '纯电' }, { id: 3, name: '液体' }, { id: 4, name: '粉末' }, { id: 5, name: '膏体' }, { id: 6, name: '带磁' }, { id: 7, name: '纺织品' }, { id: 8, name: '无' }],
      supList: [{ id: 1, name: '个' }, { id: 2, name: '台' }, { id: 3, name: '条' }],
      dsplist: [[]],
      dspzlist: [[]],
      // pricedislist: [false],
      // orgdislist: [true],
      // supplierdislist: [true],
      upLoadUrl: process.env.VUE_APP_API_BASEURL + 'admin/v1/product/upload',
      showImgUrl: '',
      upLoadQuery: {
        type: 'images',
        language_id: store.state.user.language.id || 1
      },
      top: '',
      attributeIdList: [],
      muleditSelList: [],
      // muleditAttr: [
      //   { id: '1', name: '是否211型号', type: 'sel', list: [{ id: 0, name: '否' }, { id: 1, name: '是' }] },
      //   { id: '2', name: '是否价格战产品', type: 'sel', list: [{ id: 0, name: '否' }, { id: 1, name: '是' }] },
      //   { id: '3', name: '物料属性', type: 'sel', list: [{ id: 1, name: '自制' }, { id: 2, name: '委外' }, { id: 3, name: '外购' }] },
      //   { id: '4', name: '供应链', type: 'sel', list: [{ id: 1, name: '深圳' }, { id: 2, name: '东莞' }, { id: 3, name: '长沙' }] },
      //   { id: '5', name: '默认供应商', type: 'selmh', list: [], url: 'v1/product/get_supplier_list' },
      //   { id: '6', name: '采购价格', type: 'ipt' },
      //   { id: '7', name: '默认供应组织', type: 'selmh', list: [], url: 'v1/product/get_org_list' },
      //   { id: '8', name: 'SKU状态', type: 'sel', list: [{ id: 0, name: '关' }, { id: 1, name: '开' }] },
      //   // {
      //   //   id: '9', name: '材质', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //   //     language_id: store.state.user.language.id || 1,
      //   //     page: 1,
      //   //     size: 5,
      //   //     value: '',
      //   //     attribute_id: 1
      //   //   }
      //   // },
      //   {
      //     id: '9', name: '材质', type: 'ipt'
      //   },
      //   {
      //     id: '10', name: '协议', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 2
      //     }
      //   },
      //   {
      //     id: '11', name: '速率', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 3
      //     }
      //   },
      //   {
      //     id: '12', name: '包装', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 4
      //     }
      //   },
      //   {
      //     id: '13', name: '安规', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 5
      //     }
      //   },
      //   // {
      //   //   id: '14', name: '接口', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //   //     language_id: store.state.user.language.id || 1,
      //   //     page: 1,
      //   //     size: 5,
      //   //     value: '',
      //   //     attribute_id: 6
      //   //   }
      //   // },
      //   {
      //     id: '14', name: '接口', type: 'ipt'
      //   },
      //   // {
      //   //   id: '15', name: '尺码/数量/长度', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //   //     language_id: store.state.user.language.id || 1,
      //   //     page: 1,
      //   //     size: 5,
      //   //     value: '',
      //   //     attribute_id: 7
      //   //   }
      //   // },
      //   {
      //     id: '15', name: '尺码/数量/长度', type: 'ipt'
      //   },
      //   {
      //     id: '16', name: '颜色', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 8
      //     }
      //   },
      //   // {
      //   //   id: '17', name: '功能/版本', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //   //     language_id: store.state.user.language.id || 1,
      //   //     page: 1,
      //   //     size: 5,
      //   //     value: '',
      //   //     attribute_id: 9
      //   //   }
      //   // },
      //   {
      //     id: '17', name: '功能/版本', type: 'ipt'
      //   },
      //   // {
      //   //   id: '18', name: '输出接口', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //   //     language_id: store.state.user.language.id || 1,
      //   //     page: 1,
      //   //     size: 5,
      //   //     value: '',
      //   //     attribute_id: 10
      //   //   }
      //   // },
      //   {
      //     id: '18', name: '输出接口', type: 'ipt'
      //   },
      // ],
      // muleditAttrEn:[
      //   {
      //     id: '9', name: '材质', type: 'ipt'
      //   },
      //   {
      //     id: '10', name: '协议', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 2
      //     }
      //   },
      //   {
      //     id: '11', name: '速率', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 3
      //     }
      //   },
      //   {
      //     id: '12', name: '包装', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 4
      //     }
      //   },
      //   {
      //     id: '13', name: '安规', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 5
      //     }
      //   },
      //   {
      //     id: '14', name: '接口', type: 'ipt'
      //   },
      //   {
      //     id: '15', name: '尺码/数量/长度', type: 'ipt'
      //   },
      //   {
      //     id: '16', name: '颜色', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
      //       language_id: store.state.user.language.id || 1,
      //       page: 1,
      //       size: 5,
      //       value: '',
      //       attribute_id: 8
      //     }
      //   },
      //   {
      //     id: '17', name: '功能/版本', type: 'ipt'
      //   },
      //   {
      //     id: '18', name: '输出接口', type: 'ipt'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
      //   }
      // ],
      muleditAttrCom: store.state.user.language.id == 1 ? [
        { id: '1', name: '是否211型号', type: 'sel', list: [{ id: 0, name: '否' }, { id: 1, name: '是' }] },
        { id: '2', name: '是否价格战产品', type: 'sel', list: [{ id: 0, name: '否' }, { id: 1, name: '是' }] },
        { id: '3', name: '物料属性', type: 'sel', list: [{ id: 1, name: '自制' }, { id: 2, name: '委外' }, { id: 3, name: '外购' }] },
        { id: '4', name: '供应链', type: 'sel', list: [{ id: 1, name: '深圳' }, { id: 2, name: '东莞' }, { id: 3, name: '长沙' }] },
        { id: '5', name: '默认供应商', type: 'selmh', list: [], url: 'v1/product/get_supplier_list' },
        { id: '6', name: '采购价格', type: 'ipt' },
        { id: '7', name: '默认供应组织', type: 'selmh', list: [], url: 'v1/product/get_org_list' },
        { id: '8', name: 'SKU状态', type: 'sel', list: [{ id: 0, name: '关' }, { id: 1, name: '开' }] },
        // {
        //   id: '9', name: '材质', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
        //     language_id: store.state.user.language.id || 1,
        //     page: 1,
        //     size: 5,
        //     value: '',
        //     attribute_id: 1
        //   }
        // },
        {
          id: '9', name: '材质', type: 'ipt'
        },
        {
          id: '10', name: '协议', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 2
          }
        },
        {
          id: '11', name: '速率', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 3
          }
        },
        {
          id: '12', name: '包装', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 4
          }
        },
        {
          id: '13', name: '安规', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 5
          }
        },
        // {
        //   id: '14', name: '接口', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
        //     language_id: store.state.user.language.id || 1,
        //     page: 1,
        //     size: 5,
        //     value: '',
        //     attribute_id: 6
        //   }
        // },
        {
          id: '14', name: '接口', type: 'ipt'
        },
        // {
        //   id: '15', name: '尺码/数量/长度', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
        //     language_id: store.state.user.language.id || 1,
        //     page: 1,
        //     size: 5,
        //     value: '',
        //     attribute_id: 7
        //   }
        // },
        {
          id: '15', name: '尺码/数量/长度', type: 'ipt'
        },
        {
          id: '16', name: '颜色', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 8
          }
        },
        // {
        //   id: '17', name: '功能/版本', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
        //     language_id: store.state.user.language.id || 1,
        //     page: 1,
        //     size: 5,
        //     value: '',
        //     attribute_id: 9
        //   }
        // },
        {
          id: '17', name: '功能/版本/容量', type: 'ipt'
        },
        // {
        //   id: '18', name: '输出接口', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
        //     language_id: store.state.user.language.id || 1,
        //     page: 1,
        //     size: 5,
        //     value: '',
        //     attribute_id: 10
        //   }
        // },
        {
          id: '18', name: '输出接口', type: 'ipt'
        },
        { id: '9', name: '特价开始时间', field: 'discount_begin_time', type: 'date' },
        { id: '10', name: '特价结束时间', field: 'discount_end_time', type: 'date' }
      ] : [
        {
          id: '9', name: '材质', type: 'ipt'
        },
        {
          id: '10', name: '协议', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 2
          }
        },
        {
          id: '11', name: '速率', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 3
          }
        },
        {
          id: '12', name: '包装', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 4
          }
        },
        {
          id: '13', name: '安规', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 5
          }
        },
        {
          id: '14', name: '接口', type: 'ipt'
        },
        {
          id: '15', name: '尺码/数量/长度', type: 'ipt'
        },
        {
          id: '16', name: '颜色', type: 'selmhsx', list: [], url: 'v1/attr_value', query: {
            language_id: store.state.user.language.id || 1,
            page: 1,
            size: 5,
            value: '',
            attribute_id: 8
          }
        },
        {
          id: '17', name: '功能/版本/容量', type: 'ipt'
        },
        {
          id: '18', name: '输出接口', type: 'ipt'
        },
        { id: '9', name: '特价开始时间', field: 'discount_begin_time', type: 'date' },
        { id: '10', name: '特价结束时间', field: 'discount_end_time', type: 'date' }
      ],
      isRefresh: 1,
      headerIndex: 1,
      valiremovedata: {},
      editSpuId: '',
      delList: [],
      requestUrl: ''
    })
    // 输入框限
    const countCom = (value, key, index) => {
      const regex = /^\d+(\.\d{0,2})?$/; // 匹配只包含最多2位小数位的数字
      if (!regex.test(value)) {
        data.list[index][key] = value.slice(0, -1); // 如果不符合要求，就把最后一个字符（即非法字符）去掉
      }
    }
    // 输入框限
    const countComOther = (value, key, index) => {
      const regex = /^\d+(\.\d{0,6})?$/; // 匹配只包含最多2位小数位的数字
      if (!regex.test(value)) {
        data.list[index][key] = value.slice(0, -1); // 如果不符合要求，就把最后一个字符（即非法字符）去掉
      }
    }
    const countBlurOther = (value, key, index) => {
      if (data.list[index][key] != "") {
        data.list[index][key] = data.list[index][key] * 1
      }
    }
    // 失去焦点
    const countBlur = (value, key, index) => {
      // current date
      const date = new Date();
      const year = date.getFullYear();
      const month = ('0' + (date.getMonth() + 1)).slice(-2);
      const day = ('0' + date.getDate()).slice(-2);
      const dateString = `${year}-${month}-${day}`;
      // 把最后一个字符（.||0）从输入框中去掉,为0的时候 = 空
      if (key != 'discount_begin_time' && key != 'discount_end_time') {
        data.list[index][key] = data.list[index][key] * 1
        data.list[index][key] = data.list[index][key] || ''
      }
      // 代理价计算
      if (key == 'agent_special_offer' || key == 'discount_begin_time' || key == 'discount_end_time') {
        console.log('输入的数字的key:' + key)
        console.log('输入的数字:' + data.list[index][key])
        console.log('参与计算字段:' + 'agent_price - agent_special_offer = agency_price_diff' + '计算出：代理价差额')
        // 判空 - 参与计算字段不存在、或为空就不计算
        let isNullCe = true;
        let isNullMl = true;
        // 差额 - 毛利 集合
        let celist = ['agent_price', 'agent_special_offer'];
        let mllist = ['agent_price', 'factory_price', 'agent_special_offer']
        // 判空 不等于0
        for (const it of celist) {
          // console.log('it:' + data.list[index][it])
          // console.log('it:' + data.list[index][it] != '')
          // console.log('it:' + data.list[index][it] > 0)
          isNullCe = data.list[index][it] && data.list[index][it] > 0 ? true : false
          if (!isNullCe) {
            break
          }
        }
        for (const it of mllist) {
          console.log(it + ' = it:' + data.list[index][it])
          console.log(it + ' = it:' + data.list[index][it] != '')
          console.log(it + ' = it:' + data.list[index][it] > 0)
          isNullMl = data.list[index][it] != '' && data.list[index][it] > 0 ? true : false
          if (!isNullMl) {
            break
          }
        }
        console.log('isNullCe', isNullCe)
        // 计算差额
        if (isNullCe) {
          data.list[index].agency_price_diff = new Decimal(data.list[index].agent_price).sub(new Decimal(data.list[index].agent_special_offer))
        }
        if (!data.list[index].agent_special_offer) {
          if (data.list[index].agent_price) {
            data.list[index].agency_price_diff = data.list[index].agent_price
          }
        }
        // 判断计算毛利使用 特价 还是 代理特价  当前时间 < 特价过期时间=(discount_end_time)
        if (data.list[index].discount_end_time && data.list[index].discount_begin_time && data.list[index].agent_special_offer) {
          const newDate = new Date(dateString);
          const startDate = new Date(data.list[index].discount_begin_time);
          const endDate = new Date(data.list[index].discount_end_time);
          // 计算毛利率 过期
          if (newDate >= startDate && newDate <= endDate) {
            // 没过期
            console.log('inner mei')
            console.log('inner mei isNullMl', isNullMl)
            if (isNullMl) {
              data.list[index].partner_gross_margin = (new Decimal(data.list[index].agent_special_offer).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].agent_special_offer)).toDP(6, 2).toString()
              data.list[index].partner_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].partner_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
            }
          } else {
            console.log('inner guo')
            console.log('inner guo isNullMl', isNullMl)
            if (isNullMl) {
              data.list[index].partner_gross_margin = (new Decimal(data.list[index].agent_price).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].agent_price)).toDP(6, 2).toString()
              data.list[index].partner_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].partner_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
            }
          }
        } else {
          if (isNullMl) {
            data.list[index].partner_gross_margin = (new Decimal(data.list[index].agent_price).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].agent_price)).toDP(6, 2).toString()
            data.list[index].partner_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].partner_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
          }
          if (!data.list[index].agent_special_offer) {
            data.list[index].partner_gross_margin = (new Decimal(data.list[index].agent_price).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].agent_price)).toDP(6, 2).toString()
            data.list[index].partner_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].partner_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
          }
        }
      }
      // 零售价计算
      if (key == 'retail_special_offer' || key == 'discount_begin_time' || key == 'discount_end_time') {
        console.log('输入的数字的key:' + key)
        console.log('输入的数字:' + data.list[index][key])
        console.log('参与计算字段:' + 'retailprice - retail_special_offer = retail_price_diff' + '计算出：代理价差额')
        // 判空 - 参与计算字段不存在、或为空就不计算
        let isNullCe = true;
        let isNullMl = true;
        // 差额 - 毛利 集合
        let celist = ['retail_price', 'retail_special_offer'];
        let mllist = ['retail_price', 'factory_price', 'retail_special_offer']
        // 判空 不等于0
        for (const it of celist) {
          console.log(it + ' = it:' + data.list[index][it])
          console.log(it + ' = it:' + data.list[index][it] != '')
          console.log(it + ' = it:' + data.list[index][it] > 0)
          isNullCe = data.list[index][it] && data.list[index][it] > 0 ? true : false
          if (!isNullCe) {
            break
          }
        }
        for (const it of mllist) {
          isNullMl = data.list[index][it] && data.list[index][it] > 0 ? true : false
          if (!isNullMl) {
            break
          }
        }
        // 计算差额
        console.log('零售特价:isNullCe=' + isNullCe)
        if (isNullCe) {
          console.log('零售特价:data.list[index].retail_price = ' + data.list[index].retail_price)
          console.log('零售特价:data.list[index].retail_special_offer = ' + data.list[index].retail_special_offer)
          data.list[index].retail_price_diff = new Decimal(data.list[index].retail_price).sub(new Decimal(data.list[index].retail_special_offer))
        }
        if (!data.list[index].retail_special_offer) {
          if (data.list[index].retail_price) {
            data.list[index].retail_price_diff = data.list[index].retail_price
          }
        }

        // 判断计算毛利使用 特价 还是 代理特价  当前时间 < 特价过期时间=(discount_end_time)
        if (data.list[index].discount_end_time && data.list[index].discount_begin_time && data.list[index].retail_special_offer) {
          const newDate = new Date(dateString);
          const startDate = new Date(data.list[index].discount_begin_time);
          const endDate = new Date(data.list[index].discount_end_time);
          // 计算毛利率 过期
          if (newDate >= startDate && newDate <= endDate) {
            // 没过期
            if (isNullMl) {
              data.list[index].b2c_gross_margin = (new Decimal(data.list[index].retail_special_offer).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].retail_special_offer)).toDP(6, 2).toString()
              data.list[index].b2c_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].b2c_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
            }
          } else {
            if (isNullMl) {
              data.list[index].b2c_gross_margin = (new Decimal(data.list[index].retail_price).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].retail_price)).toDP(6, 2).toString()
              data.list[index].b2c_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].b2c_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
            }
          }
        } else {
          if (isNullMl) {
            data.list[index].b2c_gross_margin = (new Decimal(data.list[index].retail_price).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].retail_price)).toDP(6, 2).toString()
            data.list[index].b2c_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].b2c_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
          }
          if (!data.list[index].retail_special_offer) {
            data.list[index].b2c_gross_margin = (new Decimal(data.list[index].retail_price).sub(new Decimal(data.list[index].factory_price))).div(new Decimal(data.list[index].retail_price)).toDP(6, 2).toString()
            data.list[index].b2c_gross_margin = Math.ceil(parseFloat(new Decimal(data.list[index].b2c_gross_margin).mul(new Decimal(100)).toString()) * 100) / 100 + '%'
          }
        }
      }
    }
    // 禁止行显示红色
    const rowClassName = ({ row }) => {
      if (row.status == 0) {
        return 'row-red'
      }
      return null
    }
    // 校验
    const validRules = ref({
      form_buy: [
        { required: true, message: '物料属性为必填' }
      ],
      // sku: [
      //   { required: true, message: '规格型号（sku）为必填' },
      //   {
      //     validator ({ cellValue, row, rowIndex }) {
      //       if (cellValue && !(/^[a-zA-Z0-9]+([.-]*[a-zA-Z0-9])*$/.test(cellValue))) {
      //         return new Error('sku由-、.、数字、字母组成，开始、结束必须数字或字母')
      //       }
      //     }
      //   }
      // ],
      purchase_price: [
        { required: false, message: '只能输入数字,小数点前9位、后6位' },
        {
          validator ({ cellValue, row, rowIndex }) {
            // if (!cellValue || !(/^\d{0,9}(\.\d{1,6})?$/.test(cellValue))) {
            if (cellValue && !(/^\d{0,8}(\.\d{1,6})?$/.test(cellValue))) {
              return new Error('只能输入数字,小数点前9位、后6位')
            }
          }
        }
      ],
      FBARCODE: [
        {
          validator ({ cellValue, row, rowIndex }) {
            if (cellValue && !(/^[0-9]*$/.test(cellValue))) {
              return new Error('只能输入数字')
            }
          }
        }
      ]
    })
    // 获取选中的行
    const getSelectRow = (selectList) => {
      data.selectList = selectList.records
    }
    // 添加行
    const insertEvent = async () => {
      const row = -1
      const $table = getDom.value
      const addRow = {
        index: null,
        sku: '',
        F_PAEZ_Combo2: '',
        fast: 0,
        is_war_for_price: 0,
        form_buy: null,
        supply_chain: '',
        FBARCODE: '',
        supplier: '',
        FUseOrgId: '',
        purchase_price: null,
        cover: '',
        image: '',
        status: 1,
        attribute_id_1: '',
        attribute_id_2: '',
        attribute_id_3: '',
        attribute_id_4: '',
        attribute_id_5: '',
        attribute_id_6: '',
        attribute_id_7: '',
        attribute_id_8: '',
        attribute_id_9: '',
        attribute_id_10: '',
        discount_begin_time: '',
        discount_end_time: '',
        FNumber: '',

        customs_cn: '',
        customs_en: '',
        import_unit_price: '',
        customs_unit_price: '',
        customs_code: '',
        special_attr: null,
        // supplier_invoicing_unit: null,
        use_type: '',
        inland_delivered: ''
      }
      let arr = ['cz', 'xy', 'sl', 'bz', 'ag', 'jk', 'cc', 'ys', 'gn', 'sc', 'dsp', 'dspz']
      arr.forEach(el => {
        data[el + 'list'].push([])
      });

      // let disarr = ['supplier', 'org']
      // disarr.forEach(ele => {
      //   data[ele + 'dislist'].push(true)
      // });
      addRow.index = data.list.length + 1
      data.list.push(JSON.parse(JSON.stringify(addRow)))
      const { row: newRow } = await $table.insertAt(JSON.parse(JSON.stringify(addRow)), row)
      await $table.setActiveCell(newRow, 'sku')
      await $table.loadData(data.list)
    }
    // 公共改变
    const changeMethods = (row, value, key) => {
      if (key == 'form_buy') {
        // row.FUseOrgId = ''
        // row.supplier = ''
        // row.purchase_price= null
        // if (value == 1) {
        //   data.pricedislist[row.index - 1] = true
        //   data.orgdislist[row.index - 1] = false
        //   data.supplierdislist[row.index - 1] = true
        // } else {
        //   data.pricedislist[row.index - 1] = false
        //   data.orgdislist[row.index - 1] = true
        //   data.supplierdislist[row.index - 1] = false
        // }
      }
    }
    // 删除选中行
    const removeCheckRow = async () => {
      if (data.selectList.length > 0) {
        const $table = getDom.value
        const type = await VXETable.modal.confirm('您确定要删除已选中数据?')
        if (type == 'confirm') {
          $table.removeCheckboxRow()
        }
        // 判断sku id是否存在 
        data.selectList.forEach(el => {
          if (el.product_sku_id) {
            data.delList.push(el.product_sku_id)
          }
        });

        // 源数据删除
        $table.getRemoveRecords().forEach(el => {
          data.list = data.list.filter(it => it.index != el.index)
        });
        // 删除多源数组 - 大 -> 小
        let dellist = ['cz', 'xy', 'sl', 'bz', 'ag', 'jk', 'cc', 'ys', 'gn', 'sc', 'dsp', 'dspz']
        let disarr = ['supplier', 'org']
        $table.getRemoveRecords().reverse().forEach(el => {
          dellist.forEach(ele => {
            data[ele + 'list'].splice(el.index - 1, 1)
          });
          // disarr.forEach(ele => {
          //   data[ele + 'dislist'].splice(el.index - 1, 1)
          // });
        })
        // 重新计算序号
        data.list.forEach((el, ind) => {
          el.index = ind + 1
        });
      } else {
        proxy.$message({ type: 'error', message: '请选择需要删除的行!' })
      }
    }
    // 批量修改
    const multipleEdit = async () => {
      if (data.selectList.length > 0) {
        data.isBatchEditShow = true
      } else {
        proxy.$message({ type: 'error', message: '请选择需要修改的行!' })
      }
    }
    // 物料、生命周期 获取Name
    const getShowName = (val, list) => {
      if (val) {
        let templist = list.filter(it => it.id == val)
        if (templist.length > 0) {
          return templist[0].name
        } else {
          return ''
        }
      } else {
        return ''
      }
    }
    // 获取Name
    const getShowMh = (val, list) => {
      if (val) {
        let templist = list.filter(it => it.id == val)
        if (templist.length > 0) {
          return templist[0].value
        } else {
          return ''
        }
      } else {
        return ''
      }
    }
    // 供应商、供应组织获取Name
    const getShowMhName = (val, list) => {
      // console.log('list',list)
      if (val) {
        let templist = list.filter(it => it.id == val)
        if (templist.length > 0) {
          return templist[0].name
        } else {
          return ''
        }
      } else {
        return ''
      }
    }
    // 获取checkbox
    const getShowbox = (val) => {
      if (val) {
        return '是'
      } else {
        return '否'
      }
    }
    // 获取checkbox
    const getShowSwitch = (val) => {
      if (val == '1') {
        return '开'
      } else {
        return '关'
      }
    }
    // 批量修改返回
    const getBatchEditObj = (val) => {
      // console.log('批量修改返回',val)
      const $table = getDom.value
      data.listHeader.forEach(el => {
        if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal !== '默认供应组织' && val.selVal !== '采购价格' && val.selVal !== '默认供应商' && val.selVal !== '物料属性') {
          data.selectList.forEach(ele => {
            ele[el.field] = val.editContent
          });
          $table.loadData(data.list)
        }
        if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal == '物料属性') {
          data.selectList.forEach(ele => {
            if (ele[el.field] !== val.editContent) {
              ele[el.field] = val.editContent
              // ele.FUseOrgId = ''
              // ele.supplier = ''
              // ele.purchase_price = null
              // if (val.editContent == 1) {
              //   data.pricedislist[ele.index - 1] = true
              //   data.orgdislist[ele.index - 1] = false
              //   data.supplierdislist[ele.index - 1] = true
              // } else {
              //   data.pricedislist[ele.index - 1] = false
              //   data.orgdislist[ele.index - 1] = true
              //   data.supplierdislist[ele.index - 1] = false
              // }
            }
          });
          $table.loadData(data.list)
        }
        // console.log('val.editContent',val.editContent)
        // console.log('el.title',el.title)
        // console.log('el.title',val.selVal)
        if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal == '采购价格') {
          data.selectList.forEach(ele => {
            if (ele[el.field] !== val.editContent) {
              ele[el.field] = val.editContent
            }
          });
          $table.loadData(data.list)
        }
        if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal == '默认供应组织') {
          let beforeStr = 'dspz'
          data.selectList.forEach(ele => {
            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            ele[el.field] = val.editContent
          })
          $table.loadData(data.list)
        }
        if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal == '默认供应商') {
          let beforeStr = 'dsp'
          data.selectList.forEach(ele => {
            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            ele[el.field] = val.editContent
          })
          $table.loadData(data.list)
        }
        // if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal == '默认供应组织') {
        //   let beforeStr = 'dspz'
        //   let lock = false
        //   let locknull = true
        //   data.selectList.every(ele => {
        //     // 判断物料属性是否一致
        //     if (!ele.form_buy) {
        //       locknull = false
        //       proxy.$message.error('物料属性不能为空')
        //       return false
        //     }
        //   })
        //   if (locknull) {
        //     data.selectList.forEach(ele => {
        //       if (ele.form_buy == 1) {
        //         data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //         ele[el.field] = val.editContent
        //       } else {
        //         lock = true
        //       } 
        //     })
        //     if (lock) {
        //       proxy.$message.error('批量修改默认供应组织，所选择行物料属性必须为自制')
        //     }
        //     $table.loadData(data.list)
        //   }
        // }
        // if (!el.hasOwnProperty('children') && el.title == val.selVal && val.selVal == '默认供应商') {
        //   let beforeStr = 'dsp'
        //   let lock = false
        //   let locknull = true
        //   data.selectList.every(ele => {
        //     // 判断物料属性是否一致
        //     if (!ele.form_buy) {
        //       locknull = false
        //       proxy.$message.error('物料属性不能为空')
        //       return false
        //     }
        //   })
        //   if (locknull) {
        //     data.selectList.forEach(ele => {
        //       if (ele.form_buy == 2 || ele.form_buy == 3) {
        //         data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //         ele[el.field] = val.editContent
        //       } else {
        //         lock = true
        //       }
        //     })
        //     if (lock) {
        //       proxy.$message.error('批量修改默认供应商，所选择行物料属性必须为委外或外购')
        //     }
        //     $table.loadData(data.list)
        //   }
        // }
        // 属性 key 反过来拿值
        // if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '材质') {
        //   let beforeStr = 'cz'
        //   data.selectList.forEach(ele => {
        //     data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //     ele[el.children[9].field] = val.selMhlist[0].id
        //   })
        //   $table.loadData(data.list)
        // }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '材质') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[el.children[9].field] = val.editContent
          });
          $table.loadData(data.list)
        }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '协议') {
          let beforeStr = 'xy'
          data.selectList.forEach(ele => {

            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            if (val.selMhlist.length > 0) {
              ele[el.children[8].field] = val.selMhlist[0].id
            } else {
              ele[el.children[8].field] = ''
            }
          })
          $table.loadData(data.list)
        }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '速率') {
          let beforeStr = 'sl'
          data.selectList.forEach(ele => {
            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            if (val.selMhlist.length > 0) {
              ele[el.children[7].field] = val.selMhlist[0].id
            } else {
              ele[el.children[7].field] = ''
            }

          })
          $table.loadData(data.list)
        }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '包装') {
          let beforeStr = 'bz'
          data.selectList.forEach(ele => {
            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            if (val.selMhlist.length > 0) {
              ele[el.children[6].field] = val.selMhlist[0].id
            } else {
              ele[el.children[6].field] = ''
            }

          })
          $table.loadData(data.list)
        }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '安规') {
          let beforeStr = 'ag'
          data.selectList.forEach(ele => {
            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            if (val.selMhlist.length > 0) {
              ele[el.children[5].field] = val.selMhlist[0].id
            } else {
              ele[el.children[5].field] = ''
            }

          })
          $table.loadData(data.list)
        }
        // if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '接口') {
        //   let beforeStr = 'jk'
        //   data.selectList.forEach(ele => {
        //     data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //     ele[el.children[4].field] = val.selMhlist[0].id
        //   })
        //   $table.loadData(data.list)
        // }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '接口') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[el.children[4].field] = val.editContent
          });
          $table.loadData(data.list)
        }
        // if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '尺寸') {
        //   let beforeStr = 'cc'
        //   data.selectList.forEach(ele => {
        //     data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //     ele[el.children[3].field] = val.selMhlist[0].id
        //   })
        //   $table.loadData(data.list)
        // }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '尺码/数量/长度') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[el.children[3].field] = val.editContent
          });
          $table.loadData(data.list)
        }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '颜色') {
          let beforeStr = 'ys'
          data.selectList.forEach(ele => {
            data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
            if (val.selMhlist.length > 0) {
              ele[el.children[2].field] = val.selMhlist[0].id
            } else {
              ele[el.children[2].field] = ''
            }

          })
          $table.loadData(data.list)
        }
        // if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '功能/版本') {
        //   let beforeStr = 'gn'
        //   data.selectList.forEach(ele => {
        //     data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //     ele[el.children[1].field] = val.selMhlist[0].id
        //   })
        //   $table.loadData(data.list)
        // }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '功能/版本/容量') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[el.children[1].field] = val.editContent
          });
          $table.loadData(data.list)
        }
        // if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '输出接口') {
        //   let beforeStr = 'sc'
        //   data.selectList.forEach(ele => {
        //     data[beforeStr + 'list'][ele.index - 1] = val.selMhlist
        //     ele[el.children[0].field] = val.selMhlist[0].id
        //   })
        //   $table.loadData(data.list)
        // }
        if (el.hasOwnProperty('children') && el.title == '属性信息' && val.selVal == '输出接口') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[el.children[0].field] = val.editContent
          });
          $table.loadData(data.list)
        }
        //  { type: 'col', field: 'discount_begin_time', title: '特价开始时间', width: '100' },
        // { type: 'col', field: 'discount_end_time', title: '特价结束时间', width: '100' },
        if (el.hasOwnProperty('children') && el.title == '价格信息' && val.selVal == '特价开始时间') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[val.attrkey] = val.editContent
          });
          $table.loadData(data.list)
        }
        if (el.hasOwnProperty('children') && el.title == '价格信息' && val.selVal == '特价结束时间') {
          data.selectList.forEach(ele => {
            // 这里 id 当 string 字段用
            ele[val.attrkey] = val.editContent
          });
          $table.loadData(data.list)
        }
      });

    }
    // 上传成功
    const handleSuccess = (res, file, files, row) => {
      if (res.status == 200) {
        // row.image = store.state.user.cdn + res.data[0].r_path
        row.image = res.data[0].r_path
      }
    }
    // 上传限制
    const handleChange = () => {
      // console.log('up load check')
    }
    // 移入
    const entryCellShowImg = (e, row) => {
      data.showImgUrl = row.image
      row.showImg = true
      data.top = 'top:' + e.clientY + 'px'
    }
    // 移出
    const leaveCellBlurImg = (row) => {
      row.showImg = false
      data.showImgUrl = ''
    }
    // 获取基础数据
    const getReqData = () => {
      // 属性信息匹配集合
      proxy.$http.get('v1/attr/name_list', { language_id: store.state.user.language.id || 1 }).then(res => {
        if (res.status == 200) {
          data.attributeIdList = res.data
        }
      })
    }
    // 获取远程数据
    const getlist = (query, index, scope, typeT) => {
      let template = data.attributeIdList.filter(it => it.name == scope.column.title)
      let type = template[0].attribute_id
      let name = template[0].name
      let beforeStr = ''
      if (name == '材质') {
        beforeStr = 'cz'
      }
      if (name == '协议') {
        beforeStr = 'xy'
      }
      if (name == '速率') {
        beforeStr = 'sl'
      }
      if (name == '包装') {
        beforeStr = 'bz'
      }
      if (name == '安规') {
        beforeStr = 'ag'
      }
      if (name == '接口') {
        beforeStr = 'jk'
      }
      if (name == '尺寸') {
        beforeStr = 'cc'
      }
      if (name == '颜色') {
        beforeStr = 'ys'
      }
      if (name == '功能/版本/容量') {
        beforeStr = 'gn'
      }
      if (name == '输出接口') {
        beforeStr = 'sc'
      }
      let queryPara = {
        language_id: store.state.user.language.id || 1,
        page: 1,
        size: 5,
        value: query,
        attribute_id: type
      }
      if (typeT == 'focus') {
        if (!query) {
          proxy.$http.showLoading(false).get('v1/attr_value', queryPara).then(res => {
            if (res.status == 200) {
              data[beforeStr + 'list'][index] = res.data.data
            }
          })
        }
      }
      if (typeT == 'other') {
        proxy.$http.showLoading(false).get('v1/attr_value', queryPara).then(res => {
          if (res.status == 200) {
            data[beforeStr + 'list'][index] = res.data.data
          }
        })
      }
    }
    // 供应组织 | 供应商 模糊匹配
    const getComList = (query, index, scope) => {
      if (query) {
        let beforeStr = ''
        let queryComUrl = ''
        scope.column.title == '默认供应商' ? beforeStr = 'dsp' : false
        scope.column.title == '默认供应商' ? queryComUrl = 'v1/product/get_supplier_list' : false
        scope.column.title == '默认供应组织' ? beforeStr = 'dspz' : false
        scope.column.title == '默认供应组织' ? queryComUrl = 'v1/product/get_org_list' : false
        let queryPara = {
          page: 1,
          size: 5,
          value: query
        }
        proxy.$http.get(queryComUrl, queryPara).then(res => {
          if (res.status == 200) {
            data[beforeStr + 'list'][index] = res.data.data
          }
        })
      }
    }
    // 输入框 清除 空格
    const clearNull = (value, index, key) => {
      if (value && key !=='sku') {
        data.list[index][key] = value.replace(/\s/g, "")
        getDom.value.data[index][key] = value.replace(/\s/g, "")
      }
    }
    // 监听父级点击事件
    watch(() => props.clickEvent, (newVal, oldVal) => {
      if (newVal.indexOf('add') != -1) {
        insertEvent()
      }
      if (newVal.indexOf('del') != -1) {
        removeCheckRow()
      }
      if (newVal.indexOf('mul') != -1) {
        multipleEdit()
      }
    })
    // 监听表格值发生改变 - 转换存入输出结构
    watch(() => data.list, (v1, v2) => {
      // console.log('v1',v1)
      context.emit('transmitTableDate', { originData: v1, outData: data.outList, delList: data.delList, reqUrl: data.requestUrl })
    }, {
      deep: true
    })
    watch(() => props.notice, (v1, v2) => {
      data.headerIndex = data.headerIndex + 1
      // console.log('notice chenge',data.headerIndex)
    })
    watch(() => props.transmitData, (v1, v2) => {
      data.valiremovedata = v1
      data.list = v1.newSkuList
      // 删除多源数组 - 大 -> 小
      let dellist = ['cz', 'xy', 'sl', 'bz', 'ag', 'jk', 'cc', 'ys', 'gn', 'sc', 'dsp', 'dspz']
      data.valiremovedata.removeSkuList.reverse().forEach(el => {
        dellist.forEach(ele => {
          data[ele + 'list'].splice(el.index - 1, 1)
        });
      })
      getDom.value.loadData(data.list)
    })
    watch(() => props.editId, (v1, v2) => {
      data.editSpuId = v1.split('|')[0]
      // 编辑sku进入 获取spu下所有sku
      if (data.editSpuId) {
        proxy.$http.get('v1/product/' + data.editSpuId, { language_id: store.state.user.language.id || 1 }).then(res => {
          if (res.status == 200) {
            data.list = res.data
            // 多元集合
            let dellist = ['cz', 'xy', 'sl', 'bz', 'ag', 'jk', 'cc', 'ys', 'gn', 'sc', 'dsp', 'dspz']
            // 添加index - 给老数据添加index
            if (!data.list[0].index) {
              data.list.forEach((el, ind) => {
                el.index = ind + 1
              })
            }
            // 处理表格多维数组结构
            data.list.forEach((el, ind) => {
              dellist.forEach((ele, inde) => {
                if (ele == 'dsp' || ele == 'dspz') {
                  if (ele == 'dspz') {
                    data[ele + 'list'][ind] = el.org_list
                  }
                  if (ele == 'dsp') {
                    data[ele + 'list'][ind] = el.supplier_list
                  }
                } else {
                  data[ele + 'list'][ind] = el[`attribute_id_${inde + 1}_list`]
                }

              });
            });
            // console.log('供应组织 --> ',data.dsplist)
            // console.log('供应商 --> ',data.dspzlist)
            // 处理物料属性禁用
            // data.list.forEach((el, ind) => {
            //   if (el.form_buy) {
            //     if (el.form_buy == 1) {
            //       data.pricedislist[ind] = true
            //       data.supplierdislist[ind] = true
            //       data.orgdislist[ind] = false
            //     } else {
            //       data.pricedislist[ind] = false
            //       data.supplierdislist[ind] = false
            //       data.orgdislist[ind] = true
            //     }
            //   } else {
            //     data.pricedislist[ind] = false
            //     data.supplierdislist[ind] = true
            //     data.orgdislist[ind] = true
            //   }
            // })
            // 拼接请求接口 新增 - 编辑 sku
            data.requestUrl = 'v1/product/' + data.editSpuId
            // 获取表格信息
            data.headerIndex = data.headerIndex + 1
            console.log('data.list', data.list)
            getDom.value.loadData(data.list)
          }
        })
      }
    })
    return {
      data,
      props,
      getSelectRow,
      getDom,
      insertEvent,
      removeCheckRow,
      multipleEdit,
      getBatchEditObj,
      getShowbox,
      getShowSwitch,
      handleSuccess,
      handleChange,
      entryCellShowImg,
      leaveCellBlurImg,
      getReqData,
      getlist,
      getShowMh,
      getComList,
      getShowMhName,
      getShowName,
      changeMethods,
      validRules,
      clearNull,
      rowClassName,
      defaulImg,
      countCom,
      countComOther,
      countBlurOther,
      countBlur
    }
  }
})
</script>
<style scoped>
.table {
  padding: 0;
  width: 100%;
}
.title_box1 .title {
  margin: 0;
}
::v-deep(.el-upload-list--picture-card .el-upload-list__item) {
  margin-bottom: 0px !important;
  width: 40px !important;
  height: 40px !important;
}
::v-deep(.el-upload-list__item),
::v-deep(.vxe-body--row) {
  width: 40px !important;
  height: 50px !important;
  line-height: 40px !important;
}
::v-deep(.el-upload-list__item) {
  position: absolute;
}

::v-deep(.avatar) {
  width: 40px;
  height: 40px;
  padding-top: 5px;
  padding-bottom: 5px;
}
::v-deep(.el-icon-plus) {
  width: 40px;
  height: 40px;
  border-radius: 2px;
  line-height: 40px;
  border: 1px dashed rgba(0, 0, 0, 0.1);
}
.img-show {
  width: 150px;
  height: 150px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  overflow: hidden;
  z-index: 9;
  background-color: #fff;
  vertical-align: middle;
  margin-top: -60px;
  text-align: center;
}
.img-show img {
  z-index: 10;
  max-width: 150px;
  vertical-align: middle;
}
::v-deep(.el-select-dropdown) {
  z-index: 9997 !important;
}
::v-deep(.my-table .vxe-body--row.row-red) {
  color: red;
}
::v-deep(.my-table .vxe-body--row.row-default) {
  color: #606266 !important;
}
::v-deep(.el-date-editor.el-input) {
  width: 150px !important;
}
</style>