add.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div class="card-container">
  3. <div class="card-content">
  4. <el-form
  5. v-loading="loading"
  6. :model="formInfo"
  7. :rules="rules"
  8. ref="addForm"
  9. label-width="200px"
  10. label-position="right">
  11. <div class="section-title">Send Notification</div>
  12. <el-row :gutter="20">
  13. <el-col :xs="24" :md="12">
  14. <el-form-item
  15. label="Notification Title"
  16. prop="title">
  17. <el-input
  18. class="add-text"
  19. v-model="formInfo.title"
  20. placeholder="Add text"
  21. maxlength="80"
  22. :readonly="!isEdit"/>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :xs="22" :md="12">
  26. <el-form-item
  27. label="Target"
  28. prop="targets">
  29. <el-select
  30. class="add-text"
  31. v-model="formInfo.targets"
  32. :disabled="!isEdit"
  33. multiple>
  34. <el-option
  35. v-for="(item, index) in targetOptions"
  36. :key="index"
  37. :label="item"
  38. :value="item"/>
  39. </el-select>
  40. </el-form-item>
  41. </el-col>
  42. </el-row>
  43. <el-row :gutter="20">
  44. <el-col :xs="24" :md="12">
  45. <el-form-item
  46. label="Notification Message"
  47. prop="message">
  48. <el-input
  49. class="add-text"
  50. v-model="formInfo.message"
  51. placeholder="Add text"
  52. :autosize="autosize"
  53. :readonly="!isEdit"
  54. type="textarea"
  55. maxlength="300"/>
  56. </el-form-item>
  57. </el-col>
  58. </el-row>
  59. <div class="sparator" style="margin: 10px -80px;"></div>
  60. <div class="buttons" v-if="isEdit">
  61. <el-button
  62. class="cancel-button"
  63. type="primary"
  64. @click="onBack">
  65. Cancel
  66. </el-button>
  67. <el-button
  68. class="confirm-button"
  69. type="primary"
  70. @click="onSend">
  71. Save
  72. </el-button>
  73. </div>
  74. <div class="buttons" v-else>
  75. <el-button
  76. class="cancel-button"
  77. type="primary"
  78. @click="onBack">
  79. Back
  80. </el-button>
  81. </div>
  82. </el-form>
  83. </div>
  84. </div>
  85. </template>
  86. <script>
  87. import api from '../../http/api/notification'
  88. export default {
  89. data() {
  90. return {
  91. loading: false,
  92. formInfo: {
  93. title: "",
  94. message: "",
  95. targets: []
  96. },
  97. autosize: {
  98. minRows: 3,
  99. maxRows: 10,
  100. },
  101. targetOptions: [],
  102. rules: {
  103. title: {
  104. required: true,
  105. trigger: 'blur',
  106. message: 'Please input title'
  107. },
  108. message: {
  109. required: true,
  110. trigger: 'blur',
  111. message: 'Please input message'
  112. },
  113. targets: {
  114. required: true,
  115. trigger: 'change',
  116. message: 'Please select target platform'
  117. }
  118. },
  119. isEdit: true
  120. }
  121. },
  122. created() {
  123. this.getTargets();
  124. if (this.$route.params.id) {
  125. this.isEdit = false;
  126. this.viewNotification()
  127. }
  128. },
  129. methods: {
  130. onBack() {
  131. this.$nextTick(() => {
  132. this.$router.replace({
  133. path: '/notification-management/in-app-notification'
  134. })
  135. })
  136. },
  137. onSend() {
  138. this.$refs['addForm'].validate(result => {
  139. if (result) {
  140. this.$confirm("Confirm to send the notificaton?", "Notification").then(res => {
  141. this.sendNotification();
  142. })
  143. }
  144. })
  145. },
  146. getTargets() {
  147. this.loading = true;
  148. api.getPlatformTarget().then(res => {
  149. if (res.data) {
  150. this.targetOptions = res.data
  151. }
  152. }).catch(err =>{
  153. }).finally(() => {
  154. this.loading = false;
  155. })
  156. },
  157. viewNotification() {
  158. this.loading = true;
  159. api.viewNotification({
  160. notificationId: this.$route.params.id
  161. }).then(res => {
  162. if (res.data) {
  163. this.formInfo = res.data
  164. }
  165. }).catch(err => {
  166. this.$message({
  167. type: 'error',
  168. message: err
  169. })
  170. }).finally(() => {
  171. this.loading = false;
  172. })
  173. },
  174. sendNotification() {
  175. this.loading = true;
  176. api.sendNotification(this.formInfo).then(res => {
  177. this.$message({
  178. type: 'success',
  179. message: "Send successfully!"
  180. })
  181. setTimeout(() => this.onBack(), 300);
  182. }).catch(err => {
  183. this.$message({
  184. type: 'error',
  185. message: err
  186. })
  187. }).finally(() => {
  188. this.loading = false;
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped="scoped" lang='scss'>
  195. @import '../../styles/variables.scss';
  196. .card-container {
  197. width: 100%;
  198. padding: 20px 60px;
  199. min-height: $mainAppMinHeight;
  200. background-color: #F0F5FC;
  201. }
  202. .card-content {
  203. padding: 15px 80px;
  204. border-radius: 6px;
  205. background-color: white;
  206. }
  207. .section-title {
  208. color: #333;
  209. margin-top: 20px;
  210. margin-bottom: 30px;
  211. font-size: 16px;
  212. user-select: none;
  213. line-height: 24px;
  214. font-weight: 500;
  215. font-family: sans-serif;
  216. text-transform: uppercase;
  217. }
  218. .add-text {
  219. width: 100%;
  220. max-width: 300px;
  221. }
  222. .add-text ::v-deep .el-textarea__inner {
  223. font-family: sans-serif;
  224. }
  225. .hr {
  226. height: 2px;
  227. margin: 10px -40px;
  228. background-color: #F0F5FC;
  229. }
  230. .hr-full {
  231. height: 2px;
  232. margin: 20px -80px;
  233. background-color: #F0F5FC;
  234. }
  235. .rate-list-view {
  236. display: flex;
  237. flex-wrap: wrap;
  238. align-items: center;
  239. }
  240. .rate-text {
  241. max-width: 150px;
  242. padding-right: 14px;
  243. }
  244. .list-item-icon {
  245. width: 30px;
  246. height: 30px;
  247. cursor: pointer;
  248. margin: 0 10px 22px;
  249. }
  250. .buttons {
  251. padding-top: 15px;
  252. padding-bottom: 30px;
  253. }
  254. @media screen and (max-width: 500px) {
  255. .card-container {
  256. padding: 0px;
  257. }
  258. .card-content {
  259. padding: 15px 40px;
  260. }
  261. }
  262. .form-unit ::v-deep .el-form-item__label {
  263. line-height: 30px;
  264. }
  265. </style>