<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="$t('ENU_NOTICE_TYPE_1')"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="expandRatio"
            :label="$t('MN_F_T_434')+'(%)'"
          >
            <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="`${$t('MN_F_T_435')}`+`(${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="$t('MN_F_T_1226')"
          >
          </el-table-column>
          <el-table-column
            align="center"
            prop="expandNumber"
            :label="$t('MN_F_T_1227')"
          >
            <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="$t('MN_F_T_434')+'(%)'"
          >
            <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="$t('MN_F_T_1228')"
          >
            <template slot-scope="scope">
              <el-select
                clearable
                v-model="scope.row.value"
                :placeholder="$t('CK_KS_38')"
                :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"
          > {{ $t('ENU_CONTROL_TYPE_2') }}</el-button
        >
        <el-button class="thebtn btn2" @click="savedate">{{$t('PER_DA_12')}}</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: this.$t('MN_F_T_412'),
          path: "bonus",
        },
        {
          name: this.$t('MN_F_T_114'),
          path: "ztpz",
        },
        {
          name: this.$t('MN_F_T_413'),
          path: "kzpz",
        },
        {
          name: this.$t('MN_F_T_116'),
          path: "fdfh",
        },

        {
          name: this.$t('MN_F_T_117'),
          path: "fwbt",
        },
        {
          name: this.$t('MN_F_T_118'),
          path: "jjkx",
        },
        {
          name: this.$t('MN_F_T_119'),
          path: "ydpz",
        },
        {
          name: this.$t('MN_F_T_120'),
          path: "hqjf",
        },
        {
          name: this.$t('MN_F_T_121'),
          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>
