zhaoxiaoqiang1
2026-01-04 f1d30d03186c79ca2cbcfe60d6d2ce7d73fba97b
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
<template>
  <div>
    <transition-group tag="ul" name="list" class="calling-list" v-if="showRecords.length > 0">
      <li v-for="item in showRecords" :key="item.callSeq">
        <div class="title">
          <p>{{item.seconds || popStayTime}}s</p>
          <p @click="close(item)">
            <i class="el-icon-close"></i>
          </p>
        </div>
        <div class="content">
          <p>客服座机:{{item.csLandline}}</p>
          <p>呼入电话:{{item.caller}}</p>
        </div>
        <div class="buttons">
          <p>
            <el-button size="small" @click="close(item)">忽略</el-button>
          </p>
          <p>
            <el-button size="small" type="primary" @click="answer(item)">接受</el-button>
          </p>
        </div>
      </li>
    </transition-group>
  </div>
</template>
<script>
import {
  pollingOrNot,
  getCallRecords,
  answerOrIgnore
} from '@comprehensive/serve/public'
import { setInterval, clearInterval } from 'timers'
 
export default {
  data() {
    return {
      landLine: '',
      showMax: 4,
      time: 5000,
      popStayTime: 0,
      callList: [],
      records: [],
      defaultUrl: `${location.origin}/cts-web/#/comprehensiveTransaction/loanApply`,
      timmer: null
    }
  },
  created() {
    this.pollingOrNot()
  },
  methods: {
    async pollingOrNot() {
      const res = await pollingOrNot({
        isShowError: false
      })
      const { pollingOrNot: flg, landLine, popStayTime } = res.result
      this.popStayTime = popStayTime
      if (flg) {
        this.landLine = landLine
        this.getCallRecords()
        this.setSeconds()
      }
    },
    async getCallRecords() {
      const { landLine, time } = this
      const res = await getCallRecords({
        landLine
      })
 
      this.addRecords(res.result)
      setTimeout(() => {
        this.getCallRecords()
      }, time)
    },
    addRecords(records) {
      const { records: currRecords } = this
      if (records.length > 0) {
        this.records = [...currRecords, ...records]
      }
    },
    close(item) {
      this.answerOrIgnore(item, false)
    },
    setSeconds() {
      this.timmer = setInterval(() => {
        const { records, showMax, popStayTime } = this
        records.forEach((item, i) => {
          if (i < showMax) {
            let { seconds = popStayTime } = item
            seconds = seconds - 1
            if (seconds <= 0) {
              this.close(item)
            } else {
              this.$set(records, i, {
                ...item,
                seconds
              })
            }
          }
        })
      }, 1000)
    },
    async answerOrIgnore(item, answerFlag) {
      const { records } = this
      const res = await answerOrIgnore({
        answerFlag,
        callSeq: item.callSeq
      })
      this.records = records.filter(({ callSeq }) => callSeq !== item.callSeq)
      if (answerFlag) {
        this.toDetail(item)
      }
    },
    // 详情页
    toDetail(item = {}) {
      const { defaultUrl } = this
      const { caller = '', screenUrl = '' } = item
      const url = screenUrl || defaultUrl
      location.href = `${url}${
        url.includes('?') ? '&' : '?'
      }customerPhone=${caller}&from=customer`
    },
    answer(item) {
      this.answerOrIgnore(item, true)
    }
  },
  beforeDestroy() {
    clearInterval(this.timmer)
  },
  computed: {
    showRecords() {
      const { records, showMax } = this
      return records.filter((item, index) => index < showMax)
    }
  }
}
</script>
<style lang="postcss" scoped>
.calling-list {
  position: fixed;
  z-index: 2000;
  right: 20px;
  top: 80px;
  overflow: hidden;
  width: 260px;
  padding: 10px;
  & li {
    box-shadow: 0 0 10px #ccc;
    margin-bottom: 14px;
    background: #fff;
    border-radius: 10px;
    overflow: hidden;
    & .title {
      background: #409eff;
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 6px 20px;
      & p {
        background: #fff;
        border-radius: 12px;
        min-width: 24px;
        height: 24px;
        text-align: center;
        line-height: 24px;
        font-size: 14px;
        color: #409eff;
        &:first-child {
          padding: 0 10px;
        }
      }
    }
    & .content {
      padding: 16px 0 0 16px;
    }
    & .buttons {
      display: flex;
      justify-content: space-between;
      padding: 16px 20px;
    }
  }
}
 
/** 插入过程 **/
.list-enter-active {
  transition: all 1s;
}
/** 移除过程 **/
.list-leave-active {
  transition: all 1s;
}
/*** 开始插入、移除结束的位置变化 ***/
.list-enter,
.list-leave-to {
  opacity: 0;
  transform: translateX(200px);
}
</style>