index.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <el-form
  3. ref="form"
  4. :model="form"
  5. label-width="80px"
  6. @submit.stop.native="submit"
  7. >
  8. <el-form-item
  9. label="相册名称"
  10. prop="name"
  11. :rules="[{required: true, message: '请输入相册名称'}]"
  12. >
  13. <el-input v-model="form.name" placeholder="请输入相册名称"/>
  14. </el-form-item>
  15. <el-form-item
  16. label="相册时间"
  17. prop="timeLine"
  18. :rules="[{required: true, message: '请选择相册时间'}]"
  19. >
  20. <el-date-picker
  21. v-model="form.timeLine"
  22. type="month"
  23. value-format="yyyy-MM-DD"
  24. style="width: 100%"
  25. placeholder="请选择相册时间">
  26. </el-date-picker>
  27. </el-form-item>
  28. <div class="dialog-footer">
  29. <el-button @click="$emit('close')">取 消</el-button>
  30. <el-button
  31. type="primary"
  32. native-type="submit"
  33. >确 定</el-button>
  34. </div>
  35. </el-form>
  36. </template>
  37. <script>
  38. import dayjs from 'dayjs'
  39. import { photoAlbumAdd, photoAlbumUpdate } from '../api'
  40. export default {
  41. props: {
  42. detail: {
  43. type: Object,
  44. }
  45. },
  46. data() {
  47. return {
  48. form: {
  49. name: '',
  50. timeLine: ''
  51. }
  52. }
  53. },
  54. mounted() {
  55. if (this.detail) {
  56. this.form.name = this.detail.name
  57. this.form.timeLine = this.detail.timeLine
  58. }
  59. },
  60. methods: {
  61. async submit(evt) {
  62. evt.stopPropagation()
  63. evt.stopImmediatePropagation()
  64. evt.preventDefault()
  65. this.$refs.form.validate(async (valid) => {
  66. if (valid) {
  67. try {
  68. if (this.detail) {
  69. await photoAlbumUpdate([{
  70. ...this.form,
  71. musicGroupId: this.$route.query.id,
  72. year: dayjs(this.form.timeLine).year(),
  73. id: this.detail.id
  74. }])
  75. this.$message.success('修改成功')
  76. } else {
  77. await photoAlbumAdd({
  78. ...this.form,
  79. musicGroupId: this.$route.query.id
  80. })
  81. this.$message.success('添加成功')
  82. }
  83. this.$emit('close')
  84. this.$emit('submited')
  85. } catch (error) {}
  86. }
  87. })
  88. },
  89. }
  90. }
  91. </script>
  92. <style lang="less" scoped>
  93. .dialog-footer{
  94. text-align: right;
  95. }
  96. </style>