gjj
2023-02-07 de2588137749cc83dc0df2377a6c2e38074be91a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<template>
  <div
    :id="'notice-cell' + cellIndex"
    class="list">
    <div class="header">
      <div
        v-photo="data"
        v-lazy:background-image="$options.filters.filterUserLazyImg(data.img)"
        class="div-photo"/>
      <div class="name-time">
        <p class="name">{{ data.realname }}</p>
        <p class="time">{{ data.createTime | moment("YYYY-MM-DD HH:mm") }}</p>
      </div>
    </div>
    <div
      class="title"
      @click="rowFun(data)">{{ data.title }}</div>
    <div
      v-if="data.preShow"
      class="data-content">{{ data.content }}</div>
    <div
      v-else
      class="data-content">{{ data.contentSub }}</div>
    <div
      v-if="data.contentSub.length < data.content.length"
      class="load-more">
      <span
        v-if="!data.loadMore"
        @click="loadMoreBtn(data)">展开全文</span>
      <span
        v-else
        @click="data.loadMore = false, data.preShow = false">收起全文</span>
    </div>
  </div>
</template>
 
<script>
// import { noticeIsReadAPI } from '@/api/oamanagement/notice'
 
export default {
  components: {},
 
  props: {
    data: Object,
    cellIndex: Number
  },
 
  data () {
    return {
      // 父元素
      parentTarget: null,
      awaitMoment: false // 等客户浏览
    }
  },
 
  mounted () {
    if (this.data.isRead === 0) {
      this.$bus.on('notice-list-box-scroll', target => {
        this.observePreview(target)
      })
      this.observePreview(
        document.getElementById('notice-cell' + this.cellIndex).parentNode
      )
    }
  },
 
  beforeDestroy () {
    this.$bus.off('notice-list-box-scroll')
  },
 
  methods: {
    /**
     * 观察预览
     */
    observePreview (target) {
      if (this.data.isRead === 0) {
        if (target) {
          this.parentTarget = target
        }
        const ispreview = this.whetherPreview()
        if (!this.awaitMoment && ispreview) {
          this.awaitMoment = true
          setTimeout(() => {
            this.awaitMoment = false
            const ispreview = this.whetherPreview()
            if (ispreview) {
              this.submiteIsRead()
            }
          }, 3000)
        }
      }
    },
 
    /**
     * 是否预览
     */
    whetherPreview () {
      const dom = this.parentTarget.children[this.cellIndex]
      if (this.parentTarget.getBoundingClientRect()) {
        const offsetTop =
          this.parentTarget.getBoundingClientRect().top -
          dom.getBoundingClientRect().top
        let ispreview = false
        if (
          offsetTop <= 0 &&
          Math.abs(offsetTop) < this.parentTarget.clientHeight
        ) {
          ispreview = true
        } else if (offsetTop > 0 && offsetTop < dom.clientHeight) {
          ispreview = true
        }
        return ispreview
      } else {
        return false
      }
    },
 
    /**
     * 提交已读
     */
    submiteIsRead () {
      // noticeIsReadAPI({
      //   announcementId: this.data.announcementId
      // })
      //   .then(res => {
      //     this.$store.dispatch('GetOAMessageNum', 'announcement')
      //     this.data.isRead = 1
      //   })
      //   .catch(() => {})
    },
 
    /**
     * 点击显示详情
     */
    rowFun (val) {
      this.$emit('handle', {
        type: 'detail',
        value: val
      })
    },
 
    loadMoreBtn (val) {
      this.$set(val, 'preShow', true)
      this.$set(val, 'loadMore', true)
    }
  }
}
</script>
 
<style scoped lang="scss">
.list {
  margin-bottom: 30px;
  padding-bottom: 30px;
  border-bottom: 1px solid #e6e6e6;
  .header {
    margin-bottom: 15px;
    .div-photo {
      width: 35px;
      height: 35px;
      border-radius: 17.5px;
      margin-right: 10px;
    }
    .name-time {
      display: inline-block;
      .time {
        color: #999;
        margin-top: 5px;
        font-size: 12px;
      }
    }
  }
  .title {
    cursor: pointer;
    display: inline-block;
  }
  .data-content {
    margin-top: 10px;
    color: #999;
    font-size: 12px;
    line-height: 18px;
    white-space: pre-wrap;
    word-wrap: break-word;
    background-color: #f0f7ff;
    padding: 15px;
    border-radius: 3px;
    color: #333;
    letter-spacing: 0.5px;
  }
  .load-more {
    text-align: left;
    margin-top: 15px;
    span {
      cursor: pointer;
      font-size: 13px;
      color: #8ab7f5;
    }
  }
}
</style>