<template>
  <div class="app-container">
    <el-form :model="form" :rules="rules"  ref="form" label-width="150px">
      <el-row>
          <el-form-item label="贷款最小金额(元)" prop="loansMinAccount">
            <el-input :disabled="formDisable" v-model="form.loansMinAccount" placeholder="请输入贷款最小金额(元)" />
          </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="贷款最大金额(元)" prop="loansMaxAccount">
          <el-input :disabled="formDisable" v-model="form.loansMaxAccount" placeholder="请输入贷款最大金额(元)" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="贷款初始金额(元)" prop="loansInitAccount">
          <el-input :disabled="formDisable" v-model="form.loansInitAccount" placeholder="请输入贷款初始金额(元)" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="允许选择月份" prop="loansMonth">
          <el-input :disabled="formDisable" v-model="form.loansMonth" placeholder="请输入允许选择月份" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="初始选择月份" prop="loansInitMonth">
          <el-input :disabled="formDisable" v-model="form.loansInitMonth" placeholder="请输入初始选择月份" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="每月还款日" prop="dueDate">
          <el-input :disabled="formDisable" v-model="form.dueDate" placeholder="请输入每月还款日" />
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="服务费率" prop="serviceRate">
          <el-input :disabled="formDisable" type="textarea" v-model="form.serviceRate" placeholder="请输入服务费率"
                    :autosize="{ minRows: 4}"/>
        </el-form-item>
      </el-row>
      <el-form-item>
        <el-button :disabled="!formDisable" type="primary" size="mini" @click="formDisable = false">编辑</el-button>
        <el-button :disabled="formDisable" :loading="buttonLoading" type="primary" size="mini" @click="submitForm">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getLoansSetting, updateLoansSetting } from '@/api/dk/LoansSetting'

export default {
  name: "LoansSetting",
  components: {
  },
  data() {
    return {
      //按钮loading
      buttonLoading: false,
      // 表单参数
      form: {
        id: undefined,
        loansMinAccount: undefined,
        loansMaxAccount: undefined,
        loansInitAccount: undefined,
        loansMonth: undefined,
        loansInitMonth: undefined,
        dueDate: undefined,
        serviceRate: undefined
      },
      // 表单校验
      rules: {
      },
      formDisable:true,
    };
  },
  created() {
    this.init();
  },
  methods: {
    init(){
      this.refreshData(this.form.appType);
    },
    refreshData(){
      getLoansSetting().then(response => {
        this.form = response.data;
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.buttonLoading = true;
          updateLoansSetting(this.form).then(response => {
            this.formDisable = true;
            this.buttonLoading = false;
            this.msgSuccess("修改成功");
          }).catch(() => {
            this.formDisable = true;
            this.buttonLoading = false;
          });
        }
      });
    }
  }
};
</script>
