<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div class="maintable">
        <el-table
          :data="tableData"
          height="400px"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
        >
          <el-table-column
            width="200px"
            align="center"
            prop="gradeName"
            :label="'等级'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="expandRatio"
            :label="'拓展比例'+'(%)'"
          >
            <template slot-scope="scope">
              <el-input
                clearable
                :disabled="ifupdate"
                v-model="scope.row.expandRatio"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="expandCapping"
            :label="`${'拓展封顶'}`+`(${isLocals()})`"
          >
            <template slot-scope="scope">
              <el-input
                clearable
                :disabled="ifupdate"
                v-model="scope.row.expandCapping"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="repurchaseRatio"
            label="复购拓展比例(%)"
          >
            <template slot-scope="scope">
              <el-input
                clearable
                :disabled="ifupdate"
                v-model="scope.row.repurchaseRatio"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="repurchaseCapping"
            label="复购拓展封顶($)"
          >
            <template slot-scope="scope">
              <el-input
                clearable
                :disabled="ifupdate"
                v-model="scope.row.repurchaseCapping"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="firstCalculate"
            label="首购计算"
          >
            <template slot-scope="scope">
              <el-select
                clearable
                :disabled="ifupdate"
                v-model="scope.row.firstCalculate"
              >
                <el-option
                  v-for="item in yesNoList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="firstAssess"
            label="首购考核"
          >
          <template slot-scope="scope">
              <el-select
                clearable
                :disabled="ifupdate"
                v-model="scope.row.firstAssess"
              >
                <el-option
                  v-for="item in ssessmentTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="repurchaseCalculate"
            label="复购计算"
          >
          <template slot-scope="scope">
              <el-select
                clearable
                :disabled="ifupdate"
                v-model="scope.row.repurchaseCalculate"
              >
                <el-option
                  v-for="item in yesNoList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="repurchaseAssess"
            label="复购考核"
          >
            <template slot-scope="scope">
              <el-select
                clearable
                :disabled="ifupdate"
                v-model="scope.row.repurchaseAssess"
              >
                <el-option
                  v-for="item in ssessmentTypeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="maintable2">
        <el-table
          :data="tableData2"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
        >
          <el-table-column
            width="200px"
            align="center"
            prop="expandName"
            :label="'4-N配置'"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="expandNumber"
            :label="'拓展次数(次)'"
          >
            <template slot-scope="scope">
              <el-input
                clearable
                :disabled="ifupdate"
                v-model="scope.row.expandNumber"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="expandRatio"
            :label="'拓展比例'+'(%)'"
          >
            <template slot-scope="scope">
              <el-input
                clearable
                :disabled="ifupdate"
                v-model="scope.row.expandRatio"
              ></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="" label=""> </el-table-column>
          <el-table-column align="center" prop="" label=""> </el-table-column>
        </el-table>

        <el-table
          :data="tableData3"
          style="width: 100%"
          :header-cell-style="{ background: '#EEEEEE' }"
          :row-class-name="tableRowClassName"
        >
          <el-table-column
            width="200px"
            align="center"
            prop="expandName"
            :label="'封顶方式'"
          >
            <template slot-scope="scope">
              <el-select
                clearable
                v-model="scope.row.value"
                :placeholder="'请选择'"
                :disabled="ifupdate"
              >
                <el-option
                  v-for="item in fdWayList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                ></el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="" label=""> </el-table-column>

          <el-table-column align="center" prop="" label=""> </el-table-column>
          <el-table-column align="center" prop="" label=""> </el-table-column>
          <el-table-column align="center" prop="" label=""> </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="footer">
      <div style="margin: 0 auto">
        <el-button class="thebtn btn1" @click="ifupdate = false"
          > {{ '修改' }}</el-button
        >
        <el-button class="thebtn btn2" @click="savedate">{{'保存'}}</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "@/components/topBar";
import {getDealerYesNo} from "@/api/delivery"
import { getExpandList, updateExpand, getbdBonusExpand,getAssessmentType } from "@/api/bonus";
import {getzccsList} from '@/api/siteConfig'
import {saveYfpz} from '@/api/system'
import {isLocals} from "@/utils/numberToCurrency";
export default {
  name: "Kzpz",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "kzpz",
      topList: [
        {
          name: '奖项配置',
          path: "bonus",
        },
        {
          name: '直推配置',
          path: "ztpz",
        },
        {
          name: '拓展配置',
          path: "kzpz",
        },
        {
          name: '辅导分红',
          path: "fdfh",
        },

        {
          name: '服务补贴',
          path: "fwbt",
        },
        {
          name: '奖金扣项',
          path: "jjkx",
        },
        {
          name: '云代配置',
          path: "ydpz",
        },
        {
          name: '环球积分',
          path: "hqjf",
        },
        {
          name: '车奖积分',
          path: "njjf",
        },
      ],
      tableData: [],
      tableData2: [],
      tableData3: [],
      ifupdate: true,
      fdWayList: [
        { value: '1', label: "日" },
        { value: '2', label: "周" },
      ],
      ssessmentTypeList: [],
      yesNoList:[]
    };
  },
  created() {
    this.getExpandList();
  },
  methods: {
    isLocals,
    //获取拓展等级列表
    getExpandList() {
      getExpandList().then((res) => {
        this.tableData = res.rows;
      });
      getbdBonusExpand().then((res) => {
        this.tableData2 = res.rows;
      });
      getzccsList({key:'EXPAND_CAP_METHOD1'}).then(res=>{
        this.tableData3 = res.data
      })
       //考核类型下拉选
       getAssessmentType().then((res) => {
        this.ssessmentTypeList = res.data;
      });
      getDealerYesNo().then(res=>{
        this.yesNoList = res.data
      })
    },
    //保存
    savedate() {
      this.ifupdate = true;
      updateExpand({
        expandList: this.tableData,
        bonusExpands: this.tableData2,
      }).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: res.msg,
            type: "success",
          });
          this.getExpandList();
        }
      });
      saveYfpz(this.tableData3).then(res=>{
      })

    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 == 1) {
        return "warning-row";
      } else if (rowIndex % 2 == 0) {
        return "success-row";
      }
      return "";
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-input.is-disabled .el-input__inner{
  color: #333333;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-input__inner {
  width: 160px !important;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}

.page {
  padding: 20px 20px 36px 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    border-radius: 8px;

    .maintable {
      max-height: 484px;
      overflow: auto;
      border-bottom: 4px solid #eeeeee;
    }
    .maintable2 {
      max-height: 280px;
      overflow: auto;
      margin-top: 20px;
    }
  }
  .footer {
    display: flex;
    margin-top: 20px;
    .thebtn {
      width: 120px;
      height: 48px;
      color: #ffffff;
      font-size: 14px;
      font-weight: bold;
    }
    .btn1 {
      background: #4391fd;
      margin-right: 80px;
    }
    .btn2 {
      background: #ffad41;
    }
  }
}
</style>
