<!--添加基础资料-->
<template>
  <ContainerTit>
    <div slot="headr">
      <el-button v-if="!goods_id" :loding="loading" @click="AddTem">
        暂存
      </el-button>
      <el-button
        v-if="$route.name !== 'BaseDataDetail'"
        type="primary"
        :loading="loading"
        @click="submitGoods"
      >
        提交保存
      </el-button>
    </div>
    <div class="detail-tab-item" style="padding: 0 20px">
      <el-tabs v-model="page_tabs">
        <el-tab-pane label="商品信息" name="1"></el-tab-pane>
        <el-tab-pane
          :disabled="base_form.isShield === 4"
          label="经营屏蔽"
          name="2"
        ></el-tab-pane>
      </el-tabs>
    </div>
    <el-form
      ref="base_form"
      :model="base_form"
      label-width="120px"
      :rules="base_rules"
      size="small"
    >
      <div v-show="page_tabs === '1'">
        <div class="detail-tab-item">
          <div class="detail-tab-title clearfix">
            <span class="float_left">商品相册</span>
            <span style="font-size: 12px; font-weight: normal; color: #e6a23c">
              （温馨提示：建议上传尺寸375px*375px，格式：jpg,jpeg,png;
              大小：建议小于1M。）
            </span>
          </div>
          <div class="detail-tab-main">
            <el-form-item prop="images" label-width="20px">
              <UploadQiniu
                :limit="10"
                :file-list="img_list"
                @uploadSuccess="uploadSuccess"
                @imgSortChange="imgSortChange"
                @handleRemove="uploadRemove"
              />
            </el-form-item>
          </div>
        </div>
        <!--      基本信息-->
        <div class="detail-tab-item">
          <p class="detail-tab-title">基本信息</p>
          <div class="detail-tab-main">
            <el-row>
              <el-col :span="8">
                <el-form-item label="商品名称：" prop="title">
                  <el-input
                    v-model="base_form.title"
                    style="width: 240px"
                    placeholder="请输入商品名称"
                  ></el-input>
                </el-form-item>
                <el-form-item label="商品品牌：" prop="brandId">
                  <el-input
                    v-model="base_form.brandName"
                    readonly
                    style="width: 240px"
                    placeholder="请选择商品品牌"
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-search"
                      @click="sel_brand = true"
                    ></i>
                  </el-input>
                  <el-button
                    style="margin-left: 5px"
                    size="mini"
                    type="text"
                    @click="add_Brand = true"
                  >
                    【新建品牌】
                  </el-button>
                </el-form-item>
                <el-form-item label="商户：">
                  <el-select
                    v-if="!goods_id"
                    v-model="base_form.merchantId"
                    placeholder="选择商户"
                    style="width: 240px"
                    clearable
                  >
                    <el-option
                      v-for="(item, index) in sel_cities"
                      :key="index"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                  <el-input
                    v-else
                    v-model="base_form.merchantName"
                    style="width: 240px"
                    disabled
                  ></el-input>
                </el-form-item>
                <el-form-item
                  v-if="shelfLifeSetUp === 5"
                  label="保质期："
                  prop="expireTime"
                >
                  <el-input-number
                    v-model="base_form.expireTime"
                    style="width: 240px"
                    :controls="false"
                    placeholder="请输入商品保质期"
                  ></el-input-number>
                  天
                </el-form-item>
                <el-form-item label="商品卖点：" prop="describe">
                  <el-input
                    v-model="base_form.describe"
                    style="width: 240px"
                    placeholder="请输入商品卖点"
                  ></el-input>
                </el-form-item>
                <el-form-item label="抄码商品：" prop="describe">
                  <el-switch
                    v-model="base_form.isEq"
                    active-color="#36B365"
                    inactive-color="#ff4949"
                    active-text="是"
                    inactive-text="否"
                    :inactive-value="4"
                    :active-value="5"
                    @change="isEqChange"
                  ></el-switch>
                </el-form-item>
                <el-form-item label="负库存销售:">
                  <el-switch
                    v-model="base_form.isDistribution"
                    active-color="#36B365"
                    inactive-color="#ff4949"
                    :active-value="5"
                    :inactive-value="4"
                    active-text="启用"
                    inactive-text="禁用"
                  ></el-switch>
                </el-form-item>
                <el-form-item label="经营屏蔽:">
                  <el-switch
                    v-model="base_form.isShield"
                    active-color="#36B365"
                    inactive-color="#ff4949"
                    :active-value="5"
                    :inactive-value="4"
                    active-text="启用"
                    inactive-text="禁用"
                  ></el-switch>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="商品分类：" prop="categoryId">
                  <el-cascader
                    v-model="base_form.categoryPath"
                    clearable
                    style="width: 240px"
                    placeholder="请选择商品分类"
                    :options="category_data"
                    :props="cate_props"
                    @change="categoryChange"
                  >
                    <div slot-scope="scope" @click="clickChange">
                      {{ scope.data.title }}
                    </div>
                  </el-cascader>
                  <el-button size="mini" type="text" @click="add_model = true">
                    【新建分类】
                  </el-button>
                </el-form-item>
                <el-form-item label="副分类：">
                  <div v-for="(item, index) in assist_cate" :key="index">
                    <el-cascader
                      v-model="item.assistCategoryPath"
                      clearable
                      style="width: 240px"
                      placeholder="请选择商品分类"
                      :options="category_data"
                      :props="cate_props"
                    >
                      <div slot-scope="scope" @click="clickChange">
                        {{ scope.data.title }}
                      </div>
                    </el-cascader>
                    <el-button
                      v-if="index === 0"
                      size="mini"
                      type="text"
                      @click="addAssistCate"
                    >
                      【添加】
                    </el-button>
                    <el-button
                      v-if="assist_cate.length > 1"
                      size="mini"
                      type="text"
                      @click="delAssistCate(index)"
                    >
                      【删除】
                    </el-button>
                  </div>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="商品编码：" prop="code">
                  <el-input
                    v-model="base_form.code"
                    style="width: 240px"
                    disabled
                    placeholder="商品编码自动生成"
                  ></el-input>
                </el-form-item>
                <el-form-item label="货架编码：" prop="code">
                  <el-input
                    v-model="base_form.storage"
                    style="width: 240px"
                    placeholder="货架编码"
                  ></el-input>
                </el-form-item>
                <el-form-item label="是否上架：">
                  <el-switch
                    v-model="base_form.enableStatus"
                    active-color="#36B365"
                    inactive-color="#ff4949"
                    :active-value="5"
                    :inactive-value="4"
                    active-text="上架"
                    inactive-text="下架"
                  ></el-switch>
                </el-form-item>
                <el-form-item label="关键词：" prop="tag">
                  <el-tag
                    v-for="tag in dynamicTags"
                    :key="tag"
                    closable
                    :disable-transitions="false"
                    @close="handleClose(tag)"
                  >
                    {{ tag }}
                  </el-tag>
                  <el-input
                    v-if="inputVisible"
                    ref="saveTagInput"
                    v-model="inputValue"
                    class="input-new-tag"
                    size="small"
                    @keyup.enter.native="handleInputConfirm"
                    @blur="handleInputConfirm"
                  ></el-input>
                  <el-button
                    v-else
                    class="button-new-tag"
                    size="small"
                    @click="showInput"
                  >
                    + 新增
                  </el-button>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
        <!--      基本信息 END-->
        <!--      商品单位-->
        <div class="detail-tab-item">
          <div class="clearfix detail-tab-title">
            <span class="float_left">商品单位</span>
            <el-button
              size="mini"
              type="text"
              @click="$router.push('/goods/manageG/UnitMeasurement')"
            >
              【单位管理】
            </el-button>
            <el-button size="mini" type="text" @click="SpecManagegetAll">
              【刷新】
            </el-button>
            <span style="font-size: 12px; font-weight: normal; color: #e6a23c">
              （温馨提示：基本单位一经设置不允许修改，基本单位应为最小度量单位）
            </span>
          </div>
          <div>
            <el-form-item prop="masterUnit">
              <div slot="label">
                <span style="color: #e60000">*</span>
                <span>基本单位</span>
                <el-tooltip
                  effect="dark"
                  content="基本单位与辅助单位之间须有固定的换算关系，例如：1箱牛奶=24盒，【单位关系】为24，基本单位为【盒】，辅助单位为【箱】"
                  placement="top-start"
                >
                  <i class="el-icon-info"></i>
                </el-tooltip>
                ：
              </div>
              <el-select
                v-model="base_form.masterUnit.unitId"
                style="width: 240px"
                :disabled="isEditSpec === 4"
                placeholder="请选择基本单位"
                @change="masterUnitChange"
              >
                <el-option
                  v-for="(itemU, indexU) in unit_options"
                  :key="indexU"
                  :disabled="
                    base_form.isEq === 5 &&
                    itemU.unitName !== 'KG' &&
                    itemU.unitName !== '斤'
                  "
                  :label="itemU.unitName"
                  :value="itemU.id"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="辅助单位：" prop="branchUnit">
              <el-tag
                v-for="(itemA, indext) in base_form.branchUnit"
                :key="indext"
                :closable="isEditSpec === 5 || base_form.isEq === 5"
                :disable-transitions="false"
                @close="delFuUnit(itemA, indext)"
              >
                <span v-if="itemA.isNew === 4">
                  1{{ base_form.masterUnit.unitName }}={{ itemA.conversion
                  }}{{ itemA.unitName }}
                </span>
                <span v-else>
                  1{{ itemA.unitName }}={{ itemA.conversion
                  }}{{ base_form.masterUnit.unitName }}
                </span>
              </el-tag>
              <el-button
                v-if="
                  base_form.isEq === 4 ||
                  (base_form.isEq === 5 && base_form.branchUnit.length < 1)
                "
                :disabled="!base_form.masterUnit.unitName"
                type="text"
                class="button-new-tag"
                size="mini"
                @click="addFuUnit"
              >
                + 新增
              </el-button>
            </el-form-item>
          </div>
        </div>
        <!--      商品单位 END-->
        <div
          v-if="isEditSpec === 5 || base_form.specType === 2"
          class="detail-tab-item"
        >
          <div class="detail-tab-title">
            <span>商品属性</span>
            <el-button
              size="mini"
              type="text"
              @click="$router.push('/goods/manageG/SpecManage')"
            >
              【属性管理】
            </el-button>
            <el-button size="mini" type="text" @click="SpecManagegetAll">
              【刷新】
            </el-button>
            <span
              v-if="isEditSpec === 5"
              style="font-size: 12px; font-weight: normal; color: #e6a23c"
            >
              （温馨提示：在该商品【采购之前】若不设置商品属性，在该商品【采购之后】，属性不允许重新设置，请谨慎操作！）
            </span>
            <span
              v-else
              style="font-size: 12px; font-weight: normal; color: #e6a23c"
            >
              （温馨提示：请确认当前属性是否有库存，一旦删除该属性无法售卖；新增规格会导致原有库存重置；请谨慎操作！）
            </span>
          </div>
          <div class="detail-tab-main">
            <div v-for="(itemS, indexS) in sku_list" :key="indexS">
              <el-form-item
                class="sku-name-item"
                prop="groupSpecId"
                label="属性名："
              >
                <el-select
                  v-model="itemS.groupSpecId"
                  style="width: 240px"
                  :disabled="!base_form.masterUnit.unitName || isEditSpec === 4"
                  filterable
                  placeholder="请选择"
                  @change="groupSpecIdChange($event, indexS)"
                >
                  <el-option
                    v-for="(itemU, indexU) in spec_data"
                    :key="indexU"
                    :label="itemU.specName"
                    :value="itemU.id"
                  ></el-option>
                </el-select>
                <el-button
                  v-if="isEditSpec === 5"
                  type="text"
                  icon="el-icon-delete"
                  style="color: #ff4040; font-size: 16px"
                  @click="delGroupSpecId(indexS)"
                ></el-button>
              </el-form-item>
              <el-form-item label="属性值：" prop="params">
                <el-tag
                  v-for="(itemC, indexC) in itemS.params"
                  :key="indexC"
                  :closable="isEditSpec === 5"
                  :disable-transitions="false"
                  @close="delSpecVal(indexC, indexS, itemC)"
                >
                  {{ itemC.specName }}
                </el-tag>
                <el-button
                  :disabled="!itemS.groupSpecId"
                  type="text"
                  @click="addSpecVal(indexS)"
                >
                  + 新增
                </el-button>
                <el-input
                  v-if="itemS.self_spec_input"
                  v-model="itemS.self_spec_val"
                  size="small"
                  style="width: 200px"
                  placeholder="请输入内容"
                  @change="selfSpecConfirm(indexS)"
                >
                  <el-button
                    slot="append"
                    icon="el-icon-check"
                    @click="selfSpecConfirm(indexS)"
                  ></el-button>
                </el-input>
                <el-button
                  v-else
                  :disabled="!itemS.groupSpecId"
                  type="text"
                  @click="itemS.self_spec_input = true"
                >
                  + 自定义属性值
                </el-button>
              </el-form-item>
            </div>
            <el-form-item
              v-if="isEditSpec === 5"
              label-width="50px"
              class="sku-name-item"
            >
              <el-button @click="addSkuP">添加规格项目</el-button>
            </el-form-item>
          </div>
        </div>
        <!--      无属性价格管理-->
        <div v-if="base_form.specType === 1" class="detail-tab-item">
          <div class="detail-tab-title">
            <span>规格明细</span>
          </div>
          <el-table style="width: 98%; margin: 0 auto" :data="unit_data">
            <el-table-column
              prop="unitName"
              label="规格"
              min-width="80"
            ></el-table-column>
            <el-table-column prop="specImage" label="规格图片" min-width="140">
              <template slot-scope="scope">
                <UploadQiniu
                  :width="50"
                  is-btn="picture"
                  :file-list="
                    scope.row.specImage.url ? [scope.row.specImage] : []
                  "
                  @uploadSuccess="uploadSpecSuccess($event, scope.$index)"
                ></UploadQiniu>
              </template>
            </el-table-column>
            <el-table-column label="销售价/元" min-width="120">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.salePrice"
                  size="mini"
                  :controls="false"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  :min="0"
                  style="width: 100%"
                  @blur="salePriceBlur(scope.$index)"
                ></el-input-number>
              </template>
            </el-table-column>
            <el-table-column
              prop="memberPrice"
              label="会员价/元"
              min-width="100"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.memberPrice"
                  style="width: 100%"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  :controls="false"
                  placeholder="会员价"
                  size="small"
                  :min="0"
                  @blur="memberPriceBlur(scope.$index)"
                ></el-input-number>
              </template>
            </el-table-column>
            <el-table-column
              prop="marketPrice"
              label="市场价/元"
              min-width="100"
            >
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.marketPrice"
                  style="width: 100%"
                  :controls="false"
                  placeholder="市场价"
                  size="small"
                  :min="0"
                ></el-input-number>
              </template>
            </el-table-column>
            <el-table-column label="起订数量" min-width="100">
              <template slot-scope="scope">
                <el-input-number
                  v-model="scope.row.setNum"
                  style="width: 100%"
                  :controls="false"
                  placeholder="起订数量"
                  size="small"
                ></el-input-number>
              </template>
            </el-table-column>
            <el-table-column label="是否销售" min-width="100">
              <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.isSale"
                  class="switchStyle"
                  active-text="启用"
                  inactive-text="禁用"
                  active-color="#2153D4"
                  inactive-color="#879BBA"
                  :active-value="5"
                  :inactive-value="4"
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column
              v-if="!!goods_id"
              prop="inventory"
              label="库存"
              min-width="100"
            >
              <template slot-scope="scope">
                {{
                  scope.row.isEditSpec === 5 ? "无记录" : scope.row.inventory
                }}
              </template>
            </el-table-column>
            <el-table-column label="商品条码" min-width="140px">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.barCode"
                  style="width: 100%"
                  size="small"
                  placeholder="请输入商品条码"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="商品重量/g" min-width="120px">
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.weight"
                  style="width: 100%"
                  size="small"
                  placeholder="请输入商品重量"
                ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="默认单位" min-width="120px">
              <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.isDefault"
                  active-color="#36B365"
                  inactive-color="#ff4949"
                  active-text="是"
                  inactive-text="否"
                  :inactive-value="4"
                  :active-value="5"
                  @change="isDefaultChange($event, scope.$index)"
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column label="阶梯价" min-width="100">
              <template slot-scope="scope">
                <el-button
                  v-if="
                    scope.row.ladderPrice.length &&
                    scope.row.enabledLadder === 1
                  "
                  type="primary"
                  size="mini"
                  @click="
                    openModal(scope.$index, 'ladder_price_show', scope.row)
                  "
                >
                  已设置
                </el-button>
                <el-button
                  v-else
                  type="info"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  size="mini"
                  @click="
                    openModal(scope.$index, 'ladder_price_show', scope.row)
                  "
                >
                  去设置
                </el-button>
              </template>
            </el-table-column>
            <el-table-column label="客户类型价" min-width="100">
              <template slot-scope="scope">
                <el-button
                  v-if="
                    scope.row.customerTypePrice.length &&
                    scope.row.customerTypePriceOpen
                  "
                  type="primary"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  size="mini"
                  @click="openModal(scope.$index, 'type_price_show', scope.row)"
                >
                  已设置
                </el-button>
                <el-button
                  v-else
                  type="info"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  size="mini"
                  @click="openModal(scope.$index, 'type_price_show', scope.row)"
                >
                  去设置
                </el-button>
              </template>
            </el-table-column>
            <el-table-column label="客户指定价" min-width="100">
              <template slot-scope="scope">
                <el-button
                  v-if="
                    scope.row.customerPrice.length &&
                    scope.row.customerPriceOpen
                  "
                  type="primary"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  size="mini"
                  @click="
                    openModal(scope.$index, 'appoint_price_show', scope.row)
                  "
                >
                  已设置
                </el-button>
                <el-button
                  v-else
                  type="info"
                  size="mini"
                  :disabled="base_form.isEq === 5 && scope.row.isMaster === 4"
                  @click="
                    openModal(scope.$index, 'appoint_price_show', scope.row)
                  "
                >
                  去设置
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!--      多规格-->
        <div v-if="base_form.specType === 2" class="detail-tab-item">
          <div class="detail-tab-title">
            <span>规格明细</span>
          </div>
          <el-tabs v-model="tabs_active" type="card">
            <el-tab-pane
              v-for="(itemU, indexU) in unit_data"
              :key="indexU"
              :label="itemU.unitName"
              :name="itemU.unitName"
            >
              <el-table
                style="width: 98%; margin: 0 auto"
                :data="itemU.spec_table_Data"
              >
                <el-table-column
                  v-for="(item, index) in sku_list"
                  :key="index"
                  prop="specName"
                  min-width="80"
                  :label="item.groupSpecName"
                >
                  <template slot-scope="scope">
                    {{
                      scope.row.specName.indexOf("_") > -1
                        ? scope.row.specName.split("_")[index] || ""
                        : scope.row.specName
                    }}
                  </template>
                </el-table-column>
                <el-table-column
                  prop="specImage"
                  label="规格图片"
                  min-width="140"
                >
                  <template slot-scope="scope">
                    <UploadQiniu
                      :width="50"
                      is-btn="picture"
                      :file-list="
                        scope.row.specImage.url ? [scope.row.specImage] : []
                      "
                      @uploadSuccess="
                        uploadSpecSuccess($event, scope.$index, indexU)
                      "
                    ></UploadQiniu>
                  </template>
                </el-table-column>

                <el-table-column label="销售价/元" min-width="120">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.salePrice"
                      size="mini"
                      :controls="false"
                      :min="0"
                      style="width: 100%"
                      @blur="salePriceBlur(scope.$index, indexU)"
                    ></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="memberPrice"
                  label="会员价/元"
                  min-width="100"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.memberPrice"
                      style="width: 100%"
                      :controls="false"
                      placeholder="会员价"
                      size="small"
                      :min="0"
                    ></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column
                  prop="marketPrice"
                  label="市场价/元"
                  min-width="100"
                >
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.marketPrice"
                      style="width: 100%"
                      :controls="false"
                      placeholder="市场价"
                      size="small"
                      :min="0"
                    ></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column label="起订数量" min-width="100">
                  <template slot-scope="scope">
                    <el-input-number
                      v-model="scope.row.setNum"
                      style="width: 80px"
                      :controls="false"
                      placeholder="起订数量"
                      size="small"
                    ></el-input-number>
                  </template>
                </el-table-column>
                <el-table-column label="是否销售" min-width="100">
                  <template slot-scope="scope">
                    <el-switch
                      v-model="scope.row.isSale"
                      class="switchStyle"
                      active-text="启用"
                      inactive-text="禁用"
                      active-color="#2153D4"
                      inactive-color="#879BBA"
                      :active-value="5"
                      :inactive-value="4"
                    ></el-switch>
                  </template>
                </el-table-column>
                <el-table-column
                  v-if="!!goods_id"
                  prop="inventory"
                  label="库存"
                  min-width="100"
                >
                  <template slot-scope="scope">
                    {{
                      scope.row.isEditSpec === 5
                        ? "无记录"
                        : scope.row.inventory
                    }}
                  </template>
                </el-table-column>
                <el-table-column label="商品条码" min-width="140px">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.barCode"
                      size="small"
                      style="width: 100%"
                      placeholder="请输入商品条码"
                    ></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="商品重量/g" min-width="120px">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.weight"
                      style="width: 100%"
                      size="small"
                      placeholder="请输入商品重量"
                    ></el-input>
                  </template>
                </el-table-column>
                <el-table-column label="默认属性" min-width="120px">
                  <template slot-scope="scope">
                    <el-switch
                      v-model="scope.row.isDefault"
                      active-color="#36B365"
                      inactive-color="#ff4949"
                      active-text="是"
                      inactive-text="否"
                      :inactive-value="4"
                      :active-value="5"
                      @change="isDefaultChange($event, scope.$index, indexU)"
                    ></el-switch>
                  </template>
                </el-table-column>
                <el-table-column label="阶梯价" min-width="100">
                  <template slot-scope="scope">
                    <el-button
                      v-if="
                        scope.row.ladderPrice.length &&
                        scope.row.enabledLadder === 1
                      "
                      type="primary"
                      size="mini"
                      @click="
                        openModal(
                          scope.$index,
                          'ladder_price_show',
                          scope.row,
                          indexU
                        )
                      "
                    >
                      已设置
                    </el-button>
                    <el-button
                      v-else
                      type="info"
                      size="mini"
                      @click="
                        openModal(
                          scope.$index,
                          'ladder_price_show',
                          scope.row,
                          indexU
                        )
                      "
                    >
                      去设置
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column label="客户类型价" min-width="100">
                  <template slot-scope="scope">
                    <el-button
                      v-if="
                        scope.row.customerTypePrice.length &&
                        scope.row.customerTypePriceOpen
                      "
                      type="primary"
                      size="mini"
                      @click="
                        openModal(
                          scope.$index,
                          'type_price_show',
                          scope.row,
                          indexU
                        )
                      "
                    >
                      已设置
                    </el-button>
                    <el-button
                      v-else
                      type="info"
                      size="mini"
                      @click="
                        openModal(
                          scope.$index,
                          'type_price_show',
                          scope.row,
                          indexU
                        )
                      "
                    >
                      去设置
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column label="客户指定价" min-width="100">
                  <template slot-scope="scope">
                    <el-button
                      v-if="
                        scope.row.customerPrice.length &&
                        scope.row.customerPriceOpen
                      "
                      type="primary"
                      size="mini"
                      @click="
                        openModal(
                          scope.$index,
                          'appoint_price_show',
                          scope.row,
                          indexU
                        )
                      "
                    >
                      已设置
                    </el-button>
                    <el-button
                      v-else
                      type="info"
                      size="mini"
                      @click="
                        openModal(
                          scope.$index,
                          'appoint_price_show',
                          scope.row,
                          indexU
                        )
                      "
                    >
                      去设置
                    </el-button>
                  </template>
                </el-table-column>
                <el-table-column label="操作" min-width="160">
                  <template slot-scope="scope">
                    <el-button
                      v-if="itemU.isMaster === 5"
                      :disabled="scope.row.isEditSpec === 4"
                      type="danger"
                      size="small"
                      plain
                      @click="specDetailDel(scope.row, scope.$index)"
                    >
                      删除
                    </el-button>
                    <el-button
                      type="primary"
                      size="small"
                      plain
                      @click="otherSetPrice(scope.row, indexU)"
                    >
                      同步
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </el-tab-pane>
          </el-tabs>
        </div>
        <!--    物流设置  -->
        <div class="detail-tab-item">
          <div class="detail-tab-title">
            <span>物流设置</span>
          </div>
          <el-form-item v-if="false" label="物流支持：" prop="deliverySupIds">
            <el-checkbox-group v-model="base_form.deliverySupIds">
              <el-checkbox label="1">快递</el-checkbox>
              <el-checkbox label="2">自提</el-checkbox>
            </el-checkbox-group>
            <p
              v-if="!goods_id"
              class="form-tip"
              @click="$router.push('/SystemSettings/jiaoyiset/Delivery')"
            >
              <el-button type="text" size="small">【配送方式配置】</el-button>
            </p>
          </el-form-item>
          <br />
          <el-form-item label="快递运费：">
            <el-radio-group v-model="base_form.expressType">
              <el-radio :label="1">包邮</el-radio>
              <el-radio :label="2">运费模版</el-radio>
              <el-radio :label="3">统一运费</el-radio>
            </el-radio-group>
          </el-form-item>
          <br />
          <div v-if="base_form.expressType === 2">
            <el-form-item label="运费模板：" prop="ruleId">
              <el-select v-model="base_form.ruleId" placeholder="请选择">
                <el-option
                  v-for="(item, index) in express_list"
                  :key="index"
                  :label="item.title"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div v-if="base_form.expressType === 3">
            <el-form-item label="统一运费：" prop="expressFee">
              <el-input-number
                v-model="base_form.expressFee"
                :controls="false"
              ></el-input-number>
              <span>元</span>
            </el-form-item>
          </div>
          <el-form-item v-if="false" label="是否展示快递：">
            <el-radio-group v-model="base_form.showExpress">
              <el-radio :label="4">不展示</el-radio>
              <el-radio :label="5">展示</el-radio>
            </el-radio-group>
          </el-form-item>
        </div>
        <div class="detail-tab-item">
          <div class="detail-tab-title">
            <span>商品详情</span>
          </div>
          <div class="info-main" style="padding: 0 49px">
            <Tinymce v-model="base_form.description" :height="300" />
          </div>
        </div>
      </div>

      <!--      经营屏蔽-->
      <div v-if="page_tabs === '2'">
        <div class="page-tip-div">
          <i class="el-icon-info"></i>
          符合以下条件的客户用将无法看到此商品
        </div>
        <el-row :gutter="10">
          <el-col :span="8">
            <div class="detail-tab-item" style="margin-bottom: 0">
              <div class="detail-tab-title">地区屏蔽</div>
              <div
                class="detail-tab-main"
                style="height: calc(100vh - 380px); overflow: auto"
              >
                <RegionTree
                  :checked-key="region_arr"
                  @checkChange="selRegion"
                />
              </div>
            </div>
          </el-col>
          <el-col :span="16">
            <div class="detail-tab-item">
              <div class="detail-tab-title">客户类型屏蔽</div>
              <div class="detail-tab-main">
                <div
                  v-if="!customer_type_list.length"
                  style="text-align: center"
                >
                  暂无客户类型
                </div>
                <el-checkbox-group v-model="customer_type_check">
                  <el-checkbox
                    v-for="(item, index) in customer_type_list"
                    :key="index"
                    :label="item.id"
                  >
                    {{ item.name }}
                  </el-checkbox>
                </el-checkbox-group>
              </div>
            </div>
            <div class="detail-tab-item">
              <div class="detail-tab-title clearfix">
                <span class="float_left">客户屏蔽</span>
                <div class="float_right">
                  <el-button
                    type="primary"
                    size="mini"
                    @click="customer_show = true"
                  >
                    选择客户
                  </el-button>
                </div>
              </div>
              <div class="detail-tab-main">
                <el-table :data="customer_list">
                  <el-table-column
                    show-overflow-tooltip
                    prop="code"
                    label="编号"
                  ></el-table-column>
                  <el-table-column
                    show-overflow-tooltip
                    prop="name"
                    label="姓名"
                  ></el-table-column>
                  <el-table-column
                    prop="customerType"
                    label="类型"
                  ></el-table-column>
                  <el-table-column
                    prop="shopName"
                    label="所属商铺"
                    show-overflow-tooltip
                  ></el-table-column>
                  <el-table-column label="管理">
                    <template slot-scope="scope">
                      <el-button
                        type="text"
                        @click="deleteCustomer(scope.$index)"
                      >
                        删除
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-form>

    <el-dialog
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="新增辅助单位"
      :visible.sync="assist_model"
      width="40%"
    >
      <el-form
        style="text-align: center"
        :model="assist_form"
        size="small"
        inline
      >
        <div v-if="isNew === 4">
          <el-form-item prop="conversion">
            1
            {{ base_form.masterUnit.unitName }}
            =
          </el-form-item>
          <el-form-item prop="unitName">
            <el-input-number
              v-model="assist_form.conversion"
              :controls="false"
            ></el-input-number>
            <el-select
              v-model="assist_form.unitId"
              placeholder="请选择辅助单位"
              @change="branchUnitChange"
            >
              <el-option
                v-for="(item, index) in unit_options"
                :key="index"
                :label="item.unitName"
                :value="item.id"
                :disabled="item.id === base_form.masterUnit.unitId"
              ></el-option>
            </el-select>
          </el-form-item>
        </div>
        <!--          v-if="
                    base_form.isEq === 4 ||
                    (base_form.isEq === 5 && item.unitName === '件')
                  "-->
        <div v-else>
          <el-form-item prop="conversion">
            1
            <el-select
              v-model="assist_form.unitId"
              placeholder="请选择辅助单位"
              @change="branchUnitChange"
            >
              <template v-for="(item, index) in unit_options">
                <el-option
                  :key="index"
                  :label="item.unitName"
                  :value="item.id"
                  :disabled="item.id === base_form.masterUnit.unitId"
                ></el-option>
              </template>
            </el-select>
            =
          </el-form-item>
          <el-form-item prop="unitName">
            <el-input-number
              v-model="assist_form.conversion"
              :controls="false"
            ></el-input-number>
            {{ base_form.masterUnit.unitName }}
          </el-form-item>
        </div>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="assist_model = false">取 消</el-button>
        <el-button type="primary" @click="subAssist">确 定</el-button>
      </span>
    </el-dialog>
    <!--   属性值 -->
    <el-dialog
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      title="属性值"
      :visible.sync="spec_model"
      width="40%"
    >
      <el-checkbox
        v-model="spec_check_all"
        :indeterminate="is_indeterminate_spec"
        @change="checkAllSpecChange"
      >
        全选
      </el-checkbox>
      <div style="margin: 15px 0"></div>
      <el-checkbox-group v-model="spec_item_check" @change="specItemChange">
        <el-checkbox
          v-for="(item, index) in spec_data_child"
          :key="index"
          :label="item.id"
        >
          {{ item.specName }}
        </el-checkbox>
      </el-checkbox-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="spec_model = false">取 消</el-button>
        <el-button type="primary" @click="selSpecVal">确 定</el-button>
      </span>
    </el-dialog>
    <BrandSelModel
      :is-check="false"
      :is-show-add="true"
      :dialog-visible="sel_brand"
      :enable="true"
      @close="sel_brand = false"
      @confirm="brandConfirm"
    />
    <!-----------------    添加分类 ----------->
    <AddCate
      v-if="add_model"
      :dialog-title="dialogTitle"
      :is-show="add_model"
      :pid-path="pid_arr"
      @confirm="subCategory"
      @cancel="modelClose"
    />
    <!--   新建品牌-->
    <el-drawer
      class="edit-drawer"
      size="50%"
      :visible.sync="add_Brand"
      direction="rtl"
    >
      <AddBrand v-if="add_Brand" @submitBrand="submitBrand" />
    </el-drawer>
    <!--  客户选择-->
    <ClientListModal
      v-if="customer_show"
      :is-show="customer_show"
      :is-check="true"
      :is-show-add="true"
      @cancel="customer_show = false"
      @confirm="customerSel"
    />
    <CustomerPrice
      v-if="appoint_price_show"
      :is-show="appoint_price_show"
      :ladder-price="ladderPrice"
      :enabled-ladder="enabledLadder"
      :customer-price-open="customerPriceOpen"
      :customer-price="customerPrice"
      :sku-id="sku_id"
      @confirm="appointPriceConfirm"
      @cancel="appointPriceCancel"
    />
    <CustomerTypePrice
      v-if="type_price_show"
      :is-show="type_price_show"
      :ladder-price="ladderPrice"
      :enabled-ladder="enabledLadder"
      :sku-id="sku_id"
      :customer-type-price-open="customerTypePriceOpen"
      :customer-type-price="customerTypePrice"
      @confirm="typePriceConfirm"
      @cancel="typePriceCancel"
    />
    <!--    阶梯价弹窗-->
    <LadderPrice
      v-if="ladder_price_show"
      :enabled-ladder="enabledLadder"
      :disabled="
        base_form.isEq === 5 && unitisMaster === 4 && base_form.specType === 1
      "
      :ladder-price="ladderPrice"
      :is-show="ladder_price_show"
      @confirm="ladderPriceConfirm"
      @cancel="ladderPriceCancel"
    />
  </ContainerTit>
