/** crm自定义列表 公共逻辑 */ import { mapGetters } from 'vuex' // import crmTypeModel from '@/views/clients/model/crmTypeModel' import CRMListHead from '../components/CRMListHead' import CRMTableHead from '../components/CRMTableHead' import FieldsSet from '../components/fieldsManager/FieldsSet' import Lockr from 'lockr' import { Loading } from 'element-ui' // import { moneyFormat } from '@/utils' import { GetCustomerPageList } from '@/api/customermanagement/customerManage' import { GetContacterList } from '@/api/customermanagement/contacts' import { GetSalesChanceList } from '@/api/customermanagement/business' import { GetAgreementList, GetManagementAgreementList } from '@/api/customermanagement/contract' import { GetQuotationSheetList, GetManagementQuotationSheetList } from '@/api/customermanagement/offer' import { GetOtherCustomerPageList, GetOtherSalesChanceList, GetOtherAgreementList } from '@/api/businessIntelligence/index' import { downloadFile } from '@/utils' export default { components: { CRMListHead, CRMTableHead, FieldsSet }, data () { return { loading: false, // 加载动画 tableHeight: document.documentElement.clientHeight - 360, // 表的高度 list: [], fieldList: [], sortData: {}, // 字段排序 currentPage: 1, // Lockr.get('crmPageSizes') pageSize: 10, pageSizes: [10, 30, 60, 100], total: 0, search: '', // 搜索内容 /** 控制详情展示 */ rowID: '', // 行信息 rowType: '', // 详情类型 showDview: false, /** 高级筛选 */ filterObj: {}, // 筛选确定数据 headObj: {}, // 筛选顶部数据 sceneId: '', // 场景筛选ID sceneName: '', // 场景名字 /** 列表展示字段管理 */ showFieldSet: false, /** 勾选行 */ // 勾选数据 用于全局导出 selectionList: [], /** 格式化规则 */ formatterRules: {}, isCreate: false, editData: {}, filterFormerData: {} // 筛选值 } }, computed: { ...mapGetters(['crm']) }, mounted () { /** 控制table的高度 */ window.onresize = () => { this.updateTableHeight() } this.getList() }, methods: { /** 获取列表数据 */ getList (data) { let isFilter if (data) { this.currentPage = 1 this.pageSize = 10 if (data.list) { // 头部筛选 isFilter = 1 this.filterFormerData = data.list } else if (data.tableType) { // 表头筛选 isFilter = 2 } } let isFilterBoo = Object.values(this.filterFormerData).length > 0 this.loading = true let crmIndexRequest = this.getIndexRequest() let params = {} if (this.crmType === 'customer' || this.crmType === 'businessCustomer') { params = { 'PageIndex': this.currentPage, 'PageSize': this.pageSize, 'SelectOwnedType': isFilterBoo ? this.filterFormerData.customer : 0, 'SalesChanceStage': isFilterBoo ? this.filterFormerData.businessType : '', 'Name': isFilterBoo ? this.filterFormerData.user : '', 'ProvinceCode': isFilterBoo ? this.filterFormerData.area : '', 'CreateStartTime': '', 'CreateEndTime': '', 'StartFollowTime': '', 'EndFolowTime': '', 'CompanyType': isFilter === 2 ? Lockr.get('comType') : '', 'CustomerIndustry': isFilter === 2 ? Lockr.get('casType') : '' } if (isFilterBoo) { params['DepartmentUserType'] = this.filterFormerData.userType params['Id'] = this.filterFormerData.customer params['BrachUserId'] = this.filterFormerData.BrachUserId } } else if (this.crmType === 'contacts') { params = { 'PageIndex': this.currentPage, 'PageSize': this.pageSize, 'SalesChanceStage': isFilterBoo ? this.filterFormerData.businessType : '', 'SelectOwnedType': isFilterBoo ? this.filterFormerData.customer : 0, 'BrachUserId': isFilterBoo ? this.filterFormerData.BrachUserId : '', 'ProvinceCode': isFilterBoo ? this.filterFormerData.area : '', 'Name': isFilterBoo ? this.filterFormerData.user : '' } } else if (this.crmType === 'business' || this.crmType === 'businessChances') { params = { 'PageIndex': this.currentPage, 'PageSize': this.pageSize, 'SalesChanceStage': isFilterBoo ? this.filterFormerData.businessType : '', 'SelectOwnedType': isFilterBoo ? this.filterFormerData.customer : 0, 'Name': isFilterBoo ? this.filterFormerData.user : '', 'SalesChanceType': isFilterBoo ? this.filterFormerData.businessType : '', 'ProvinceCode': isFilterBoo ? this.filterFormerData.area : '', 'CreateStartTime': '', 'CreateEndTime': '', 'ProjectProperty': isFilter === 2 ? (data.tableType === '项目属性' ? data.value : '') : '', 'UploadStatusName': isFilter === 2 ? (data.tableType === '提交' ? data.value : '') : '', 'ReportStatusName': isFilter === 2 ? (data.tableType === '审批' ? data.value : '') : '' } if (isFilterBoo) { params['DepartmentUserType'] = this.filterFormerData.userType params['Id'] = this.filterFormerData.customer params['BrachUserId'] = this.filterFormerData.BrachUserId } } else if (this.crmType === 'contract' || this.crmType === 'offers' || this.crmType === 'businessContract') { params = { 'PageIndex': this.currentPage, 'PageSize': this.pageSize, 'SelectOwnedType': isFilterBoo ? this.filterFormerData.customer : 0, 'AuditStatus': 0, 'SealStatus': 0, 'Name': isFilterBoo ? this.filterFormerData.user : '', 'CreateStartTime': '', 'CreateEndTime': '' } if (isFilterBoo) { params['DepartmentUserType'] = this.filterFormerData.userType params['Id'] = this.filterFormerData.customer params['BrachUserId'] = this.filterFormerData.BrachUserId } if (isFilter === 2) { params['SealType'] = data.value } } else if (this.crmType === 'sealContract' || this.crmType === 'sealOffers') { params = { 'PageIndex': this.currentPage, 'PageSize': this.pageSize, 'AuditStatus': 0, 'SealStatus': 0, 'Name': isFilterBoo ? this.filterFormerData.user : '', 'CreateStartTime': '', 'CreateEndTime': '' } if (isFilterBoo) { params['DepartmentUserType'] = this.filterFormerData.userType params['Id'] = this.filterFormerData.customer } if (isFilter === 2) { params['SealType'] = data.value } } crmIndexRequest(params) .then(res => { if (res.data.ErrorCode === 200) { if (res.data.Result.Count > 0) { this.list = res.data.Result.List } else { this.list = [] } this.total = res.data.Result.Count this.loading = false } else { this.$message.error(res.data.Message) this.loading = false } }) .catch(() => { this.loading = false }) }, // 列表编辑 editList (row) { console.log(row) this.isCreate = true this.editData = row }, /** 获取列表请求 */ getIndexRequest () { if (this.crmType === 'leads') { // return crmLeadsIndex } else if (this.crmType === 'customer') { return GetCustomerPageList } else if (this.crmType === 'contacts') { return GetContacterList } else if (this.crmType === 'business') { return GetSalesChanceList } else if (this.crmType === 'contract') { return GetAgreementList } else if (this.crmType === 'offers') { return GetQuotationSheetList } else if (this.crmType === 'sealContract') { return GetManagementAgreementList } else if (this.crmType === 'sealOffers') { return GetManagementQuotationSheetList } else if (this.crmType === 'receivables') { // return crmReceivablesIndex } else if (this.crmType === 'businessCustomer') { return GetOtherCustomerPageList } else if (this.crmType === 'businessContract') { return GetOtherAgreementList } else if (this.crmType === 'businessChances') { return GetOtherSalesChanceList } }, /** 获取字段 */ getFieldList () { if (this.fieldList.length === 0) { this.loading = true } else { // 获取好字段开始请求数据 this.getList() } }, /** 格式化字段 */ fieldFormatter (row, column) { // var aRules = this.formatterRules[column.property] // if (aRules) { // return aRules.formatter(row[column.property]) // } if (column.property === 'ReportStatus') { switch (row[column.property]) { case 0: row[column.property] = '--' break case 1: row[column.property] = '待提交' break case 2: row[column.property] = '已提交' break case 3: row[column.property] = '报备成功' break case 4: row[column.property] = '报备失败' break } } else if (column.property === 'SalesChanceStage') { switch (row[column.property]) { case 0: row[column.property] = '--' break case 1: row[column.property] = '初期沟通' break case 2: row[column.property] = '需求分析' break case 3: row[column.property] = '方案报价' break case 4: row[column.property] = '商务谈判' break case 5: row[column.property] = '成功' break case 6: row[column.property] = '搁置' break } } else if (column.property === 'UploadStatus') { switch (row[column.property]) { case 0: row[column.property] = '--' break case 1: row[column.property] = '待上传' break case 2: row[column.property] = '审核中' break case 3: row[column.property] = '已上传' break } } else 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] } else if (column.property === 'ExpectedAmount') { return '¥' + JSON.parse(row.ExpectedAmount) } else if (column.property === 'ChanceRequestType') { switch (row[column.property]) { case 0: row[column.property] = 'Other' break case 1: row[column.property] = 'LC' break case 2: row[column.property] = 'ACAD' break case 3: row[column.property] = 'AEC' break case 4: row[column.property] = 'MFG' break case 5: row[column.property] = 'MNE' break } } else if (column.property === 'AuditStatus') { switch (row[column.property]) { case 0: row[column.property] = '--' break case 1: row[column.property] = '审批中' break case 2: row[column.property] = '通过' break case 3: row[column.property] = '驳回' break } } else if (column.property === 'SealType') { switch (row[column.property]) { case 1: row[column.property] = '合同章' break case 2: row[column.property] = '公章' break } } else if (column.property === 'IsSeal') { switch (row[column.property]) { case false: row[column.property] = '否' break case true: row[column.property] = '是' break } } else if (column.property === 'TrackStatus') { switch (row['IsAutoPassed']) { case false: row[column.property] = row[column.property] break case true: row[column.property] = '通过' break } } // 如果需要格式化 return row[column.property] || '--' }, /** */ /** */ /** 搜索操作 */ crmSearch (value) { this.currentPage = 1 this.search = value if (this.fieldList.length) { this.getList() } }, /** 列表操作 */ // 当某一行被点击时会触发该事件 handleRowClick (row, column, event) { console.log(row) if (column.type === 'selection') { return // 多选布局不能点击 } if (this.crmType === 'leads') { if (column.property === 'leadsName') { this.rowID = row.leadsId this.showDview = true } else { this.showDview = false } } else if (this.crmType === 'customer') { if (column.property === 'businessCheck' && row.businessCount > 0) { return // 列表查看商机不展示详情 } if (column.property === 'CustomerName') { this.rowID = row.Id this.rowType = 'customer' this.showDview = true console.log('yesss') } } else if (this.crmType === 'contacts') { if (column.property === 'CustomerName') { this.rowID = row.CustomerId this.rowType = 'customer' this.showDview = true } else if (column.property === 'RealName') { this.rowID = row.Id this.rowType = 'contacts' this.showDview = true } else { this.showDview = false } } else if (this.crmType === 'business') { if (column.property === 'CustomerName') { this.isFollow = false this.rowID = row.CustomerId this.rowType = 'customer' this.showDview = true } else if (column.property === 'ChanceName') { this.isFollow = false this.rowID = row.Id this.rowType = 'business' this.showDview = true } } else if (this.crmType === 'contract') { if (column.property === 'CustomerName') { this.rowID = row.CustomerId this.rowType = 'customer' this.showDview = true } else if (column.property === 'SalesChanceName') { this.rowID = row.SalesChanceId this.rowType = 'business' this.showDview = true } else if (column.property === 'ContacterName') { this.rowID = row.contactsId this.rowType = 'contacts' this.showDview = true } else if (column.property === 'BeforeSealFile' || column.property === 'SealFile') { if (column.property === 'BeforeSealFile' && row.BeforeSealFile !== '') { this.handleFile(column, row) } if (column.property === 'SealFile' && row.SealFile !== '') { this.handleFile(column, row) } } } else if (this.crmType === 'offers') { if (column.property === 'CustomerName') { this.rowID = row.CustomerId this.rowType = 'customer' this.showDview = true } else if (column.property === 'SalesChanceName') { this.rowID = row.SalesChanceId this.rowType = 'business' this.showDview = true } else if (column.property === 'ContacterName') { this.rowID = row.contactsId this.rowType = 'contacts' this.showDview = true } else if (column.property === 'BeforeSealFile' || column.property === 'SealFile') { if (column.property === 'BeforeSealFile' && row.BeforeSealFile !== '') { this.handleFile(column, row) } if (column.property === 'SealFile' && row.SealFile !== '') { this.handleFile(column, row) } } } else if (this.crmType === 'sealContract') { if (column.property === 'CustomerName') { this.rowID = row.CustomerId this.rowType = 'businessCustomer' this.showDview = true } else if (column.property === 'SalesChanceName') { this.rowID = row.SalesChanceId this.rowType = 'businessChances' this.showDview = true } else if (column.property === 'BeforeSealFile' || column.property === 'SealFile') { if (column.property === 'BeforeSealFile' && row.BeforeSealFile !== '') { this.handleFile(column, row) } if (column.property === 'SealFile' && row.SealFile !== '') { this.handleFile(column, row) } } } else if (this.crmType === 'sealOffers') { if (column.property === 'CustomerName') { this.rowID = row.CustomerId this.rowType = 'businessCustomer' this.showDview = true } else if (column.property === 'SalesChanceName') { this.rowID = row.SalesChanceId this.rowType = 'businessChances' this.showDview = true } else if (column.property === 'BeforeSealFile' || column.property === 'SealFile') { if (column.property === 'BeforeSealFile' && row.BeforeSealFile !== '') { this.handleFile(column, row) } if (column.property === 'SealFile' && row.SealFile !== '') { this.handleFile(column, row) } } } else if (this.crmType === 'businessCustomer') { if (column.property === 'businessCheck' && row.businessCount > 0) { return // 列表查看商机不展示详情 } if (column.property === 'CustomerName') { this.rowID = row.Id this.rowType = 'businessCustomer' this.showDview = true console.log('yesss') } } else if (this.crmType === 'businessChances') { if (column.property === 'CustomerName') { this.isFollow = false this.rowID = row.CustomerId this.rowType = 'businessCustomer' this.showDview = true } else if (column.property === 'ChanceName') { this.isFollow = false this.rowID = row.Id this.rowType = 'businessChances' this.showDview = true } } else if (this.crmType === 'businessContract') { if (column.property === 'CustomerName') { this.rowID = row.CustomerId this.rowType = 'businessCustomer' this.showDview = true } else if (column.property === 'SalesChanceName') { this.rowID = row.SalesChanceId this.rowType = 'businessChances' this.showDview = true } else if (column.property === 'BeforeSealFile' || column.property === 'SealFile') { if (column.property === 'BeforeSealFile' && row.BeforeSealFile !== '') { this.handleFile(column, row) } if (column.property === 'SealFile' && row.SealFile !== '') { this.handleFile(column, row) } } } else if (this.crmType === 'receivables') { if (column.property === 'CustomerName') { this.rowID = row.Id this.rowType = 'customer' this.showDview = true } else if (column.property === 'contractNum') { this.rowID = row.contractId this.rowType = 'contract' this.showDview = true } else if (column.property === 'number') { this.rowID = row.receivablesId this.rowType = 'receivables' this.showDview = true } else { this.showDview = false } } if (this.showDview) { this.timer = new Date().getTime() } }, handleFile (column, data) { if (column.property === 'BeforeSealFile') { downloadFile({ path: data.BeforeSealFile, name: data.BeforeSealFile }) } else if (column.property === 'SealFile') { downloadFile({ path: data.SealFile, name: data.SealFile }) } }, /** * 导出 线索 客户 联系人 产品 * @param {*} data */ // 导出操作 exportInfos () { var params = { search: this.search } if (this.sceneId) { params.sceneId = this.sceneId } if (this.filterObj && Object.keys(this.filterObj).length > 0) { params.data = this.filterObj } let request // 公海的请求 // if (this.isSeas) { // request = crmCustomerPoolExcelAllExport // } else { // request = { // customer: crmCustomerExcelAllExport, // leads: crmLeadsExcelAllExport, // contacts: crmContactsExcelAllExport, // product: crmProductExcelAllExport // }[this.crmType] // } const loading = Loading.service({ fullscreen: true, text: '导出中...' }) request(params) .then(res => { var blob = new Blob([res.data], { type: 'application/vnd.ms-excel;charset=utf-8' }) var downloadElement = document.createElement('a') var href = window.URL.createObjectURL(blob) // 创建下载的链接 downloadElement.href = href downloadElement.download = decodeURI( res.headers['content-disposition'].split('filename=')[1] ) || '' // 下载后文件名 document.body.appendChild(downloadElement) downloadElement.click() // 点击下载 document.body.removeChild(downloadElement) // 下载完成移除元素 window.URL.revokeObjectURL(href) // 释放掉blob对象 loading.close() }) .catch(() => { loading.close() }) }, /** 筛选操作 */ handleFilter (data) { this.filterObj = data var offsetHei = document.documentElement.clientHeight var removeHeight = Object.keys(this.filterObj).length > 0 ? 310 : 240 this.tableHeight = offsetHei - removeHeight this.currentPage = 1 this.getList() }, /** 场景操作 */ handleScene (data) { this.sceneId = data.id this.sceneName = data.name this.currentPage = 1 this.getFieldList() }, /** 勾选操作 */ handleHandle (data) { if (data.type === 'alloc' || data.type === 'get' || data.type === 'transfer' || data.type === 'transform' || data.type === 'delete' || data.type === 'put_seas') { this.showDview = false } if (data.type !== 'edit') { this.getList() } }, /** 自定义字段管理 */ setSave () { this.fieldList = [] this.getFieldList() }, /** */ /** 页面头部操作 */ listHeadHandle (data) { console.log('cvvvvvvvvvvvvv', data) // if (data.type === 'save-success') { // 重新请求第一页数据 this.currentPage = 1 this.getList() // } }, // 设置点击 handleTableSet () { this.showFieldSet = true }, /** * 字段排序 */ sortChange (column, prop, order) { this.currentPage = 1 this.sortData = column this.getList() }, /** 勾选操作 */ // 当选择项发生变化时会触发该事件 handleSelectionChange (val) { console.log(val) this.selectionList = val // 勾选的行 this.$refs.crmTableHead.headSelectionChange(val) }, // 当拖动表头改变了列的宽度的时候会触发该事件 handleHeaderDragend (newWidth, oldWidth, column, event) { if (column.property) { // const crmType = this.isSeas ? this.crmType + '_pool' : this.crmType // crmFieldColumnWidth({ // types: 'crm_' + crmType, // field: column.property, // width: newWidth // }) // .then(res => { // }) // .catch(() => { }) } }, // 更改每页展示数量 handleSizeChange (val) { // Lockr.set('crmPageSizes', val) this.pageSize = val this.getList() }, // 更改当前页数 handleCurrentChange (val) { this.currentPage = val this.getList() }, // 0待审核、1审核中、2审核通过、3已拒绝 4已撤回 5未提交 修正 以 getStatusName 为准 getStatusStyle (status) { if (status === 0) { return { 'border-color': '#E6A23C', 'background-color': '#FDF6EC', 'color': '#E6A23C' } } else if (status === 3) { return { 'border-color': '#409EFF', 'background-color': '#ECF5FF', 'color': '#409EFF' } } else if (status === 1) { return { 'border-color': '#67C23A', 'background-color': '#F0F9EB', 'color': '#67C23A' } } else if (status === 2) { return { 'border-color': '#F56C6B', 'background-color': '#FEF0F0', 'color': '#F56C6B' } } else if (status === 4 || status === 5) { return { 'background-color': '#FFFFFF' } } else if (status === 6) { return { 'border-color': '#E9E9EB', 'background-color': '#F4F4F5', 'color': '#909399' } } }, 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 '' }, /** * 更新表高 */ updateTableHeight () { var offsetHei = document.documentElement.clientHeight var removeHeight = Object.keys(this.filterObj).length > 0 ? 310 : 240 this.tableHeight = offsetHei - removeHeight }, /** * 导出 */ exportData (params) { this.$refs.listHead.handleTypeDrop('out', params) } }, beforeDestroy () { } }