<template>
  <div>
    <vxe-modal
      :value="isShow"
      show-footer
      title="特殊日期"
      show-confirm-button
      :width="defaultModalSize.sWidth"
      :height="defaultModalSize.sHeight"
      esc-closable
      transfer
      :fullscreen="$store.getters.device === 'mobile'"
      @input="e => $emit('update:isShow',e)"
    >
      <el-form ref="elForm" :model="form" :rules="rules" label-position="top" label-width="100">
        <el-form-item label="名字" prop="name">
          <el-input v-model="form.name" />
        </el-form-item>
        <el-form-item label="标识" prop="key">
          <el-input v-model="form.key" />
        </el-form-item>
        <el-form-item label="值" prop="value">
          <el-input v-model="form.value" />
        </el-form-item>
        <el-form-item label="排序" prop="mysort">
          <el-input-number v-model="form.mysort" controls-position="right" :precision="0" />
        </el-form-item>
      </el-form>

      <template #footer>
        <el-button type="primary" :loading="loading" @click="submit">确认</el-button>
      </template>
    </vxe-modal>
  </div>
</template>

<script>
import { save } from '@/api/config'
import {defaultModalSize} from "@/settings";
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false,
      required: true
    }
  },
  data() {
    return {
      defaultModalSize,
      loading: false,
      form: {
        name: '',
        key: '',
        value: '',
        mysort: 0
      },
      rules: {}
    }
  },
  computed: {},
  methods: {
    submit() {
      this.$refs['elForm'].validate(async valid => {
        if (valid) {
          this.loading = true
          try {
            await save(this.form)
            this.$message.success('新增成功')
            this.$emit('refresh')
            this.$emit('update:isShow', false)
            this.loading = false
            this.$refs['elForm'].resetFields()
          } catch (err) {
            this.loading = false
          }
        }
      })
    }
  }
}
</script>

<style scoped lang="scss">
</style>
