<template>
  <el-dialog
    title="新增参数"
    :visible.sync="visible"
    width="600px"
    append-to-body
    @close="close"
  >
    <el-form
      ref="addForm"
      :model="addForm"
      label-position="left"
      size="mini"
      label-width="80px"
      :rules="rules"
    >
      <el-row :gutter="36">
        <el-col :span="24">
          <el-form-item label="业务类型" prop="transType">
            <el-select style="width: 100%" v-model="addForm.transType">
              <el-option
                v-for="item in busiTypeArr"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="层级" prop="level">
            <el-select style="width: 100%" v-model="addForm.level">
              <el-option
                v-for="item in orgLevelArr"
                :key="item.value"
                :value="item.value"
                :label="item.label"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="金额" prop="amount">
            <el-input
              type="number"
              :min="0"
              v-model="addForm.amount"
              placeholder="请输入"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="submit">确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { addModel } from '@/api/configure/paramsSetting.js'
import { Message } from 'element-ui'
export default {
  props: {
    dialogVisible: Boolean,
    busiTypeArr: Array,
    orgLevelArr: Array,
  },
  data() {
    return {
      addForm: {},
      rules: {
        transType: [
          {
            required: true,
            message: "请选择业务类型",
            trigger: "change",
          },
        ],
        level: [
          {
            required: true,
            message: "请选择层级",
            trigger: "change",
          },
        ],
        amount: [
          {
            required: true,
            message: "请输入金额",
            trigger: "blur",
          },
        ],
      },
      visible: false,
    };
  },
  watch: {
    dialogVisible(newVal, olaVal) {
      this.visible = newVal
    },
  },
  methods: {
    close() {
      this.visible = false
      this.$refs.addForm.resetFields()
      this.$emit("close")
    },
    submit() {
      this.$refs.addForm.validate((valid) => {
        if (valid) {
            addModel(this.addForm).then(res => {
                if (res.code === 200) {
                Message.success('新增成功!')
                this.close()
                this.$emit("fresh")
                }
            })
        }
      });
    },
  },
};
</script>
