index.vue 2.0 KB

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