<template>
  <div class="app-container">
    <el-tabs
      v-model="tabPaneType"
      tab-position="left"
      @tab-click="handleTagToggle"
    >
      <el-tab-pane label="奖励支出" name="0">
        <el-form label-width="80px">
          <ul style="padding-left:10px;">
            <li class="fixed_reward">
              <p class="label">1.	销售主管1-销售主管2 进货奖励</p>
              <el-form-item label="精装版">
                <el-input
                  v-model="fixedReward_level_1.jz"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版">
                <el-input
                  v-model="fixedReward_level_1.jy"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版">
                <el-input
                  v-model="fixedReward_level_1.lr"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info">销售主管2进货，给销售主管1提成：精装版每套<span class="red">{{ fixedReward_level_1.jz }}</span>元，简约版每件<span class="red">{{ fixedReward_level_1.jy }}</span>元,老人版每件<span class="red">{{ fixedReward_level_1.lr }}</span>元；<span class="red">若销售主管1在两个月内不升级的话，则两个月以后不再拿提成（两个月内有提成），推荐关系顺上进行</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(1)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">2.	销售主管1-销售经理2 进货奖励</p>
              <el-form-item label="精装版">
                <el-input
                  v-model="fixedReward_level_2.jz"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版">
                <el-input
                  v-model="fixedReward_level_2.jy"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版">
                <el-input
                  v-model="fixedReward_level_2.lr"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info">销售经理2进货，给销售主管1提成：精装版每套<span class="red">{{ fixedReward_level_2.jz }}</span>元，简约版每件<span class="red">{{ fixedReward_level_2.jy }}</span>元,老人版每件<span class="red">{{ fixedReward_level_2.lr }}</span>元；<span class="red">若销售主管1在两个月内不升级的话，则两个月以后不再拿提成（两个月内有提成），推荐关系顺上进行</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(2)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">3.	销售主管1-代理公司2 进货奖励</p>
              <el-form-item label="精装版">
                <el-input
                  v-model="fixedReward_level_3.jz"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版">
                <el-input
                  v-model="fixedReward_level_3.jy"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版">
                <el-input
                  v-model="fixedReward_level_3.lr"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info">代理公司2进货，给销售主管1提成：精装版每套<span class="red">{{ fixedReward_level_3.jz }}</span>元，简约版每件<span class="red">{{ fixedReward_level_3.jy }}</span>元,老人版每件<span class="red">{{ fixedReward_level_3.lr }}</span>元；<span class="red">若销售主管1在两个月内不升级的话，则两个月以后不再拿提成（两个月内有提成），推荐关系顺上进行</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(3)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">4.	销售经理1-销售经理2 进货奖励</p>
              <el-form-item label="精装版">
                <el-input
                  v-model="fixedReward_level_4.jz"
                  type="number"
                  size="mini"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版">
                <el-input
                  v-model="fixedReward_level_4.jy"
                  type="number"
                  size="mini"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版">
                <el-input
                  v-model="fixedReward_level_4.lr"
                  type="number"
                  size="mini"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info">销售经理2进货，给销售经理1提成：精装版每套{{ fixedReward_level_4.jz }}元，简约版每件{{ fixedReward_level_4.jy }}元,老人版每件{{ fixedReward_level_4.lr }}元；<span class="red">如果销售经理1保持不被降级的话，提成是永久的</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(4)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">5.	销售经理1-代理公司2 进货奖励</p>
              <el-form-item label="精装版">
                <el-input
                  v-model="fixedReward_level_5.jz"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版">
                <el-input
                  v-model="fixedReward_level_5.jy"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版">
                <el-input
                  v-model="fixedReward_level_5.lr"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info">代理公司2进货，给销售经理1提成：精装版每套<span class="red">{{ fixedReward_level_5.jz }}</span>元，简约版每件<span class="red">{{ fixedReward_level_5.jy }}</span>元,老人版每件<span class="red">{{ fixedReward_level_5.lr }}</span>元；<span class="red">如果销售经理1保持不被降级的话，提成是永久的</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(5)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">6.	代理公司1-代理公司2 进货奖励</p>
              <el-form-item label="精装版">
                <el-input
                  v-model="fixedReward_level_6.jz"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版">
                <el-input
                  v-model="fixedReward_level_6.jy"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版">
                <el-input
                  v-model="fixedReward_level_6.lr"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info">代理公司2进货，给代理公司1提成：精装版每套<span class="red">{{ fixedReward_level_6.jz }}</span>元，简约版每件<span class="red">{{ fixedReward_level_6.jy }}</span>元,老人版每件<span class="red">{{ fixedReward_level_6.lr }}</span>元；<span class="red">提成是永久的</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(6)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">7.	代理公司1-代理公司2-代理公司3 进货奖励</p>
              <el-row>
                <el-col :span="12">
                  <p>代理公司2:</p>
                  <el-form-item label="精装版">
                    <el-input
                      v-model="fixedReward_level_7.jz1"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="简约版">
                    <el-input
                      v-model="fixedReward_level_7.jy1"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="老人版">
                    <el-input
                      v-model="fixedReward_level_7.lr1"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <p>代理公司1:</p>
                  <el-form-item label="精装版">
                    <el-input
                      v-model="fixedReward_level_7.jz2"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="简约版">
                    <el-input
                      v-model="fixedReward_level_7.jy2"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="老人版">
                    <el-input
                      v-model="fixedReward_level_7.lr2"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <div class="set-item-info">
                <i class="el-icon-info">代理公司3进货，给代理公司2提成：精装版每套<span class="red">{{ fixedReward_level_7.jz1 }}</span>元，简约版每件<span class="red">{{ fixedReward_level_7.jy1 }}</span>元,老人版每件<span class="red">{{ fixedReward_level_7.lr1 }}</span>元；再给代理公司1提成：精装版每套<span class="red">{{ fixedReward_level_7.jz2 }}</span>元，简约版每件<span class="red">{{ fixedReward_level_7.jy2 }}</span>元,老人版每件<span class="red">{{ fixedReward_level_7.lr2 }}</span>元;<span class="red">提成是永久的</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(7)"
              >
                设置
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">8.	代理公司1-销售经理2-代理公司3 进货奖励</p>
              <el-row>
                <el-col :span="12">
                  <p>销售经理2:</p>
                  <el-form-item label="精装版">
                    <el-input
                      v-model="fixedReward_level_8.jz1"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="简约版">
                    <el-input
                      v-model="fixedReward_level_8.jy1"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="老人版">
                    <el-input
                      v-model="fixedReward_level_8.lr1"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                </el-col>
                <el-col :span="12">
                  <p>代理公司1:</p>
                  <el-form-item label="精装版">
                    <el-input
                      v-model="fixedReward_level_8.jz2"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="简约版">
                    <el-input
                      v-model="fixedReward_level_8.jy2"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                  <el-form-item label="老人版">
                    <el-input
                      v-model="fixedReward_level_8.lr2"
                      type="number"
                      size="mini"
                      min="0"
                      placeholder="请输入奖励金额"
                    />
                  </el-form-item>
                </el-col>
              </el-row>
              <div class="set-item-info">
                <i class="el-icon-info">代理公司3进货，给销售经理2提成：精装版每套<span class="red">{{ fixedReward_level_8.jz1 }}</span>元，简约版每件<span class="red">{{ fixedReward_level_8.jy1 }}</span>元,老人版每件<span class="red">{{ fixedReward_level_8.lr1 }}</span>元；再给代理公司1提成：精装版每套<span class="red">{{ fixedReward_level_8.jz2 }}</span>元，简约版每件<span class="red">{{ fixedReward_level_8.jy2 }}</span>元,老人版每件<span class="red">{{ fixedReward_level_8.lr2 }}</span>元;<span class="red">若销售经理2被降级为销售主管之后两个月不升级，则销售主管不再拿提成，代理公司3变成代理公司1的直属代理（推荐关系顺上进行）</span> </i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetFixed(8)"
              >
                设置
              </el-button>
            </li>
          </ul>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="业绩奖励" name="1">
        <el-form label-width="80px">
          <i class="el-icon-info" style="margin-bottom:20px;margin-left:20px;">奖励区间设置规则:(例: 500-1000) 包含1000但不包含500 </i>
          <el-form-item label="奖励区间:">
            <div
              v-for="(item, i) in quotaSet"
              :key="i"
              class="section_item"
            >
              <el-input
                v-model="item.start"
                placeholder="业绩下限"
                type="number"
                size="mini"
                style="width:200px"
              />
              <span class="division">-</span>
              <el-input
                v-model="item.end"
                placeholder="业绩上限"
                type="number"
                size="mini"
                style="width:200px"
              />
              <span class="division">奖励百分比:</span>
              <el-input
                v-model="item.price"
                placeholder="百分比"
                type="number"
                size="mini"
                min="0"
                max="100"
                style="width:200px"
              />
              <el-button
                v-if="i > 0"
                size="mini"
                class="delete"
                @click="handleDeleteQuota(i)"
              >
                删除
              </el-button>
            </div>
            <div>
              <el-button
                size="mini"
                @click="handleAddQuota"
              >
                添加
              </el-button>
              <el-button
                size="mini"
                @click="handleResetQuota"
              >
                重置
              </el-button>
              <el-button
                type="primary"
                size="mini"
                @click="handleSubmitQuota"
              >
                提交
              </el-button>
            </div>
          </el-form-item>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="店铺奖励" name="2">
        <el-form label-width="100px">
          <ul style="padding-left:10px;">
            <li class="fixed_reward">
              <p class="label">1.	工作室</p>
              <el-form-item label="奖励类型:">
                <el-radio v-model="shop.gzs.type" label="1">货</el-radio>
              </el-form-item>
              <el-form-item
                label="进货额百分比:"
              >
                <el-input
                  v-model="shop.gzs.val"
                  type="number"
                  size="mini"
                  min="0"
                  max="100"
                  placeholder="百分比"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info"><span class="red">销售经理</span>和<span class="red">代理公司</span>可申请开工作室</i>
                <i class="el-icon-info">奖励兑换规则：<span class="red">本月本人</span>进货总金额*<span class="red">{{ shop.gzs.val ? shop.gzs.val : '0' }}%</span>/对应款式的<span class="red">零售价</span> = 可兑换的套数</i>
                <i class="el-icon-info">零售价说明：精装版<span class="red">399/套</span>，简约版：<span class="red">169/套</span>；老人版：<span class="red">199/套</span></i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetShop(1)"
              >
                确定
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">2.	优享店</p>
              <el-form-item label="奖励类型:">
                <el-radio v-model="shop.yxd.type" label="goods">货</el-radio>
                <el-radio v-model="shop.yxd.type" label="money">钱</el-radio>
              </el-form-item>
              <el-form-item
                v-if="shop.yxd.type === 'goods'"
                label="进货额百分比:"
              >
                <el-input
                  v-model="shop.yxd.val"
                  type="number"
                  size="mini"
                  min="0"
                  max="100"
                  placeholder="百分比"
                />
              </el-form-item>
              <div v-else>
                <el-form-item label="精装版:">
                  <el-input
                    v-model="shop.yxd.jz"
                    type="number"
                    size="mini"
                    min="0"
                    placeholder="请输入奖励金额"
                  />
                </el-form-item>
                <el-form-item label="简约版:">
                  <el-input
                    v-model="shop.yxd.jy"
                    type="number"
                    size="mini"
                    min="0"
                    placeholder="请输入奖励金额"
                  />
                </el-form-item>
                <el-form-item label="老人版:">
                  <el-input
                    v-model="shop.yxd.lr"
                    type="number"
                    size="mini"
                    min="0"
                    placeholder="请输入奖励金额"
                  />
                </el-form-item>
              </div>
              <div class="set-item-info">
                <i class="el-icon-info"><span class="red">代理公司</span>可申请开优享店</i>
                <div v-if="shop.yxd.type === 'goods'">
                  <i class="el-icon-info">奖励兑换规则<span class="red">货</span>：<span class="red">本月本人</span>进货总金额*<span class="red">{{ shop.gzs.val ? shop.gzs.val : '0' }}%</span>/对应款式的<span class="red">零售价</span> = 可兑换的套数</i>
                  <i class="el-icon-info">零售价说明：精装版<span class="red">399/套</span>，简约版：<span class="red">169/套</span>；老人版：<span class="red">199/套</span></i>
                </div>
                <div v-else>
                  <i class="el-icon-info"><span class="red">货</span>：<span class="red">本月本人</span>进货具体数量 * 每套奖励：精装版每套奖励<span class="red">{{ shop.yxd.jz }}</span>元，简约版每套奖励<span class="red">{{ shop.yxd.jy }}</span>元, 老人版每套奖励<span class="red">{{ shop.yxd.lr }}</span>元</i>
                </div>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetShop(2, shop.yxd.type)"
              >
                确定
              </el-button>
            </li>
            <li class="fixed_reward">
              <p class="label">3.	体验店</p>
              <el-form-item label="奖励类型:">
                <el-radio v-model="shop.tyd.type" label="0">钱</el-radio>
              </el-form-item>
              <el-form-item label="精装版:">
                <el-input
                  v-model="shop.tyd.jz"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="简约版:">
                <el-input
                  v-model="shop.tyd.jy"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <el-form-item label="老人版:">
                <el-input
                  v-model="shop.tyd.lr"
                  type="number"
                  size="mini"
                  min="0"
                  placeholder="请输入奖励金额"
                />
              </el-form-item>
              <div class="set-item-info">
                <i class="el-icon-info"><span class="red">代理公司</span>可申请开体验店,可多个代理公司合伙</i>
                <i class="el-icon-info">体验店所在城市<span class="red">所有的代理公司的代理进货</span>的具体<span class="red">数量</span> * 每套奖励的金额 给体验店的<span class="red">负责人</span>（如果是多个负责人，按照股份比例给）。精装版每套奖励<span class="red">{{ shop.tyd.jz }}</span>元，简约版每套奖励<span class="red">{{ shop.tyd.jy }}</span>元, 老人版每套奖励<span class="red">{{ shop.tyd.lr }}</span>元</i>
              </div>
              <el-button
                type="primary"
                size="mini"
                @click="handleSetShop(3)"
              >
                确定
              </el-button>
            </li>
          </ul>
        </el-form>
      </el-tab-pane>
    </el-tabs>
    <div v-if="loading" v-loading="loading" class="loadingShade" />
  </div>
