index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. <div class="dialog-footer">
  16. <el-button @click="$emit('close')">取 消</el-button>
  17. <el-button
  18. type="primary"
  19. native-type="submit"
  20. >确 定</el-button>
  21. </div>
  22. </el-form>
  23. </template>
  24. <script>
  25. import { photoAlbumAdd, photoAlbumUpdate } from '../api'
  26. export default {
  27. props: {
  28. detail: {
  29. type: Object,
  30. }
  31. },
  32. data() {
  33. return {
  34. form: {
  35. name: ''
  36. }
  37. }
  38. },
  39. mounted() {
  40. if (this.detail) {
  41. this.form.name = this.detail.name
  42. }
  43. },
  44. methods: {
  45. async submit(evt) {
  46. evt.stopPropagation()
  47. evt.stopImmediatePropagation()
  48. evt.preventDefault()
  49. this.$refs.form.validate(async (valid) => {
  50. if (valid) {
  51. try {
  52. if (this.detail) {
  53. await photoAlbumUpdate({
  54. ...this.form,
  55. musicGroupId: this.$route.query.id,
  56. id: this.detail.id
  57. })
  58. this.$message.success('修改成功')
  59. } else {
  60. await photoAlbumAdd({
  61. ...this.form,
  62. musicGroupId: this.$route.query.id
  63. })
  64. this.$message.success('添加成功')
  65. }
  66. this.$emit('close')
  67. this.$emit('submited')
  68. } catch (error) {}
  69. }
  70. })
  71. },
  72. }
  73. }
  74. </script>
  75. <style lang="less" scoped>
  76. .dialog-footer{
  77. text-align: right;
  78. }
  79. </style>