index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.path)
  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. search = search ? search : this.model
  56. this.searchs.update(search, undefined, type)
  57. },
  58. validate(FC) {
  59. this.$refs.form.validate(valid => {
  60. FC(valid)
  61. if (valid) {
  62. this.searchs.update(this.model, undefined, 'form')
  63. }
  64. })
  65. },
  66. resetFields() {
  67. this.$refs.form.resetFields()
  68. this.searchs.update(this.model, undefined, 'form')
  69. this.searchs.update({}, undefined, 'page')
  70. }
  71. },
  72. }
  73. </script>
  74. <style lang="less" scoped>
  75. .save-form{
  76. /deep/ .el-input__inner{
  77. width: 180px;
  78. }
  79. /deep/ .el-form-item__content .el-col {
  80. width: 180px;
  81. }
  82. /deep/ .el-col.line{
  83. width: 15px!important;
  84. text-align: center;
  85. }
  86. /deep/ .el-date-editor--daterange{
  87. width: 375px;
  88. }
  89. /deep/ .el-form-item__content .el-col:last-child .el-form-item{
  90. margin-right: 0;
  91. }
  92. }
  93. </style>