<template>
  <div class="page">
    <topBar v-if="topList.length > 0" :top-list="topList" :moren="moren" />
    <div v-if="topList[0].changed == true" class="main">
      <div class="main_title">
        <div class="bluekuai" />
        <div class="title_word">注册次数</div>
      </div>
      <div class="main_content">
        <el-form ref="form" :model="form" label-width="auto">
          <el-row>
            <el-col v-for="(aitem, aindex) in timeList" :key="aindex" :span="6">
              <el-form-item
                :prop="aitem.key"
                :label="aitem.label"
                class="selects"
              >
                <el-input
                  v-model="aitem.value"
                  clearable
                  :placeholder="'请输入'"
                  @blur="changeInput(aitem.value)"
                />
              </el-form-item> </el-col></el-row>
        </el-form>
      </div>
    </div>
    <div v-if="topList[0].changed == true" class="my_footer">
      <div style="margin: 0 auto">
        <el-button class="myBtn"> {{ '取消' }}</el-button>
        <el-button
          v-has-buttons="['xtcsConfirm']"
          class="myBtn1"
          style="margin-left: 40px"
          @click="saveDate('form')"
        >
          {{ '确认' }}</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import topBar from '@/components/topBarRole'
import { getzccsList, saveYfpz } from '@/api/system'
import { getRouters } from '@/api/settle'
export default {
  name: 'Xtcs',
  components: {
    topBar
  },
  data() {
    return {
      rules: {
        REGISTER_NUMBER_1: [
          {
            message: '注册次数不能为空',
            trigger: 'blur'
          }
        ],
        REGISTER_NUMBER_3: [
          {
            message: '海粉注册次数不能为空',
            trigger: 'blur'
          }
        ]
      },
      moren: 'xtcs',
      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: 'sjfs',
          changed: false
        },
        {
          name: '直推方式',
          path: 'ztfs',
          url: 'ztfs',
          changed: false
        }
      ],
      form: {},
      timeList: []
    }
  },
  created() {
    this.getzccsList()
    this.getUserRoute()
  },
  methods: {
    changeInput(val) {
      if (!val) {
        this.$message({
          message: '请输入',
          type: 'warning'
        })
      }
    },
    getUserRoute() {
      getRouters().then((res) => {
        res.data.forEach((item) => {
          this.topList.forEach((items) => {
            if (item.routeName == items.url) {
              items.changed = true
            }
          })
        })
      })
    },
    getzccsList() {
      getzccsList({ key: 'REGISTER_NUMBER' }).then((res) => {
        this.timeList = res.data
      })
    },
    saveDate(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          saveYfpz(this.timeList).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: res.msg,
                type: 'success'
              })
            }
            this.getzccsList()
          })
        }
      })
    }
  }
}
</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: -80px;
  top: 50%;
  margin-top: -17px;
}
::v-deep .el-input {
  width: 166px;
}
::v-deep .el-input__inner {
  width: 166px;
  height: 32px;
}
::v-deep .el-form-item__label {
  color: #333;
  font-weight: inherit;
}
.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);
    //height: 1000px;
    .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 {
    .thebtn {
      width: 120px;
      height: 38px;
    }
  }
}
</style>