</template>
<script>

import {
  setFixed,
  setShop,
  setQuota
} from '@/api/system/reward'

import {
  filterSet
} from '@/filters/systemSet'

export default {
  name: 'RewardSet',
  data() {
    return {
      tabPaneType: '1',
      loading: false,
      loadingTime: 1,
      setting: [],
      // 销售主管1-销售主管2
      fixedReward_level_1: {
        jz: '',
        jy: '',
        lr: ''
      },
      // 销售主管1-销售经理2
      fixedReward_level_2: {
        jz: '',
        jy: '',
        lr: ''
      },
      fixedReward_level_3: {
        jz: '',
        jy: '',
        lr: ''
      },
      fixedReward_level_4: {
        jz: '',
        jy: '',
        lr: ''
      },
      fixedReward_level_5: {
        jz: '',
        jy: '',
        lr: ''
      },
      fixedReward_level_6: {
        jz: '',
        jy: '',
        lr: ''
      },
      fixedReward_level_7: {
        jz1: '',
        jy1: '',
        lr1: '',
        jz2: '',
        jy2: '',
        lr2: ''
      },
      fixedReward_level_8: {
        jz1: '',
        jy1: '',
        lr1: '',
        jz2: '',
        jy2: '',
        lr2: ''
      },
      shop: {
        gzs: {
          type: '1',
          val: ''
        },
        yxd: {
          type: 'goods',
          val: '',
          jz: '',
          jy: '',
          lr: ''
        },
        tyd: {
          type: '0',
          jz: '',
          jy: '',
          lr: ''
        }
      },
      quotaSet: [
        {
          start: '',
          end: '',
          price: ''
        }
      ]
    }
  },
  watch: {
    'tabPaneType'(to, from) {
      this.init()
    }
  },
  methods: {
    // 选项卡切换
    handleTagToggle(tab) {
      this.tabPaneType = tab.name
    },
    // 初始化
    init() {
      const type = this.tabPaneType
      switch (type) {
        case '0':
          this.getFixed()
          break
        case '1':
          this.getQuota()
          break
        case '2':
          this.getShop()
          break
        default:
      }
    },
    // 获取所有设置
    getSetting() {
      this.$store.dispatch('system/get').then(setting => {
        this.setting = setting
        this.init()
      }).catch(e => {
        this.$message.error(e)
      })
    },
    // 获取店铺奖励设置
    getShop() {
      const data = this.setting
      // 工作室
      const gzs = filterSet(data, 'store_reward_goods_job').values
      this.shop.gzs.val = gzs
      // 优享店-货
      const yxd_h = filterSet(data, 'store_reward_goods_enjoy').values
      this.shop.yxd.val = yxd_h
      // 优享店-钱
      const yxd_q = filterSet(data, 'store_reward_money_enjoy').values.split('/')
      this.shop.yxd.jz = yxd_q[0]
      this.shop.yxd.jy = yxd_q[1]
      this.shop.yxd.lr = yxd_q[2]
      // 体验店
      const tyd = filterSet(data, 'store_reward_money_experience').values.split('/')
      this.shop.tyd.jz = tyd[0]
      this.shop.tyd.jy = tyd[1]
      this.shop.tyd.lr = tyd[2]
    },
    // 获取奖励支出
    getFixed() {
      const data = this.setting
      // 销售主管1-销售主管2
      const level1 = filterSet(data, 'reward_super_super').values.split('/')
      this.fixedReward_level_1.jz = level1[0]
      this.fixedReward_level_1.jy = level1[1]
      this.fixedReward_level_1.lr = level1[2]
      // 销售主管1-销售经理2
      const level2 = filterSet(data, 'reward_super_top').values.split('/')
      this.fixedReward_level_2.jz = level2[0]
      this.fixedReward_level_2.jy = level2[1]
      this.fixedReward_level_2.lr = level2[2]
      // 销售主管1-代理公司2
      const level3 = filterSet(data, 'reward_super_crown').values.split('/')
      this.fixedReward_level_3.jz = level3[0]
      this.fixedReward_level_3.jy = level3[1]
      this.fixedReward_level_3.lr = level3[2]
      // 销售经理1-销售经理2
      const level4 = filterSet(data, 'reward_top_top').values.split('/')
      this.fixedReward_level_4.jz = level4[0]
      this.fixedReward_level_4.jy = level4[1]
      this.fixedReward_level_4.lr = level4[2]
      // 销售经理1-代理公司2
      const level5 = filterSet(data, 'reward_top_crown').values.split('/')
      this.fixedReward_level_5.jz = level5[0]
      this.fixedReward_level_5.jy = level5[1]
      this.fixedReward_level_5.lr = level5[2]
      // 代理公司1-代理公司2
      const level6 = filterSet(data, 'reward_crown_crown').values.split('/')
      this.fixedReward_level_6.jz = level6[0]
      this.fixedReward_level_6.jy = level6[1]
      this.fixedReward_level_6.lr = level6[2]
      // 代理公司1-代理公司2-代理公司3
      const level7 = filterSet(data, 'reward_crown_crown_crown').values.split('/')
      this.fixedReward_level_7.jz1 = level7[0].split('*')[0]
      this.fixedReward_level_7.jy1 = level7[1].split('*')[0]
      this.fixedReward_level_7.lr1 = level7[2].split('*')[0]
      this.fixedReward_level_7.jz2 = level7[0].split('*')[1]
      this.fixedReward_level_7.jy2 = level7[1].split('*')[1]
      this.fixedReward_level_7.lr2 = level7[2].split('*')[1]
      // 代理公司1-销售经理2-代理公司3
      const level8 = filterSet(data, 'reward_crown_top_crown').values.split('/')
      this.fixedReward_level_8.jz1 = level8[0].split('*')[0]
      this.fixedReward_level_8.jy1 = level8[1].split('*')[0]
      this.fixedReward_level_8.lr1 = level8[2].split('*')[0]
      this.fixedReward_level_8.jz2 = level8[0].split('*')[1]
      this.fixedReward_level_8.jy2 = level8[1].split('*')[1]
      this.fixedReward_level_8.lr2 = level8[2].split('*')[1]
    },
    // 获取业绩奖励
    getQuota() {
      const data = this.setting
      // 业绩
      const quotaArr = filterSet(data, 'sales_area_reward').values.split('/')
      if (quotaArr.length < 1) {
        this.quotaSet = [
          {
            start: '',
            end: '',
            price: ''
          }
        ]
      } else {
        this.quotaSet = []
        quotaArr.map(item => {
          const arr = item.split('*')
          const data = {
            start: arr[0] ? arr[0] : '',
            end: arr[1] ? arr[1] : '',
            price: arr[2] ? arr[2] : ''
          }
          this.quotaSet.push(data)
        })
      }
    },
    // 设置奖励支出
    handleSetFixed(type) {
      const data = this[`fixedReward_level_${type}`]
      data['type'] = type
      this.setFixed(data)
    },
    // 设置奖励支出
    async setFixed(data) {
      const res = await setFixed(data)
      try {
        const { message, code } = res
        if (code === 200) {
          this.$message.success(message)
          this.getSetting()
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        let message = res.message ? res.message : e.message
        message = e.message ? e.message : '请求失败'
        this.$message.error(message)
      }
    },
    // 设置店铺奖励
    handleSetShop(level, type = '') {
      if (level === 1) {
        this.setShop({
          level,
          type: 'goods',
          val: this.shop.gzs.val
        })
      } else if (level === 3) {
        const { jz, jy, lr } = this.shop.tyd
        this.setShop({
          level,
          type: 'money',
          jz,
          jy,
          lr
        })
      } else {
        if (type === 'goods') {
          this.setShop({
            level: 2,
            type,
            val: this.shop.yxd.val
          })
        } else {
          const { jz, jy, lr } = this.shop.yxd
          this.setShop({
            level: 2,
            type,
            jz,
            jy,
            lr
          })
        }
      }
    },
    // 设置店铺奖励
    async setShop(data) {
      const res = await setShop(data)
      try {
        const { message, code } = res
        if (code === 200) {
          this.$message.success(message)
          this.getSetting()
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        let message = res.message ? res.message : e.message
        message = e.message ? e.message : '请求失败'
        this.$message.error(message)
      }
    },
    // 添加业绩区间
    handleAddQuota() {
      this.quotaSet.push({
        start: '',
        end: '',
        price: ''
      })
    },
    // 删除业绩区间
    handleDeleteQuota(i) {
      if (i === 0) {
        this.$message.warning('业绩区间设置至少为1个')
        return false
      }
      this.quotaSet.splice(i, 1)
    },
    // 重置业绩区间
    handleResetQuota() {
      this.quotaSet = [
        {
          start: '',
          end: '',
          price: ''
        }
      ]
    },
    // 提交业绩区间
    handleSubmitQuota() {
      const filterArr = this.quotaSet.filter(item => {
        return item.start && item.end && item.price
      })
      if (filterArr.length < 1) {
        this.$message.warning('请添加至少一个奖励区间并填写完整')
        return false
      }
      if (filterArr.length !== this.quotaSet.length) {
        this.$message.warning('请将未填写的内容填写完整或删除')
        return false
      }
      this.setQuota({
        rate: filterArr
      })
    },
    // 提交业绩区间
    async setQuota(data) {
      const res = await setQuota(data)
      try {
        const { message, code } = res
        if (code === 200) {
          this.$message.success(message)
          this.getSetting()
        } else {
          this.$message.error(message)
        }
      } catch (e) {
        let message = res.message ? res.message : e.message
        message = e.message ? e.message : '请求失败'
        this.$message.error(message)
      }
    }
  }
}
</script>
<style lang="scss">
  .fixed_reward{
    list-style: none;

    .label{
      background: #e5e5e5;
      font-size: 14px;
      padding: 15px;
      margin-bottom: 15px;
    }

    input{
      width: 250px !important;
    }

    .el-form-item{
      margin-bottom: 10px;
    }
  }

  .section_item{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .division{
      margin: 0 15px;
    }
    .delete{
      margin-left: 15px;
    }
  }
</style>
