<!--添加基础资料-->
<template>
  <ContainerTit>
    <span v-if="!!goods_id" slot="pagetit">商品详情</span>
    <span v-if="!!basicGoodsId" slot="pagetit">商品发布</span>
    <div
      v-if="
        (!!basicGoodsId || !!goods_id) &&
        $accessCheck($Access.PublishGoodsEditGoods)
      "
      slot="headr"
    >
      <el-button :loading="sub_load" type="primary" @click="checkSub">
        提交保存
      </el-button>
    </div>
    <div v-if="$route.name === 'AddGoods'" slot="headr">
      <el-button :loading="sub_load" @click="delPauseSave(1)">
        清除暂存
      </el-button>
      <el-button :loading="sub_load" @click="tempData">暂存</el-button>
      <el-button :loading="sub_load" type="primary" @click="checkSub">
        提交保存
      </el-button>
    </div>
    <el-form
      ref="base_form"
      label-position="right"
      :model="base_form"
      :rules="base_rules"
      size="small"
      label-width="130px"
    >
      <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-tab-pane label="商品服务" name="4"></el-tab-pane>-->
          <!--<el-tab-pane
            v-if="goods_id"
            label="价格波动图"
            name="3"
          ></el-tab-pane>-->
        </el-tabs>
      </div>
      <!--      商品信息-->
      <div v-if="page_tabs === '1'">
        <el-row :gutter="10">
          <el-col :span="12">
            <div class="detail-tab-item">
              <div class="detail-tab-title">基础信息</div>
              <div class="detail-tab-main" style="padding-bottom: 1px">
                <el-form-item
                  v-if="systemType === 1"
                  label="选择店铺:"
                  prop="shopName"
                >
                  <SelectShop
                    v-model="base_form.shopId"
                    :is-default="true"
                    :clearable="false"
                    :action="1"
                    :materiel-id="basicGoodsId"
                    @change="selChose"
                    @default="shopDefault"
                  />
                  <el-button size="mini" type="text" @click="getShop">
                    【新建店铺】
                  </el-button>
                </el-form-item>
                <el-form-item v-else label="当前店铺:" prop="shopName">
                  {{ base_form.shopName }}
                </el-form-item>
                <el-form-item label="选择商品:" prop="goodsName">
                  <el-input
                    v-if="!basicGoodsId"
                    v-model="base_form.goodsName"
                    style="width: 200px"
                    :disabled="!base_form.shopName || !!goods_id"
                    readonly
                    placeholder="请选择商品"
                  >
                    <i
                      slot="suffix"
                      class="el-input__icon el-icon-search"
                      @click="openGoodsModel"
                    ></i>
                  </el-input>
                  <span v-else>{{ base_form.goodsName || "--" }}</span>
                </el-form-item>
                <el-form-item label="商品分组:">
                  <el-select
                    v-model="options_value"
                    multiple
                    style="width: 200px"
                    placeholder="请选择"
                  >
                    <el-option
                      v-for="item in goods_groups"
                      :key="item.id"
                      :label="item.name"
                      :value="item.id"
                    ></el-option>
                  </el-select>
                </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="负库存销售:">
                  <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-form-item
                  v-if="goods_data.specType === 2"
                  label="重量属性斤价:"
                >
                  <el-switch
                    v-model="base_form.showMinUnitPrice"
                    active-color="#36B365"
                    inactive-color="#ff4949"
                    :active-value="5"
                    :inactive-value="4"
                    active-text="显示"
                    inactive-text="不显示"
                  ></el-switch>
                  <el-tooltip placement="right">
                    <div slot="content">
                      根据最小单位换算比例换算当前重量属性每斤价钱
                      <br />
                      例如：10公斤=50元换算后1斤=2.5元
                    </div>
                    <i
                      style="
                        position: absolute;
                        top: 30%;
                        left: 150px;
                        color: rgb(192, 197, 207);
                      "
                      class="el-icon-question"
                    ></i>
                  </el-tooltip>
                </el-form-item>
              </div>
            </div>
          </el-col>
          <el-col :span="12">
            <!--    物流设置  -->
            <div class="detail-tab-item" style="height: 330px">
              <div class="detail-tab-title clearfix">物流设置</div>
              <div class="detail-tab-main">
                <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>
                <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>
                <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
                      v-model="base_form.expressFee"
                      style="width: 200px"
                      type="number"
                      :controls="false"
                    >
                      <el-button slot="append">元</el-button>
                    </el-input>
                  </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-title clearfix">商品服务</div>
              <div class="detail-tab-main">
                <el-checkbox-group
                  v-model="choose_support"
                  style="margin-left: 25px"
                >
                  <el-checkbox
                    v-for="(item, index) in tableData"
                    :key="index"
                    :label="item.id"
                  >
                    {{ item.servicesName }}
                    <el-tooltip
                      class="item"
                      effect="dark"
                      :content="item.describe"
                      placement="top"
                    >
                      <span
                        class="el-icon-question"
                        style="color: rgb(96, 98, 102)"
                      ></span>
                    </el-tooltip>
                  </el-checkbox>
                </el-checkbox-group>
              </div>
            </div>
          </el-col>
        </el-row>

        <!--      无属性价格管理-->
        <div v-if="goods_data.specType === 1" class="detail-tab-item">
          <div class="detail-tab-title clearfix">价格管理</div>
          <div class="detail-tab-main">
            <el-table border :data="price_data">
              <el-table-column
                prop="unitName"
                label="属性"
                min-width="80"
              ></el-table-column>
              <el-table-column label="换算比例" min-width="80">
                <template slot-scope="scope">
                  <span v-if="scope.row.isMaster === 4">
                    1{{ scope.row.unitName }}={{ Number(scope.row.conversion)
                    }}{{ primary_unit }}
                  </span>
                  <span v-else>主单位</span>
                </template>
              </el-table-column>
              <el-table-column
                v-if="goods_data.supplierId && !goods_id"
                prop="costPrice"
                label="成本价/元"
                min-width="100"
              >
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.costPrice"
                    style="width: 80px"
                    :controls="false"
                    placeholder="成本价"
                    size="small"
                  ></el-input-number>
                </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)"
                  ></el-input-number>
                </template>
              </el-table-column>
              <el-table-column label="会员价/元" min-width="120">
                <template slot-scope="scope">
                  <el-input-number
                    v-model="scope.row.memberPrice"
                    size="mini"
                    :controls="false"
                    :min="0"
                    style="width: 100%"
                    @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"
                    :precision="0"
                    :min="1"
                  ></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 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="infCustomerTypePrice.vueo"
                    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">
                  <div v-if="$route.name !== 'EditGoods'">
                    <el-button
                      v-if="
                        scope.row.customerTypePrice.length &&
                        scope.row.customerTypePriceOpen
                      "
                      type="primary"
                      size="mini"
                      @click="
                        openModal(scope.$index, 'type_price_show', scope.row)
                      "
                    >
                      已设置
                    </el-button>
                    <el-button
                      v-else
                      type="info"
                      size="mini"
                      @click="
                        openModal(scope.$index, 'type_price_show', scope.row)
                      "
                    >
                      去设置
                    </el-button>
                  </div>
                  <div v-else>
                    <el-button
                      :type="
                        scope.row.customerTypePriceOpen ? 'primary' : 'info'
                      "
                      size="mini"
                      @click="
                        openModal(scope.$index, 'type_price_show', scope.row)
                      "
                    >
                      {{ scope.row.customerTypePriceOpen ? "查看" : "未设置" }}
                    </el-button>
                  </div>
                </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)
                    "
                  >
                    已设置
                  </el-button>
                  <el-button
                    v-else
                    type="info"
                    size="mini"
                    @click="
                      openModal(scope.$index, 'appoint_price_show', scope.row)
                    "
                  >
                    去设置
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <!--      多属性价格管理-->
        <div v-if="goods_data.specType === 2" class="detail-tab-item">
          <div class="detail-tab-title clearfix">价格管理</div>
          <div class="detail-tab-main">
            <el-form-item v-if="false" label="商品推荐:" prop="isRecommend">
              <el-radio v-model="base_form.isRecommend" :label="5">是</el-radio>
              <el-radio v-model="base_form.isRecommend" :label="4">否</el-radio>
            </el-form-item>
            <el-tabs v-model="unit_name_tab" type="card">
              <el-tab-pane
                v-for="(itemU, indexU) in goods_data.unitData"
                :key="indexU"
                :label="itemU.unitName"
                :name="itemU.unitName"
              >
                <el-table
                  :data="itemU.priceData"
                  border
                  style="width: 100%"
                  size="mini"
                >
                  <el-table-column
                    prop="skuName"
                    label="属性"
                    min-width="80"
                  ></el-table-column>
                  <el-table-column
                    v-if="base_form.showMinUnitPrice === 5"
                    prop="skuName"
                    label="换算比例"
                    min-width="100"
                  >
                    <template slot="header" slot-scope="scope">
                      <span v-if="false">{{ scope.$index }}</span>
                      {{ itemU.unitName }}/元换算比例
                    </template>
                    <template slot-scope="scope">
                      <el-input-number
                        v-model="scope.row.minUnitPriceConvert"
                        size="mini"
                        :controls="false"
                      ></el-input-number>
                    </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"
                        @blur="salePriceBlur(scope.$index, indexU)"
                      ></el-input-number>
                    </template>
                  </el-table-column>
                  <el-table-column label="会员价/元" min-width="120">
                    <template slot-scope="scope">
                      <el-input-number
                        v-model="scope.row.memberPrice"
                        size="mini"
                        :controls="false"
                      ></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: 80px"
                        :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"
                        :precision="0"
                        :min="1"
                      ></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 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="100">
                    <template slot-scope="scope">
                      <el-button
                        type="text"
                        size="small"
                        @click="otherSetPrice(scope.row, indexU)"
                      >
                        同步
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            </el-tabs>
          </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 border :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>
      <!--      价格波动图-->
      <div v-if="page_tabs === '3'">
        <div class="ph" style="height: 350px">
          <div style="padding-bottom: 20px">
            <el-date-picker
              v-model="time"
              clearable
              type="daterange"
              value-format="timestamp"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              @change="orderDate"
            ></el-date-picker>
            <chart1
              :time-data="time_data"
              :goods-num="goodsNum_data"
              :order-num="orderNum_data"
              :order-money="orderMoney_data"
            ></chart1>
          </div>
        </div>
      </div>
      <!--      商品服务-->
      <!--      <div v-show="page_tabs === '4'">-->
      <!--        <el-table-->
      <!--          ref="multipleTable"-->
      <!--          :data="tableData"-->
      <!--          tooltip-effect="dark"-->
      <!--          @selection-change="handleSelectionChange"-->
      <!--        >-->
      <!--          <el-table-column type="selection"></el-table-column>-->
      <!--          <el-table-column-->
      <!--            prop="servicesName"-->
      <!--            label="商品服务名称"-->
      <!--          ></el-table-column>-->
      <!--          <el-table-column prop="describe" label="描述"></el-table-column>-->
      <!--        </el-table>-->
      <!--        <FooterPage-->
      <!--          :page-size="pageSize"-->
      <!--          :total-page.sync="total"-->
      <!--          :current-page.sync="page"-->
      <!--          @pageChange="pageChange"-->
      <!--          @sizeChange="sizeChange"-->
      <!--        ></FooterPage>-->
      <!--      </div>-->
    </el-form>

    <!--    商品列表-->
    <GoodsWarehouse
      v-if="show_goods"
      :modal="!goodsId"
      :shop-id="base_form.shopId"
      goods-warehouse
      :is-check="false"
      :is-show="show_goods"
      :enable="true"
      @cancel="show_goods = false"
      @confirm="selGoods"
    />
    <!--  客户选择-->
    <ClientListModal
      v-if="customer_show"
      :is-show="customer_show"
      :is-check="true"
      :modal="!basicGoodsId"
      :is-show-add="true"
      @cancel="customer_show = false"
      @confirm="customerSel"
    />
    <!--    客户调价-->
    <CustomerPrice
      v-if="appoint_price_show"
      :is-show="appoint_price_show"
      :customer-price-open="customerPriceOpen"
      :customer-price="customerPrice"
      :modal="!basicGoodsId && !goodsId"
      :ladder-price="ladderPrice"
      :sku-id="sku_id"
      :enabled-ladder="enabledLadder"
      @confirm="appointPriceConfirm"
      @cancel="appointPriceCancel"
    />
    <!--    客户类型调价-->
    <CustomerTypePrice
      v-if="type_price_show"
      :is-show="type_price_show"
      :customer-type-price-open="customerTypePriceOpen"
      :customer-type-price="customerTypePrice"
      :ladder-price="ladderPrice"
      :enabled-ladder="enabledLadder"
      :modal="!basicGoodsId && !goodsId"
      :sku-id="sku_id"
      @confirm="typePriceConfirm"
      @cancel="typePriceCancel"
    />
    <!--    阶梯价弹窗-->
    <LadderPrice
      v-if="ladder_price_show"
      :enabled-ladder="enabledLadder"
      :ladder-price="ladderPrice"
      :is-show="ladder_price_show"
      :modal="!basicGoodsId && !goodsId"
      @confirm="ladderPriceConfirm"
      @cancel="ladderPriceCancel"
    />
    <!--    :disabled="-->
    <!--    goods_data.isEq === 5 && unitisMaster === 4 && goods_data.specType === 1-->
    <!--    "-->
  </ContainerTit>
