notice-item.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template id="notice-item">
  2. <div class="notice-body">
  3. <div class="notice-box" :style="shadow()" @click="showNotice">
  4. <div class="notice-header">
  5. <div class="notice-title">
  6. <span v-if="checkIsRead()" style="color: red">*</span>
  7. <span>
  8. {{ item.title }}
  9. </span>
  10. </div>
  11. <div class="notice-time">
  12. {{ item.created_at | dateTimeFormat('Y-m-d H:i') }}
  13. </div>
  14. </div>
  15. <el-collapse-transition>
  16. <div class="notice-content" v-if="show">
  17. {{ item.content }}
  18. </div>
  19. </el-collapse-transition>
  20. </div>
  21. </div>
  22. </template>
  23. <script>
  24. Vue.component('notice-item', {
  25. template: '#notice-item',
  26. props: {
  27. item: {
  28. type: Object,
  29. default: {},
  30. },
  31. show: {
  32. type: Boolean,
  33. default: false,
  34. },
  35. index: {
  36. type: Number,
  37. default: 0
  38. }
  39. },
  40. data() {
  41. return {
  42. isRead: false,
  43. }
  44. },
  45. methods: {
  46. shadow() {
  47. return this.show ? 'box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1)' : ''
  48. },
  49. checkIsRead() {
  50. if (this.item.is_read) {
  51. return false
  52. }
  53. if (this.isRead) {
  54. return false
  55. }
  56. return true
  57. },
  58. showNotice() {
  59. if (this.item.is_read == 0) {
  60. this.readNotice(this.item.id)
  61. }
  62. this.$emit('reading', this.show ? '' : this.index)
  63. },
  64. readNotice(id) {
  65. if (!this.isRead) {
  66. this.isRead = true
  67. request({
  68. params: {
  69. r: 'mall/notice/read',
  70. id: id,
  71. },
  72. method: 'get',
  73. })
  74. }
  75. },
  76. }
  77. });
  78. </script>
  79. <style>
  80. .notice-body::after {
  81. display: block;
  82. content: "";
  83. border-top: 1px solid #eee;
  84. }
  85. .notice-box {
  86. padding: 20px 20px;
  87. cursor: pointer;
  88. }
  89. .notice-header {
  90. display: flex;
  91. align-items: center;
  92. justify-content: space-between;
  93. }
  94. .notice-title {
  95. font-size: 14px;
  96. /* font-weight: 400; */
  97. }
  98. .notice-content::before {
  99. content: "";
  100. display: block;
  101. height: 10px;
  102. }
  103. .notice-content {
  104. color: #999;
  105. }
  106. </style>