123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311 |
- // pages/liveBoard/index.js
- import * as echarts from '../../components/ec-canvas/echarts';
- const app = getApp()
- Page({
- //页面的初始数据
- data: {
- time_arr: {
- 'liveDetailTime':null,
- 'ShowGoodsTime':null,
- 'todayShowDetailTime':null,
- 'getRewardTime':null,
- 'getVulgarTycoonTime':null,
- 'getbarrageListTime':null,
- 'getGiftListTime':null},
- live_stream_id: "",
- detailInfo:{},
- ec: {
- lazyLoad: true
- },
- goodsTrendInfo:{
- isCommoditySales:false,
- isRewardTrend:false
- },
- goodsListInfo:{},
- barrageData:{
- list:[],
- total:-1,
- barrage_direction:'top',
- barrage_marquee:0
- },
- giftData:{
- list:[],
- total:-1
- },
- vulgarTycoonData:{//土豪数据
- list:[]
- },
- goodsStatisticsData:{//商品趋势图
- checkDrawPie:1,
- checkPriceTrend:1,
- checkChannelTrend:1
- },
- barrageTime:10000,//弹幕轮训时间10s
- otherTime:30000,//其他轮训时间30s
- isLiveOne:false,//是否是第一次进入此次直播展板
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- console.log('onLoad')
- console.log(options)
- this.setData({
- 'live_stream_id': options.live_stream_id,
- 'user_id': options.user_id,
- })
- this.liveDetail();
- },
- onShow: function () {
- if(this.data.live_stream_id == ''){
- return;
- }
- console.log('onShow')
- for(var i in this.data.time_arr){
- clearTimeout(this.data.time_arr[i])
- }
- this.liveDetail();
- },
- getStatus(){//判断弹幕是否开启
- app.func.req('/api/kwai/barrageScrapeStatus','post',{
- 'liveStreamId':this.data.live_stream_id,
- 'user_id':this.data.user_id
- },(res) => {
- if(res&& res.errno == 0){
- if(res.rst.barrageScrapeStatus!=2){//爬取中:2 爬取开始或结束:0
- this.addBarrageScrape()//开启弹幕爬取
- }else if(res.rst.hasBarrage){//是否开启过弹幕监测,为true时开启过
- this.getbarrageList();
- this.getGiftList();
- }
- }else {
- }
- },(err)=>{
- console.log(err)
- })
- },
- addBarrageScrape() {// 开启弹幕监测
- app.func.req('/api/kwai/addBarrageScrape','post',{
- 'liveStreamId':this.data.live_stream_id
- },(res) => {
- if(res.auno == 4403 || res.errno == 4003){
- this.setData({
- barrageData:Object.assign(this.data.barrageData,{'hasAuno':true})
- })
- this.setData({
- giftData:Object.assign(this.data.giftData,{'hasAuno':true})
- })
- return;
- }
- if(res&& res.errno == 0){
- this.getbarrageList();
- this.getGiftList();
- }else if(res.errno!=4003){
- wx.showToast({
- title: '弹幕开启失败!',
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- console.log(err)
- })
- },
- liveDetail(){//直播详情
- wx.showLoading({
- title: '加载中',
- })
- var that = this;
- app.func.req('/v2/api/show/showDetailInfo','get',{
- 'live_stream_id':this.data.live_stream_id,
- 'user_id':this.data.user_id
- },(res) => {
- if(res && res.errno == 0){
- //成功
- var data = res.rst;
- if(data.minute){
- data = Object.assign(data, {'minutes_CN':this.formatDuring(data.minute)})
- }
- this.setData({
- detailInfo: data
- })
- if(!this.data.isLiveOne){
- console.log('第一次进入此次直播展板')
- this.todayShowDetail();
- this.ShowGoods();
- this.getReward();
- this.getVulgarTycoon();
- this.getStatus();//判断弹幕是否开启
- }
- this.setData({
- isLiveOne:true
- })
- this.userGoodsStatistics();//数据趋势
- this.timeOut('liveDetailTime',this.data.otherTime,'liveDetail')
- }else{
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- wx.hideLoading()
- this.timeOut('liveDetailTime',this.data.otherTime,'liveDetail')
- })
- },
- ShowGoods(){// 直播商品列表
- var that = this;
- app.func.req('/v2/api/kwai/showGoods','post',{
- 'page': 1,
- 'user_id':'',
- 'pagesize': 999,
- 'name':'',
- 'stime':'',
- 'etime':'',
- 'top_cid': 0,//分类id
- 'title':'',
- 'commodity_id':'',
- 'live_stream_id': this.data.live_stream_id,
- 'user_id': this.data.user_id,
- 'sort':5 //上架时间
- },(res) => {
- if(res.auno == 4403 || res.errno == 4003){
- this.setData({
- goodsListInfo:Object.assign(this.data.goodsListInfo,{'hasAuno':true})
- })
- return;
- }
- if(res&& res.errno == 0){
- var data=res.rst.data;
- this.setData({
- goodsListInfo:Object.assign(this.data.goodsListInfo,{'goodsList':data})
- })
- this.timeOut('ShowGoodsTime',this.data.otherTime,'ShowGoods')
- }else if(res.errno!=4003){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- this.timeOut('ShowGoodsTime',this.data.otherTime,'ShowGoods')
- })
- },
- todayShowDetail() {// 直播趋势接口
- // clearTimeout(this.timerTrend)
- app.func.req('/api/kwai/todayShowDetail','post',{
- 'liveStreamId':this.data.live_stream_id,
- 'user_id':this.data.user_id,
- },(res) => {
- if(res.auno==4403||res.errno==4003) {
- this.setData({
- goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'hasAuno':true})
- })
- return
- }
- if (res && res.errno == 0) {
- var watching_count_record = res.rst?res.rst.watching_count_record : {}; //在线人数曲线
- var watching_count_record_arr = { keyes: [], value: [] };
- for (let item in watching_count_record) {
- watching_count_record_arr.keyes.push(item);
- watching_count_record_arr.value.push(watching_count_record[item]);
- }
- var like_count_record = res.rst?res.rst.like_count_record : {}; //点赞数
- var like_count_record_arr = { keyes: [], value: [] };
- for (let item in like_count_record) {
- like_count_record_arr.keyes.push(item);
- like_count_record_arr.value.push(like_count_record[item]);
- }
- var reward_count_record = res.rst?res.rst.reward_count_record : {}; //打赏数
- var reward_count_record_arr = { keyes: [], value: [] };
- for (let item in reward_count_record) {
- reward_count_record_arr.keyes.push(item);
- reward_count_record_arr.value.push(reward_count_record[item]);
- }
- var live_commodity_sum_record = res.rst?res.rst.live_commodity_sum_record : {}; //商品销量
- this.setData({
- goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'isCommoditySales':Object.keys(live_commodity_sum_record).length==0})
- })
- var live_commodity_sum_record_arr = { keyes: [], value: [] };
- for (var item in live_commodity_sum_record) {
- live_commodity_sum_record_arr.keyes.push(item);
- live_commodity_sum_record_arr.value.push(
- live_commodity_sum_record[item]
- );
- }
- if(!this.data.goodsTrendInfo.isCommoditySales){
- this.CommoditySales(live_commodity_sum_record_arr); //商品销量
- }
- this.OnlineNumber(watching_count_record_arr); //在线人数
- this.timeOut('todayShowDetailTime',this.data.otherTime,'todayShowDetail')
- } else if(res.errno!=4003){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- this.timeOut('todayShowDetailTime',this.data.otherTime,'todayShowDetail')
- });
- },
- CommoditySales(data) {//商品销量曲线
- var echartsComponnet = this.selectComponent('#commoditySales')
- echartsComponnet.init((canvas, width, height, dpr) => {
- // 初始化图表
- const Chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- var _this = this;
- var option = {
- tooltip: {
- trigger: "axis",
- formatter: function(params) {
- var result = params[0].name + "\n";
- params.forEach((item,index)=>{
- result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
- })
- return result;
- }
- },
- grid: {
- left: "6%",
- right: "8%",
- bottom: "0",
- top: "5%",
- bottom: "5%",
- containLabel: true
- },
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- data: data.keyes.map((item) => {
- return item.split(" ")[1]
- }),
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- }
- },
- axisTick: { // X轴线 刻度线
- show: false,
- length: 10,
- lineStyle: {
- color: 'red',
- type: 'solid',
- width: 2
- }
- },
- }
- ],
- yAxis: [
- {
- type: "value",
- splitLine:{
- show: true, // X轴线 颜色类型的修改
- lineStyle: {
- type: 'solid',
- color: '#4E588A'
- }
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- },
- formatter: function(params) {
- var result = params;
- return app.func.NumberHandle(result);
- }
- },
- }
- ],
- series: [
- {
- name: "商品销量",
- type: "line",
- itemStyle: {
- normal: {
- color: '#83FFF4',
- // borderColor: "#83FFF4" //拐点边框颜色
- }
- },
- smooth: true,
- // smooth: 0.6,
- symbol: "none",
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(41,244,241,.23)' // 0% 处的颜色
- }, {
- offset: 1, color: 'rgba(47,74,166,.33)' // 100% 处的颜色
- }],
- global: false // 缺省为 false
- }
- },
- data: data.value
- }
- ]
- };
- Chart.setOption(option);
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return Chart;
- });
- },
- OnlineNumber(data) {//在线人数曲线
- var echartsComponnet = this.selectComponent('#onlineNumber')
- echartsComponnet.init((canvas, width, height, dpr) => {
- // 初始化图表
- const Chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- var _this = this;
- var option = {
- tooltip: {
- trigger: "axis",
- formatter: function(params) {
- var result = params[0].name + "\n";
- params.forEach((item,index)=>{
- result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
- })
- return result;
- }
- },
- grid: {
- left: "6%",
- right: "8%",
- bottom: "0",
- top: "5%",
- bottom: "5%",
- containLabel: true
- },
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- data: data.keyes.map((item) => {
- return item.split(" ")[1]
- }),
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- }
- },
- axisTick: { // X轴线 刻度线
- show: false,
- length: 10,
- lineStyle: {
- color: 'red',
- type: 'solid',
- width: 2
- }
- },
- }
- ],
- yAxis: [
- {
- type: "value",
- splitLine:{
- show: true, // X轴线 颜色类型的修改
- lineStyle: {
- type: 'solid',
- color: '#4E588A'
- }
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- },
- formatter: function(params) {
- var result = params;
- return app.func.NumberHandle(result);
- }
- },
- }
- ],
- series: [
- {
- name: "在线人数",
- type: "line",
- itemStyle: {
- normal: {
- color: '#83FFF4',
- // borderColor: "#83FFF4" //拐点边框颜色
- }
- },
- smooth: true,
- // smooth: 0.6,
- symbol: "none",
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(41,244,241,.23)' // 0% 处的颜色
- }, {
- offset: 1, color: 'rgba(47,74,166,.33)' // 100% 处的颜色
- }],
- global: false // 缺省为 false
- }
- },
- data: data.value
- }
- ]
- };
- Chart.setOption(option);
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return Chart;
- });
- },
- getReward() {//送礼榜单趋势接口
- app.func.req('/v2/api/show/showtopinfo','get',{
- 'show_id':this.data.live_stream_id,
- 'user_id':this.data.user_id,
- },(res) => {
- if(res.auno==4403||res.errno==4003) {
- this.setData({
- goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'hasAuno2':true})
- })
- return;
- }
- if(res&&res.errno==0) {
- var data=res.rst
- var rewardObj = {
- timeArr: [],
- incrCount: [],
- incrSum: [],
- countArr: [],
- sumArr: []
- }
- data.forEach((item) => {
- rewardObj.timeArr.push(item.count_at);
- rewardObj.incrCount.push(item.new_reward_count);
- rewardObj.incrSum.push(item.new_reward_sum);
- rewardObj.countArr.push(item.reward_count);
- rewardObj.sumArr.push(item.reward_sum);
- })
- this.setData({
- goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'isRewardTrend':rewardObj.timeArr.length==0})
- })
- this.drawReward(rewardObj);
- this.timeOut('getRewardTime',this.data.otherTime,'getReward')
- }else if(res.errno != '4003' && res.errno != '4403'){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- this.timeOut('getRewardTime',this.data.otherTime,'getReward')
- })
- },
- drawReward(data) {//打赏趋势曲线
- var rewardObj = data;
- var echartsComponnet = this.selectComponent('#rewardNumber')
- echartsComponnet.init((canvas, width, height, dpr) => {
- // 初始化图表
- const Chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- var _this = this;
- var option = {
- tooltip: {
- trigger: "axis",
- formatter: function(params) {
- var result = params[0].name + "\n";
- params.forEach((item,index)=>{
- result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
- })
- return result;
- }
- },
- grid: {
- left: "6%",
- right: "8%",
- bottom: "0",
- top: "5%",
- bottom: "5%",
- containLabel: true
- },
- xAxis: [
- {
- type: "category",
- boundaryGap: false,
- data: rewardObj.timeArr.map((item) => {
- return item.split(" ")[1];
- }),
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- }
- },
- axisTick: { // X轴线 刻度线
- show: false,
- length: 10,
- lineStyle: {
- color: 'red',
- type: 'solid',
- width: 2
- }
- },
- }
- ],
- yAxis: [
- {
- splitLine:{
- show: true, // X轴线 颜色类型的修改
- lineStyle: {
- type: 'solid',
- color: '#4E588A'
- }
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- },
- formatter: function(params) {
- var result = params;
- return app.func.NumberHandle(result);
- }
- },
- }
- ],
- series: [
- {
- name: "打赏金额",
- type: "line",
- itemStyle: {
- normal: {
- color: '#83FFF4',
- }
- },
- smooth: true,
- // smooth: 0.6,
- symbol: "none",
- areaStyle: {
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: 'rgba(41,244,241,.23)' // 0% 处的颜色
- }, {
- offset: 1, color: 'rgba(47,74,166,.33)' // 100% 处的颜色
- }],
- global: false // 缺省为 false
- }
- },
- data: rewardObj.sumArr
- }
- ]
- };
- Chart.setOption(option);
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return Chart;
- });
- },
- getbarrageList() {// 弹幕列表
- app.func.req('/api/kwai/barrageList','post',{
- 'liveStreamId':this.data.live_stream_id,
- 'user_id': this.data.user_id,
- 'type': 1,//左侧弹幕
- 'page': 1,
- 'pagesize': 100
- },(res) => {
- if(res.auno == 4403 || res.errno == 4003){
- this.setData({
- barrageData:Object.assign(this.data.barrageData,{'hasAuno':true})
- })
- }
- if(res&& res.errno == 0){
- var arr = res.rst.data;
- var obj = {};
- arr = arr.reduce(function(item,next){
- obj[next.created_at+next.kwai_id]?'':obj[next.created_at+next.kwai_id] = true&&item.push(next);
- return item;
- },[]);
- this.setData({
- barrageData:Object.assign(this.data.barrageData,{
- list: arr.reverse(),
- total:res.rst.pageInfo.total
- })
- })
- this.barrageAnimation('contentDiv1','contentTrDiv1','animationData')
- this.timeOut('getbarrageListTime',this.data.barrageTime, 'getbarrageList')
- }else if(res.errno!=4003){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- this.timeOut('getbarrageListTime',this.data.barrageTime,'getbarrageList')
- })
- },
- getGiftList(){//礼物弹幕列表
- app.func.req('/api/kwai/barrageList','post',{
- 'liveStreamId':this.data.live_stream_id,
- 'user_id': this.data.user_id,
- 'type': 2,//礼物弹幕
- 'page': 1,
- 'pagesize': 100
- },(res) => {
- if(res.auno == 4403 || res.errno == 4003){
- this.setData({
- giftData:Object.assign(this.data.giftData,{'hasAuno':true})
- })
- }
- if(res&& res.errno == 0){
- var arr = res.rst.data;
- var obj = {};
- arr = arr.reduce(function(item,next){
- obj[next.created_at+next.kwai_id]?'':obj[next.created_at+next.kwai_id] = true&&item.push(next);
- return item;
- },[]);
- this.setData({
- giftData:Object.assign(this.data.giftData,{
- list: arr.reverse(),
- total:res.rst.pageInfo.total
- })
- })
- this.barrageAnimation('contentDiv2','contentTrDiv2','animationData2')
- this.timeOut('getGiftListTime',this.data.barrageTime,'getGiftList')
- }else if(res.errno!=4003){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- this.timeOut('getGiftListTime',this.data.barrageTime,'getGiftList')
- })
- },
- getVulgarTycoon() {//土豪送礼列表
- app.func.req('/v2/api/show/showtopuserinfo','get',{
- 'show_id':this.data.live_stream_id,
- 'user_id':this.data.user_id,
- },(res) => {
- if(res.auno == 4403 || res.errno == 4003){
- this.setData({
- vulgarTycoonData:Object.assign(this.data.vulgarTycoonData,{'hasAuno':true})
- })
- return;
- }
- if(res&&res.errno==0) {
- var data=res.rst
- this.setData({
- vulgarTycoonData:{
- list:data
- }
- })
- this.timeOut('getVulgarTycoonTime',this.data.otherTime,'getVulgarTycoon')
- }else if(res.errno!=4003){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- this.timeOut('getVulgarTycoonTime',this.data.otherTime,'getVulgarTycoon')
- })
- },
- userGoodsStatistics() {//商品统计--趋势
- if(this.data.goodsStatisticsData.hasAuno){//防止刷新直播详情接口的时候,趋势接口在无权限的时候跟着更新,浪费资源
- return;
- }
- app.func.req('/v2/api/kwai/goodsStatistics','post',{
- 'user_id':this.data.detailInfo.user_id,
- 'live_stream_id':this.data.live_stream_id
- },(res) => {
- wx.hideLoading()
- if(res.auno==4403||res.errno==4003) {
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'hasAuno':true})
- })
- }
- this.dataObj = res.rst;
- if(res&&res.errno==0) {
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'dataObj':res.rst})
- })
- if(!res.rst.category||res.rst.category.length == 0){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'goodsStatisticsFlag':false})
- })
- }else {
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'goodsStatisticsFlag':true})
- })
- var categoryName = [],categoryPercent = [];
- res.rst.category.forEach((item,index) => {
- categoryName.push(item.name)
- categoryPercent.push({'value':item.percent,'name':item.name})
- });
- }
- var priceName = [],priceData = [];
- if(res.rst.price&&res.rst.price.length){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'priceEchartsLoding':true})
- })
- res.rst.price.forEach((item,index) => {
- priceName.push(item.price)
- priceData.push(item.percent)
- });
- }else{
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'priceEchartsLoding':false})
- })
- }
- if(!res.rst.channel||res.rst.channel.length == 0){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'channelEchartsLoding':false})
- })
- }else {
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'channelEchartsLoding':true})
- })
- var channelName = [],channelData = [];
- res.rst.channel.forEach((item,index) => {
- channelName.push(item.name)
- channelData.push({'value':item.percent,'name':item.name})
- });
- }
- if(this.data.goodsStatisticsData.goodsStatisticsFlag){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'checkDrawPie':1
- })
- })
- this.drawPie(categoryName,categoryPercent)//类别分析
- }
- if(this.data.goodsStatisticsData.priceEchartsLoding){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'checkPriceTrend':1
- })
- })
- this.drawPrice(priceName,priceData)//价格分布
- }
- if(this.data.goodsStatisticsData.channelEchartsLoding){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'checkChannelTrend':1
- })
- })
- this.drawChannel(channelName,channelData)//商品来源分布
- }
- }else if(res.errno != 4003){
- wx.showToast({
- title: res.err,
- icon: 'none',
- duration: 2000
- })
- }
- },(err)=>{
- wx.hideLoading()
- })
- },
- drawPie(name,data) {//分类占比
- var colorArr = ['#2296F3','#FF5A7B','#BCA4FC',"#F6564A","#FF936B","#9CCCFF","#FFACB8","#B7EEA8","#FFB89D","#FCE500","#9F9F9F",'#78ADF9'];
- for(var i = 0; i<data.length; i++){
- if(i>=colorArr.length){
- colorArr.push('rgba(' + [
- Math.round(Math.random() * 255),
- Math.round(Math.random() * 200),
- Math.round(Math.random() * 160),
- 0.8
- ].join(',') + ')')
- }
- }
- data = data.splice(0,12)
- var echartsComponnet = this.selectComponent('#typeDis')
- echartsComponnet.init((canvas, width, height, dpr) => {
- // 初始化图表
- const Chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- var option = {
- color:colorArr,
- tooltip: {
- show: true,
- formatter: "{b}: {c}%"
- },
- grid: {
- top: '0%',
- left:'10%',
- right:'10%',
- bottom: '30%'
- },
- series: [{
- center: ['50%', '50%'],
- radius: ['40%', '60%'],
- minShowLabelAngle: 4,
- minAngle: 18,//最小的扇区角度(0 ~ 360),用于防止某个值过小导致扇区太小影响交互
- avoidLabelOverlap:true,////是否启用防止标签重叠策略
- label: {
- normal: {
- formatter(v) {
- let text = v.name + '' + Math.round(v.percent)+'%'
- return text
- },//文字换行
- show: true,
- position: 'outside',
- }
- },
- labelLine: {
- show: true
- },
- label: {
- normal: {
- formatter(v) {
- let text = v.name
- return text
- },//文字换行
- show: true,
- position: 'outside',
- }
- },
- avoidLabelOverlap: false,
- type: 'pie',
- data: data
-
- }]
- };
- Chart.setOption(option);
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return Chart;
- });
- },
- drawPrice(name,data) {//价格分布
- var echartsComponnet = this.selectComponent('#priceDis')
- echartsComponnet.init((canvas, width, height, dpr) => {
- // 初始化图表
- const Chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- var option = {
- color:["#57C2FF"],
- tooltip: {
- trigger: 'axis',
- formatter: "{b}: {c}%",
- },//展示数据
- grid: {
- left: "6%",
- right: "8%",
- bottom: "0",
- top: "5%",
- bottom: "5%",
- containLabel: true
- },
- xAxis:[
- {
- type:"category",
- data:name,
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- }
- },
- axisTick: { // X轴线 刻度线
- show: false,
- length: 10,
- lineStyle: {
- color: 'red',
- type: 'solid',
- width: 2
- }
- },
- }
- ],
- yAxis: [
- {
- type: "value",
- splitLine:{
- show: true, // X轴线 颜色类型的修改
- lineStyle: {
- type: 'solid',
- color: '#4E588A'
- }
- },
- axisLine: {
- show: false
- },
- axisTick: {
- show: false
- },
- axisLabel: {
- show: true,
- textStyle: {
- color: '#fff'
- }
- },
- }
- ],
- series: [{
- type: 'bar',
- barWidth: '20',
- data:data,
- itemStyle:{
- // color:'#78ADF9',
- color: {
- type: 'linear',
- x: 0,
- y: 0,
- x2: 0,
- y2: 1,
- colorStops: [{
- offset: 0, color: '#53FAF9' // 0% 处的颜色
- }, {
- offset: 1, color: '#1E56FE' // 100% 处的颜色
- }],
- global: false // 缺省为 false
- },
- barBorderRadius: [4,4,4,4],
- borderType:'dotted'
- }
- }]
- };
- Chart.setOption(option);
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return Chart;
- });
- },
- drawChannel(name,data) {//商品来源分析
- var colorArr = ['#2296F3','#FF5A7B','#BCA4FC',"#F6564A","#FF936B","#9CCCFF","#FFACB8","#B7EEA8","#FFB89D","#FCE500","#9F9F9F",'#78ADF9'];
- for(var i = 0; i<data.length; i++){
- if(i>=colorArr.length){
- colorArr.push('rgba(' + [
- Math.round(Math.random() * 255),
- Math.round(Math.random() * 200),
- Math.round(Math.random() * 160),
- 0.8
- ].join(',') + ')')
- }
- }
- data = data.splice(0,12)
- var echartsComponnet = this.selectComponent('#channel')
- echartsComponnet.init((canvas, width, height, dpr) => {
- // 初始化图表
- const Chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr
- });
- var option = {
- color:colorArr,
- tooltip: {
- show: true,
- formatter: "{b}: {c}%"
- },
- grid: {
- top: '0%',
- left:'10%',
- right:'10%',
- bottom: '30%'
- },
- series: [{
- center: ['50%', '50%'],
- radius: ['40%', '60%'],
- minShowLabelAngle: 4,
- minAngle: 18,//最小的扇区角度(0 ~ 360),用于防止某个值过小导致扇区太小影响交互
- avoidLabelOverlap:true,////是否启用防止标签重叠策略
- label: {
- normal: {
- formatter(v) {
- let text = v.name + '' + Math.round(v.percent)+'%'
- return text
- },//文字换行
- show: true,
- position: 'outside',
- }
- },
- labelLine: {
- show: true
- },
- label: {
- normal: {
- formatter(v) {
- // let text = v.name + '' + Math.round(v.percent)+'%'
- let text = v.name
- return text
- },//文字换行
- show: true,
- position: 'outside',
- }
- },
- avoidLabelOverlap: false,
- type: 'pie',
- data: data
-
- }]
- };
- Chart.setOption(option);
- // 注意这里一定要返回 chart 实例,否则会影响事件处理等
- return Chart;
- });
- },
- checkDrawPie(e) {//分类占比 type 切换
- var checkType = e.currentTarget.dataset.type;
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'checkDrawPie':checkType
- })
- })
- if(this.data.goodsStatisticsData.hasAuno){
- return
- }
- if(!this.data.goodsStatisticsData.dataObj.category||this.data.goodsStatisticsData.dataObj.category.length == 0){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'goodsStatisticsFlag':false
- })
- })
- }else {
- var categoryName = [],categoryPercent = [];
- var data = checkType==1?this.data.goodsStatisticsData.dataObj.category:checkType==2?this.data.goodsStatisticsData.dataObj.categoryBySellCount:this.data.goodsStatisticsData.dataObj.categoryBySellMoney
- data.forEach((item,index) => {
- categoryName.push(item.name)
- categoryPercent.push({'value':item.percent,'name':item.name})
- });
- }
- if(this.data.goodsStatisticsData.goodsStatisticsFlag){
- this.drawPie(categoryName,categoryPercent)//类别分析
- }
- },
- checkPriceTrend(e) {//价格分布 type 切换
- var priceType = e.currentTarget.dataset.type;
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'checkPriceTrend':priceType
- })
- })
- if(this.data.goodsStatisticsData.hasAuno){
- return
- }
- var priceName = [],priceData = [];
- if(this.data.goodsStatisticsData.dataObj.price&&this.data.goodsStatisticsData.dataObj.price.length){
- var data = priceType==1?this.data.goodsStatisticsData.dataObj.price:priceType==2?this.data.goodsStatisticsData.dataObj.priceBySellCount:this.data.goodsStatisticsData.dataObj.priceBySellMoney
- data.forEach((item,index) => {
- priceName.push(item.price)
- priceData.push(item.percent)
- });
- }else{
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'priceEchartsLoding':false
- })
- })
- }
- if(this.data.goodsStatisticsData.priceEchartsLoding){
- this.drawPrice(priceName,priceData)
- }
- },
- checkChannelTrend(e) {//商品来源分布 type 切换
- var sourceType = e.currentTarget.dataset.type;
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'checkChannelTrend':sourceType
- })
- })
- if(this.data.goodsStatisticsData.hasAuno){
- return
- }
- if(!this.data.goodsStatisticsData.dataObj.channel||this.data.goodsStatisticsData.dataObj.channel.length == 0){
- this.setData({
- goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
- 'channelEchartsLoding':false
- })
- })
- }else {
- var data = sourceType==1?this.data.goodsStatisticsData.dataObj.channelBySellCount:sourceType==2?this.data.goodsStatisticsData.dataObj.channelBySellCount:this.data.goodsStatisticsData.dataObj.channelBySellMoney
- var channelName = [],channelData = [];
- data.forEach((item,index) => {
- channelName.push(item.name)
- channelData.push({'value':item.percent,'name':item.name})
- });
- }
- if(this.data.goodsStatisticsData.channelEchartsLoding){
- this.drawChannel(channelName,channelData)
- }
- },
- // 将毫秒转换成几天
- formatDuring(mss) {
- // 分钟*60*1000=毫秒
- mss = mss*60*1000;
- var days = parseInt(mss / (1000 * 60 * 60 * 24))+'天';
- var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))+'小时';
- var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60))+'分钟';
- return (parseInt(days)>0?days:'') + (parseInt(hours)>0?hours:'') + (parseInt(minutes)>0?minutes:'');
- },
- timeOut(timer_name,time,fun){//公共开启定时器方法
- if(this.data.detailInfo.enable == 1){
- clearTimeout(this.data.time_arr[timer_name])
- var time_arr = this.data.time_arr;
- time_arr[timer_name] = setTimeout(()=>{
- this[fun]()
- },time)
- this.setData({
- time_arr:time_arr
- })
- }
- },
- util: function (obj) {//弹幕动画效果
- var continueTime = (parseInt(obj.list / obj.container) + 1) * 1500;
- var setIntervalTime = 50 + continueTime;
- var animation = wx.createAnimation({
- duration: 200, //动画时长
- timingFunction: "linear", //线性
- delay: 0 //0则不延迟
- });
- this.animation = animation;
- animation.translateY(10).step({ duration: 50, timingFunction: 'step-start' }).translateY(-obj.list + obj.container).step({ duration: continueTime });
- this.setData({
- [obj.animation_name]: animation.export()
- })
- setTimeout(() => {
- animation.translateY(0).step({ duration: 50, timingFunction: 'step-start' })
- this.setData({
- [obj.animation_name]: animation.export()
- })
- }, setIntervalTime)
- },
- barrageAnimation(frame,scroll_frame,animation) {
- if(this.data.detailInfo.enable != 1){
- return;
- }
- var obj = new Object();
- //创建节点选择器
- var query = wx.createSelectorQuery();
- query.select('.'+frame).boundingClientRect()
- query.select('.'+scroll_frame).boundingClientRect()
- query.exec((res) => {
- obj.container = res[0].height; // 框的height
- obj.list = res[1].height; // list的height
- obj.animation_name = animation;//动画的名称
- this.util(obj);
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- console.log('onHide')
- for(var i in this.data.time_arr){
- clearTimeout(this.data.time_arr[i])
- }
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- console.log('onUnload')
- console.log(this.data.time_arr)
- for(var i in this.data.time_arr){
- clearTimeout(this.data.time_arr[i])
- }
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|