index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <el-form
  3. class="save-form"
  4. v-bind="{...$attrs, ...$props}"
  5. v-on="$listeners"
  6. ref="form"
  7. >
  8. <slot/>
  9. </el-form>
  10. </template>
  11. <script>
  12. import { Searchs } from '@/helpers'
  13. export default {
  14. name: 'save-form',
  15. props: ['model', 'save-key'],
  16. data() {
  17. return {
  18. searchs: null
  19. }
  20. },
  21. mounted() {
  22. const searchs = new Searchs(this['save-key'] || this.$route.fullPath)
  23. this.searchs = searchs
  24. const active = searchs.get()
  25. for (const key in active.form) {
  26. if (active.form.hasOwnProperty(key)) {
  27. const item = active.form[key]
  28. this.model[key] = item
  29. }
  30. }
  31. },
  32. methods: {
  33. save(search = null, type = 'form') {
  34. this.searchs.update(search, undefined, type)
  35. },
  36. validate(FC) {
  37. this.$refs.form.validate(valid => {
  38. FC(valid)
  39. if (valid) {
  40. this.searchs.update(this.model, undefined, 'form')
  41. }
  42. })
  43. },
  44. resetFields() {
  45. this.searchs.update(this.model, undefined, 'form')
  46. this.searchs.update({}, undefined, 'page')
  47. this.$refs.form.resetFields()
  48. }
  49. },
  50. }
  51. </script>
  52. <style lang="less" scoped>
  53. .save-form{
  54. /deep/ .el-input__inner{
  55. width: 180px;
  56. }
  57. /deep/ .el-form-item__content .el-col {
  58. width: 180px;
  59. }
  60. /deep/ .el-col.line{
  61. width: 15px!important;
  62. text-align: center;
  63. }
  64. /deep/ .el-date-editor--daterange{
  65. width: 375px;
  66. }
  67. /deep/ .el-form-item__content .el-col:last-child .el-form-item{
  68. margin-right: 0;
  69. }
  70. }
  71. </style>