zjf
2023-03-03 bafa9dff4d9880c562f4d3a7b83bd4c1129240c5
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
<template>
  <div v-loading="loading">
    <div v-empty="list.length === 0">
      <div class="log-items">
        <follow-record-cell
          v-for="(item, index) in list"
          :item="item"
          :index="index"
          :crm-type="crmType"
          :key="index"
          @on-handle="cellHandle"/>
        <div class="load">
          <el-button
            :loading="loadMoreLoading"
            type="text">{{ loadMoreLoading ? '加载更多' : '没有更多了' }}</el-button>
        </div>
      </div>
    </div>
  </div>
</template>
 
<script>
import FollowRecordCell from './components/FollowRecordCell' // 跟进记录
// import { crmLeadsRecordIndex } from '@/api/customermanagement/clue'
import { GetBusinessFollowRecordList } from '@/api/common'
// import { GetCustomerFollowRecordList } from '@/api/customermanagement/customerManage'
// import { crmContactsRecordIndex } from '@/api/customermanagement/contacts'
// import { GetSalesChanceFollowList } from '@/api/customermanagement/business'
// import { crmContractRecordIndex } from '@/api/customermanagement/contract'
export default {
  /** 线索管理 的 线索详情 的 跟进记录 */
  name: 'RecordLog',
  components: {
    FollowRecordCell
  },
  props: {
    /** 模块ID */
    id: [String, Number],
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      loading: false,
      loadMoreLoading: true,
      isPost: false,
      page: 1,
      list: [] // 跟进记录列表
    }
  },
  computed: {},
  watch: {
    id: function (val) {
      console.log(val)
      this.refreshList()
    }
  },
  mounted () {
    this.$bus.on('follow-log-refresh', data => {
      if (data.type === 'record-log') {
        this.refreshList()
      }
    })
 
    // 分批次加载
    const dom = document.getElementById('follow-log-content')
    dom.onscroll = () => {
      const scrollOff = dom.scrollTop + dom.clientHeight - dom.scrollHeight
      // 滚动条到底部的条件
      if (Math.abs(scrollOff) < 10 && this.loadMoreLoading === true) {
        if (!this.isPost) {
          this.isPost = true
          this.page++
          this.getList()
        } else {
          this.loadMoreLoading = false
        }
      }
    }
 
    this.getList()
  },
  activated: function () {},
  deactivated: function () {},
 
  beforeDestroy () {
    this.$bus.off('follow-log-refresh')
  },
  methods: {
    getList () {
      this.loading = true
      let request = {
        customer: GetBusinessFollowRecordList,
        // leads: crmLeadsRecordIndex,
        contacts: GetBusinessFollowRecordList,
        business: GetBusinessFollowRecordList
      // contract: crmContractRecordIndex
      }[this.crmType]
 
      const params = {
        PageIndex: this.page,
        PageSize: 10
      }
      params['BusinessOperationType'] = {
        customer: 1,
        contacts: 2,
        business: 3
      }[this.crmType]
      params['SourceId'] = this.id
      // if (request === 'GetBusinessFollowRecordList') {
      // } else {
      //   params['Id'] = this.id
      // }
      console.log(params)
      request(params)
        .then(res => {
          this.list = this.list.concat(res.data.Result.List)
          if (res.data.Result.length < 10) {
            this.loadMoreLoading = false
          } else {
            this.loadMoreLoading = true
          }
          this.loading = false
          this.isPost = false
        })
        .catch(() => {
          this.isPost = false
          this.loading = false
        })
    },
    refreshList () {
      this.page = 1
      this.list = []
      this.getList()
    },
    /**
     * 行布局删除
     */
    cellHandle (data) {
      console.log(data)
      if (data.type === 'delete') {
        this.list.splice(data.data.index, 1)
      }
    }
  }
}
</script>
 
<style lang="less" scoped>
.log-items {
  min-height: 400px;
  position: relative;
}
 
.load {
  color: #999;
  font-size: 13px;
  margin: 0 auto 15px;
  text-align: center;
  .el-button,
  .el-button:focus {
    color: #ccc;
    cursor: auto;
  }
}
</style>