index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. search = search ? search : this.model
  35. this.searchs.update(search, undefined, type)
  36. },
  37. validate(FC) {
  38. this.$refs.form.validate(valid => {
  39. FC(valid)
  40. if (valid) {
  41. this.searchs.update(this.model, undefined, 'form')
  42. }
  43. })
  44. },
  45. resetFields() {
  46. this.$refs.form.resetFields()
  47. this.searchs.update(this.model, undefined, 'form')
  48. this.searchs.update({}, undefined, 'page')
  49. }
  50. },
  51. }
  52. </script>
  53. <style lang="less" scoped>
  54. .save-form{
  55. /deep/ .el-input__inner{
  56. width: 180px;
  57. }
  58. /deep/ .el-form-item__content .el-col {
  59. width: 180px;
  60. }
  61. /deep/ .el-col.line{
  62. width: 15px!important;
  63. text-align: center;
  64. }
  65. /deep/ .el-date-editor--daterange{
  66. width: 375px;
  67. }
  68. /deep/ .el-form-item__content .el-col:last-child .el-form-item{
  69. margin-right: 0;
  70. }
  71. }
  72. </style>