</template>

<script>
  import CustomerPrice from "../components/CustomerPrice";
  import LadderPrice from "../components/LadderPrice";
  import CustomerTypePrice from "../components/CustomerTypePrice";
  // import GoodsCategory from "@/component/common/GoodsCategory.vue";
  import BrandSelModel from "@/component/goods/BrandSelModel.vue";
  import Tinymce from "@/component/Tinymce";
  import UploadQiniu from "@/component/common/UploadQiniu.vue";
  // 新增分类
  import AddCate from "@/component/goods/AddCate.vue";
  import AddBrand from "../manageG/AddBrand";
  import { getAllExpressRule, getAllCustomerSource } from "@/api/System";
  import {
    getAllUnit,
    defineSpec,
    SpecManagegetAll,
    getQuickGoodsInfo,
    editQuickGoods,
    addBasicAndPublishGoods,
    getAllCategoryPost,
  } from "@/api/goods";
  import { addPauseSave, delPauseSave, getPauseSave } from "@/api/common";
  const priceDataLi = {
    enabledLadder: 0,
    marketPrice: "",
    memberPrice: "",
    salePrice: "",
    setNum: 1,
    isSale: 5,
    salePriceAreaType: 1,
    // 客户类型和客户快速调价
    customerTypePrice: [],
    customerTypePriceOpen: false,
    customerPrice: [],
    customerPriceOpen: false,
    ladderPrice: [
      /* {
        from: 1,
        price: 0.01,
        to: 2
      }, {
        from: 3,
        price: 0.01,
        to: 4
      },
      {
        from: 5,
        price: 0.01,
        to: 999999999
      } */
    ],
  };
  import ClientListModal from "@/component/common/ClientListModal";
  import RegionTree from "@/component/common/RegionTree";
  import { mapGetters } from "vuex";
  import {
    CustomerPriceAdjustmentAdd,
    addCustomerTypePriceAdjustment,
    getCustomerPriceByGoodsIds,
    getCustomerTypePriceByGoodsIds,
  } from "@/api/Price";
  import { getAllMerchantList } from "@/api/Merchants";
  export default {
    name: "AddBaseData",
    components: {
      // GoodsCategory,
      BrandSelModel,
      Tinymce,
      UploadQiniu,
      AddCate,
      AddBrand,
      RegionTree,
      ClientListModal,
      CustomerPrice,
      CustomerTypePrice,
      LadderPrice,
    },
    data() {
      const validateUnit = (rule, value, callback) => {
        if (value.unitName === "") {
          callback(new Error("请设置基本单位"));
        } else {
          callback();
        }
      };
      return {
        unitisMaster: "",
        unit_index: 0,
        sku_index: 0,
        ladderPrice: [],
        enabledLadder: 0,
        ladder_price_show: false, // 阶梯价弹窗
        type_price_show: false, // 客户类型价弹窗
        customerTypePriceOpen: false, // 客户类型价弹窗开关
        customerTypePrice: [], // 客户类型价弹窗数据
        customerPriceOpen: false,
        customerPrice: [],
        appoint_price_show: false, // 客户指定价弹窗
        customer_show: false, // 经营屏蔽->客户列表弹窗选择
        customer_list: [], // 经营屏蔽->客户列表
        customer_type_check: [], // 经营屏蔽->客户类型选择数组
        customer_type_list: [], // 经营屏蔽->客户类型列表
        region_arr: [], // 经营屏蔽->当前商品已选择过的区域
        page_tabs: "1", // 页面tab切换
        express_list: [], // 运费模版列表
        isEditSpec: 5, // 5 表示此商品从未采购过，允许用户随意编辑单位和属性；4 表示商品已经采购过，隐藏添加属性按钮，避免skuid重组
        // 计量单位
        self_spec_val: "", // 自定义属性值输入框
        spec_name_index: 0, // 属性名index
        self_spec_input: false, // 显示自定义属性值输入框
        spec_model: false, // 选择属性值弹窗
        spec_item_check: [], // 属性值弹窗单选value
        is_indeterminate_spec: false, // 批量选择属性值 全选选择框状态
        spec_check_all: false, // 属性值 全选选择框value
        spec_data: [], // 属性列表
        spec_data_child: [], // 属性值列表
        spec_table_Data: [], // 规格明细
        sku_list: [
          // 商品属性列表
          {
            spec_data_child: [],
            groupSpecId: "",
            self_spec_val: "",
            self_spec_input: false,
            groupSpecName: "",
            params: [],
          },
        ],
        add_model: false, // 新建分类
        dialogTitle: "新建分类",
        pid_arr: [],
        add_Brand: false, // 新增品牌
        pageName: "", // 暂存数据参数
        loading: false,
        img_list: [],
        // 关键词
        dynamicTags: [],
        inputVisible: false,
        inputValue: "",
        // 关键词 END
        assist_model: false,
        edit_assist_model: false,
        assist_index: 0,
        unit_options: [],
        // 计量单位弹窗
        assist_form: {
          unitName: "",
          barCode: "",
          isMaster: 4,
          isDefault: 4,
          isEditSpec: 5,
          unitId: "",
          conversion: "",
        },
        sel_brand: false, // 打开品牌选择弹窗
        sel_shop: false, // 打开店铺选择弹窗
        master_unit_name: "",
        base_form: {
          //  基本信息
          enableStatus: 5, // 是否上架
          isDistribution: 4, //负库存销售
          isShield: 4, // 经营屏蔽 4关闭 5开启
          isEq: 4, // 抄码商品
          specType: 1, // 是否多规格
          delUnitIds: [], // 辅助单位删除delUnitIds (unitId)
          delSpecSkuIds: [], // 属性删除delSpecSkuIds（这个用id）
          branchUnit: [],
          brandName: "",
          categoryId: "",
          assistCategoryId: "",
          categoryPath: [], // 分类选择
          assistCategoryPath: [], // 分类选择
          unitData: [],
          masterUnit: {
            barCode: "",
            weight: "",
            isMaster: 5,
            isDefault: 5,
            unitName: "",
            unitId: "",
          },
          describe: "",
          title: "",
          storage: "",
          code: "",
          barCode: "", // 商品条码
          weight: "", // 商品重量
          expireTime: "",
          brandId: "",
          tag: "",
          description: "",
          salesShop: "",
          images: [],
          deliverySupIds: ["1", "2"], // 物流支持 固定值 1 快递 2 自提 传参格式：1,2
          expressType: 1, // 快递运费 1 包邮 2 运费模版 3 固定费用
          expressFee: "", // 固定费用
          showExpress: 5, // 是否展示快递 5展示 4不展示
          ruleId: "", // 运费模版id
          notArea: [], //经营屏蔽地区
          notCustomerType: "", //经营屏蔽 客户类型屏蔽
          notCustomer: "", //经营屏蔽 客户屏蔽
          merchantId: "", //商户ID
        },
        sel_cities: [], // 商户列表
        base_rules: {
          // 基本信息验证
          images: [
            {
              type: "array",
              required: true,
              message: "请上传商品图片",
              trigger: "change",
            },
          ],
          title: [
            { required: true, message: "请输入商品名称", trigger: "blur" },
          ],
          categoryId: [
            { required: true, message: "请选择商品分类", trigger: "change" },
          ],
          expireTime: [
            { required: true, message: "请输入商品保质期", trigger: "blur" },
          ],
          // brandId: [{ required: true, message: '请选择商品品牌', trigger: 'change' }],
          // describe: [{ required: true, message: '请输入商品描述', trigger: 'blur' }],
          masterUnit: [{ validator: validateUnit, trigger: "change" }],
          deliverySupIds: [
            {
              required: true,
              type: "array",
              message: "请选择物流支持",
              trigger: "change",
            },
          ],
          ruleId: [
            { required: true, message: "请选择运费模板", trigger: "change" },
          ],
          expressFee: [
            { required: true, message: "请输入运费", trigger: "blur" },
          ],
          // branchUnit: [{ required: true, type: 'array', message: '请设置辅助单位', trigger: 'change' }]
          // tag: [{ required: true, message: '请设置商品关键词', trigger: 'change' }]
        },
        goods_id: 0,
        list_page_data: "1_10",
        unit_data: [], // 单位明细
        tabs_active: "", // 多属性单位切换
        isNew: 5, // 5 标示这是一个最近新增的商品，基本单位为最小单位，4标示这是之前的老数据，基本单位为最大单位
        category_data: [], //商品分类列表
        cate_props: {
          label: "title",
          value: "id",
          checkStrictly: true,
        },
        assist_cate: [
          {
            assistCategoryPath: [],
          },
        ],
        sku_id: "",
      };
    },
    computed: {
      ...mapGetters({
        salePriceTimes: "MUser/salePriceTimes",
        systemType: "MUser/systemType", // 当前后台
      }),
    },
    async created() {
      // 商户管理
      await this.getAllMerchantList();
      // 商品分类列表
      await this.getAllCategoryPost();
      this.pageName = this.$route.name;
      // 属性管理
      await this.SpecManagegetAll();
      await this.getAllUnit();
      // 客户类型
      await this.getAllCustomerSource();
      if (this.$route.params.id) {
        this.goods_id = this.$route.params.id;
        this.list_page_data = this.$route.params.page;
        await this.getGoodsBasicInfoById();
      } else {
        // 获取暂存信息
        await this.getPauseSave();
      }
      await this.getAllExpressRule();
    },
    methods: {
      // 获取运费模版
      async getAllExpressRule() {
        const { data } = await getAllExpressRule();

        this.express_list = data;
      },
      isDefaultChange(val, index, sIndex) {
        if (val === 5) {
          const target = this.$_common.deepClone(this.unit_data);
          if (this.base_form.specType === 2) {
            target.forEach((item, indexU) => {
              item.spec_table_Data.forEach((itemB, indexB) => {
                if (indexU !== sIndex) {
                  itemB.isDefault = 4;
                } else {
                  if (indexB !== index) {
                    itemB.isDefault = 4;
                  }
                }
              });
            });
          } else {
            target.forEach((item, indexU) => {
              if (indexU !== index) {
                item.isDefault = 4;
              }
            });
          }
          this.unit_data = target;
        }
      },
      // 请求基本单位数据
      async getAllUnit() {
        const { data } = await getAllUnit({
          page: 1,
          pageSize: 99,
        });

        this.unit_options = data;
      },
      modelClose() {
        this.add_model = false;
      },
      // 打开新增弹窗
      openModel(title, row) {
        this.add_model = true;
        this.dialogTitle = title;
        if (title === "新建子分类") {
          let link = row.link
            ? row.link.split(",").map((item) => {
                return parseInt(item);
              })
            : [];
          link.push(row.id);
          this.pid_arr = link;
        }
      },
      // 新增/编辑分类
      async subCategory() {
        this.getAllCategoryPost();
        this.$message("新建分类成功");
      },
      // 新建品牌
      submitBrand() {
        this.add_Brand = false;
      },
      // 添加暂存
      async AddTem() {
        const params = {
          ...this.base_form,
          specGroup: this.sku_list,
          specMultiple: this.spec_table_Data,
          tag: this.dynamicTags,
          assist_cate: this.assist_cate,
        };
        this.loading = true;
        const data = await addPauseSave({
          key: this.pageName,
          data: params,
        });
        this.loading = false;

        this.$message({
          type: "success",
          message: "暂存成功",
        });
        if (this.systemType === 3) {
          this.$closeCurrentGoEdit(`/goods/sale/MerchantsGoods`);
        } else {
          this.$closeCurrentGoEdit(`/goods/sale/PublishGoods`);
        }
      },
      // 删除暂存信息
      async delPauseSave() {
        const data = delPauseSave({
          key: this.pageName,
        });
      },
      // 获取暂存信息
      async getPauseSave() {
        const { data } = await getPauseSave({
          key: this.pageName,
        });

        if (JSON.stringify(data) === "{}") return;
        this.base_form = {
          ...data,
          categoryPath: Array.isArray(data.categoryPath)
            ? data.categoryPath
            : [],
          assistCategoryPath: Array.isArray(data.assistCategoryPath)
            ? data.assistCategoryPath
            : [],
        };
        this.assist_cate = data.assist_cate || [{ assistCategoryPath: [] }];
        this.sku_list = data.specGroup || [];
        this.spec_table_Data = data.specMultiple || [];
        this.dynamicTags = data.tag || [];
        if (data.images) {
          this.img_list = data.images.map((item) => {
            return {
              name: "",
              url: item,
            };
          });
        }
      },
      // 规格图片
      uploadSpecSuccess(val, index, indexU) {
        let target = this.$_common.deepClone(this.unit_data);
        if (this.base_form.specType === 1) {
          target[index].specImage = {
            name: "",
            url: val,
          };
        } else {
          target[indexU].spec_table_Data[index].specImage = {
            name: "",
            url: val,
          };
        }
        this.unit_data = target;
      },
      // 添加规格项目
      addSkuP() {
        if (!this.goods_id) {
          this.sku_list.push({
            spec_data_child: [],
            self_spec_input: false,
            self_spec_val: "",
            groupSpecId: "",
            groupSpecName: "",
            params: [],
          });
        } else {
          this.$confirm(
            "新增规格会导致原有库存重置,请谨慎操作! 是否继续?",
            "提示",
            {
              confirmButtonText: "继续新增",
              cancelButtonText: "取消",
              type: "warning",
            }
          ).then(() => {
            this.sku_list.push({
              spec_data_child: [],
              self_spec_input: false,
              self_spec_val: "",
              groupSpecId: "",
              groupSpecName: "",
              params: [],
            });
          });
        }
      },
      // 规格明切换
      groupSpecIdChange(val, indexS) {
        let target = this.$_common.deepClone(this.sku_list);
        const specDataItem = this.spec_data.find((item) => item.id === val);
        target[indexS].groupSpecName = specDataItem.specName;
        target[indexS].spec_data_child = specDataItem.child || [];
        target[indexS].params = [];
        this.sku_list = target;
        // 重排规格组合
        // this.specGroupRest()
        // console.log(this.sku_list)
        // console.log(this.spec_table_Data)
      },
      // 重排规格组合
      specGroupRest() {
        // 编辑页面存储详情接口返回规格组合id
        // this.spec_table_Data.forEach(item => {
        //   if (item.specGroupHash && this.base_form.delSpecSkuIds.indexOf(item.specGroupHash) === -1) {
        //     this.base_form.delSpecSkuIds.push(item.specGroupHash)
        //   }
        // })

        const skuArr = this.sku_list.map((item) => {
          item.params = item.params.map((itemP) => {
            return {
              ...itemP,
              groupSpecName: item.groupSpecName,
            };
          });
          return item.params;
        });

        let skuArrDo = [];
        if (skuArr.length) {
          skuArrDo = this.doExchange(skuArr);
        }
        // 备份一份规格明细，用来填充重排规格组之前的图片
        const cloneUnitData = this.$_common.deepClone(this.unit_data);
        this.unit_data = this.unit_data.map((item, index) => {
          const cloneSpecGroup = cloneUnitData[index].spec_table_Data || [];
          return {
            ...item,
            spec_table_Data: skuArrDo.map((itemSp) => {
              const indexSS = cloneSpecGroup.findIndex(
                (itemC) => itemC.id === itemSp.id
              );
              return {
                ...itemSp,
                barCode:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].barCode
                    : itemSp.barCode,
                weight:
                  indexSS > -1 ? cloneSpecGroup[indexSS].weight : itemSp.weight,
                isDefault:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].isDefault
                    : itemSp.isDefault,
                specImage:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].specImage
                    : itemSp.specImage,
                inventory:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].inventory
                    : itemSp.inventory || 0,
                isEditSpec:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].isEditSpec
                    : itemSp.isEditSpec || 5,
                salePrice:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].salePrice
                    : itemSp.salePrice,
                enabledLadder:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].enabledLadder
                    : itemSp.enabledLadder,
                ladderPrice:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].ladderPrice
                    : itemSp.ladderPrice,
                marketPrice:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].marketPrice
                    : itemSp.marketPrice,
                memberPrice:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].memberPrice
                    : itemSp.memberPrice,
                setNum:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].setNum
                    : itemSp.setNum || 1,
                isSale:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].isSale
                    : itemSp.isSale || 5,
                customerTypePrice:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].customerTypePrice
                    : itemSp.customerTypePrice || [],
                customerTypePriceOpen:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].customerTypePriceOpen
                    : itemSp.customerTypePriceOpen || false,
                customerPrice:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].customerPrice
                    : itemSp.customerPrice || [],
                customerPriceOpen:
                  indexSS > -1
                    ? cloneSpecGroup[indexSS].customerPriceOpen
                    : itemSp.customerPriceOpen || false,
              };
            }),
          };
        });
        // 判断是否是多属性
        this.base_form.specType = this.unit_data.some(
          (item) => item.spec_table_Data && item.spec_table_Data.length > 0
        )
          ? 2
          : 1;
        if (this.base_form.specType === 2 && !this.tabs_active) {
          this.tabs_active = this.unit_data[0].unitName;
        }
      },
      // 规格组合
      doExchange(doubleArrays) {
        const len = doubleArrays.length;
        if (len >= 2) {
          const len1 = doubleArrays[0].length;
          const len2 = doubleArrays[1].length;
          const newlen = len1 * len2;
          const temp = new Array(newlen);
          let index = 0;
          for (let i = 0; i < len1; i++) {
            for (let j = 0; j < len2; j++) {
              temp[index] = {
                groupSpecId:
                  doubleArrays[0][i].groupSpecId +
                  "_" +
                  doubleArrays[1][j].groupSpecId,
                groupSpecName:
                  doubleArrays[0][i].groupSpecName +
                  "_" +
                  doubleArrays[1][j].groupSpecName,
                id: doubleArrays[0][i].id + "_" + doubleArrays[1][j].id,
                specName:
                  doubleArrays[0][i].specName +
                  "_" +
                  doubleArrays[1][j].specName,
                specImage: {
                  name: "",
                  url: "",
                },
                setNum: 1,
                isSale: 5,
                salePrice: 0.01,
                enabledLadder: 0,
                ladderPrice: [],
                marketPrice: 0.01,
                memberPrice: "",
                barCode: "",
                weight: "",
                isDefault: 4,
                // 客户类型和客户快速调价
                customerTypePrice: [],
                customerTypePriceOpen: false,
                customerPrice: [],
                customerPriceOpen: false,
              };
              index++;
            }
          }
          let newArray = new Array(len - 1);
          newArray[0] = temp;
          if (len > 2) {
            let _count = 1;
            for (let i = 2; i < len; i++) {
              newArray[_count] = doubleArrays[i];
              _count++;
            }
          }
          return this.doExchange(newArray);
        } else {
          return doubleArrays[0].map((item) => {
            return {
              ...item,
              specImage: {
                name: "",
                url: "",
              },
              setNum: 1,
              isSale: 5,
              barCode: "",
              weight: "",
              isDefault: 4,
              salePrice: 0.01,
              enabledLadder: 0,
              ladderPrice: [],
              marketPrice: 0.01,
              memberPrice: "",
              // 客户类型和客户快速调价
              customerTypePrice: [],
              customerTypePriceOpen: false,
              customerPrice: [],
              customerPriceOpen: false,
            };
          });
        }
      },
      // 自定义属性值输入框确定  添加自定义属性
      async selfSpecConfirm(index) {
        const target = this.$_common.deepClone(this.sku_list);
        if (!target[index].self_spec_val) {
          target[index].self_spec_input = false;
          this.sku_list = target;
          return;
        }
        const { data } = await defineSpec({
          specName: target[index].self_spec_val,
          pid: target[index].groupSpecId,
          hidden: 4,
        });

        target[index].self_spec_input = false;

        target[index].params.push({
          specName: data.specName,
          id: data.id,
          groupSpecId: target[index].groupSpecId,
        });
        target[index].self_spec_val = "";
        this.sku_list = target;
        // 重排规格组合
        this.specGroupRest();
      },
      // 新增规格值
      addSpecVal(indexS) {
        this.spec_model = true;
        this.spec_data_child = this.sku_list[indexS].spec_data_child;
        this.spec_name_index = indexS;
        this.spec_item_check = this.sku_list[indexS].params.map(
          (item) => item.id
        );
        // 使用属性值单选方法，为了设置全选选择框状态
        this.specItemChange(this.spec_item_check);
      },
      // 选择属性值
      selSpecVal() {
        const target = this.$_common.deepClone(this.sku_list);
        const specval = this.spec_data_child
          .filter((item) => {
            return (
              this.spec_item_check.findIndex((itemS) => itemS === item.id) > -1
            );
          })
          .map((item) => {
            return {
              specName: item.specName,
              id: item.id,
              groupSpecId: item.pid,
            };
          });
        target[this.spec_name_index].params = this.$_common.unique(
          target[this.spec_name_index].params.concat(specval),
          ["id"]
        );
        this.sku_list = target;
        this.spec_model = false;
        // 重排规格组合
        this.specGroupRest();
      },
      // 属性值全选
      checkAllSpecChange(val) {
        this.is_indeterminate_spec = false;
        if (val) {
          this.spec_item_check = this.spec_data_child.map((item) => {
            return item.id;
          });
        } else {
          this.spec_item_check = [];
        }
      },
      // 属性值单选
      specItemChange(val) {
        let checkedCount = val.length;
        this.spec_check_all = checkedCount === this.spec_data_child.length;
        this.is_indeterminate_spec =
          checkedCount > 0 && checkedCount < this.spec_data_child.length;
      },
      // 删除规格值
      delSpecVal(indexC, indexS, itemC) {
        this.$confirm("确定要删除该规格值吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          // 编辑页面规格明细操作
          if (this.goods_id) {
            this.base_form.delSpecSkuIds = this.spec_table_Data
              .filter((item) => item.specName.indexOf(itemC.specName) > -1)
              .map((itemM) => {
                return itemM.specGroupHash;
              });
          }
          // 新增页面规格明细操作
          this.unit_data = this.unit_data.map((itemU) => {
            return {
              ...itemU,
              spec_table_Data: itemU.spec_table_Data.filter(
                (item) => item.specName.indexOf(itemC.specName) === -1
              ),
            };
          });

          const target = this.$_common.deepClone(this.sku_list);
          target[indexS].params.splice(indexC, 1);
          this.sku_list = target;
        });
      },
      // 删除规格组
      delGroupSpecId(indexS) {
        this.$confirm("确定要删除该规格组吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async () => {
          this.sku_list.splice(indexS, 1);
          if (this.goods_id) {
            this.base_form.delSpecSkuIds = this.base_form.specMultiple.map(
              (item) => {
                return item.specGroupHash;
              }
            );
          }
          // 重排规格组合
          this.specGroupRest();
        });
      },

      // 获取属性列表
      async SpecManagegetAll() {
        const { data, pageTotal } = await SpecManagegetAll({
          page: 1,
          pageSize: 50,
        });

        this.spec_data = data.filter((item) => item.specName !== "计量单位");
        // this.unit_options = data.find(item => item.specName === '计量单位').child
      },
      // 选择图片
      uploadSuccess(val, res, file, fileList) {
        const imgArr = fileList.map((item) => {
          return item.content;
        });

        if (this.base_form.images.length) {
          this.base_form.images = this.base_form.images.concat(imgArr);
        } else {
          this.base_form.images = imgArr;
        }
        this.img_list = this.base_form.images.map((item) => {
          return {
            name: "",
            content: item,
          };
        });
      },
      imgSortChange(fileList) {
        this.base_form.images = fileList.map((item) => {
          return item.content;
        });
      },
      uploadRemove(file, fileList) {
        this.base_form.images = fileList.map((item) => {
          return item.content;
        });
      },
      // 关键词删除
      handleClose(tag) {
        this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
      },
      // 关键词显示输入框
      showInput() {
        this.inputVisible = true;
        this.$nextTick((_) => {
          this.$refs.saveTagInput.$refs.input.focus();
        });
      },
      // 关键词显示输入确定
      handleInputConfirm() {
        let inputValue = this.inputValue;
        if (inputValue) {
          this.dynamicTags.push(inputValue);
        }
        this.inputVisible = false;
        this.inputValue = "";
      },
      // 关键词END
      // 设置计量单位
      // 删除辅助单位
      delFuUnit(row, it) {
        this.base_form.branchUnit.splice(it, 1);
        if (this.goods_id) {
          if (
            row.unitId &&
            this.base_form.delUnitIds.indexOf(row.unitId) === -1
          ) {
            this.base_form.delUnitIds.push(row.unitId);
          }
          const spec = this.unit_data.find(
            (item) => item.unitName === row.unitName
          );
          if (spec && spec.specGroupHash) {
            if (
              this.base_form.delSpecSkuIds.indexOf(spec.specGroupHash) === -1
            ) {
              this.base_form.delSpecSkuIds.push(spec.specGroupHash);
            }
          }
        }
        this.unit_data.splice(it + 1, 1);
      },
      // 新增辅助单位
      addFuUnit() {
        this.assist_model = true;
        this.edit_assist_model = false;
        this.assist_form = {
          unitName: "",
          isMaster: 4,
          unitId: "",
          conversion: "",
        };
      },
      // 修改附单位
      EditFuUnit(it) {
        this.assist_model = true;
        this.edit_assist_model = true;
        this.assist_form = this.base_form.branchUnit[it];
        this.assist_index = it;
      },
      // 弹窗提交 辅助单位
      subAssist() {
        if (!this.assist_form.conversion) {
          this.$message.warning("请输入单位换算关系");
          return;
        }
        if (!this.assist_form.unitName) {
          this.$message.warning("请选择辅助单位");
          return;
        }
        this.base_form.branchUnit.push({
          ...this.assist_form,
          isEditSpec: 5,
        });
        if (this.base_form.specType === 2) {
          const specTableData = this.unit_data[0]
            ? this.$_common.deepClone(this.unit_data[0].spec_table_Data || [])
            : [];
          this.unit_data.push({
            ...this.$_common.deepClone(this.assist_form),
            ...this.$_common.deepClone(priceDataLi),
            isMaster: 4,
            isEditSpec: 5,
            specImage: {
              name: "",
              url: "",
            },
            spec_table_Data: specTableData,
          });
        } else {
          this.unit_data.push({
            ...this.$_common.deepClone(this.assist_form),
            ...this.$_common.deepClone(priceDataLi),
            isMaster: 4,
            isEditSpec: 5,
            specImage: {
              name: "",
              url: "",
            },
          });
        }
        // 重排规格组合
        this.specGroupRest();
        this.assist_model = false;
      },
      // 基本单位切换
      masterUnitChange(val) {
        this.base_form.masterUnit.unitName = this.unit_options.find(
          (item) => item.id === val
        ).unitName;
        const index = this.unit_data.findIndex((item) => item.isMaster === 5);
        if (index === -1) {
          this.unit_data.unshift({
            ...this.base_form.masterUnit,
            ...this.$_common.deepClone(priceDataLi),
            isMaster: 5,
            specImage: {
              name: "",
              url: "",
            },
          });
        } else {
          this.$set(this.unit_data, index, {
            ...this.unit_data[index],
            ...this.base_form.masterUnit,
          });
        }
        // 重排规格组合
        this.specGroupRest();
        if (this.base_form.specType === 2) {
          this.tabs_active = this.unit_data[0].unitName;
        }
      },
      // 辅助单位切换
      branchUnitChange(val) {
        this.assist_form.unitName = this.unit_options.find(
          (item) => item.id === val
        ).unitName;
      },
      // 获取详情
      async getGoodsBasicInfoById() {
        const { data } = await getQuickGoodsInfo(this.goods_id);

        this.region_arr = data.notArea;
        this.customer_type_check = data.notCustomerType
          ? data.notCustomerType.split(",").map((item) => parseInt(item))
          : [];
        this.customer_list = data.notCustomerLists || [];

        this.isEditSpec = data.isEditSpec;
        // return

        let masterUnit = data.unitData.find((item) => item.isMaster === 5) || {
          barCode: "",
          weight: "",
          isMaster: 5,
          isDefault: 5,
          unitName: "",
          unitId: "",
        };
        this.isNew = masterUnit ? masterUnit.isNew || 4 : 4;
        let branchUnit = [];
        if (data.specType === 2) {
          const unitData = data.unitData.filter((item) => item.isMaster === 4);
          branchUnit = (unitData || []).map((item) => {
            return {
              ...item,
              isEditSpec: data.isEditSpec,
            };
          });
        } else if (data.specType === 1) {
          const unitData = data.specMultiple.filter(
            (item) => item.isMaster === 4
          );
          branchUnit = (unitData || []).map((item) => {
            return {
              conversion: item.conversion,
              id: item.id,
              isMaster: item.isMaster,
              unitId: item.unitId,
              unitName: item.unitName,
              isEditSpec: item.isEditSpec,
            };
          });
        }
        this.base_form = {
          ...data,
          masterUnit: masterUnit,
          storage: data.storage,
          delUnitIds: [],
          delSpecSkuIds: [],
          specType: data.specType,
          branchUnit: branchUnit,
          categoryPath: data.categoryPath
            ? data.categoryPath.split(",").map((item) => {
                return parseInt(item);
              })
            : [],
          categoryId: data.categoryId,
          assistCategoryId: data.assistCategoryId,
          assistCategoryPath: data.assistCategoryPath || [],
          isEq: data.isEq, // 抄码商品
          isDistribution: data.isDistribution, // 负库存销售
          isShield: data.isShield, // 经营屏蔽
          deliverySupIds: data.deliverySupIds.split(","), // 物流支持 固定值 1 快递 2 自提 传参格式：1,2
          expressType: data.expressType, // 快递运费 1 包邮 2 运费模版 3 固定费用
          expressFee: data.expressFee, // 固定费用
          showExpress: data.showExpress, // 是否展示快递 5展示 4不展示
          ruleId: data.ruleId, // 运费模版id
        };
        // 副分类
        if (data.assistCategoryPath && data.assistCategoryPath.length) {
          this.assist_cate = data.assistCategoryPath.map((item) => {
            return {
              assistCategoryPath: item.split(",").map((iteme) => {
                return parseInt(iteme);
              }),
            };
          });
        } else {
          this.assist_cate = [
            {
              assistCategoryPath: [],
            },
          ];
        }
        this.img_list = data.images.map((item) => {
          return {
            name: "",
            url: item,
          };
        });
        this.dynamicTags = data.tag.filter((item) => !!item);
        // 多规格数据
        if (parseInt(this.base_form.specType) === 2) {
          this.sku_list = data.specGroup.map((item) => {
            return {
              spec_data_child: this.spec_data.find(
                (itemF) => itemF.id === item.groupSpec.specId
              ).child,
              groupSpecId: item.groupSpec.specId,
              groupSpecName: item.groupSpec.specName,
              self_spec_val: "",
              self_spec_input: false,
              params: item.params.map((itemC) => {
                return {
                  id: itemC.specValueId,
                  specName: itemC.specValueName,
                  groupSpecId: item.groupSpec.specId,
                };
              }),
            };
          });
          this.unit_data = data.unitData.map((item) => {
            const specTableData = data.specMultiple
              .filter((itemU) => itemU.unitId === item.unitId)
              .map((itemSP) => {
                return {
                  isEditSpec: itemSP.isEditSpec,
                  inventory: itemSP.inventory - 0,
                  specGroupHash: itemSP.specGroupHash,
                  id_D: itemSP.id,
                  conversion: itemSP.conversion,
                  unitId: itemSP.unitId,
                  specName: (itemSP.specGroup || [])
                    .map((itemP) => {
                      return itemP.specValueName;
                    })
                    .join("_"),
                  id: (itemSP.specGroup || [])
                    .map((itemP) => {
                      return itemP.specValueId;
                    })
                    .join("_"),
                  groupSpecId: (itemSP.specGroup || [])
                    .map((itemP) => {
                      return itemP.specId;
                    })
                    .join("_"),
                  groupSpecName: (itemSP.specGroup || [])
                    .map((itemP) => {
                      return itemP.specName;
                    })
                    .join("_"),
                  specImage: {
                    name: "",
                    url: itemSP.specImage || "",
                  },
                  barCode: itemSP.barCode,
                  weight: itemSP.weight,
                  isDefault: itemSP.isDefault,
                  salePrice: itemSP.salePrice.salePrice,
                  enabledLadder: itemSP.salePrice.enabledLadder,
                  ladderPrice: itemSP.salePrice.ladderPrice,
                  marketPrice: itemSP.salePrice.marketPrice,
                  memberPrice: itemSP.memberPrice,
                  setNum: itemSP.salePrice.setNum,
                  isSale: itemSP.isSale || 5,
                  // 客户类型和客户快速调价
                  customerTypePrice: [],
                  customerTypePriceOpen: false,
                  customerPrice: [],
                  customerPriceOpen: false,
                };
              });
            return {
              ...item,
              spec_table_Data: specTableData,
            };
          });
          this.tabs_active = this.unit_data[0].unitName;
        } else {
          this.unit_data = data.specMultiple.map((item) => {
            return {
              isEditSpec: item.isEditSpec,
              inventory: item.inventory - 0,
              specGroupHash: item.specGroupHash,
              id_D: item.id,
              isMaster: item.isMaster,
              conversion: item.conversion,
              unitName: item.unitName,
              unitId: item.unitId,
              specImage: {
                name: "",
                url: item.specImage || "",
              },
              barCode: item.barCode,
              weight: item.weight,
              isDefault: item.isDefault,
              salePrice: item.salePrice.salePrice,
              enabledLadder: item.salePrice.enabledLadder,
              ladderPrice: item.salePrice.ladderPrice,
              marketPrice: item.salePrice.marketPrice,
              memberPrice: item.memberPrice,
              setNum: item.salePrice.setNum,
              isSale: item.isSale || 5,
              // 客户类型和客户快速调价
              customerTypePrice: [],
              customerTypePriceOpen: false,
              customerPrice: [],
              customerPriceOpen: false,
            };
          });
        }
        // 获取指定商品的最后生效的客户调价单数据
        await this.getCustomerPriceByGoodsIds();
        //获取指定商品的最后生效的客户类型调价数据
        await this.getCustomerTypePriceByGoodsIds();
      },
      // 发布商品
      async submitGoods() {
        // console.log(JSON.stringify(this.unit_data))
        // console.log(this.unit_data)
        // return
        this.$refs["base_form"].validate(async (valid) => {
          if (valid) {
            let specGroup = [];
            let specMultiple = [];
            if (this.base_form.specType === 2) {
              // 多规格
              specGroup = this.sku_list.map((item) => {
                return {
                  groupSpec: {
                    specName: item.groupSpecName,
                    specId: item.groupSpecId,
                  },
                  params: item.params.map((item) => {
                    return {
                      specValueId: item.id,
                      specValueName: item.specName,
                    };
                  }),
                };
              });
              this.unit_data.forEach((item) => {
                item.spec_table_Data.forEach((itemSP) => {
                  let specIdG = (itemSP.id + "").split("_");
                  let specNameG = itemSP.specName.split("_");
                  let groupSpecNameG = itemSP.groupSpecName.split("_");
                  let groupSpecIdG = (itemSP.groupSpecId + "").split("_");
                  let specGroupS = groupSpecIdG.map((itemUU, indexUU) => {
                    return {
                      specId: groupSpecIdG[indexUU],
                      specName: groupSpecNameG[indexUU],
                      specValueName: specNameG[indexUU],
                      specValueId: specIdG[indexUU],
                    };
                  });
                  let salePriceS = {
                    conversion: item.conversion || 0,
                    unitName: item.unitName + "_" + itemSP.specName,
                    unitId: item.unitId,
                    isMaster: item.isMaster,
                    deleteStatus: itemSP.deleteStatus || 4,
                    enabledLadder: itemSP.enabledLadder,
                    salePriceAreaType: 1,
                    salePrice: itemSP.salePrice,
                    ladderPrice: itemSP.ladderPrice,
                    marketPrice: itemSP.marketPrice,
                    memberPrice: itemSP.memberPrice,
                    setNum: itemSP.setNum,
                    isSale: itemSP.isSale,
                  };
                  let customerPrice = [];
                  itemSP.customerPrice.forEach((itemP) => {
                    if (!item.priceId) {
                      customerPrice.push({
                        price: itemP.price,
                        unitName: itemP.unitName,
                        adjPricetag: itemP.adjPricetag,
                        customerName: itemP.name,
                        customerId: itemP.id,
                        ladderPrice: itemP.ladderPrice,
                      });
                    }
                  });
                  let customerTypePrice = [];
                  itemSP.customerTypePrice.forEach((itemP) => {
                    if (!item.priceId) {
                      customerTypePrice.push({
                        price: itemP.price,
                        unitName: itemP.unitName,
                        adjPricetag: itemP.adjPricetag,
                        customerName: itemP.name,
                        customerType: itemP.id,
                        ladderPrice: itemP.ladderPrice,
                      });
                    }
                  });
                  specMultiple.push({
                    unitId: item.unitId,
                    unitName: item.unitName,
                    isMaster: item.isMaster,
                    conversion: item.conversion || 0,
                    specImage: itemSP.specImage.url,
                    isDefault: itemSP.isDefault,
                    barCode: itemSP.barCode,
                    weight: itemSP.weight,
                    specGroup: specGroupS,
                    salePrice: salePriceS,
                    customerPrice: customerPrice,
                    customerTypePrice: customerTypePrice,
                  });
                });
              });
            } else {
              // 单规格
              specMultiple = this.unit_data.map((item) => {
                const salePriceS = {
                  conversion: item.conversion || 0,
                  unitName: item.unitName,
                  unitId: item.unitId,
                  isMaster: item.isMaster,
                  deleteStatus: item.deleteStatus || 4,
                  enabledLadder: item.enabledLadder,
                  salePriceAreaType: 1,
                  salePrice: item.salePrice,
                  ladderPrice: item.ladderPrice,
                  marketPrice: item.marketPrice,
                  memberPrice: item.memberPrice,
                  setNum: item.setNum,
                  isSale: item.isSale,
                };
                let customerPrice = [];
                item.customerPrice.forEach((itemP) => {
                  if (!itemP.priceId) {
                    customerPrice.push({
                      price: itemP.price,
                      unitName: itemP.unitName,
                      adjPricetag: itemP.adjPricetag,
                      customerName: itemP.name,
                      customerId: itemP.id,
                      ladderPrice: itemP.ladderPrice,
                    });
                  }
                });
                let customerTypePrice = [];
                item.customerTypePrice.forEach((itemP) => {
                  if (!itemP.priceId) {
                    customerTypePrice.push({
                      price: itemP.price,
                      adjPricetag: itemP.adjPricetag,
                      customerName: itemP.name,
                      customerType: itemP.id,
                      unitName: itemP.unitName,
                      ladderPrice: itemP.ladderPrice,
                    });
                  }
                });
                return {
                  barCode: item.barCode,
                  weight: item.weight,
                  isDefault: item.isDefault,
                  unitId: item.unitId,
                  unitName: item.unitName,
                  isMaster: item.isMaster,
                  conversion: item.conversion || 0,
                  specImage: item.specImage.url,
                  specGroup: [],
                  salePrice: salePriceS,
                  customerTypePrice: customerTypePrice,
                  customerPrice: customerPrice,
                };
              });
            }
            const isFSale = specMultiple.every(
              (item) => item.salePrice.isSale === 4
            );
            if (isFSale) {
              this.$message.warning("至少保留一条规格的销售状态为【启用】");
              return;
            }
            const unitData = this.$_common.deepClone(this.base_form.branchUnit);
            unitData.unshift(this.base_form.masterUnit);
            const notCustomer = this.customer_list.map((item) => {
              return item.id;
            });
            // 副分类数据组装
            let assistCategoryPath = [];
            let assistCategoryId = [];
            // 过滤只有选择分类的数据
            const assistCate = this.assist_cate.filter(
              (item) => !!item.assistCategoryPath.length
            );
            assistCate.forEach((item) => {
              assistCategoryPath.push(item.assistCategoryPath.join(","));
              assistCategoryId.push(
                item.assistCategoryPath[item.assistCategoryPath.length - 1]
              );
            });
            const params = {
              merchantId: this.base_form.merchantId,
              categoryPath: this.base_form.categoryPath.join(","),
              categoryId: this.base_form.categoryId,
              assistCategoryPath: assistCategoryPath,
              assistCategoryId: assistCategoryId.join(","),
              title: this.base_form.title,
              storage: this.base_form.storage,
              delUnitIds: this.base_form.delUnitIds,
              delSpecSkuIds: this.base_form.delSpecSkuIds,
              specType: this.base_form.specType,
              createUserName: this.userName,
              specGroup: specGroup,
              specMultiple: specMultiple,
              unitData: unitData,
              describe: this.base_form.describe,
              code: this.base_form.code,
              barCode: this.base_form.barCode,
              weight: this.base_form.weight,
              expireTime: this.base_form.expireTime,
              brandId: this.base_form.brandId,
              tag: this.dynamicTags.join(","),
              description: this.base_form.description,
              noSalesShop: "",
              images: this.base_form.images,
              enableStatus: this.base_form.enableStatus,
              isEq: this.base_form.isEq, //抄码商品
              isDistribution: this.base_form.isDistribution, //是否负库存销售
              isShield: this.base_form.isShield, //经营屏蔽
              deliverySupIds: this.base_form.deliverySupIds.join(","), // 物流支持 固定值 1 快递 2 自提 传参格式：1,2
              expressType: this.base_form.expressType, // 快递运费 1 包邮 2 运费模版 3 固定费用
              expressFee: this.base_form.expressFee, // 固定费用
              showExpress: this.base_form.showExpress, // 是否展示快递 5展示 4不展示
              ruleId: this.base_form.ruleId, // 运费模版id
              notArea:
                this.base_form.isShield === 5 ? this.base_form.notArea : [], // 经营屏蔽地区
              notCustomerType:
                this.base_form.isShield === 5
                  ? this.customer_type_check.join(",")
                  : "", //经营屏蔽 客户类型屏蔽
              notCustomer:
                this.base_form.isShield === 5 ? notCustomer.join(",") : "", //经营屏蔽 客户屏蔽
              isStore: this.systemType === 3,
            };
            // console.log(params)
            // return
            this.loading = true;
            let target = {};
            try {
              if (this.$route.params.id) {
                target = await editQuickGoods({
                  ...params,
                  id: this.goods_id,
                  basicGoodsId: this.base_form.basicGoodsId,
                });
              } else {
                target = await addBasicAndPublishGoods(params);
              }
              this.loading = false;

              this.$message({
                type: "success",
                message: "提交成功",
              });
              await this.delPauseSave();
              if (this.systemType === 3) {
                await this.$closeCurrentGoEdit(`/goods/sale/MerchantsGoods`);
              } else {
                await this.$closeCurrentGoEdit(`/goods/sale/PublishGoods`);
              }
            } finally {
              this.loading = false;
            }
          }
        });
      },
      // 商品分类选择
      categoryChange(val) {
        this.base_form.categoryId = val[val.length - 1];
      },
      // 商品副分类选择
      categoryAssistChange(val) {
        this.base_form.assistCategoryId = val[val.length - 1];
      },
      // 品牌选择
      brandConfirm(val) {
        if (val.length > 1) {
          this.$message({
            type: "error",
            message: "请选择一个品牌！",
          });
          return;
        }
        this.base_form.brandName = val[0].title;
        this.base_form.brandId = val[0].id;
      },
      // 计算市场价
      salePriceBlur(index, indexU) {
        if (this.base_form.specType === 1) {
          const target = this.$_common.deepClone(this.unit_data);
          const marketPrice = this.$NP.times(
            target[index].salePrice,
            this.salePriceTimes
          );
          target[index] = {
            ...target[index],
            marketPrice: marketPrice,
          };
          // 当前失去焦点的为主单位
          if (target[index].isMaster === 5) {
            // 单位换算关系存在且这个单位为辅助单位且当前单位未设置过价格
            target.forEach((item) => {
              if (item.conversion && item.isMaster === 4 && !item.salePrice) {
                item.salePrice = this.$NP.times(
                  target[index].salePrice,
                  item.conversion
                );
                item.marketPrice = this.$NP.times(marketPrice, item.conversion);
              }
            });
          }

          this.unit_data = target;
        } else {
          this.unit_data[indexU].spec_table_Data[
            index
          ].marketPrice = this.$NP.times(
            this.unit_data[indexU].spec_table_Data[index].salePrice,
            this.salePriceTimes
          );
        }
      }, // 会员价失去焦点
      memberPriceBlur(index) {
        // 根据比例自动换算 会员价
        if (this.base_form.specType === 1) {
          const target = this.$_common.deepClone(this.unit_data);
          target.forEach((item) => {
            if (item.conversion && item.isMaster === 4) {
              item.memberPrice = this.$NP.times(
                target[index].memberPrice,
                item.conversion
              );
            }
          });
          this.unit_data = target;
        }
      },
      // 规格明细同步数据
      otherSetPrice(row, index) {
        const target = this.$_common.deepClone(this.unit_data);
        target[index].spec_table_Data = target[index].spec_table_Data.map(
          (item) => {
            return {
              ...item,
              marketPrice: row.marketPrice,
              memberPrice: row.memberPrice,
              salePrice: row.salePrice,
              enabledLadder: row.enabledLadder,
              ladderPrice: row.ladderPrice,
              setNum: row.setNum,
              isSale: row.isSale || 5,
              specImage: row.specImage,
              barCode: row.barCode,
              weight: row.weight,
              // 客户类型和客户快速调价
              customerTypePrice: row.customerTypePrice,
              customerTypePriceOpen: row.customerTypePriceOpen,
              customerPrice: row.customerPrice,
              customerPriceOpen: row.customerPriceOpen,
            };
          }
        );
        this.unit_data = target;
      },
      // 规格明细删除
      specDetailDel(row, index) {
        let target = this.$_common.deepClone(this.unit_data);
        if (this.goods_id) {
          if (this.base_form.delSpecSkuIds.indexOf(row.specGroupHash) === -1) {
            this.base_form.delSpecSkuIds.push(row.specGroupHash);
          }
        }

        target = target.map((item) => {
          item.spec_table_Data.splice(index, 1);
          return item;
        });
        // target[0].spec_table_Data.splice(index, 1)
        const specNameArr = row.specName.indexOf("_")
          ? row.specName.split("_")
          : row.specName;
        let isFalseVal = "";
        for (let i in specNameArr) {
          let itemS = specNameArr[i];
          const isHave = target.some((itemU) => {
            return itemU.spec_table_Data.find(
              (item) => item.specName.indexOf(itemS) > -1
            );
          });
          if (!isHave) {
            isFalseVal = itemS;
            break;
          }
        }

        // console.log("isStay,", isFalseVal);
        if (isFalseVal) {
          this.sku_list.forEach((item) => {
            const indexP = item.params.findIndex(
              (itemP) => itemP.specName === isFalseVal
            );
            if (indexP > -1) {
              item.params.splice(indexP, 1);
            }
          });
        }
        this.unit_data = target;
      },

      // 选择商铺
      selChose(val, row) {
        this.base_form.shopId = row[0].id;
        this.base_form.shopName = row[0].name;
      },
      // 地区选择
      selRegion(row) {
        this.base_form.notArea = row.map((item) => {
          return item.codePath;
        });
      },
      // 获取客户类型
      async getAllCustomerSource() {
        const data = await getAllCustomerSource({
          page: 1,
          pageSize: 50,
        });

        this.customer_type_list = data.data;
      },
      // 选择客户
      customerSel(val) {
        this.customer_list = val;
      },
      // 删除客户
      deleteCustomer(index) {
        this.customer_list.splice(index, 1);
      },
      // 打开指定价弹窗
      openModal(index, key, row, indexU) {
        // 获取阶梯价数据，做阶梯价调价
        if (row) {
          this.unitisMaster = row.isMaster;
          this.sku_id = row.id;
          this.ladderPrice = row.ladderPrice;
          this.enabledLadder = row.enabledLadder;
          if (key === "type_price_show") {
            // 客户类型指定价调价数据
            this.customerTypePriceOpen = row.customerTypePriceOpen;
            this.customerTypePrice = row.customerTypePrice;
          }
          if (key === "appoint_price_show") {
            // 客户指定价调价数据
            this.customerPriceOpen = row.customerPriceOpen;
            this.customerPrice = row.customerPrice;
          }
        }
        this.sku_index = index;
        if (indexU > -1) {
          this.unit_index = indexU;
        }
        this[key] = true;
      },
      // 指定价数据确定
      appointPriceConfirm(customerPriceOpen, customerPrice) {
        console.log(customerPrice);
        if (this.base_form.specType === 1) {
          // 单规格
          const target = this.$_common.deepClone(this.unit_data);
          target[this.sku_index].customerPriceOpen = customerPriceOpen;
          target[this.sku_index].customerPrice = customerPriceOpen
            ? customerPrice
            : [];
          this.unit_data = target;
        } else {
          // 多规格
          const target = this.$_common.deepClone(this.unit_data);
          target[this.unit_index].spec_table_Data[
            this.sku_index
          ].customerPriceOpen = customerPriceOpen;
          target[this.unit_index].spec_table_Data[
            this.sku_index
          ].customerPrice = customerPriceOpen ? customerPrice : [];
          this.unit_data = target;
        }
      },
      // 指定价数据取消
      appointPriceCancel() {
        this.appoint_price_show = false;
      },
      typePriceConfirm(customerTypePriceOpen, customerTypePrice) {
        if (this.base_form.specType === 1) {
          // 单规格
          const target = this.$_common.deepClone(this.unit_data);
          target[this.sku_index].customerTypePriceOpen = customerTypePriceOpen;
          target[this.sku_index].customerTypePrice = customerTypePriceOpen
            ? customerTypePrice
            : [];
          this.unit_data = target;
        } else {
          // 多规格
          const target = this.$_common.deepClone(this.unit_data);
          target[this.unit_index].spec_table_Data[
            this.sku_index
          ].customerTypePriceOpen = customerTypePriceOpen;
          target[this.unit_index].spec_table_Data[
            this.sku_index
          ].customerTypePrice = customerTypePriceOpen ? customerTypePrice : [];
          this.unit_data = target;
        }
      },
      typePriceCancel() {
        this.type_price_show = false;
      },
      // 阶梯价设置
      ladderPriceConfirm(enabledLadder, ladderPrice) {
        if (this.base_form.specType === 1) {
          // 单规格
          const target = this.$_common.deepClone(this.unit_data);
          if (this.base_form.isEq === 5) {
            // 抄码商品根据比例自动换算销售价
            target.forEach((item) => {
              item.enabledLadder = enabledLadder;
              if (enabledLadder) {
                if (item.conversion && item.isMaster === 4) {
                  item.ladderPrice = ladderPrice.map((ladder) => {
                    return {
                      ...ladder,
                      price: this.$NP.times(ladder.price, item.conversion),
                    };
                  });
                } else {
                  item.ladderPrice = ladderPrice;
                }
              } else {
                item.ladderPrice = [];
              }
            });
          } else {
            target[this.sku_index].enabledLadder = enabledLadder;
            target[this.sku_index].ladderPrice = enabledLadder
              ? ladderPrice
              : [];
          }
          this.unit_data = target;
        } else {
          // 多规格
          const target = this.$_common.deepClone(this.unit_data);
          target[this.unit_index].spec_table_Data[
            this.sku_index
          ].enabledLadder = enabledLadder;
          target[this.unit_index].spec_table_Data[
            this.sku_index
          ].ladderPrice = enabledLadder ? ladderPrice : [];
          this.unit_data = target;
        }
      },
      ladderPriceCancel() {
        this.ladder_price_show = false;
      },
      // 客户调价单
      async CustomerPriceAdjustmentAdd(params) {
        if (!params.length) return;
        const { data } = await CustomerPriceAdjustmentAdd(params);
      },
      // 客户类型调价单
      async addCustomerTypePriceAdjustment(params) {
        if (!params.length) return;
        const { data } = await addCustomerTypePriceAdjustment(params);
      },
      // 商品分类列表
      async getAllCategoryPost() {
        const { data } = await getAllCategoryPost({
          enableStatus: 5,
        });

        if (JSON.stringify(data) === "{}") {
          this.category_data = [];
        } else {
          this.category_data = data;
        }
      },
      // 自定义选择即改变
      clickChange(event) {
        event.target.parentElement.parentElement.firstChild.click();
      },
      delAssistCate(index) {
        this.assist_cate.splice(index, 1);
      },
      addAssistCate() {
        this.assist_cate.push({
          assistCategoryPath: [],
        });
      },
      // 获取商户列表
      async getAllMerchantList() {
        const { data } = await getAllMerchantList();
        this.sel_cities = data;
      },
      // 抄码商品切换
      isEqChange(val) {
        if (this.isEditSpec !== 4 && val === 5) {
          this.base_form.masterUnit = {
            isDefault: 5,
            isMaster: 5,
            weight: "",
            unitName: "",
            unitId: "",
            barCode: "",
          };
          this.base_form.branchUnit = [];
          this.unit_data = [];
        }
      },
      // 获取指定商品的最后生效的客户调价单数据
      async getCustomerPriceByGoodsIds() {
        const { data, pageTotal } = await getCustomerPriceByGoodsIds({
          goodsId: this.goods_id,
          page: 1,
          pageSize: 200,
        });
        this.customerPrice = data;
      },
      // 获取指定商品的最后生效的客户类型调价数据
      async getCustomerTypePriceByGoodsIds() {
        const { data } = await getCustomerTypePriceByGoodsIds({
          goodsId: this.goods_id,
          page: 1,
          pageSize: 20,
        });
        this.customerTypePrice = data;
        this.adjustmentData();
      },
      adjustmentData() {
        if (this.base_form.specType === 1) {
          this.unit_data = this.unit_data.map((item) => {
            //客户类型价
            let customerTypePrice = [];
            this.customerTypePrice.forEach((type) => {
              if (type.salePrice && type.salePrice.length) {
                type.salePrice.forEach((pitem) => {
                  if (parseInt(pitem.skuId) === item.id_D) {
                    customerTypePrice.push({
                      adjPricetag: pitem.adjPricetag,
                      ladderPrice: pitem.ladderPrice || [],
                      price: pitem.price,
                      name: type.customerTypeName,
                      id: type.customerType,
                      priceId: type.id,
                    });
                  }
                });
              }
            });
            //客户价
            let customerPrice = [];
            this.customerPrice.forEach((type) => {
              if (type.salePrice && type.salePrice.length) {
                type.salePrice.forEach((pitem) => {
                  if (parseInt(pitem.skuId) === item.id_D) {
                    customerPrice.push({
                      adjPricetag: pitem.adjPricetag,
                      ladderPrice: pitem.ladderPrice || [],
                      price: pitem.price,
                      name: type.customerName,
                      id: type.customerId,
                      priceId: type.id,
                    });
                  }
                });
              }
            });
            return {
              ...item,
              // 客户类型和客户快速调价
              customerTypePrice: customerTypePrice,
              customerTypePriceOpen: customerTypePrice.length > 0,
              customerPrice: customerPrice,
              customerPriceOpen: customerPrice.length > 0,
            };
          });
        } else {
          this.unit_data = this.unit_data.map((itemU) => {
            return {
              ...itemU,
              spec_table_Data: itemU.spec_table_Data.map((item) => {
                //客户类型价
                let customerTypePrice = [];
                this.customerTypePrice.forEach((type) => {
                  if (type.salePrice && type.salePrice.length) {
                    type.salePrice.forEach((pitem) => {
                      if (parseInt(pitem.skuId) === item.id_D) {
                        customerTypePrice.push({
                          adjPricetag: pitem.adjPricetag,
                          ladderPrice: pitem.ladderPrice || [],
                          price: pitem.price,
                          name: type.customerTypeName,
                          id: type.customerType,
                          priceId: type.id,
                        });
                      }
                    });
                  }
                });
                //客户价
                let customerPrice = [];
                this.customerPrice.forEach((type) => {
                  if (type.salePrice && type.salePrice.length) {
                    type.salePrice.forEach((pitem) => {
                      if (parseInt(pitem.skuId) === item.id_D) {
                        customerPrice.push({
                          adjPricetag: pitem.adjPricetag,
                          ladderPrice: pitem.ladderPrice || [],
                          price: pitem.price,
                          name: type.customerName,
                          id: type.customerId,
                          priceId: type.id,
                        });
                      }
                    });
                  }
                });
                return {
                  ...item,
                  customerTypePrice: customerTypePrice,
                  customerTypePriceOpen: customerTypePrice.length > 0,
                  customerPrice: customerPrice,
                  customerPriceOpen: customerPrice.length > 0,
                };
              }),
            };
          });
        }
        console.log(" this.unit_data:", this.unit_data);
      },
    },
  };
</script>
<style scoped>
  .sku-name-item {
    background-color: #f4f4f4;
    padding: 5px 0;
  }
</style>
