<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :topList="topList"
      :moren="moren"
    ></topBar>
    <div class="main">
      <div class="main_title">
        <div class="bluekuai"></div>
        <div class="title_word">{{'极左极下'}}</div>
      </div>
      <div class="main_content">
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-row class="selects">
            <el-col :span="5">
<!--              <a class="star">*</a>-->
              <el-form-item :label="'极左极下'" prop="jzjx">
                <el-select clearable v-model="form.jzjx">
                  <el-option
                    v-for="item in alowList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item> </el-col
          ></el-row>
        </el-form>
      </div>

      <div class="main_title">
        <div class="bluekuai"></div>
        <div class="title_word">{{ '安置校验' }}</div>
      </div>
      <div class="main_content">
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-row class="selects">
            <el-col :span="5">
<!--              <a class="star">*</a>-->
              <el-form-item :label="'直推校验'" prop="ztjy">
                <el-select clearable v-model="form.ztjy">
                  <el-option
                    v-for="item in alowList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5" class="selects">
<!--              <a class="star">*</a>-->
              <el-form-item :label="'安置位置'" prop="jyazwz">
                <el-select clearable v-model="form.jyazwz">
                  <el-option
                    v-for="item in azwzList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="main_title">
        <div class="bluekuai"></div>
        <div class="title_word">{{ '注册位置' }}</div>
      </div>
      <div class="main_content">
        <el-form ref="form" :rules="rules" :model="form" label-width="80px">
          <el-row>
            <el-col :span="5" class="selects">
<!--              <a class="star">*</a>-->
              <el-form-item :label="'注册等级'" prop="zcdj">
                <el-select clearable v-model="form.zcdj">
                  <el-option
                    v-for="item in gradeValueList"
                    :key="item.gradeValue"
                    :label="item.gradeName"
                    :value="item.gradeValue"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5" class="selects">
<!--              <a class="star">*</a>-->
              <el-form-item :label="'业绩类型'" prop="yjlx">
                <el-select clearable v-model="form.yjlx">
                  <el-option
                    v-for="item in yejiList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="5" class="selects">
<!--              <a class="star">*</a>-->
              <el-form-item :label="'安置位置'" prop="zcazwz">
                <el-select clearable v-model="form.zcazwz">
                  <el-option
                    v-for="item in azwzList2"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </div>
    <div class="footer">
      <div style="margin: 0 auto">
        <el-button class="thebtn"> {{ '取消' }}</el-button>
        <el-button type="primary" class="thebtn" @click="saveDate('form')"
                   v-has-buttons="['azjyConfirm']"
          > {{ '确认' }}</el-button
        >
      </div>
    </div>
  </div>
</template>

