main.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <el-dialog
  3. v-dialogdrag
  4. title="发送通知"
  5. :visible.sync="visible"
  6. append-to-body
  7. width="45%"
  8. :close-on-click-modal="false"
  9. :destroy-on-close="true"
  10. :close-on-press-escape="false"
  11. :before-close="closeDialog"
  12. >
  13. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  14. <el-form-item label="接受者" prop="toUserId">
  15. <el-select
  16. v-model="form.toUserId"
  17. clearable
  18. filterable
  19. size="small"
  20. >
  21. <el-option
  22. v-for="(item, index) in userOption"
  23. :key="index"
  24. :label="item.realName"
  25. :value="item.id"
  26. @change="getUserName"
  27. ></el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item label="发送内容" prop="messageBody">
  31. <el-input type="textarea" v-model="form.messageBody" size="small" placeholder="请输入发送内容"></el-input>
  32. </el-form-item>
  33. </el-form>
  34. <span slot="footer" class="dialog-footer">
  35. <el-button type="primary" @click="sendHandle">发送</el-button>
  36. <el-button @click="closeDialog">取消</el-button>
  37. </span>
  38. </el-dialog>
  39. </template>
  40. <script>
  41. import { getList } from "@/api/system/user";
  42. import { sendMessage,sendManyMessage } from "@/api/basicData/message"
  43. export default {
  44. name: "main",
  45. props: {},
  46. data() {
  47. return {
  48. visible: false,
  49. form: {},
  50. userOption: [],
  51. rules: {
  52. toUserId: [{required: true, message: " ", trigger: "change"}],
  53. messageBody: [{required: true, message: " ", trigger: "blur"}],
  54. },
  55. }
  56. },
  57. created() {
  58. getList().then(res => {
  59. this.userOption = res.data.data.records;
  60. })
  61. },
  62. methods: {
  63. // 打开
  64. init() {
  65. this.visible = true;
  66. },
  67. closeDialog() {
  68. this.visible = false;
  69. this.form = {}
  70. this.$refs.form.clearValidate();
  71. this.$emit("closeDialog")
  72. },
  73. // 发送消息
  74. sendHandle() {
  75. this.$refs["form"].validate(valid => {
  76. if (valid) {
  77. const data = {
  78. ...this.form,
  79. messageType: 1
  80. }
  81. sendManyMessage(data).then(res => {
  82. this.$message.success('发送成功')
  83. this.closeDialog()
  84. })
  85. }
  86. })
  87. },
  88. getUserName() {
  89. if (this.form.toUserId) {
  90. this.userOption.forEach(item => {
  91. if (item.form.toUserId == this.form.toUserId) {
  92. this.$set(this.form, 'toUserName', item.realName)
  93. }
  94. })
  95. }
  96. },
  97. },
  98. }
  99. </script>
  100. <style scoped>
  101. </style>