function dateFormatter (date, pattern) { return new Date(date).pattern(pattern) } var vm = new Vue({ delimiters: ['${', '}'], el: '#analysis', components: { keywordComponent: keywordComponent, areaCityMobile: areaCityMobileComponent, industryComponent: industryComponent, cateComponent: cateComponent, dateComponent: dateComponent, chartExample: chartExample, // 图表 projectScatter: projectScatter, marketTimeScatter: marketTimeScatter, marketAreaScatter: marketAreaScatter, marketTop3Table: marketTop3Table, marketUserScatter: marketUserScatter, marketSegment: marketSegment, lineChartScatter: lineChartScatter, }, data: { sessStorageKey: '$data-report_analysis', tabActiveName: 'analysis', // analysis/history tabList: [ { label: '定制化市场分析', name: 'analysis' }, { label: '历史报告', name: 'history' } ], tabConf: { titleActiveColor: '#2ABED1', titleInactiveColor: '#5F5E64', lineWidth: '24', color: '#2ABED1' }, timeOptions: [ { name: '近3个月', value: 'lately90', selected: false }, { name: '近半年', value: 'lately180', selected: false }, { name: '今年全年', value: 'thisYear', selected: false }, { name: '去年至今', value: 'sinceLastYear', selected: false }, { name: '前年至今', value: 'sinceYearBeforeLast', selected: false } ], scrollTop: 0, filtersPageShow: true, filters: { selectKeysArr: [], // 关键词简单数组,用于恢复选择状态 keys: [], // 关键词详细数组,用于提交数据 area: {}, industry: [], industryDetail: {}, buyerclass: [], rangeTime: { start: '', end: '', exact: 'sinceYearBeforeLast', }, }, filterDialogShow: { keys: false, area: false, industry: false, buyerclass: false, rangeTime: false }, // 分析结果页面数据 activeDimension: 'market', dimensionList: [ { id: 'market', name: '市场规模', top: 0, anchor: 'market-overview' }, { id: 'buyer', name: '采购单位', top: 0, anchor: 'buyerclass-scatter' }, { id: 'bidder', name: '中标单位', top: 0, anchor: 'winner-scatter' }, ], analysis: { // 开始分析请求的loaed和loading loaded: false, loading: false }, rid: '', // reportId reportFilters: { keys: [], selectTime: '', selectTimeExtra: '', area: {}, industry: {}, buyerclass: [] }, sections: { market: { overview: [], refine: { dataAlready: false, projectCountData: null, projectAmountData: null, // 项目数量Top3 projectCountTop3: null, // 项目金额Top3 projectAmountTop3: null } }, projectScatter: { dataAlready: false, chartData: null, tableData: [ // { // projectname: 'xxxx', // area: 'xx', // city: 'xxx', // sortprice: 'zzz', // jgtime: 'zzzz', // winner_s: [ // { // name: 'w1', // id: '33' // }, // { // name: 'w2', // id: '33' // } // ] // }, // { // projectname: 'xxxx', // area: 'xx', // city: 'xxx', // sortprice: 'zzz', // jgtime: 'zzzz', // winner_s: [ // { // name: 'w1', // id: '33' // }, // { // name: 'w2', // id: '33' // } // ] // } ] }, timeScatter: { dataAlready: false, // 数据准备好之后才能开始渲染 activeAction: 'month', actionList: [ { label: '月度数据', value: 'month' }, { label: '年度数据', value: 'year' } ], month: { count: {}, amount: {} }, year: { count: {}, amount: {} } }, areaScatter: { dataAlready: false, chartData: null, // 项目数量Top3 projectCountTop3: null, // 项目金额Top3 projectAmountTop3: null }, userScatter: { list: [], // 项目数量Top3 projectCountTop3: null, // 项目金额Top3 projectAmountTop3: null }, buyerclass: { dataAlready: false, chartData: null, // 项目数量Top3 projectCountTop3: null, // 项目金额Top3 projectAmountTop3: null }, winner: { dataAlready: false, chartData: null, // 项目数量Top3 projectCountTop3: null, // 项目金额Top3 projectAmountTop3: null } }, empty: { defaultMsg: '对不起,没有匹配到相关信息
请修改您的分析条件', msg: '' }, stickyOffset: 0, notSetKey: false, // 未设置关键词 isSubCount: false, // 是否子账号 powerInfo: {}, isWeixin: false }, computed: { getStatus: function () { if (JSON.stringify(this.powerInfo) !== '{}') { return this.powerInfo.power.indexOf(10) !== -1 } }, anchorTopList: function () { var arr = [] this.dimensionList.forEach(function (item) { arr.push(item.top) }) return arr }, // 报告详情筛选条件只有一个省份 // 此时不显示地区分布chart notOneAreaFilter () { var area = this.reportFilters.area var showArea = area && (Object.keys(area).length > 1 || Object.keys(area).length === 0) return showArea }, emptyShow () { return !this.rid && this.analysis.loaded }, tabActive: function () { var _this = this var active = {} this.tabList.some(function (item) { var findThis = item.name === _this.tabActiveName if (findThis) { active = item return findThis } }) return active }, buyerclassSectionShow () { const winnerState = this.sections.buyerclass return winnerState.dataAlready && winnerState.projectCountTop3 && winnerState.projectAmountTop3 }, winnerSectionShow () { const winnerState = this.sections.winner return winnerState.dataAlready && winnerState.projectCountTop3 && winnerState.projectAmountTop3 }, overviewRateTotal: function () { var total = 0 this.sections.market.overview.forEach(function (item) { if (item.ringRatio !== undefined && item.ringRatio !== null) { total += item.ringRatio } }) return total } }, watch: { filtersPageShow (newVal) { if (!newVal) { this.isWeixin = utils.isWeiXinBrowser if (!this.isWeixin) { this.calcStickyOffset() } } } }, created () { this.calcLastTimeText() this.getPower() var id = utils.getParam('id') if (id) { this.rid = decodeURIComponent(id) this.filtersPageShow = false } }, mounted: function () { setTimeout(() => { var restored = this.reStoreState() if (!restored) { if (this.rid) { this.getReportResult() } } else { this.$nextTick(this.calcOffsetTop) if (utils.isIos) { setTimeout(this.calcOffsetTop, 1000) } } }, 0) this.addEventListeners() utils.iosBackRefresh() }, methods: { gotable () { this.saveState() if(this.isWeiXinBrower()){ window.location.href='/big/wx/page/report_table?source=analysis'+'&flag=3'+'&rid='+this.rid+'&header=客户类型分布详情' } else { window.location.href='/jyapp/big/page/report_table?source=analysis'+'&flag=3'+'&rid='+this.rid+'&header=客户类型分布详情' } }, isWeiXinBrower() { var ua = navigator.userAgent.toLowerCase(); if(ua.match(/MicroMessenger/i) == 'micromessenger') { return true; } else { return false; } }, showLoading: function () { return this.$toast.loading({ duration: 0, forbidClick: true, message: 'loading...', }) }, showToast: function (message) { return this.$toast({ duration: 1500, forbidClick: true, message: message, }) }, showDialog: function (conf) { var defaultConf = { title: '提示', message: 'message', className: 'j-confirm-dialog', showConfirmButton: true, showCancelButton: true, confirmButtonText: '确定', confirmButtonColor: '#2abed1' } if (conf) { Object.assign(defaultConf, conf) } return this.$dialog.confirm(defaultConf) }, calcOffsetTop: function () { var sticky = $('.van-sticky') var stickyHeight = 0 if (sticky.length) { stickyHeight = sticky[0].clientHeight } this.dimensionList.forEach(function (item) { var anchor = $('.' + item.anchor) var offsetTop = 0 if (anchor.length) { offsetTop = parseInt(anchor[0].offsetTop - stickyHeight) } item.top = offsetTop }) }, addEventListeners: function () { this.scrollToTop() }, scrollToTop: function () { var $scrollDOM = $('.j-container.search-result > .j-main') // 1. 检查当前高度是否满足显示快速滚动到顶部 this.checkScrollTopButtonShow() // 2. 具体逻辑 $scrollDOM.on('scroll', this.checkScrollTopButtonShow) setTimeout(function () { // 2s后绑定(尽可能保证top能够被计算完) $scrollDOM.on('scroll', this.checkAnchorItemActive) }.bind(this), 2500) $('.scroll-to-top').on('click', function () { $scrollDOM.animate({ scrollTop: 0 }) }) }, checkAnchorItemActive: function () { var $scrollDOM = $('.j-container.search-result > .j-main') var anchorTopList = this.anchorTopList var scrollTop = parseInt($scrollDOM.scrollTop()) + 3 // (误差校正) var i = 0 if (scrollTop >= anchorTopList[1] && scrollTop < anchorTopList[2]) { i = 1 } else if (scrollTop > anchorTopList[2] && scrollTop > anchorTopList[1] && scrollTop > anchorTopList[0]) { //逻辑上多余判断条件 ,为了处理高度还没有计算出起始的 anchorTopList[2]为0 tab回显错误问题 i = 2 } else if (scrollTop < anchorTopList[1]) { i = 0 } this.activeDimension = this.dimensionList[i].id }, checkScrollTopButtonShow: function () { var showButtonHeight = 300 var $scrollDOM = $('.j-container.search-result > .j-main') var button = $('.scroll-to-top') var scrollTop = $scrollDOM.scrollTop() if (scrollTop > showButtonHeight) { button.show() } else { button.hide() } }, calcStickyOffset: function () { setTimeout(function () { var headerHeight = $('.jy-app-header')[0].clientHeight var tabHeight = $('.analysis-tab')[0].clientHeight this.stickyOffset = headerHeight + tabHeight - 5 }.bind(this), 1000) }, setScrollTop: function (scrollTop) { this.$nextTick(function () { var wrapper = document.querySelector('.j-container.search-result > .j-main') wrapper.scrollTop = scrollTop }) }, saveScrollTop: function () { var wrapper = document.querySelector('.j-container.search-result > .j-main') if (wrapper.scrollTop) { this.scrollTop = parseInt(wrapper.scrollTop) } }, beforeTabChange: function (name) { if (name !== this.tabActiveName) { this.goToAnalysisHistory() } return false }, goToAnalysisHistory: function () { location.href = './report_analysis_history' }, formatSelectTime (value) { if (!value) return '-' const timeArr = value.split('-') return `${dateFormatter(timeArr[0] * 1000, 'yyyy/MM/dd')}-${dateFormatter(timeArr[1] * 1000, 'yyyy/MM/dd')}` }, getPower:function () { var _this = this $.ajax({ type:'POST', url:'/bigmember/use/isAdd', success:function(res) { _this.powerInfo = res.data if (res.data && res.data.isSubCount){ _this.isSubCount = true } } }) }, init: function () { // 初始化页面数据 this.initDateTimeSelector('sinceYearBeforeLast') }, // 时间选择器选中状态 initDateTimeSelector: function (exact) { if (exact === 'exact') { this.$refs.dateSelector.setState(this.filters.rangeTime) } else { this.$refs.dateSelector.setTimeSelectListState(exact) this.$refs.dateSelector.dateStyle = false } }, resolveSelected: function (type) { var filters = this.filters var prefix = '已选:' var text = '' if (type === 'keys') { if (this.notSetKey) return '请设置' text = this.resolveSelectKeysText(filters.keys) } else if (type === 'area') { text = this.resolveSelectAreaText(filters.area) } else if (type === 'industry') { text = this.resolveSelectIndustryText(filters.industryDetail) } else if (type === 'buyerclass') { text = this.resolveSelectBuyerclassText(filters.buyerclass) } return prefix + text }, resolveSelectKeysText: function (keys) { if (Array.isArray(keys)) { if (keys.length === 0) { return '全部' } else { var count = 0 var arr = [] keys.forEach(function (classify) { if (Array.isArray(classify.a_key) && classify.a_key.length) { count += classify.a_key.length classify.a_key.forEach(function (item) { arr.push(item.key.join(' ')) }) } }) if (count <= 0) { return '全部' } else { return arr.join(',') } } } else { return '全部' } }, resolveSelectAreaText: function (area) { if (!area || Object.keys(area).length === 0) return '全国' var areaArr = [] var cityArr = [] for (var key in area) { if (area[key].length === 0) { areaArr.push(key) } else { cityArr = cityArr.concat(area[key]) } } return areaArr.concat(cityArr).join(',') }, resolveSelectIndustryText: function (industry) { if (!industry || Object.keys(industry).length === 0) return '全部' var keyArr = [] var valueArr = [] for (var key in industry) { if (industry[key].length === 0) { keyArr.push(key) } else { valueArr = valueArr.concat(industry[key]) } } return keyArr.concat(valueArr).join(',') }, resolveSelectBuyerclassText: function (buyerclass) { if (!Array.isArray(buyerclass)) return '全部' if (buyerclass.length === 0) return '全部' return buyerclass.join(',') }, calcLastTimeText: function () { const renameList = [ 'thisYear', // 今年全年 'sinceLastYear', // 去年至今 'sinceYearBeforeLast' // 前年至今 ] const thisYear = new Date().getFullYear() this.timeOptions.forEach(item => { if (renameList.indexOf(item.value) !== -1) { if (item.value === renameList[0]) { item.name = `${thisYear}年全年` } else if (item.value === renameList[1]) { item.name = `${thisYear - 1}年至今` } else if (item.value === renameList[2]) { item.name = `${thisYear - 2}年至今` } } }) }, // 重置 resetFilter: function (type) { var filters = this.filters if (type === 'keys') { filters.keys = [] filters.selectKeysArr = [] try { this.$refs.keywordSelector.resetAllNoSelect() } catch (error) {} } else if (type === 'area') { filters.area = {} } else if (type === 'industry') { filters.industry = [] filters.industryDetail = {} } else if (type === 'buyerclass') { filters.buyerclass = [] } else if (type === 'date') { this.filters.rangeTime.start = '' this.filters.rangeTime.edd = '' this.filters.rangeTime.exact = 'sinceYearBeforeLast' this.initDateTimeSelector(this.filters.rangeTime.exact) } else { this.resetFilter('keys') this.resetFilter('area') this.resetFilter('industry') this.resetFilter('buyerclass') this.resetFilter('date') } }, clickCell: function (key) { var _this = this var dialog = this.filterDialogShow if (key === 'keys') { if (this.notSetKey) { return this.setKeyTip() } } else if (key === 'area') { setTimeout(function () { _this.$refs.areaCitySelector.setState(_this.filters.area) }, 0) } else if (key === 'buyerclass') { setTimeout(function () { _this.$refs.buyerclassSelector.setState() }, 0) } else if (key === 'industry') { setTimeout(function () { _this.$refs.industrySelector.setState() }, 0) } dialog[key] = true }, cancel: function (e, key) { var dialog = this.filterDialogShow this.resetFilter(key) dialog[key] = false }, confirm: function (e, key) { var dialog = this.filterDialogShow var filters = this.filters if (key === 'keys') { filters.keys = e.detail filters.selectKeysArr = e.data } else if (key === 'area') { filters.area = e.data } else if (key === 'industry') { filters.industry = e.data filters.industryDetail = e.detail } else if (key === 'buyerclass') { filters.buyerclass = e.data console.log(e.data) } dialog[key] = false }, dateTimeSelectorConfirm () { var result = this.$refs.dateSelector.getState() this.filters.rangeTime.start = result.start this.filters.rangeTime.end = result.end this.filters.rangeTime.exact = result.exact }, resetAllFilters: function () { this.analysis.loaded = false this.resetFilter('all') }, getReportResult () { this.sendRequest() }, getSelectedKeys () { const keys = this.filters.keys if (Array.isArray(keys) && keys.length) { return JSON.stringify(keys) } else { var allKeys = this.$refs.keywordSelector.keywordGroupList return JSON.stringify(allKeys) } }, startAnalysis: function () { this.dateTimeSelectorConfirm() const query = { keysItems: this.getSelectedKeys(), rangeTime: `${parseInt(this.filters.rangeTime.start / 1000)}-${parseInt(this.filters.rangeTime.end / 1000)}`, rangeTimeExtra: this.filters.rangeTime.exact, area: JSON.stringify(this.filters.area), industry: JSON.stringify(this.filters.industryDetail), buyerclass: this.filters.buyerclass.join(',') } this.analysis.loaded = false this.analysis.loading = true this.showLoading() $.ajax({ type: 'POST', url: '/bigmember/marketAnalysis/doAnalysis', data: query, success: function (res) { if (res && res.error_code === 0 && res.data) { this.rid = res.data this.analysis.loaded = true // location.replace('./report_analysis?id=' + res.data) this.rid = res.data history.replaceState({}, null, '?id=' + this.rid) this.getReportResult() } else { this.$toast(res.error_msg) } }.bind(this), complete: function () { this.analysis.loading = false }.bind(this) }) }, // 保存页面状态 saveState: function () { this.saveScrollTop() this.dateTimeSelectorConfirm() var $data = { analysis: this.analysis, filters: this.filters, scrollTop: this.scrollTop, filtersPageShow: this.filtersPageShow, reportFilters: this.reportFilters, sections: this.sections, isSubCount: this.isSubCount } sessionStorage.setItem(this.sessStorageKey, JSON.stringify($data)) }, reStoreState: function () { var $data = sessionStorage.getItem(this.sessStorageKey) if ($data) { $data = JSON.parse($data) this.isSubCount = $data.isSubCount this.scrollTop = $data.scrollTop this.filtersPageShow = $data.filtersPageShow Object.assign(this.analysis, $data.analysis) this.$set(this, 'filters', $data.filters) this.$set(this, 'reportFilters', $data.reportFilters) this.$set(this, 'sections', $data.sections) setTimeout(function () { // 恢复滚动高度 this.setScrollTop(this.scrollTop) this.initDateTimeSelector(this.filters.rangeTime.exact) }.bind(this), 0) sessionStorage.removeItem(this.sessStorageKey) } else { this.init() } return $data }, onEmpty (info) { if (this.loading) { this.loading.clear() } this.filtersPageShow = true this.analysis.loaded = true this.rid = '' if (info && info.msg) { this.empty.msg = info.msg } else { this.empty.msg = this.empty.defaultMsg } }, sendRequest () { let _this = this // 先请求概况(1),判断报告是否为空 const query = { rid: this.rid, flag: 1 } if (!query.rid) { return } this.loading = this.showLoading() $.ajax({ type: 'POST', async: false, url: '/bigmember/marketAnalysis/getAnalysisResult', data: query, success: function(res) { if (res && res.error_code === 0 && res.data) { var empty = _this.formatterData(query.flag, res.data) if (empty) { return _this.onEmpty() } } else { if (res.error_msg.indexOf('项目数量超出上限') === -1) { return _this.onEmpty() } else { return _this.onEmpty({ msg: '当前分析条件涉及项目数量已超过最大限制,请修改分析条件进行精确分析' }) } } } }).responseJSON this.filtersPageShow = false const flagArr = [ 0, // 筛选条件 // 1, // 市场概括与时间分布 2, // 项目规模Top10 3, // 项目规模分布/地区规模分布/客户分布/地区分布及客户分布&Top3(table+chart) 4, // 细分市场 5 // 采购单位/中标单位&Top3(table+chart) ] flagArr.forEach(this.getReport) if (this.loading) { this.loading.clear() } }, getReport (flag) { const query = { rid: this.rid, flag } if (!query.rid) { return } $.ajax({ type: 'POST', url: '/bigmember/marketAnalysis/getAnalysisResult', data: query, success: function (res) { if (res && res.error_code === 0 && res.data) { if(flag==3){ sessionStorage.setItem('getAnalysisResult_',JSON.stringify(res)) } this.formatterData(flag, res.data) } else { this.$toast('请求失败') } }.bind(this) }) }, formatterData (flag, data) { if (flag === 0) { this.sortReportFilters(data) } else if (flag === 1) { // 市场概况 const totalCount = this.sortMarketOverview(data.market_profile) if (!totalCount) { return true } // 时间分布 this.sortTimeScatter(data) } else if (flag === 2) { // 项目规模Top10 this.sortProjectTop10(data.ProjectTop10) } else if (flag === 3) { // 项目规模分布/地区规模分布/客户分布/地区分布及客户分布&Top3(table+chart) // 项目规模分布 this.sortProjectScatter(data.projectScale) // 地区规模分布 this.sortAreaScatter(data.area_infos) // 客户分布 if(data.customer_scale){ if(data.customer_scale.length!=0){ let data_=data.customer_scale.slice(0,10) this.sortUserScatter(data_) } } // 地区分布及客户分布Top3 this.sortAreaUserTop3(data) } else if (flag === 4) { // 细分市场 this.sortMarketRefineData(data) } else if (flag === 5) { // 采购单位/中标单位&Top3(table+chart) this.sortBuyerclassData(data) // 中标单位分析 this.sortWinnerData(data) } this.$nextTick(this.calcOffsetTop) }, formatSelectTime (value) { if (!value) return '-' const timeArr = value.split('-') return `${dateFormatter(timeArr[0] * 1000, 'yyyy/MM/dd')}-${dateFormatter(timeArr[1] * 1000, 'yyyy/MM/dd')}` }, // 整理数据,并赋值给filters sortReportFilters (data) { if (data.keysItems && data.keysItems !== '[]') { this.reportFilters.keys = JSON.parse(data.keysItems) this.filters.keys = this.reportFilters.keys var keyArr = [] this.filters.keys.forEach(function (classify) { if(Array.isArray(classify.a_key)) { classify.a_key.forEach(function (item) { keyArr.push(item.key.join(' ')) }) } }) this.filters.selectKeysArr = keyArr } // if (data.s_rangeTimeExtra) { // this.reportFilters.selectTimeExtra = data.s_rangeTimeExtra // this.filters.rangeTime.exact = this.reportFilters.selectTimeExtra // } else { // this.filters.rangeTime.exact = 'exact' // } this.filters.rangeTime.exact = 'exact' if (data.rangeTime) { this.reportFilters.selectTime = data.rangeTime var arr = data.rangeTime.split('-') this.filters.rangeTime.start = arr[0] * 1000 this.filters.rangeTime.end = arr[1] * 1000 if (this.filters.rangeTime.exact === 'exact') { var date = new Date(this.filters.rangeTime.end) var timeString = date.pattern('yyyy/MM/dd') this.filters.rangeTime.end = new Date(timeString).getTime() } } this.$refs.dateSelector.setState(this.filters.rangeTime) if (data.area && data.area !== '{}') { this.reportFilters.area = JSON.parse(data.area) this.filters.area = this.reportFilters.area } if (data.industry && data.industry !== '{}') { this.reportFilters.industry = JSON.parse(data.industry) this.$set(this.filters, 'industryDetail', this.reportFilters.industry) var industry = [] for (var key in this.reportFilters.industry) { this.reportFilters.industry[key].forEach(function (item) { industry.push(key + '_' + item) }) } this.filters.industry = industry } if (data.buyerclass) { this.reportFilters.buyerclass = data.buyerclass.split(',') this.filters.buyerclass = this.reportFilters.buyerclass } }, // 市场概况 sortMarketOverview (profile) { if (!profile) return const list = [ { label: '项目总数', unit: '个', count: 0, ringRatio: 0 }, { label: '项目总金额', unit: '万元', count: 0, ringRatio: 0 }, { label: '项目平均金额', unit: '万元', count: 10.04, ringRatio: 0 }, { label: '中标单位数', unit: '家', count: 10628, ringRatio: 0 }, { label: '采购单位数', unit: '家', count: 16215, ringRatio: 0 } ] // 项目总数 list[0].count = profile.project_count ? profile.project_count : 0 list[0].ringRatio = profile.project_count_ratio ? (profile.project_count_ratio * 100).toFixed(2) : 0 // 项目总金额 const projectTotalMoney = this.moneyUnit(profile.projctamout ? profile.projctamout : 0) list[1].count = projectTotalMoney.count || 0 list[1].unit = projectTotalMoney.unit || '万元' list[1].ringRatio = profile.projctamount_ratio ? (profile.projctamount_ratio * 100).toFixed(2) : 0 // 项目平均金额 const projectAvgMoney = this.moneyUnit(profile.projectavgmoney ? profile.projectavgmoney : 0) list[2].count = projectAvgMoney.count || 0 list[2].unit = projectAvgMoney.unit || '万元' list[2].ringRatio = profile.projectavgmoney_ratio ? (profile.projectavgmoney_ratio * 100).toFixed(2) : 0 // 中标单位数 list[3].count = profile.winnercount ? profile.winnercount : 0 list[3].ringRatio = profile.winnercount_ratio ? (profile.winnercount_ratio * 100).toFixed(2) : 0 // 采购单位数 list[4].count = profile.buyercount ? profile.buyercount : 0 list[4].ringRatio = profile.winnercount_ratio ? (profile.winnercount_ratio * 100).toFixed(2) : 0 var totalCount = list.reduce((total, item) => item.count + total, 0) if (totalCount) { this.sections.market.overview = list } return totalCount }, // 时间分布 sortTimeScatter (data) { const hasDataM = this.sortTimeScatterData('month', data.month_distribution) const hasDataY = this.sortTimeScatterData('year', data.year_distribution) const hasData = hasDataM && hasDataY this.sections.timeScatter.dataAlready = hasData }, sortTimeScatterData (type, data) { // columns: ['日期', '项目规模', '环比增长率(%)'], // rows: [ // { // 日期: '6月', // 项目规模: 0, // '环比增长率(%)': -99 // }, // { // 日期: '7月', // 项目规模: 736325, // '环比增长率(%)': 0 // }, // ] if (!data) return // 项目数量 const mDCount = { columns: ['日期', '项目数量(个)', '项目数量环比'], rows: [] } let mDCountTotal = 0 if (Array.isArray(data.project_count)) { const field = { [mDCount.columns[0]]: 'minth', [mDCount.columns[1]]: 'value', [mDCount.columns[2]]: 'ratio' } data.project_count.forEach(item => { const row = {} mDCount.columns.forEach(column => { var value = item[field[column]] if (value) { if (field[column] === 'ratio') { row[column] = utils.formatMoney(value * 100, undefined, true) - 0 } else { row[column] = value } } else { row[column] = null } if (typeof value === 'number') { mDCountTotal += value } }) mDCount.rows.push(row) }) } if (mDCountTotal || isNaN(mDCountTotal)) { this.$set(this.sections.timeScatter[type], 'count', mDCount) } // 项目规模 const mDAmount = { columns: ['日期', '项目金额(万元)', '项目金额环比'], rows: [] } let mDAmuntTotal = 0 if (Array.isArray(data.project_amount)) { const field = { [mDAmount.columns[0]]: 'minth', [mDAmount.columns[1]]: 'value', [mDAmount.columns[2]]: 'ratio' } data.project_amount.forEach(item => { const row = {} mDAmount.columns.forEach(column => { const value = item[field[column]] if (value) { if (field[column] === 'value') { row[column] = utils.formatMoney(value / 10000, undefined, true) - 0 } else if (field[column] === 'ratio') { row[column] = utils.formatMoney(value * 100, undefined, true) } else { row[column] = value } } else { row[column] = null } if (typeof value === 'number') { mDAmuntTotal += value } }) mDAmount.rows.push(row) }) } if (mDAmuntTotal || !isNaN(mDAmuntTotal)) { this.$set(this.sections.timeScatter[type], 'amount', mDAmount) } const r = !!(mDCountTotal + mDAmuntTotal) const hasOneNaN = isNaN(mDCountTotal) || isNaN(mDAmuntTotal) return hasOneNaN || r }, // 项目规模分布 sortProjectScatter (data) { // const chartData = { // columns: ['项目规模', '项目总金额占比', '项目总数占比'], // rows: [ // { // 项目规模: '≥1亿', // 项目总金额占比: 20, // 项目总数占比: 10 // }, // { // 项目规模: '1000万-1亿', // 项目总金额占比: 50, // 项目总数占比: 40 // }, // { // 项目规模: '500万-1000万', // 项目总金额占比: 20, // 项目总数占比: 30 // }, // { // 项目规模: '100万-500万', // 项目总金额占比: 20, // 项目总数占比: 30 // } // ] // } const scaleList = data const scaleData = { columns: ['项目规模', '项目总金额占比', '项目总数占比'], rows: [] } let total = 0 if (scaleList && Array.isArray(scaleList)) { const field = { [scaleData.columns[0]]: 'Name', [scaleData.columns[1]]: 'Persent_c', [scaleData.columns[2]]: 'Persent_a' } scaleList.forEach(item => { const row = {} scaleData.columns.forEach(column => { if (field[column] === 'Persent_c' || field[column] === 'Persent_a') { row[column] = (item[field[column]] * 100).toFixed(2) total += (item[field[column]] - 0) } else { row[column] = item[field[column]] } }) scaleData.rows.push(row) }) } if (total) { scaleData.rows.reverse() this.$set(this.sections.projectScatter, 'chartData', scaleData) if (this.sections.projectScatter.tableData.length) { this.sections.projectScatter.dataAlready = true } } }, // 项目规模Top10 sortProjectTop10 (top10List) { if (!Array.isArray(top10List)) return this.sections.projectScatter.tableData = top10List.map(top => { let winners = top.winner_s ? top.winner_s.join(',') : '' if (!winners) { winners = [] } else { winners = top.winner_s } winners = winners.map((item, index) => { return { name: item, id: Array.isArray(top.eidlist) ? top.eidlist[index] : null } }) top.area = top.area ? top.area : '' top.city = top.city ? top.city : '' top.sortprice = top.sortprice ? utils.formatMoney(top.sortprice / 10000, undefined, true) : '' top.jgtime = top.jgtime ? dateFormatter(top.jgtime * 1000, 'yyyy-MM-dd') : '' top.winner_s = winners return top }) if (this.sections.projectScatter.chartData) { this.sections.projectScatter.dataAlready = true } }, // 地区规模分布 sortAreaScatter (areaList) { // const chartData = { // columns: ['项目所在地', '项目数量', '项目金额'], // rows: [ // { // 项目所在地: '河南', // 项目数量: 2, // 项目金额: 2222 // }, // { // 项目所在地: '北京', // 项目数量: 22, // 项目金额: 565666 // }, // { // 项目所在地: '浙江', // 项目数量: 22, // 项目金额: 765666 // } // ] // } const areaChartData = { columns: ['项目所在地', '项目数量'], sColumns: ['项目金额'], rows: [] } let total = 0 if (areaList && Array.isArray(areaList)) { const field = { [areaChartData.columns[0]]: 'area', [areaChartData.columns[1]]: 'total', [areaChartData.sColumns[0]]: 'amount' } areaList.forEach(item => { const row = {} areaChartData.columns.concat(areaChartData.sColumns).forEach(column => { if (field[column] === 'amount') { row[column] = utils.formatMoney(item[field[column]] / 10000, undefined, true) - 0 } else { row[column] = item[field[column]] } if (field[column] === 'amount' || field[column] === 'total') { total += (item[field[column]] - 0) } }) areaChartData.rows.push(row) }) } if (total) { this.$set(this.sections.areaScatter, 'chartData', areaChartData) this.sections.areaScatter.dataAlready = true } }, // 客户分布 sortUserScatter (userList) { if (Array.isArray(userList)) { this.sections.userScatter.list = userList.map(item => { item.name = item.buyclass item.value = item.total item.amount = utils.formatMoney(item.amount / 10000, undefined, true) return item }) } }, // 地区分布及客户分布Top3 sortAreaUserTop3 (data) { if (data.scaleAreaCountTop || data.scaleAreaAmountTop) { this.sorAreaTop3(data) } if (data.scaleBuyclassCountTop || data.scaleBuyclassAmountTop) { this.sorUserTop3(data) } }, sorAreaTop3 (data) { const tableDataCount = { columns: ['序号', '地区:项目数量(个),占比', '前3中标单位:中标数量(个)'], // ,该地区占比 rows: [] } const tableDataAmount = { columns: ['序号', '地区:项目金额(万元),占比', '前3中标单位:中标金额(万元)'], // ,该地区占比 rows: [] } const scaleAreaCountTop3 = data.scaleAreaCountTop if (Array.isArray(scaleAreaCountTop3)) { scaleAreaCountTop3.forEach((item, index) => { item.name = item.name item.subInfo1 = item.area_count ? `项目数量:${item.area_count}个` : '' item.subInfo2 = item.area_scale ? `全国占比:${utils.formatMoney(item.area_scale * 100, undefined, true)}%` : '' item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.winner)) { item.winner.forEach((w, i) => { const row = { name: w.winner, id: w.id, type: 'winner', subInfo1: w.winner_total ? `中标个数:${w.winner_total}个` : '', // subInfo2: w.total_scale ? `地区占比:${utils.formatMoney(w.total_scale * 100, undefined, true)}%` : 0 } item.children.push(row) }) } }) tableDataCount.rows = scaleAreaCountTop3 } const scaleAreaAmountTop3 = data.scaleAreaAmountTop if (Array.isArray(scaleAreaAmountTop3)) { scaleAreaAmountTop3.forEach((item, index) => { item.name = item.name item.subInfo1 = item.area_amount ? `中标金额:${utils.formatMoney(item.area_amount / 10000, undefined, true)}万元` : '' item.subInfo2 = item.area_scale ? `全国占比:${utils.formatMoney(item.area_scale * 100, undefined, true)}%` : '' item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.winner)) { item.winner.forEach((w, i) => { const row = { name: w.winner, id: w.id, type: 'winner', subInfo1: w.winner_amount ? `中标金额:${utils.formatMoney(w.winner_amount / 10000, undefined, true)}万元` : '', // subInfo2: w.amount_scale ? `地区占比:${utils.formatMoney(w.amount_scale * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) tableDataAmount.rows = scaleAreaAmountTop3 } if (tableDataCount.rows.length) { this.$set(this.sections.areaScatter, 'projectCountTop3', tableDataCount.rows) } if (tableDataAmount.rows.length) { this.$set(this.sections.areaScatter, 'projectAmountTop3', tableDataAmount.rows) } }, sorUserTop3 (data) { const tableDataCount = { columns: ['序号', '客户类型:项目数量(个),占比', '前3中标单位:中标数量(个)'], // ,该客户类型占比 rows: [] } const tableDataAmount = { columns: ['序号', '客户类型:项目金额(万元),占比', '前3中标单位:中标金额(万元)'], // ,该客户类型占比 rows: [] } const countTop3 = data.scaleBuyclassCountTop if (Array.isArray(countTop3)) { countTop3.forEach((item, index) => { item.name = item.name item.subInfo1 = item.buyclass_count ? `项目数量:${item.buyclass_count}个` : '' item.subInfo2 = item.buyclass_scale ? `全部占比:${utils.formatMoney(item.buyclass_scale * 100, undefined, true)}%` : '' item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.winner)) { item.winner.forEach((w, i) => { const row = { name: w.winner, id: w.id, type: 'winner', subInfo1: w.winner_total ? `中标个数:${w.winner_total}个` : '', // subInfo2: w.total_scale ? `该行业占比:${utils.formatMoney(w.total_scale * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) tableDataCount.rows = countTop3 } const amountTop3 = data.scaleBuyclassAmountTop if (Array.isArray(amountTop3)) { amountTop3.forEach((item, index) => { item.name = item.name item.subInfo1 = item.buyclass_amount ? `项目金额:${utils.formatMoney(item.buyclass_amount / 10000, undefined, true)}万元` : '' item.subInfo2 = item.buyclass_scale ? `全部占比:${utils.formatMoney(item.buyclass_scale * 100, undefined, true)}%` : 0 item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.winner)) { item.winner.forEach((w, i) => { const row = { name: w.winner, id: w.id, type: 'winner', subInfo1: w.winner_amount ? `中标金额:${utils.formatMoney(w.winner_amount / 10000, undefined, true)}万元` : '', // subInfo2: w.amount_scale ? `该行业占比:${utils.formatMoney(w.amount_scale * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) tableDataAmount.rows = amountTop3 } if (tableDataCount.rows.length) { this.$set(this.sections.userScatter, 'projectCountTop3', tableDataCount.rows) } if (tableDataAmount.rows.length) { this.$set(this.sections.userScatter, 'projectAmountTop3', tableDataAmount.rows) } }, // 细分市场 sortMarketRefineData (data) { const refineCount = { columns: ['行业', '项目数量'], rows: [] } const refineAmount = { columns: ['行业', '项目金额'], rows: [] } let total = 0 const refineAll = data.scaleRefineAll if (Array.isArray(refineAll)) { const field = { 行业: 'name', 项目数量: 'total', 项目金额: 'amount' } refineAll.forEach(item => { const row = {} for (const key in field) { if (field[key] === 'amount') { row[key] = utils.formatMoney(item[field[key]] / 10000, undefined, true) } else { row[key] = item[field[key]] } if (field[key] === 'total' || field[key] === 'amount') { total += (item[field[key]] - 0) } } refineCount.rows.push(row) refineAmount.rows.push(row) }) } if (total) { this.$set(this.sections.market.refine, 'projectCountData', refineCount) this.$set(this.sections.market.refine, 'projectAmountData', refineAmount) this.sections.market.refine.dataAlready = true } this.sortRefineTop3(data) }, sortRefineTop3 (data) { const tableDataCount = { columns: ['序号', '细分市场:项目数量(个)', '前3中标单位:中标数量(个)'], // ,占比,该细分市场占比 rows: [] } const tableDataAmount = { columns: ['序号', '细分市场:项目金额(万元)', '前3中标单位:中标金额(万元)'], // ,占比,该细分市场占比 rows: [] } const countTop3 = data.scaleRefineTotalTop if (Array.isArray(countTop3)) { countTop3.forEach((item, index) => { item.name = item.name item.subInfo1 = item.value ? `项目数量:${item.value}个` : '' // item.subInfo2 = item.prop ? `全部占比:${utils.formatMoney(item.prop * 100, undefined, true)}%` : 0 item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.topList)) { item.topList.forEach((w, i) => { const row = { name: w.name, id: w.id, type: 'winner', subInfo1: w.value ? `中标个数:${w.value}个` : '', // subInfo2: w.prop ? `该细分市场占比:${utils.formatMoney(w.prop * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) tableDataCount.rows = countTop3 } const amountTop3 = data.scaleRefineAmountTop if (Array.isArray(amountTop3)) { amountTop3.forEach((item, index) => { item.name = item.name item.subInfo1 = item.value ? `项目金额:${utils.formatMoney(item.value / 10000, undefined, true)}万元` : '' // item.subInfo2 = item.prop ? `全部占比:${utils.formatMoney(item.prop * 100, undefined, true)}%` : 0 item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.topList)) { item.topList.forEach((w, i) => { const row = { name: w.name, id: w.id, type: 'winner', subInfo1: w.value ? `中标金额:${utils.formatMoney(w.value / 10000, undefined, true)}万元` : '', // subInfo2: w.prop ? `该细分市场占比:${utils.formatMoney(w.prop * 100, undefined, true)}%`: '' } item.children.push(row) }) } }) tableDataAmount.rows = amountTop3 } if (tableDataCount.rows.length) { this.$set(this.sections.market.refine, 'projectCountTop3', tableDataCount.rows) } if (tableDataAmount.rows.length) { this.$set(this.sections.market.refine, 'projectAmountTop3', tableDataAmount.rows) } }, // 采购单位 sortBuyerclassData (data) { const buyerclassChartData = { columns: ['金额区间', '采购总金额占比', '采购单位数量占比'], rows: [] } let total = 0 const buyerclassList = data.buyer_time_distribution if (Array.isArray(buyerclassList)) { const field = { [buyerclassChartData.columns[0]]: 'key', [buyerclassChartData.columns[1]]: 'total_amount', [buyerclassChartData.columns[2]]: 'total_number' } buyerclassList.forEach(item => { const row = {} buyerclassChartData.columns.forEach(column => { if (field[column] === 'total_amount' || field[column] === 'total_number') { row[column] = (item[field[column]] * 100).toFixed(2) total += (item[field[column]] - 0) } else { row[column] = item[field[column]] } }) buyerclassChartData.rows.push(row) }) } if (total) { buyerclassChartData.rows.reverse() this.$set(this.sections.buyerclass, 'chartData', buyerclassChartData) this.sections.buyerclass.dataAlready = true } this.sortBuyerclassTableData(data) }, sortBuyerclassTableData (data) { const dataCount = { columns: ['序号', '采购单位:采购数量(个)', '前3中标单位:中标数量(个)'], //,占比 | ,占该采购单位 rows: [] } const dataAmount = { columns: ['序号', '采购单位:采购金额(万元)', '前3中标单位:中标金额(万元)'], //,占比 | ,占该采购单位 rows: [] } const countTop3 = data.buyer_count_top3 if (Array.isArray(countTop3)) { countTop3.forEach((item, index) => { item.name = item.name item.type = 'buyer' item.id = item.name item.subInfo1 = item.number ? `项目数量:${item.number}个` : '' // item.subInfo2 = item.accounted ? `全部占比:${utils.formatMoney(item.accounted * 100, undefined, true)}%` : '' item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.winnertop3)) { item.winnertop3.forEach((w, i) => { const row = { name: w.name, id: w.id, type: 'winner', subInfo1: w.number ? `中标个数:${w.number}个` : '', // subInfo2: w.accounted ? `占该采购单位:${utils.formatMoney(w.accounted * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) dataCount.rows = countTop3 } const amountTop3 = data.buyer_amount_top3 if (Array.isArray(amountTop3)) { amountTop3.forEach((item, index) => { item.name = item.name item.type = 'buyer' item.id = item.name item.subInfo1 = item.amount ? `采购金额:${utils.formatMoney(item.amount / 10000, undefined, true)}万元` : '' // item.subInfo2 = item.accounted ? `全部占比:${utils.formatMoney(item.accounted * 100, undefined, true)}%` : '' item.actionText = `中标单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.winnertop3)) { item.winnertop3.forEach((w, i) => { const row = { name: w.name, id: w.id, type: 'winner', subInfo1: w.amount ? `中标金额:${utils.formatMoney(w.amount / 10000, undefined, true)}万元` : '', // subInfo2: w.accounted ? `该行业占比:${utils.formatMoney(w.accounted * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) dataAmount.rows = amountTop3 } if (dataCount.rows.length) { this.$set(this.sections.buyerclass, 'projectCountTop3', dataCount.rows) } if (dataAmount.rows.length) { this.$set(this.sections.buyerclass, 'projectAmountTop3', dataAmount.rows) } }, // 中标单位 sortWinnerData (data) { const chartData = { columns: ['金额区间', '中标总金额占比', '中标单位数量占比'], rows: [] } let total = 0 const chartLIst = data.winner_time_distribution if (Array.isArray(chartLIst)) { const field = { [chartData.columns[0]]: 'key', [chartData.columns[1]]: 'total_amount', [chartData.columns[2]]: 'total_number' } chartLIst.forEach(item => { const row = {} chartData.columns.forEach(column => { if (field[column] === 'total_amount' || field[column] === 'total_number') { row[column] = (item[field[column]] * 100).toFixed(2) total += (item[field[column]] - 0) } else { row[column] = item[field[column]] } }) chartData.rows.push(row) }) } if (total) { chartData.rows.reverse() this.$set(this.sections.winner, 'chartData', chartData) this.sections.winner.dataAlready = true } this.sortWinnerTableData(data) }, sortWinnerTableData (data) { const dataCount = { columns: ['序号', '中标单位:中标数量(个)', '前3采购单位:采购数量(个)'], // ,占比 | ,占该中标单位 rows: [] } const dataAmount = { columns: ['序号', '中标单位:中标金额(万元),占比', '前3采购单位:采购金额(万元),占该中标单位'], // ,占比 | ,占该中标单位 rows: [] } const countTop3 = data.winner_count_top3 if (Array.isArray(countTop3)) { countTop3.forEach((item, index) => { item.name = item.name item.type = 'winner' item.id = item.id item.subInfo1 = item.number ? `中标数量:${item.number}个` : '' // item.subInfo2 = item.accounted ? `全部占比:${utils.formatMoney(item.accounted * 100, undefined, true)}%` : '' item.actionText = `采购单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.buyertop3)) { item.buyertop3.forEach((w, i) => { const row = { name: w.name, id: w.name, type: 'buyer', subInfo1: w.number ? `采购数量:${w.number}个` : '', // subInfo2: w.accounted ? `占该中标单位:${utils.formatMoney(w.accounted * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) dataCount.rows = countTop3 } const amountTop3 = data.winner_amount_top3 if (Array.isArray(amountTop3)) { amountTop3.forEach((item, index) => { item.name = item.name item.type = 'winner' item.id = item.id item.subInfo1 = item.amount ? `中标金额:${utils.formatMoney(item.amount / 10000, undefined, true)}万元` : '' // item.subInfo2 = item.accounted ? `全部占比:${utils.formatMoney(item.accounted * 100, undefined, true)}%` : '' item.actionText = `采购单位 TOP3` item.childrenShow = true item.children = [] if (Array.isArray(item.buyertop3)) { item.buyertop3.forEach((w, i) => { const row = { name: w.name, id: w.name, type: 'buyer', subInfo1: w.amount ? `采购金额:${utils.formatMoney(w.amount / 10000, undefined, true)}万元` : '', // subInfo2: w.accounted ? `占该中标单位:${utils.formatMoney(w.accounted * 100, undefined, true)}%` : '' } item.children.push(row) }) } }) dataAmount.rows = amountTop3 } if (dataCount.rows.length) { this.$set(this.sections.winner, 'projectCountTop3', dataCount.rows) } if (dataAmount.rows.length) { this.$set(this.sections.winner, 'projectAmountTop3', dataAmount.rows) } }, toAnalysisPage: function () { this.rid = '' this.analysis.loaded = false this.filtersPageShow = true }, moneyUnit (num, type, lv) { const m = utils.moneyUnit(num, type, lv) let unit = String(m).match(/[\u4e00-\u9fa5]/g) if (unit && Array.isArray(unit)) { unit = unit.join('') } else { unit = '' } let count = '' if (unit) { count = m.replace(unit, '') - 0 } return { unit, count } }, anchorTo (item) { // if (!item.top) return var offsetTop = item.top || 0 this.activeDimension = item.id this.$nextTick(function () { $('.search-result > .j-main')[0].scrollTop = offsetTop }) }, showSetKeyTip: function () { this.notSetKey = true }, setKeyTip: function () { this.showDialog({ title: '', message: '分析内容为您订阅的关键词组,您
当前尚未订阅,请前往完善', className: 'j-confirm-dialog text-center', showConfirmButton: true, showCancelButton: true, confirmButtonText: '订阅管理', confirmButtonColor: '#2abed1' }).then(() => { if (this.isSubCount) { // 提示联系管理员 this.showToast('请联系管理员完善订阅的关键词') // this.showDialog({ // title: '', // message: '请联系管理员完善订阅的关键词', // className: 'j-confirm-dialog text-center', // showConfirmButton: true, // showCancelButton: false, // confirmButtonText: '我知道了', // confirmButtonColor: '#2abed1' // }) } else { this.toSubManage() } }) }, toSubManageButtonClick: function () { if (this.isSubCount) { this.showToast('请联系管理员完善订阅的关键词') } else { this.toSubManage() } }, toSubManage: function () { this.isWeixin = utils.isWeiXinBrowser let rootlink = 'f' if (this.powerInfo.memberStatus > 0) { rootlink = 'm' } else if (this.powerInfo.vipStatus > 0) { rootlink = 'v' } else { rootlink = 'f' } if(this.isWeixin) { location.href = '/front/vipsubscribe/toSetKeyWordPage?vSwitch=' + rootlink } else { location.href = '/jyapp/vipsubscribe/toSetKeyWordPage?vSwitch=' + rootlink } }, toArticleContent (item) { this.saveState() location.href = `/jyapp/article/content/${item._id}.html` }, toPortrait (id, type) { if (!type || !id) return this.saveState() if (type === 'winner') { location.href = `./ent_portrait?eId=${id}` } else if (type === 'buyer') { location.href = `./unit_portrayal?entName=${id}` } } } })