</template>

<script>
  import GoodsWarehouse from "@/component/goods/GoodsWarehouse";
  import Chart1 from "../components/Chart1";
  import SelectShop from "@/component/goods/SelectShop.vue";
  import { getAllExpressRule, getAllCustomerSource } from "@/api/System";
  import { addPauseSave, delPauseSave, getPauseSave } from "@/api/common";
  import {
    getGoodsInfo,
    editGoods,
    addGoods,
    getGoodsBasicInfoById,
    getAllGoodsSupport,
    getAllGoodsGroups,
  } from "@/api/goods";
  import ClientListModal from "@/component/common/ClientListModal";
  import CustomerPrice from "../components/CustomerPrice";
  import LadderPrice from "../components/LadderPrice";
  import CustomerTypePrice from "../components/CustomerTypePrice";
  import RegionTree from "@/component/common/RegionTree";
  import { mapGetters } from "vuex";
  import { Enterprise } from "@/api/user";
  import {
    CustomerPriceAdjustmentAdd,
    addCustomerTypePriceAdjustment,
    getCustomerPriceByGoodsIds,
    getCustomerTypePriceByGoodsIds,
  } from "@/api/Price";
  const priceDataLi = {
    enabledLadder: 0,
    marketPrice: "",
    memberPrice: "",
    costPrice: "",
    salePrice: "",
    setNum: 0,
    isSale: 5,
    salePriceAreaType: 1,
    ladderPrice: [
      /* {
        from: 1,
        price: 0.01,
        to: 2
      }, {
        from: 3,
        price: 0.01,
        to: 4
      },
      {
        from: 5,
        price: 0.01,
        to: 999999999
      } */
    ],
  };
  export default {
    name: "AddBaseData",
    components: {
      SelectShop,
      GoodsWarehouse,
      RegionTree,
      ClientListModal,
      Chart1,
      CustomerPrice,
      CustomerTypePrice,
      LadderPrice,
    },
    props: {
      goodsId: {
        type: [Number, String],
        default: 0,
      },
      basicGoodsId: {
        type: [Number, String],
        default: 0,
      },
    },
    data() {
      return {
        // flagS: false,
        unitisMaster: 4,
        choose_support: [],
        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切换
        unit_name_tab: "",
        show_region: false,
        goods_data: {
          specType: 1,
        },
        primary_unit: "",
        price_data: [
          // { marketPrice: '' }
        ],
        show_goods: false,
        show_chose: false,
        isModel: false,
        base_rules: {
          shopName: [
            { required: true, message: "请选择店铺", trigger: "change" },
          ],
          goodsName: [
            { required: true, message: "请选择商品", trigger: "change" },
          ],
          deliverySupIds: [
            {
              required: true,
              type: "array",
              message: "请选择物流支持",
              trigger: "change",
            },
          ],
          ruleId: [
            { required: true, message: "请选择运费模板", trigger: "change" },
          ],
          expressFee: [
            { required: true, message: "请输入运费", trigger: "blur" },
          ],
        },
        price: "",
        express_list: [], // 运费模版列表
        base_form: {
          createUserName: "",
          goodsName: "",
          enableStatus: 5,
          isDistribution: 4, //负库存销售
          specType: "",
          goodsBasicId: 0, // 商品基础资料
          shopId: "", // 店铺
          shopName: "", // 店铺
          images: [], // 相册
          salesArea: [], // 销售区域
          serviceInfo: 1,
          price: [], // 区域价
          specification: [], // // 规格
          content: "", // 商品描述
          isRecommend: 5, // 5推荐 4不推荐
          sort: "999", // 排序
          deliverySupIds: ["1", "2"], // 物流支持 固定值 1 快递 2 自提 传参格式：1,2
          expressType: 1, // 快递运费 1 包邮 2 运费模版 3 固定费用
          expressFee: "", // 固定费用
          showExpress: 5, // 是否展示快递 5展示 4不展示
          ruleId: "", // 运费模版id
          isShield: 4, // 经营屏蔽 4关闭 5开启
          notArea: [], //经营屏蔽地区
          notCustomerType: "", //经营屏蔽 客户类型屏蔽
          notCustomer: "", //经营屏蔽 客户屏蔽
          showMinUnitPrice: 4, //最小单位
        },
        delivery_form: {},
        user_power: {},
        goods_id: 0,
        sub_load: false,
        pageName: "",
        time_data: [],
        goodsNum_data: [],
        orderMoney_data: [],
        orderNum_data: [],
        time: [],
        tableData: [],
        page: 1,
        pageSize: 20,
        total: 0,
        support: [],
        options_value: [],
        goods_groups: [],
        sku_id: "",
      };
    },
    computed: {
      ...mapGetters({
        salePriceTimes: "MUser/salePriceTimes",
        systemType: "MUser/systemType",
        storeData: "MUser/storeData",
      }),
    },
    async created() {
      this.pageName = this.$route.name;
      if (this.basicGoodsId) {
        await this.selGoods([], this.basicGoodsId);
        return;
      }
      if (this.$route.params.id) {
        this.goods_id = this.$route.params.id;
        await this.getDetail();
      } else {
        await this.getPauseSave();
		
        if ([2, 3].includes(this.systemType)) {
			console.log( this.pageName);
          this.base_form.shopId = this.storeData.id; // 店铺
          this.base_form.shopName = this.storeData.name; // 店铺
        }
      }
      // 获取运费模版
      await this.getAllExpressRule();
      // 获取客户类型
      await this.getAllCustomerSource();
      // 获取商品服务
      await this.getAllGoodsSupport();
      // 商品分组
      await this.getAllGoodsGroups();
    },
    methods: {
      getShop() {
        this.$emit("closeShop");
        this.$router.push("/SystemSettings/liansuoguanli/AddShop");
      },
      // 获取运费模版
      async getAllExpressRule() {
        const { data } = await getAllExpressRule();
        this.express_list = data;
        const data1 = await Enterprise({
          ranking: 1, // "1销量排行 2销额排行",
          businessOverviewShopId: "", // "经营概况按店铺筛选：为空则筛选全店",
          categoryRankingShopId: "", // "类目排行按店铺筛选：为空则筛选全店",
          goodsRankingShopId: "", // "商品排行按店铺筛选：为空则筛选全店",
          supplierRankingShopId: "", // 供应商排行按店铺筛选：为空则筛选全店"
        });
        if (data1.data.aggregateStatistics) {
          if (this.time_data.length) {
            this.time_data = [];
          }
          this.$nextTick(() => {
            data1.data.chartData.forEach((value) => {
              this.time_data.push(value.date);
            });
          });
        }
      },
      // 计算市场价
      salePriceBlur(index, indexU) {
        if (this.goods_data.specType === 1) {
          // 根据比例自动换算销售价
          const target = this.$_common.deepClone(this.price_data);
          const marketPrice = this.$NP.times(
            target[index].salePrice,
            this.salePriceTimes
          );
          target[index] = {
            ...target[index],
            marketPrice: marketPrice,
          };
          // target.forEach((item) => {
          //   if (
          //     item.conversion &&
          //     item.isMaster === 4 &&
          //     this.goods_data.isEq === 5
          //   ) {
          //     item.salePrice = this.$NP.times(
          //       target[index].salePrice,
          //       item.conversion
          //     );
          //     item.marketPrice = this.$NP.times(marketPrice, item.conversion);
          //   }
          // });
          this.price_data = target;
        } else {
          this.goods_data.unitData[indexU].priceData[
            index
          ].marketPrice = this.$NP.times(
            this.goods_data.unitData[indexU].priceData[index].salePrice,
            this.salePriceTimes
          );
        }
      },
      // 会员价失去焦点
      memberPriceBlur(index) {
        return;
        // 根据比例自动换算 会员价
        if (this.goods_data.specType === 1) {
          const target = this.$_common.deepClone(this.price_data);
          target.forEach((item) => {
            if (
              item.conversion &&
              item.isMaster === 4 &&
              this.goods_data.isEq === 5
            ) {
              item.memberPrice = this.$NP.times(
                target[index].memberPrice,
                item.conversion
              );
            }
          });
          this.price_data = target;
        }
      },
      shopDefault(val, row) {
        this.base_form.shopId = val;
        this.base_form.shopName = row.name;
      },
      otherSetPrice(row, index) {
        const target = this.$_common.deepClone(this.goods_data);
        target.unitData[index].priceData = target.unitData[index].priceData.map(
          (item) => {
            return {
              ...item,
              customerTypePrice: row.customerTypePrice,
              customerTypePriceOpen: row.customerTypePriceOpen,
              customerPrice: row.customerPrice,
              customerPriceOpen: row.customerPriceOpen,
              marketPrice: row.marketPrice,
              memberPrice: row.memberPrice,
              salePrice: row.salePrice,
              enabledLadder: row.enabledLadder,
              ladderPrice: row.ladderPrice,
              setNum: row.setNum,
              isSale: row.isSale || 5,
            };
          }
        );
        this.goods_data = target;
      },
      openShop() {
        if (this.goods_id) return;
        this.show_chose = true;
      },
      openGoodsModel() {
        if (!this.base_form.shopName || !!this.goods_id) return;
        this.show_goods = true;
      },
      // 获取商品详情
      async getDetail() {
        const { data } = await getGoodsInfo(this.goods_id);
        this.goods_data = data;
        this.choose_support = data.support;
        let arr = [];
        data.goodsGroups.forEach((item) => {
          if (item) {
            arr.push(Number(item));
          }
        });
        this.options_value = arr;
        this.base_form = {
          createUserName: this.userName,
          goodsName: data.title,
          enableStatus: data.enableStatus, // 是否上架
          isDistribution: data.isDistribution, //是否负库存销售
          goodsBasicId: data.basicGoodsId, // 商品基础资料
          shopId: data.shopId, // 店铺
          shopName: data.shopName, // 店铺
          images: data.images, // 相册
          salesArea: data.salesArea, // 销售区域
          serviceInfo: data.serviceInfo,
          price: [],
          specification: data.specification, // // 规格
          content: data.content, // 商品描述
          isRecommend: data.isRecommend, // 5推荐 4不推荐
          sort: data.sort, // 排序
          specType: data.specType, // 2 多规格 1单规格
          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
          isShield: data.isShield, // 经营屏蔽
          notArea: data.notArea,
          notCustomerType: data.notCustomerType,
          notCustomer: data.notCustomer,
          showMinUnitPrice: data.showMinUnitPrice,
        };
        this.region_arr = data.notArea;
        this.customer_type_check = data.notCustomerType
          ? data.notCustomerType.split(",").map((item) => parseInt(item))
          : [];
        this.customer_list = data.notCustomerLists || [];
        if (data.specType === 1) {
          this.price_data = data.specMultiple.map((item) => {
            return {
              ...item,
              isSale: item.isSale || 5,
              // 客户类型和客户快速调价
              customerTypePrice: [],
              customerTypePriceOpen: false,
              customerPrice: [],
              customerPriceOpen: false,
            };
          });
        } else if (data.specType === 2) {
          if (this.goods_data.unitData && this.goods_data.unitData.length) {
            this.unit_name_tab = this.goods_data.unitData[0].unitName;
            this.goods_data.unitData = this.goods_data.unitData.map((itemU) => {
              const priceData = data.specMultiple
                .filter((itemF) => itemF.unitId === itemU.unitId)
                .map((item) => {
                  const skuName = item.specGroup
                    .map((itemM) => {
                      return itemM.specValueName;
                    })
                    .join("_");
                  // item.specGroup.forEach((itemS) => {
                  //   if (itemS.specId === 11) {
                  //     this.flagS = true;
                  //   }
                  // });
                  return {
                    ...item,
                    isSale: item.isSale || 5,
                    skuName: skuName,
                    // 客户类型和客户快速调价
                    customerTypePrice: [],
                    customerTypePriceOpen: false,
                    customerPrice: [],
                    customerPriceOpen: false,
                    minUnitPriceConvert: item.minUnitPriceConvert || "",
                  };
                });
              return {
                ...itemU,
                priceData: priceData,
              };
            });
          }
        }
        // this.region_arr = data.salesArea
        if (data.basicGoodsId) {
          await this.selGoods([], data.basicGoodsId);
        }
        this.toggleSelection();
        // 获取指定商品的最后生效的客户调价单数据
        await this.getCustomerPriceByGoodsIds();
        //获取指定商品的最后生效的客户类型调价数据
        await this.getCustomerTypePriceByGoodsIds();
      },
      // 检查提交
      checkSub() {
        this.$refs.base_form.validate((valid) => {
          if (valid) {
            let priceData = [];
            if (this.goods_data.specType === 2) {
              // 多属性
              this.goods_data.unitData.forEach((item) => {
                item.priceData.forEach((itemP) => {
                  priceData.push({
                    id: itemP.id,
                    conversion: itemP.conversion,
                    unitName: itemP.unitName,
                    unitId: itemP.unitId,
                    isMaster: itemP.isMaster,
                    deleteStatus: itemP.deleteStatus || 4,
                    enabledLadder: itemP.enabledLadder,
                    salePriceAreaType: itemP.salePriceAreaType,
                    salePrice: itemP.salePrice,
                    ladderPrice: itemP.ladderPrice,
                    marketPrice: itemP.marketPrice,
                    memberPrice: itemP.memberPrice,
                    setNum: itemP.setNum,
                    isSale: itemP.isSale || 5,
                    minUnitPriceConvert: itemP.minUnitPriceConvert,
                  });
                });
              });
            } else {
              priceData = this.$_common
                .deepClone(this.price_data)
                .map((item) => {
                  delete item.customerTypePrice;
                  delete item.customerTypePriceOpen;
                  delete item.customerPrice;
                  delete item.customerPriceOpen;
                  return item;
                });
            }

            let ladderPriceLength = true;
            let isLadderPrice = true;
            for (let i in priceData) {
              const item = priceData[i];
              if (item.enabledLadder === 1) {
                if (item.ladderPrice.length < 2) {
                  ladderPriceLength = false;
                  break;
                } else if (
                  !item.ladderPrice.every((itemP) => itemP.price > 0)
                ) {
                  isLadderPrice = false;
                  break;
                }
              } else {
                if (!item.salePrice) {
                  isLadderPrice = false;
                  break;
                }
              }
            }
            if (!ladderPriceLength) {
              this.$message.warning("请至少设置两条阶梯价");
              return;
            }
            if (!isLadderPrice) {
              this.$message.warning("请输入价格");
              return;
            }
            this.price = priceData.map((item) => {
              if (item.ladderPrice.length) {
                item.ladderPrice[item.ladderPrice.length - 1].to = 9999999999;
              }
              let min = 0;
              if (item.enabledLadder === 1) {
                const arr = item.ladderPrice.map((itemM) => {
                  return itemM.price;
                });
                min = Math.min.apply(null, arr);
              }
              return {
                ...item,
                ladderPrice: item.enabledLadder === 0 ? [] : item.ladderPrice,
                salePrice: item.enabledLadder === 1 ? min : item.salePrice,
              };
            });
            this.price = priceData;
            this.subData();
          }
        });
      },
      // 商品新建提交
      async subData() {
        let target = {};
        const notCustomer = this.customer_list.map((item) => {
          return item.id;
        });
        const isFSale = this.price.every((item) => item.isSale === 4);
        if (isFSale) {
          this.$message.warning("至少保留一条规格的销售状态为【启用】");
          return;
        }
        const params = {
          ...this.base_form,
          price: this.price,
          deliverySupIds: this.base_form.deliverySupIds.join(","),
          notCustomerType: this.customer_type_check.join(","),
          notCustomer: notCustomer.join(","),
          support: this.choose_support,
          goodsGroups: this.options_value,
        };
        this.sub_load = true;
        try {
          if (this.goods_id) {
            target = await editGoods(this.goods_id, params);
            this.sub_load = false;
            await this.AdjustPrice(this.goods_id);
          } else {
            target = await addGoods({
              ...params,
              createUserName: this.userName,
            });
            this.sub_load = false;
            await this.AdjustPrice(target.data);
            await this.delPauseSave();
          }
          this.$message({
            type: "success",
            message: "提交成功",
          });
          if (this.basicGoodsId) {
            this.$emit("subData");
          } else {
            if (this.systemType === 2) {
              await this.$closeCurrentGoEdit(
                "/SingleStore/goods/GoodsAdministration"
              );
            } else {
              await this.$closeCurrentGoEdit("/goods/sale/PublishGoods");
            }
          }
        } finally {
          this.sub_load = false;
        }
      },
      // 请求快速调价接口
      async AdjustPrice(goodsId) {
        let typeParams = [];
        let customerParams = [];
        let typePrice = [];
        let customerPrice = [];
        if (this.goods_data.specType === 1) {
          this.price_data.forEach((item) => {
            if (item.customerTypePriceOpen) {
              item.customerTypePrice.forEach((type) => {
                // if (!type.priceId) {
                typeParams.push({
                  createUserName: this.userName,
                  goodsName: this.base_form.goodsName,
                  goodsId: goodsId,
                  shopId: this.base_form.shopId,
                  shopName: this.base_form.shopName,
                  customerName: type.name,
                  customerType: type.id,
                  effective: 5, //调价单立即生效effective 5立即生效 4需要手动生效
                  salePrice: [
                    {
                      price: type.price,
                      skuId: item.id,
                      unitName: item.unitName,
                      adjPricetag: type.adjPricetag,
                      ladderPrice: type.ladderPrice || [],
                    },
                  ],
                });
                // }
              });
            }
            if (item.customerPriceOpen) {
              item.customerPrice.forEach((type) => {
                // if (!type.priceId) {
                customerParams.push({
                  createUserName: this.userName,
                  goodsName: this.base_form.goodsName,
                  goodsId: goodsId,
                  shopId: this.base_form.shopId,
                  shopName: this.base_form.shopName,
                  customerName: type.name,
                  customerId: type.id,
                  effective: 5, //调价单立即生效effective 5立即生效 4需要手动生效
                  salePrice: [
                    {
                      price: type.price,
                      skuId: item.id,
                      unitName: item.unitName,
                      adjPricetag: type.adjPricetag,
                      ladderPrice: type.ladderPrice || [],
                    },
                  ],
                });
                // }
              });
            }
          });
        } else {
          // 多属性
          this.goods_data.unitData.forEach((item) => {
            item.priceData.forEach((itemP) => {
              if (itemP.customerTypePriceOpen) {
                itemP.customerTypePrice.forEach((type) => {
                  // if (!type.priceId) {
                  typeParams.push({
                    createUserName: this.userName,
                    goodsName: this.base_form.goodsName,
                    goodsId: goodsId,
                    shopId: this.base_form.shopId,
                    shopName: this.base_form.shopName,
                    customerName: type.name,
                    customerType: type.id,
                    effective: 5, //调价单立即生效effective 5立即生效 4需要手动生效
                    salePrice: [
                      {
                        price: type.price,
                        skuId: itemP.id,
                        unitName: itemP.unitName,
                        adjPricetag: type.adjPricetag,
                        ladderPrice: type.ladderPrice || [],
                      },
                    ],
                  });
                  // }
                });
              }
              if (itemP.customerPriceOpen) {
                itemP.customerPrice.forEach((type) => {
                  // if (!type.priceId) {
                  customerParams.push({
                    createUserName: this.userName,
                    goodsName: this.base_form.goodsName,
                    goodsId: goodsId,
                    shopId: this.base_form.shopId,
                    shopName: this.base_form.shopName,
                    customerName: type.name,
                    customerId: type.id,
                    effective: 5, //调价单立即生效effective 5立即生效 4需要手动生效
                    salePrice: [
                      {
                        price: type.price,
                        skuId: itemP.id,
                        unitName: itemP.unitName,
                        adjPricetag: type.adjPricetag,
                        ladderPrice: type.ladderPrice || [],
                      },
                    ],
                  });
                  // }
                });
              }
            });
          });
        }
        //客户类型
        typeParams.forEach((item) => {
          const index = typePrice.findIndex(
            (price) => price.customerType === item.customerType
          );
          if (index === -1) {
            typePrice.push({
              ...item,
            });
          } else {
            typePrice[index].salePrice = typePrice[index].salePrice.concat(
              item.salePrice
            );
          }
        });
        //客户价格
        customerParams.forEach((item) => {
          const index = customerPrice.findIndex(
            (price) => price.customerId === item.customerId
          );
          if (index === -1) {
            customerPrice.push({
              ...item,
            });
          } else {
            customerPrice[index].salePrice = customerPrice[
              index
            ].salePrice.concat(item.salePrice);
          }
        });

        // console.log("typePrice", typePrice);
        // console.log("customerPrice", customerPrice);
        await this.addCustomerTypePriceAdjustment(typePrice);
        await this.CustomerPriceAdjustmentAdd(customerPrice);
      },
      // 获取暂存信息
      async getPauseSave() {
        const { data } = await getPauseSave({
          key: this.pageName,
        });

        if (JSON.stringify(data) === "{}") return;
        if (data.goods_data) {
          this.goods_data = data.goods_data;
        }
        if (data.base_form) {
          this.base_form = data.base_form;
          this.region_arr = this.base_form.notArea;
        }
        if (data.price) {
          this.price_data = data.price;
        }
        if (data.unit_name_tab) {
          this.unit_name_tab = data.unit_name_tab;
        }
        if (data.customer_list) {
          this.customer_list = data.customer_list;
        }
      },
      // 删除暂存信息
      async delPauseSave(type) {
        const data = delPauseSave({
          key: this.pageName,
        });

        if (type) {
          this.$message({
            type: "success",
            message: "清除暂存成功",
          });
          this.$closeCurrentGoEdit("/goods/sale/AddGoods");
        }
      },
      // 商品暂存
      async tempData() {
        this.sub_load = true;
        try {
          const data = await addPauseSave({
            key: this.pageName,
            data: {
              base_form: this.base_form,
              price: this.price,
              goods_data: this.goods_data,
              unit_name_tab: this.unit_name_tab,
              customer_list: this.customer_list,
            },
          });
          this.sub_load = false;

          this.$message({
            type: "success",
            message: "暂存成功",
          });
          if (this.systemType === 2) {
            this.$closeCurrentGoEdit("/SingleStore/goods/GoodsAdministration");
          } else {
            this.$closeCurrentGoEdit("/goods/sale/PublishGoods");
          }
        } finally {
          this.sub_load = false;
        }
      },
      // 选择商品
      async selGoods(row, basicGoodsId) {
        const { data } = await getGoodsBasicInfoById(
          basicGoodsId || row[0].id,
          {
            isAddGoods: 5,
          }
        );

        if (this.goods_id) {
          this.goods_data = {
            ...this.goods_data,
            categoryTitle: data.categoryTitle,
            brandTitle: data.brandTitle,
            expireTime: data.expireTime,
            description: data.description,
            tag: data.tag,
            masterUnit: data.unitData.find((item) => item.isMaster === 5),
            branchUnit: data.unitData.filter((item) => item.isMaster === 4),
          };
          return;
        }
        this.goods_data = {
          ...data,
          masterUnit: data.unitData.find((item) => item.isMaster === 5),
          branchUnit: data.unitData.filter((item) => item.isMaster === 4),
        };
        this.base_form.goodsName = data.title;
        this.unit_name_tab = data.unitData[0].unitName;
        this.base_form.images = data.images;
        this.base_form.specType = data.specType;
        this.base_form.content = data.description;
        this.base_form.goodsBasicId = data.id;
        let priceData = [];
        const priceDataItem = this.$_common.deepClone(priceDataLi);
        if (data.specType === 1) {
          priceData = data.unitData.map((item) => {
            return {
              ...item,
              ...priceDataItem,
              isSale: 5,
              // 客户类型和客户快速调价
              customerTypePrice: [],
              customerTypePriceOpen: false,
              customerPrice: [],
              customerPriceOpen: false,
            };
          });
          this.price_data = priceData;
        } else if (data.specType === 2) {
          this.goods_data.unitData = this.goods_data.unitData.map((itemU) => {
            const priceD = data.specMultiple
              .filter((itemF) => itemF.unitId === itemU.unitId)
              .map((item) => {
                const skuName = item.specGroup
                  .map((itemM) => {
                    return itemM.specValueName;
                  })
                  .join("_");
                // item.specGroup.forEach((itemS) => {
                //   if (itemS.specId === 11) {
                //     this.flagS = true;
                //   }
                // });
                return {
                  ...item,
                  ...priceDataItem,
                  isSale: 5,
                  skuName: skuName,
                  // 客户类型和客户快速调价
                  customerTypePrice: [],
                  customerTypePriceOpen: false,
                  customerPrice: [],
                  customerPriceOpen: false,
                };
              });
            return {
              ...itemU,
              priceData: priceD,
            };
          });
        }
        let specification = [];
        if (row[0]) {
          if (row[0].specType === 1) {
            specification = (row[0].branchUnit || []).concat(row[0].masterUnit);
          } else if (row[0].specType === 2) {
            specification = row[0].specMultiple;
          }
        }
        this.base_form.specification = specification;
        let arr = "";
        this.price_data.forEach((item) => {
          if (item.isMaster === 5) {
            arr = item.unitName;
          }
        });
        this.primary_unit = arr;
      },
      // 选择商铺
      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);
      },
      // 价格波动图
      orderDate() {
        console.log(this.time);
      },
      // 打开指定价弹窗
      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) {
        if (this.goods_data.specType === 1) {
          // 单规格
          const target = this.$_common.deepClone(this.price_data);
          target[this.sku_index].customerPriceOpen = customerPriceOpen;
          target[this.sku_index].customerPrice = customerPriceOpen
            ? customerPrice
            : [];
          this.price_data = target;
        } else {
          // 多规格
          const target = this.$_common.deepClone(this.goods_data.unitData);
          target[this.unit_index].priceData[
            this.sku_index
          ].customerPriceOpen = customerPriceOpen;
          target[this.unit_index].priceData[
            this.sku_index
          ].customerPrice = customerPriceOpen ? customerPrice : [];
          this.goods_data.unitData = target;
        }
      },
      // 指定价数据取消
      async appointPriceCancel(customerPriceOpen, customerPrice) {
        this.appoint_price_show = false;
        if (this.$route.params.id) {
          await this.appointPriceConfirm(customerPriceOpen, customerPrice);
        }
      },
      // 客户类型价设置
      typePriceConfirm(customerTypePriceOpen, customerTypePrice) {
        if (this.goods_data.specType === 1) {
          // 单规格
          const target = this.$_common.deepClone(this.price_data);
          target[this.sku_index].customerTypePriceOpen = customerTypePriceOpen;
          target[this.sku_index].customerTypePrice = customerTypePriceOpen
            ? customerTypePrice
            : [];
          this.price_data = target;
        } else {
          // 多规格
          const target = this.$_common.deepClone(this.goods_data.unitData);
          target[this.unit_index].priceData[
            this.sku_index
          ].customerTypePriceOpen = customerTypePriceOpen;
          target[this.unit_index].priceData[
            this.sku_index
          ].customerTypePrice = customerTypePriceOpen ? customerTypePrice : [];
          this.goods_data.unitData = target;
        }
      },
      // 客户类型价数据取消
      async typePriceCancel(customerTypePriceOpen, customerTypePrice) {
        this.type_price_show = false;
        if (this.$route.params.id) {
          //获取指定商品的最后生效的客户类型调价数据
          await this.typePriceConfirm(customerTypePriceOpen, customerTypePrice);
        }
      },
      // 阶梯价设置
      ladderPriceConfirm(enabledLadder, ladderPrice) {
        if (this.goods_data.specType === 1) {
          // 单规格
          const target = this.$_common.deepClone(this.price_data);
          // if (this.goods_data.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
          //     : [];
          // }
          target[this.sku_index].enabledLadder = enabledLadder;
          target[this.sku_index].ladderPrice = enabledLadder ? ladderPrice : [];
          this.price_data = target;
        } else {
          // 多规格
          const target = this.$_common.deepClone(this.goods_data.unitData);
          target[this.unit_index].priceData[
            this.sku_index
          ].enabledLadder = enabledLadder;
          target[this.unit_index].priceData[
            this.sku_index
          ].ladderPrice = enabledLadder ? ladderPrice : [];
          this.goods_data.unitData = 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 getAllGoodsSupport() {
        const { data, pageTotal } = await getAllGoodsSupport({
          page: this.page,
          pageSize: this.pageSize,
        });
        this.tableData = data;
        this.total = pageTotal;
      },
      toggleSelection() {
        let arr = [];
        this.goods_data.support.forEach((item) => {
          arr.push(Number(item));
        });
        this.choose_support = arr;
      },
      // 商品组
      async getAllGoodsGroups() {
        const { data } = await getAllGoodsGroups({
          page: 1,
          pageSize: 999,
          name: "",
        });
        this.goods_groups = 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: 999,
        });
        this.customerTypePrice = data;
        this.adjustmentData();
      },
      adjustmentData() {
        if (this.base_form.specType === 1) {
          this.price_data = this.price_data.map((item) => {
            //客户类型价
            let customerTypePrice = [];
            this.customerTypePrice.forEach((type) => {
              if (type.salePrice && type.salePrice.length) {
                type.salePrice.forEach((pitem) => {
                  if (pitem.skuId === item.id) {
                    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 (pitem.skuId === item.id) {
                    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.goods_data.unitData = this.goods_data.unitData.map((itemU) => {
            return {
              ...itemU,
              priceData: itemU.priceData.map((item) => {
                //客户类型价
                let customerTypePrice = [];
                this.customerTypePrice.forEach((type) => {
                  if (type.salePrice && type.salePrice.length) {
                    type.salePrice.forEach((pitem) => {
                      if (pitem.skuId === item.id) {
                        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 (pitem.skuId === item.id) {
                        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,
                };
              }),
            };
          });
        }
      },
    },
  };
</script>
<style scoped lang="scss">
  .ph {
    background-color: #fff;
    height: 240px;
    padding: 12px 17px 12px 17px;
    border-radius: 6px;
    box-shadow: 0 2px 6px 0 rgba(76, 80, 88, 0.16);
    position: relative;
    .ranking-sel {
      position: absolute;
      left: 130px;
      top: 14px;
    }
    h4 {
      display: inline-block;
      width: 120px;
    }
    .ph-num-text {
      font-size: 16px;
      font-weight: 600;
      color: #24365c;
      margin: -8px 0 0 10px;
    }
  }
  .switch-div {
    padding-bottom: 10px;
  }
  .td-label {
    display: inline-block;
    width: 80px;
    text-align: right;
    font-size: 13px;
    vertical-align: middle;
  }
  .ladder-price-ul {
    vertical-align: middle;
    display: inline-block;
  }
</style>
