<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="140px" :rules="rules">
      <p class="title">代理申请账户码配置</p>
      <el-form-item label="省级申请最少数量" prop="provinceMinAccountNum">
        <el-input-number
          v-model="form.provinceMinAccountNum"
          controls-position="right"
          placeholder="请输入省级申请最少数量"
          :min="1"
          :precision="0"
          style="width: 300px"
        ></el-input-number>
        <span class="el-form-item__tip"
          >输入的数值是省代在用户端找平台申请的最少数量</span
        >
      </el-form-item>
      <el-form-item label="地代申请最少数量" prop="regionMinAccountNum">
        <el-input-number
          v-model="form.regionMinAccountNum"
          controls-position="right"
          placeholder="请输入地代申请最少数量"
          :min="1"
          :precision="0"
          style="width: 300px"
        ></el-input-number>
        <span class="el-form-item__tip"
          >输入的数值是地代在用户端找省代申请的最少数量</span
        >
      </el-form-item>
      <el-form-item label="" prop="">
        <el-button type="primary" @click="handleSave" :loading="loading"
          >保存</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { agentConfigInfo, agentConfigAdd } from "@/api/agentManage";
export default {
  data() {
    return {
      loading: false,
      form: {},
      rules: {
        provinceMinAccountNum: [
          { required: true, message: "请输入省级申请最少数量", trigger: "blur" },
        ],
        regionMinAccountNum: [
          { required: true, message: "请输入地代申请最少数量", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getConfigInfo();
  },
  methods: {
    getConfigInfo() {
      agentConfigInfo().then((res) => {
        if (res.code == 200) {
          this.form = res.data || {};
        }
      });
    },
    handleSave() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.loading = true;
          agentConfigAdd(this.form)
            .then((res) => {
              this.loading = false;
              if (res.code == 200) {
                this.$message.success("保存成功");
              }
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 30px;
  .title {
    font-size: 16px;
    font-weight: bold;
    margin: 20px 0;
  }
  .el-form-item__tip {
    color: red;
    margin-left: 10px;
  }
}
</style>