<script>
import topBar from "@/components/topBarRole";
import { getzccsList, saveYfpz } from "@/api/system";
import { getgradeRanglist } from "@/api/level";
import {getRouters} from "@/api/settle";
export default {
  name: "Azjy",
  components: {
    topBar,
  },
  data() {
    return {
      moren: "azjy",
      topList: [
        {
          name: '注册次数',
          path: "xtcs",
          url: "xtcs",
          changed: false,
        },
        {
          name: '运输方式',
          path: "ysfs",
          url: "ysfs",
          changed: false,
        },
        {
          name: '支付配置',
          path: "zfpz",
          url: "zfpz",
          changed: false,
        },
        {
          name: '邮费配置',
          path: "yfpz",
          url: "yfpz",
          changed: false,
        },
        {
          name: '安置校验',
          path: "azjy",
          url: "azjy",
          changed: false,
        },
        {
          name: '撤单日期',
          path: "cdsj",
          url: "cdsj",
          changed: false,
        },
        {
          name: '升级方式',
          path: "sjfs",
          url: "cdsj",
          changed: false,
        },
        {
          name:'直推方式',
          path:'ztfs',
          url: "ztfs",
          changed: false,
        }
      ],
      alowList: [
        { value: "0", label: '允许' },
        { value: "1", label: '禁止' },
      ],
      azwzList: [
        //安置位置列表
        { value: "0", label:'任意' },
        { value: "1", label:'左' },
        { value: "2", label:'右' },
      ],
      azwzList2: [
        { value: "1", label: '大区' },
        { value: "2", label: '小区' },
      ],
      gradeValueList: [], //注册等级列表
      yejiList: [
        {
          //业绩类型列表
          value: 1,
          label: '首购',
        },
        {
          value: 2,
          label: '复购',
        },
        {
          value: 3,
          label: '真实',
        },
      ],
      form: {
        jzjx: "", //极左极下
        ztjy: "", //直推校验
        jyazwz: "", //校验安置位置
        zcdj: "", //注册等级
        yjlx: "", //业绩类型
        zcazwz: "", //注册安置位置
      },
      rules: {
        jzjx: [{ required: true, message: '请选择', trigger: "change" }],
        ztjy: [
          {
            required: true,
            message: '请选择',
            trigger: "change",
          },
        ],
        jyazwz: [
          {
            required: true,
            message: '请选择',
            trigger: "change",
          },
        ],
        zcdj: [
          {
            required: true,
            message: '请选择',
            trigger: "change",
          },
        ],
        zcazwz: [
          {
            required: true,
            message: '请选择',
            trigger: "change",
          },
        ],
      },
      azList: [],
    };
  },
  created() {
    this.getzccsList();
    this.getgradeRanglist();
    this.getUserRoute()
  },
  methods: {
    getUserRoute() {
      getRouters().then((res)=>{
        res.data.forEach((item)=>{
          this.topList.forEach((items)=>{
            if (item.routeName == items.url){
              items.changed = true
            }
          })
        })
      })
    },
    //注册等级列表
    getgradeRanglist() {
      getgradeRanglist().then((res) => {
        this.gradeValueList = res.data;
      });
    },
    //获取安置校验列表
    getzccsList() {
      getzccsList({ key: "PLACE" }).then((res) => {
        this.azList = res.data;
        this.azList.forEach((element) => {
          if (element.key == "PLACE_1") {
            this.form.jzjx = element.value;
          } else if (element.key == "PLACE_2") {
            this.form.ztjy = element.value;
          } else if (element.key == "PLACE_3") {
            this.form.jyazwz = element.value;
          } else if (element.key == "PLACE_4") {
            this.form.zcdj = Number(element.value);
          } else if (element.key == "PLACE_5") {
            this.form.yjlx = Number(element.value);
          } else if (element.key == "PLACE_6") {
            this.form.zcazwz = element.value;
          }
        });
      });
    },
    saveDate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.azList.forEach((element) => {
            if (element.key == "PLACE_1") {
              element.value = this.form.jzjx;
            } else if (element.key == "PLACE_2") {
              element.value = this.form.ztjy;
            } else if (element.key == "PLACE_3") {
              element.value = this.form.jyazwz;
            } else if (element.key == "PLACE_4") {
              element.value = this.form.zcdj;
            } else if (element.key == "PLACE_5") {
              element.value = this.form.yjlx;
            } else if (element.key == "PLACE_6") {
              element.value = this.form.zcazwz;
            }
          });
          saveYfpz(this.azList).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: "success",
              });
              this.getzccsList();
            } else {
              this.$message({
                message: res.msg,
                type: "warning",
              });
            }
            this.getzccsList();
          });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.myBtn{
  width: 120px;
  height: 38px;
  border-radius: 5px;
  color: #fff;
  background-color: #CCCCCC;
  border-color: #ccc;
}
.myBtn1{
  width: 120px;
  height: 38px;
  border-radius: 5px;
  color: #fff;
  background-color: #C8161D;
  border-color: #C8161D;
}
.selects{
  position: relative;
}
::v-deep .el-form-item{
  position: relative;
}
.star{
  color: #ED1D25;
  position: absolute;
  left: 0;
  top: 50%;
  margin-top:-15px;
}
::v-deep .el-form-item__label:before{
  display: none;
}
::v-deep .el-input__icon{
  line-height: 45px;
}
//::v-deep .el-icon-arrow-up:before{
//  content: url('~@/assets/images/down.png') !important;
//  height: 7px;
//}
::v-deep .el-input{
  width: 166px;
}
::v-deep .el-form-item__label{
  color: #333;
  font-weight: inherit;
}
::v-deep .el-input__inner{
  width: 166px;
  height: 32px;
}
::v-deep .el-select{
  width: 166px;
}
::v-deep .el-select .el-input input{
  text-align: center;
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #ffffff;
    border-radius: 8px;
    box-shadow: 0px 2px 20px 0px rgba(238, 238, 238, 0.5);
    .main_title {
      display: flex;
      align-items: center;
      padding: 10px 0;
      border-bottom: 1px solid rgba(0, 0, 0, 0.1);
      .bluekuai {
        width: 5px;
        height: 19px;
        background: #C8161D;
        margin-right: 20px;
      }
      .title_word {
        font-size: 14px;
        font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
        font-weight: bold;
        color: #333333;
      }
    }
    .main_content {
      padding: 20px 25px;
    }
  }
  .footer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 15px 0;
    .thebtn {
      width: 120px;
      height: 38px;
    }
  }
}
</style>
