EmailRecipient.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div>
  3. <el-form
  4. :model="formData"
  5. :rules="rule"
  6. ref="recipForm"
  7. label-position="left"
  8. label-width="150px">
  9. <el-form-item
  10. label="Recipients:"
  11. prop="recipient"
  12. label-width="100px">
  13. <div class="flexcr" style="margin-top: -5px;">
  14. <el-input
  15. class="input-text"
  16. v-model="formData.recipient"
  17. placeholder=""
  18. maxlength="50"/>
  19. <el-button
  20. type="primary"
  21. icon="el-icon-plus"
  22. @click="addRecipient">
  23. Add
  24. </el-button>
  25. </div>
  26. </el-form-item>
  27. <el-form-item
  28. label="Added Recipients:">
  29. <div class="flexl">
  30. <div class="receip-item" v-for="(item, index) in emails" :key="index">
  31. <span>{{item}}</span>
  32. <i class="el-icon-close" @click="deleteRecipient(index)"></i>
  33. </div>
  34. <div v-if="emails.length > 0">
  35. <span class="link-button" @click="clearAllRecipient">Clear All</span>
  36. </div>
  37. </div>
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. name: "EmailRecipient",
  45. props: {
  46. value: {
  47. type: Array,
  48. default: []
  49. }
  50. },
  51. data() {
  52. return {
  53. emails: [],
  54. formData: {
  55. recipient: ""
  56. },
  57. rule: {
  58. "recipient": {
  59. pattern: /^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/,
  60. trigger: 'blur',
  61. message: 'Please type a correct recipient'
  62. }
  63. }
  64. };
  65. },
  66. model: {
  67. prop: 'value',
  68. event: 'change'
  69. },
  70. watch: {
  71. value: {
  72. deep: true,
  73. handler(n, o) {
  74. if (!n) {
  75. this.emails = [];
  76. this.onChange()
  77. } else {
  78. this.emails = n;
  79. }
  80. }
  81. }
  82. },
  83. methods: {
  84. onChange() {
  85. this.$emit('change', this.emails);
  86. },
  87. addRecipient() {
  88. if (this.formData.recipient) {
  89. this.$refs["recipForm"].validate(result => {
  90. if (result) {
  91. this.emails.push(this.formData.recipient);
  92. this.formData.recipient = "";
  93. this.onChange();
  94. }
  95. });
  96. }
  97. },
  98. deleteRecipient(index) {
  99. this.emails.splice(index, 1);
  100. this.onChange();
  101. },
  102. clearAllRecipient() {
  103. this.$confirm('Clear all recipients?', 'Prompt', {
  104. confirmButtonText: 'Confirm',
  105. cancelButtonText: 'Cancel',
  106. type: 'warning'
  107. }).then(res => {
  108. this.emails = [];
  109. this.onChange();
  110. })
  111. }
  112. }
  113. }
  114. </script>
  115. <style scoped>
  116. .input-text {
  117. width: 100%;
  118. max-width: 200px;
  119. margin-top: 5px;
  120. margin-right: 10px;
  121. margin-bottom: 5px;
  122. }
  123. .link-button {
  124. color: #3179E4;
  125. font-size: 14px;
  126. cursor: pointer;
  127. margin: 0 -10px;
  128. padding: 0 10px;
  129. display: inline-block;
  130. white-space: nowrap;
  131. text-decoration: underline;
  132. }
  133. .receip-item {
  134. display: flex;
  135. align-items: center;
  136. font-size: 14px;
  137. line-height: 1em;
  138. padding-top: 10px;
  139. }
  140. .receip-item i {
  141. color: #666;
  142. padding: 0 10px;
  143. cursor: pointer;
  144. }
  145. .receip-item i:hover,
  146. .receip-item i:active,
  147. .link-button:hover {
  148. color: #ff5500;
  149. }
  150. </style>