zjf
2023-02-24 2126cd24b8a0174ac0597340917c0a4595f72254
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<template>
  <div class="rc-cont">
    <flexbox
      v-if="!isSeas"
      class="rc-head"
      direction="row-reverse">
      <!--<el-button
        class="rc-head-item"
        type="primary"
        @click.native="createClick('plan')">新建回款计划</el-button>-->
    </flexbox>
    <el-table
      :data="palnList"
      :height="tableHeight"
      :header-cell-style="headerRowStyle"
      :cell-style="planCellStyle"
      style="width: 100%;border: 1px solid #E6E6E6;margin-bottom: 30px;">
      <el-table-column
        v-for="(item, index) in planFieldList"
        :key="index"
        :prop="item.prop"
        :label="item.label"
        :formatter="planFieldFormatter"
        show-overflow-tooltip>
        <template
          slot="header"
          slot-scope="scope">
          <div class="table-head-name">{{ scope.column.label }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        width="100"
        v-if="crmType!=='businessCustomer'&& crmType!=='businessChances'">
        <template
          slot="header"
          slot-scope="scope">
          <div class="table-head-name">操作</div>
        </template>
        <template slot-scope="scope">
          <flexbox justify="center">
            <el-button
              type="text"
              @click.native="handleFile('edit', scope)">编辑</el-button>
            <el-button
              type="text"
              @click.native="handleFile('delete', scope)">删除</el-button>
          </flexbox>
        </template>
      </el-table-column>
    </el-table>
 
    <!--<flexbox
      class="rc-head"
      direction="row-reverse"
      style="margin-top: 15px;">
      <el-button
        v-if="!isSeas"
        class="rc-head-item"
        type="primary"
        @click.native="createClick('money')">新建回款</el-button>
    </flexbox>-->
    <el-table
      :data="list"
      :height="tableHeight"
      :header-cell-style="headerRowStyle"
      :cell-style="cellStyle"
      style="width: 100%;border: 1px solid #E6E6E6;"
      @row-click="handleRowClick">
      <el-table-column
        v-for="(item, index) in fieldList"
        :key="index"
        :prop="item.prop"
        :formatter="fieldFormatter"
        :label="item.label"
        show-overflow-tooltip>
        <template
          slot="header"
          slot-scope="scope">
          <div class="table-head-name">{{ scope.column.label }}</div>
        </template>
      </el-table-column>
    </el-table>
    <div class="p-contianer" v-show='total>0'>
        <el-pagination
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size.sync="pageSize"
          :total="total"
          class="p-bar"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"/>
      </div>
 
    <c-r-m-full-screen-detail
      :visible.sync="showFullDetail"
      :crm-type="showFullCrmType"
      :id="showFullId"
      @handle="detailHandle"/>
    <c-r-m-create-view
      v-if="isCreate"
      :crm-type="createCrmType"
      :action="createActionInfo"
      @save-success="saveSuccess"
      @hiden-view="isCreate=false"/>
  </div>
</template>
 
<script type="text/javascript">
import loading from '../mixins/loading'
import CRMCreateView from './CRMCreateView'
import {
  GetCustomerPaymentRecordList,
  GetCustomerPaymentPlanList
} from '@/api/customermanagement/customerManage'
// import {
//   crmContractQueryReceivables,
//   crmContractQueryReceivablesPlan
// } from '@/api/clients/contract'
// import {
//   crmReceivablesPlanDeleteAPI
// } from '@/api/clients/money'
/** 注意  需要删除接口 */
import { objDeepCopy, moneyFormat } from '@/utils'
 
export default {
  name: 'RelativeReturnMoney', // 相关回款  可能再很多地方展示 放到客户管理目录下
 
  components: {
    CRMCreateView,
    CRMFullScreenDetail: () => import('./CRMFullScreenDetail.vue')
  },
 
  mixins: [loading],
 
  props: {
    /** 模块ID */
    id: [String, Number],
    /** 没有值就是全部类型 有值就是当个类型 */
    crmType: {
      type: String,
      default: ''
    },
    /** 是公海 默认是客户 */
    isSeas: {
      type: Boolean,
      default: false
    },
    /** 客户和 合同下 可新建 回款计划 */
    detail: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
 
  data () {
    return {
      list: [],
      fieldList: [],
      tableHeight: '250px',
      showFullDetail: false,
      showFullCrmType: 'receivables',
      showFullId: '', // 查看全屏详情的 ID
      createCrmType: 'receivables_plan', // 创建回款计划
      isCreate: false, // 新建回款回款
      palnList: [],
      planFieldList: [],
      createActionInfo: {}, // 新建回款计划的时候 在客户 合同下导入关联信息
      total: 0,
      currentPage: 1,
      pageSize: 10,
      pageSizes: [10, 30, 60, 100]
    }
  },
 
  computed: {},
 
  watch: {
    id: function (val) {
      this.list = []
      this.palnList = []
      this.getList()
      this.getPlanList()
    }
  },
 
  mounted () {
    this.planFieldList = [
      { prop: 'num', width: '200', label: '期数' },
      { prop: 'customerName', width: '200', label: '客户名称' },
      { prop: 'contractNum', width: '200', label: '合同编号' },
      { prop: 'money', width: '200', label: '计划回款金额' },
      { prop: 'returnDate', width: '200', label: '计划回款日期' },
      { prop: 'returnType', width: '200', label: '计划回款方式' },
      { prop: 'remind', width: '200', label: '提前几日提醒' },
      { prop: 'remark', width: '200', label: '备注' }
    ]
 
    this.getPlanList()
 
    this.fieldList = [
      { prop: 'receivablesNum', width: '200', label: '回款编号' },
      { prop: 'contractName', width: '200', label: '合同名称' },
      { prop: 'contractMoney', width: '200', label: '合同金额' },
      { prop: 'receivablesMoney', width: '200', label: '回款金额' },
      { prop: 'planNum', width: '200', label: '期数' },
      { prop: 'ownerUserName', width: '200', label: '负责人' },
      { prop: 'checkStatus', width: '200', label: '状态' },
      { prop: 'returnTime', width: '200', label: '回款日期' }
    ]
    this.getList()
  },
 
  methods: {
    handleSizeChange (newSize) {
      this.pageSize = newSize
      this.getDetail()
    },
    handleCurrentChange (newPage) {
      this.currentPage = newPage
      this.getDetail()
    },
    /** 格式化字段 */
    planFieldFormatter (row, column) {
      var aRules = this.formatterRules[column.property]
      if (aRules) {
        return aRules.formatter(row[column.property])
      }
      if (column.property === 'Sex') {
        return { 1: '男', 2: '女' }[row.Sex]
      } else if (column.property === 'IsCustomerDefault') {
        return { true: '是', false: '否' }[row.IsCustomerDefault]
      } else if (column.property === 'CompanyType') {
        return {0: '暂无', 1: '国企', 2: '外企', 3: '民营', 4: '其他'}[row.CompanyType]
      }
      // 如果需要格式化
      return row[column.property] || '--'
    },
    /**
     * 回款计划列表
     */
    getPlanList () {
      this.loading = true
      const request = {
        customer: GetCustomerPaymentPlanList,
        businessCustomer: GetCustomerPaymentPlanList
        // contract: crmContractQueryReceivablesPlan
      }[this.crmType]
      request(this.getParams())
        .then(res => {
          this.loading = false
          this.palnList = res.data.Result.List
        })
        .catch(() => {
          this.loading = false
        })
    },
 
    /**
     * 回款列表
     */
    getList () {
      this.loading = true
      const request = {
        customer: GetCustomerPaymentRecordList,
        businessCustomer: GetCustomerPaymentRecordList
        // contract: crmContractQueryReceivables
      }[this.crmType]
      request(this.getParams())
        .then(res => {
          this.loading = false
          this.list = res.data.Result.List
          this.total = res.data.Result.Count
        })
        .catch(() => {
          this.loading = false
        })
    },
 
    /**
     * 获取上传参数
     */
    getParams () {
      if (this.crmType === 'customer' || this.crmType === 'businessCustomer') {
        return { Id: this.id, PageSize: this.pageSize, PageIndex: this.currentPage }
      } else if (this.crmType === 'contract' || this.crmType === 'businessContract') {
        return { contractId: this.id, pageType: 0 }
      }
      return {}
    },
 
    /**
     * 当某一行被点击时会触发该事件
     */
    handleRowClick (row, column, event) {
      // this.showFullId = row.receivablesId
      // this.showFullCrmType = 'receivables'
      // this.showFullDetail = true
    },
 
    /**
     * 通过回调控制style
     */
    cellStyle ({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        return { color: '#4D88FF', textAlign: 'center', cursor: 'pointer' }
      } else {
        return { textAlign: 'left' }
      }
    },
 
    /**
     * 通过回调控制style
     */
    planCellStyle ({ row, column, rowIndex, columnIndex }) {
      return { textAlign: 'left' }
    },
 
    /**
     * 新建回款和回款计划
     */
    createClick (type) {
      this.createActionInfo = {
        type: 'relative',
        crmType: this.crmType,
        data: {}
      }
      if (type === 'money') {
        if (this.crmType === 'contract') {
          this.createActionInfo.data['customer'] = objDeepCopy(this.detail)
          this.createActionInfo.data['contract'] = objDeepCopy(this.detail)
        } else if (this.crmType === 'customer') {
          this.createActionInfo.data['customer'] = this.detail
        }
        this.createCrmType = 'receivables'
        this.isCreate = true
      } else if (type === 'plan') {
        if (this.crmType === 'contract') {
          this.createActionInfo.data['customer'] = objDeepCopy(this.detail)
          this.createActionInfo.data['contract'] = objDeepCopy(this.detail)
        } else if (this.crmType === 'customer') {
          this.createActionInfo.data['customer'] = this.detail
        }
        this.createCrmType = 'receivables_plan'
        this.isCreate = true
      }
    },
 
    /**
     * 新建成功
     */
    saveSuccess () {
      if (this.createCrmType === 'receivables') {
        this.getList()
      } else {
        this.getPlanList()
      }
    },
 
    /**
     * 编辑操作
     */
    handleFile (type, item) {
      if (type === 'edit') {
        this.createActionInfo = { type: 'update', id: item.row.planId }
        this.createCrmType = 'receivables_plan'
        this.isCreate = true
      } else if (type === 'delete') {
        this.$confirm('您确定要删除吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            // crmReceivablesPlanDeleteAPI({
            //   planIds: item.row.planId
            // })
            //   .then(res => {
            //     this.palnList.splice(item.$index, 1)
            //     this.$message.success('删除成功')
            //   })
            //   .catch(() => {})
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消操作'
            })
          })
      }
    },
 
    /**
     * 格式化字段
     */
    fieldFormatter (row, column, cellValue) {
      // 如果需要格式化
      if (column.property === 'checkStatus') {
        return this.getStatusName(row.checkStatus)
      } else if (['contractMoney', 'receivablesMoney', 'money'].includes(column.property)) {
        return moneyFormat(cellValue)
      }
      return cellValue
    },
 
    /**
     * 对应的状态名
     */
    getStatusName (status) {
      if (status === 0) {
        return '待审核'
      } else if (status === 1) {
        return '通过'
      } else if (status === 2) {
        return '拒绝'
      } else if (status === 3) {
        return '审核中'
      } else if (status === 4) {
        return '撤回'
      } else if (status === 5) {
        return '未提交'
      } else if (status === 6) {
        return '已作废'
      }
      return ''
    },
 
    /**
     * 通过回调控制表头style
     */
    headerRowStyle ({ row, column, rowIndex, columnIndex }) {
      return { textAlign: 'left' }
    },
 
    /**
     * 详情操作
     */
    detailHandle (data) {
      if (data.type === 'delete') {
        this.getList()
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../styles/relativecrm.scss';
</style>