dialog.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <el-dialog v-model="visible" :title="`回复@${form.replyName}`" width="680" @closed="$emit('closed')">
  3. <el-input v-model="form.messageContent" type="textarea" autosize clearable show-word-limit maxlength="140" placeholder="发布你的回复"></el-input>
  4. <template #footer>
  5. <el-button :loading="isSaving" type="primary" :disabled="!form.messageContent" @click="submit">回复</el-button>
  6. </template>
  7. </el-dialog>
  8. </template>
  9. <script>
  10. import API from "@/api/policy/message";
  11. export default {
  12. emits: ["success", "closed"],
  13. props: {
  14. refId: { type: String, default: "" },
  15. refType: { type: String, default: "policy_share" }
  16. },
  17. data() {
  18. return {
  19. visible: false,
  20. isSaving: false,
  21. form: {
  22. parentId: null,
  23. refId: this.refId,
  24. refType: this.refType,
  25. replyId: null,
  26. replyName: null,
  27. messageContent: null
  28. }
  29. }
  30. },
  31. methods: {
  32. open() {
  33. this.visible = true;
  34. return this;
  35. },
  36. setData(data) {
  37. if (data.parentId == 0) {
  38. this.form.parentId = data.id;
  39. } else {
  40. this.form.parentId = data.parentId;
  41. this.form.replyId = data.createId;
  42. this.form.replyName = data.createName;
  43. }
  44. },
  45. // 表单提交方法
  46. submit() {
  47. this.isSaving = true;
  48. API.add(this.form).then(res => {
  49. this.isSaving = false;
  50. if (res.code === 200) {
  51. ElMessage.success("操作成功");
  52. this.visible = false;
  53. this.$emit("success", this.form.parentId);
  54. } else ElMessage.error(res.msg);
  55. }).catch(() => this.isSaving = false);
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss" scoped>
  61. .el-textarea {
  62. margin: 10px 0 18px;
  63. }
  64. </style>