<template>
  <el-form
    class="save-form"
    v-bind="{...$attrs, ...$props}"
    v-on="$listeners"
    ref="form"
  >
    <slot/>
  </el-form>
</template>
<script>
import { Searchs } from '@/helpers'
export default {
  name: 'save-form',
  props: ['model'],
  data() {
    return {
      searchs: null
    }
  },
  mounted() {
    const searchs = new Searchs(this.$route.fullPath)
    this.searchs = searchs
    const active = searchs.get()
    for (const key in active.form) {
      if (active.form.hasOwnProperty(key)) {
        const item = active.form[key]
        this.model[key] = item
      }
    }
  },
  methods: {
    validate(FC) {
      this.$refs.form.validate(valid => {
        FC(valid)
        if (valid) {
          this.searchs.update(this.model, undefined, 'form')
        }
      })
    },
    resetFields() {
      this.searchs.update(this.model, undefined, 'form')
      this.searchs.update({}, undefined, 'page')
      this.$refs.form.resetFields()
    }
  },
}
</script>
<style lang="less" scoped>
.save-form{

}

</style>
