问星数据小程序

index.js 41KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311
  1. // pages/liveBoard/index.js
  2. import * as echarts from '../../components/ec-canvas/echarts';
  3. const app = getApp()
  4. Page({
  5. //页面的初始数据
  6. data: {
  7. time_arr: {
  8. 'liveDetailTime':null,
  9. 'ShowGoodsTime':null,
  10. 'todayShowDetailTime':null,
  11. 'getRewardTime':null,
  12. 'getVulgarTycoonTime':null,
  13. 'getbarrageListTime':null,
  14. 'getGiftListTime':null},
  15. live_stream_id: "",
  16. detailInfo:{},
  17. ec: {
  18. lazyLoad: true
  19. },
  20. goodsTrendInfo:{
  21. isCommoditySales:false,
  22. isRewardTrend:false
  23. },
  24. goodsListInfo:{},
  25. barrageData:{
  26. list:[],
  27. total:-1,
  28. barrage_direction:'top',
  29. barrage_marquee:0
  30. },
  31. giftData:{
  32. list:[],
  33. total:-1
  34. },
  35. vulgarTycoonData:{//土豪数据
  36. list:[]
  37. },
  38. goodsStatisticsData:{//商品趋势图
  39. checkDrawPie:1,
  40. checkPriceTrend:1,
  41. checkChannelTrend:1
  42. },
  43. barrageTime:10000,//弹幕轮训时间10s
  44. otherTime:30000,//其他轮训时间30s
  45. isLiveOne:false,//是否是第一次进入此次直播展板
  46. },
  47. /**
  48. * 生命周期函数--监听页面加载
  49. */
  50. onLoad: function (options) {
  51. console.log('onLoad')
  52. console.log(options)
  53. this.setData({
  54. 'live_stream_id': options.live_stream_id,
  55. 'user_id': options.user_id,
  56. })
  57. this.liveDetail();
  58. },
  59. onShow: function () {
  60. if(this.data.live_stream_id == ''){
  61. return;
  62. }
  63. console.log('onShow')
  64. for(var i in this.data.time_arr){
  65. clearTimeout(this.data.time_arr[i])
  66. }
  67. this.liveDetail();
  68. },
  69. getStatus(){//判断弹幕是否开启
  70. app.func.req('/api/kwai/barrageScrapeStatus','post',{
  71. 'liveStreamId':this.data.live_stream_id,
  72. 'user_id':this.data.user_id
  73. },(res) => {
  74. if(res&& res.errno == 0){
  75. if(res.rst.barrageScrapeStatus!=2){//爬取中:2 爬取开始或结束:0
  76. this.addBarrageScrape()//开启弹幕爬取
  77. }else if(res.rst.hasBarrage){//是否开启过弹幕监测,为true时开启过
  78. this.getbarrageList();
  79. this.getGiftList();
  80. }
  81. }else {
  82. }
  83. },(err)=>{
  84. console.log(err)
  85. })
  86. },
  87. addBarrageScrape() {// 开启弹幕监测
  88. app.func.req('/api/kwai/addBarrageScrape','post',{
  89. 'liveStreamId':this.data.live_stream_id
  90. },(res) => {
  91. if(res.auno == 4403 || res.errno == 4003){
  92. this.setData({
  93. barrageData:Object.assign(this.data.barrageData,{'hasAuno':true})
  94. })
  95. this.setData({
  96. giftData:Object.assign(this.data.giftData,{'hasAuno':true})
  97. })
  98. return;
  99. }
  100. if(res&& res.errno == 0){
  101. this.getbarrageList();
  102. this.getGiftList();
  103. }else if(res.errno!=4003){
  104. wx.showToast({
  105. title: '弹幕开启失败!',
  106. icon: 'none',
  107. duration: 2000
  108. })
  109. }
  110. },(err)=>{
  111. console.log(err)
  112. })
  113. },
  114. liveDetail(){//直播详情
  115. wx.showLoading({
  116. title: '加载中',
  117. })
  118. var that = this;
  119. app.func.req('/v2/api/show/showDetailInfo','get',{
  120. 'live_stream_id':this.data.live_stream_id,
  121. 'user_id':this.data.user_id
  122. },(res) => {
  123. if(res && res.errno == 0){
  124. //成功
  125. var data = res.rst;
  126. if(data.minute){
  127. data = Object.assign(data, {'minutes_CN':this.formatDuring(data.minute)})
  128. }
  129. this.setData({
  130. detailInfo: data
  131. })
  132. if(!this.data.isLiveOne){
  133. console.log('第一次进入此次直播展板')
  134. this.todayShowDetail();
  135. this.ShowGoods();
  136. this.getReward();
  137. this.getVulgarTycoon();
  138. this.getStatus();//判断弹幕是否开启
  139. }
  140. this.setData({
  141. isLiveOne:true
  142. })
  143. this.userGoodsStatistics();//数据趋势
  144. this.timeOut('liveDetailTime',this.data.otherTime,'liveDetail')
  145. }else{
  146. wx.showToast({
  147. title: res.err,
  148. icon: 'none',
  149. duration: 2000
  150. })
  151. }
  152. },(err)=>{
  153. wx.hideLoading()
  154. this.timeOut('liveDetailTime',this.data.otherTime,'liveDetail')
  155. })
  156. },
  157. ShowGoods(){// 直播商品列表
  158. var that = this;
  159. app.func.req('/v2/api/kwai/showGoods','post',{
  160. 'page': 1,
  161. 'user_id':'',
  162. 'pagesize': 999,
  163. 'name':'',
  164. 'stime':'',
  165. 'etime':'',
  166. 'top_cid': 0,//分类id
  167. 'title':'',
  168. 'commodity_id':'',
  169. 'live_stream_id': this.data.live_stream_id,
  170. 'user_id': this.data.user_id,
  171. 'sort':5 //上架时间
  172. },(res) => {
  173. if(res.auno == 4403 || res.errno == 4003){
  174. this.setData({
  175. goodsListInfo:Object.assign(this.data.goodsListInfo,{'hasAuno':true})
  176. })
  177. return;
  178. }
  179. if(res&& res.errno == 0){
  180. var data=res.rst.data;
  181. this.setData({
  182. goodsListInfo:Object.assign(this.data.goodsListInfo,{'goodsList':data})
  183. })
  184. this.timeOut('ShowGoodsTime',this.data.otherTime,'ShowGoods')
  185. }else if(res.errno!=4003){
  186. wx.showToast({
  187. title: res.err,
  188. icon: 'none',
  189. duration: 2000
  190. })
  191. }
  192. },(err)=>{
  193. this.timeOut('ShowGoodsTime',this.data.otherTime,'ShowGoods')
  194. })
  195. },
  196. todayShowDetail() {// 直播趋势接口
  197. // clearTimeout(this.timerTrend)
  198. app.func.req('/api/kwai/todayShowDetail','post',{
  199. 'liveStreamId':this.data.live_stream_id,
  200. 'user_id':this.data.user_id,
  201. },(res) => {
  202. if(res.auno==4403||res.errno==4003) {
  203. this.setData({
  204. goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'hasAuno':true})
  205. })
  206. return
  207. }
  208. if (res && res.errno == 0) {
  209. var watching_count_record = res.rst?res.rst.watching_count_record : {}; //在线人数曲线
  210. var watching_count_record_arr = { keyes: [], value: [] };
  211. for (let item in watching_count_record) {
  212. watching_count_record_arr.keyes.push(item);
  213. watching_count_record_arr.value.push(watching_count_record[item]);
  214. }
  215. var like_count_record = res.rst?res.rst.like_count_record : {}; //点赞数
  216. var like_count_record_arr = { keyes: [], value: [] };
  217. for (let item in like_count_record) {
  218. like_count_record_arr.keyes.push(item);
  219. like_count_record_arr.value.push(like_count_record[item]);
  220. }
  221. var reward_count_record = res.rst?res.rst.reward_count_record : {}; //打赏数
  222. var reward_count_record_arr = { keyes: [], value: [] };
  223. for (let item in reward_count_record) {
  224. reward_count_record_arr.keyes.push(item);
  225. reward_count_record_arr.value.push(reward_count_record[item]);
  226. }
  227. var live_commodity_sum_record = res.rst?res.rst.live_commodity_sum_record : {}; //商品销量
  228. this.setData({
  229. goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'isCommoditySales':Object.keys(live_commodity_sum_record).length==0})
  230. })
  231. var live_commodity_sum_record_arr = { keyes: [], value: [] };
  232. for (var item in live_commodity_sum_record) {
  233. live_commodity_sum_record_arr.keyes.push(item);
  234. live_commodity_sum_record_arr.value.push(
  235. live_commodity_sum_record[item]
  236. );
  237. }
  238. if(!this.data.goodsTrendInfo.isCommoditySales){
  239. this.CommoditySales(live_commodity_sum_record_arr); //商品销量
  240. }
  241. this.OnlineNumber(watching_count_record_arr); //在线人数
  242. this.timeOut('todayShowDetailTime',this.data.otherTime,'todayShowDetail')
  243. } else if(res.errno!=4003){
  244. wx.showToast({
  245. title: res.err,
  246. icon: 'none',
  247. duration: 2000
  248. })
  249. }
  250. },(err)=>{
  251. this.timeOut('todayShowDetailTime',this.data.otherTime,'todayShowDetail')
  252. });
  253. },
  254. CommoditySales(data) {//商品销量曲线
  255. var echartsComponnet = this.selectComponent('#commoditySales')
  256. echartsComponnet.init((canvas, width, height, dpr) => {
  257. // 初始化图表
  258. const Chart = echarts.init(canvas, null, {
  259. width: width,
  260. height: height,
  261. devicePixelRatio: dpr
  262. });
  263. var _this = this;
  264. var option = {
  265. tooltip: {
  266. trigger: "axis",
  267. formatter: function(params) {
  268. var result = params[0].name + "\n";
  269. params.forEach((item,index)=>{
  270. result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
  271. })
  272. return result;
  273. }
  274. },
  275. grid: {
  276. left: "6%",
  277. right: "8%",
  278. bottom: "0",
  279. top: "5%",
  280. bottom: "5%",
  281. containLabel: true
  282. },
  283. xAxis: [
  284. {
  285. type: "category",
  286. boundaryGap: false,
  287. data: data.keyes.map((item) => {
  288. return item.split(" ")[1]
  289. }),
  290. axisLine: {
  291. show: false
  292. },
  293. axisTick: {
  294. show: false
  295. },
  296. axisLabel: {
  297. show: true,
  298. textStyle: {
  299. color: '#fff'
  300. }
  301. },
  302. axisTick: { // X轴线 刻度线
  303. show: false,
  304. length: 10,
  305. lineStyle: {
  306. color: 'red',
  307. type: 'solid',
  308. width: 2
  309. }
  310. },
  311. }
  312. ],
  313. yAxis: [
  314. {
  315. type: "value",
  316. splitLine:{
  317. show: true, // X轴线 颜色类型的修改
  318. lineStyle: {
  319. type: 'solid',
  320. color: '#4E588A'
  321. }
  322. },
  323. axisLine: {
  324. show: false
  325. },
  326. axisTick: {
  327. show: false
  328. },
  329. axisLabel: {
  330. show: true,
  331. textStyle: {
  332. color: '#fff'
  333. },
  334. formatter: function(params) {
  335. var result = params;
  336. return app.func.NumberHandle(result);
  337. }
  338. },
  339. }
  340. ],
  341. series: [
  342. {
  343. name: "商品销量",
  344. type: "line",
  345. itemStyle: {
  346. normal: {
  347. color: '#83FFF4',
  348. // borderColor: "#83FFF4" //拐点边框颜色
  349. }
  350. },
  351. smooth: true,
  352. // smooth: 0.6,
  353. symbol: "none",
  354. areaStyle: {
  355. color: {
  356. type: 'linear',
  357. x: 0,
  358. y: 0,
  359. x2: 0,
  360. y2: 1,
  361. colorStops: [{
  362. offset: 0, color: 'rgba(41,244,241,.23)' // 0% 处的颜色
  363. }, {
  364. offset: 1, color: 'rgba(47,74,166,.33)' // 100% 处的颜色
  365. }],
  366. global: false // 缺省为 false
  367. }
  368. },
  369. data: data.value
  370. }
  371. ]
  372. };
  373. Chart.setOption(option);
  374. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  375. return Chart;
  376. });
  377. },
  378. OnlineNumber(data) {//在线人数曲线
  379. var echartsComponnet = this.selectComponent('#onlineNumber')
  380. echartsComponnet.init((canvas, width, height, dpr) => {
  381. // 初始化图表
  382. const Chart = echarts.init(canvas, null, {
  383. width: width,
  384. height: height,
  385. devicePixelRatio: dpr
  386. });
  387. var _this = this;
  388. var option = {
  389. tooltip: {
  390. trigger: "axis",
  391. formatter: function(params) {
  392. var result = params[0].name + "\n";
  393. params.forEach((item,index)=>{
  394. result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
  395. })
  396. return result;
  397. }
  398. },
  399. grid: {
  400. left: "6%",
  401. right: "8%",
  402. bottom: "0",
  403. top: "5%",
  404. bottom: "5%",
  405. containLabel: true
  406. },
  407. xAxis: [
  408. {
  409. type: "category",
  410. boundaryGap: false,
  411. data: data.keyes.map((item) => {
  412. return item.split(" ")[1]
  413. }),
  414. axisLine: {
  415. show: false
  416. },
  417. axisTick: {
  418. show: false
  419. },
  420. axisLabel: {
  421. show: true,
  422. textStyle: {
  423. color: '#fff'
  424. }
  425. },
  426. axisTick: { // X轴线 刻度线
  427. show: false,
  428. length: 10,
  429. lineStyle: {
  430. color: 'red',
  431. type: 'solid',
  432. width: 2
  433. }
  434. },
  435. }
  436. ],
  437. yAxis: [
  438. {
  439. type: "value",
  440. splitLine:{
  441. show: true, // X轴线 颜色类型的修改
  442. lineStyle: {
  443. type: 'solid',
  444. color: '#4E588A'
  445. }
  446. },
  447. axisLine: {
  448. show: false
  449. },
  450. axisTick: {
  451. show: false
  452. },
  453. axisLabel: {
  454. show: true,
  455. textStyle: {
  456. color: '#fff'
  457. },
  458. formatter: function(params) {
  459. var result = params;
  460. return app.func.NumberHandle(result);
  461. }
  462. },
  463. }
  464. ],
  465. series: [
  466. {
  467. name: "在线人数",
  468. type: "line",
  469. itemStyle: {
  470. normal: {
  471. color: '#83FFF4',
  472. // borderColor: "#83FFF4" //拐点边框颜色
  473. }
  474. },
  475. smooth: true,
  476. // smooth: 0.6,
  477. symbol: "none",
  478. areaStyle: {
  479. color: {
  480. type: 'linear',
  481. x: 0,
  482. y: 0,
  483. x2: 0,
  484. y2: 1,
  485. colorStops: [{
  486. offset: 0, color: 'rgba(41,244,241,.23)' // 0% 处的颜色
  487. }, {
  488. offset: 1, color: 'rgba(47,74,166,.33)' // 100% 处的颜色
  489. }],
  490. global: false // 缺省为 false
  491. }
  492. },
  493. data: data.value
  494. }
  495. ]
  496. };
  497. Chart.setOption(option);
  498. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  499. return Chart;
  500. });
  501. },
  502. getReward() {//送礼榜单趋势接口
  503. app.func.req('/v2/api/show/showtopinfo','get',{
  504. 'show_id':this.data.live_stream_id,
  505. 'user_id':this.data.user_id,
  506. },(res) => {
  507. if(res.auno==4403||res.errno==4003) {
  508. this.setData({
  509. goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'hasAuno2':true})
  510. })
  511. return;
  512. }
  513. if(res&&res.errno==0) {
  514. var data=res.rst
  515. var rewardObj = {
  516. timeArr: [],
  517. incrCount: [],
  518. incrSum: [],
  519. countArr: [],
  520. sumArr: []
  521. }
  522. data.forEach((item) => {
  523. rewardObj.timeArr.push(item.count_at);
  524. rewardObj.incrCount.push(item.new_reward_count);
  525. rewardObj.incrSum.push(item.new_reward_sum);
  526. rewardObj.countArr.push(item.reward_count);
  527. rewardObj.sumArr.push(item.reward_sum);
  528. })
  529. this.setData({
  530. goodsTrendInfo:Object.assign(this.data.goodsTrendInfo,{'isRewardTrend':rewardObj.timeArr.length==0})
  531. })
  532. this.drawReward(rewardObj);
  533. this.timeOut('getRewardTime',this.data.otherTime,'getReward')
  534. }else if(res.errno != '4003' && res.errno != '4403'){
  535. wx.showToast({
  536. title: res.err,
  537. icon: 'none',
  538. duration: 2000
  539. })
  540. }
  541. },(err)=>{
  542. this.timeOut('getRewardTime',this.data.otherTime,'getReward')
  543. })
  544. },
  545. drawReward(data) {//打赏趋势曲线
  546. var rewardObj = data;
  547. var echartsComponnet = this.selectComponent('#rewardNumber')
  548. echartsComponnet.init((canvas, width, height, dpr) => {
  549. // 初始化图表
  550. const Chart = echarts.init(canvas, null, {
  551. width: width,
  552. height: height,
  553. devicePixelRatio: dpr
  554. });
  555. var _this = this;
  556. var option = {
  557. tooltip: {
  558. trigger: "axis",
  559. formatter: function(params) {
  560. var result = params[0].name + "\n";
  561. params.forEach((item,index)=>{
  562. result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
  563. })
  564. return result;
  565. }
  566. },
  567. grid: {
  568. left: "6%",
  569. right: "8%",
  570. bottom: "0",
  571. top: "5%",
  572. bottom: "5%",
  573. containLabel: true
  574. },
  575. xAxis: [
  576. {
  577. type: "category",
  578. boundaryGap: false,
  579. data: rewardObj.timeArr.map((item) => {
  580. return item.split(" ")[1];
  581. }),
  582. axisLine: {
  583. show: false
  584. },
  585. axisTick: {
  586. show: false
  587. },
  588. axisLabel: {
  589. show: true,
  590. textStyle: {
  591. color: '#fff'
  592. }
  593. },
  594. axisTick: { // X轴线 刻度线
  595. show: false,
  596. length: 10,
  597. lineStyle: {
  598. color: 'red',
  599. type: 'solid',
  600. width: 2
  601. }
  602. },
  603. }
  604. ],
  605. yAxis: [
  606. {
  607. splitLine:{
  608. show: true, // X轴线 颜色类型的修改
  609. lineStyle: {
  610. type: 'solid',
  611. color: '#4E588A'
  612. }
  613. },
  614. axisLine: {
  615. show: false
  616. },
  617. axisTick: {
  618. show: false
  619. },
  620. axisLabel: {
  621. show: true,
  622. textStyle: {
  623. color: '#fff'
  624. },
  625. formatter: function(params) {
  626. var result = params;
  627. return app.func.NumberHandle(result);
  628. }
  629. },
  630. }
  631. ],
  632. series: [
  633. {
  634. name: "打赏金额",
  635. type: "line",
  636. itemStyle: {
  637. normal: {
  638. color: '#83FFF4',
  639. }
  640. },
  641. smooth: true,
  642. // smooth: 0.6,
  643. symbol: "none",
  644. areaStyle: {
  645. color: {
  646. type: 'linear',
  647. x: 0,
  648. y: 0,
  649. x2: 0,
  650. y2: 1,
  651. colorStops: [{
  652. offset: 0, color: 'rgba(41,244,241,.23)' // 0% 处的颜色
  653. }, {
  654. offset: 1, color: 'rgba(47,74,166,.33)' // 100% 处的颜色
  655. }],
  656. global: false // 缺省为 false
  657. }
  658. },
  659. data: rewardObj.sumArr
  660. }
  661. ]
  662. };
  663. Chart.setOption(option);
  664. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  665. return Chart;
  666. });
  667. },
  668. getbarrageList() {// 弹幕列表
  669. app.func.req('/api/kwai/barrageList','post',{
  670. 'liveStreamId':this.data.live_stream_id,
  671. 'user_id': this.data.user_id,
  672. 'type': 1,//左侧弹幕
  673. 'page': 1,
  674. 'pagesize': 100
  675. },(res) => {
  676. if(res.auno == 4403 || res.errno == 4003){
  677. this.setData({
  678. barrageData:Object.assign(this.data.barrageData,{'hasAuno':true})
  679. })
  680. }
  681. if(res&& res.errno == 0){
  682. var arr = res.rst.data;
  683. var obj = {};
  684. arr = arr.reduce(function(item,next){
  685. obj[next.created_at+next.kwai_id]?'':obj[next.created_at+next.kwai_id] = true&&item.push(next);
  686. return item;
  687. },[]);
  688. this.setData({
  689. barrageData:Object.assign(this.data.barrageData,{
  690. list: arr.reverse(),
  691. total:res.rst.pageInfo.total
  692. })
  693. })
  694. this.barrageAnimation('contentDiv1','contentTrDiv1','animationData')
  695. this.timeOut('getbarrageListTime',this.data.barrageTime, 'getbarrageList')
  696. }else if(res.errno!=4003){
  697. wx.showToast({
  698. title: res.err,
  699. icon: 'none',
  700. duration: 2000
  701. })
  702. }
  703. },(err)=>{
  704. this.timeOut('getbarrageListTime',this.data.barrageTime,'getbarrageList')
  705. })
  706. },
  707. getGiftList(){//礼物弹幕列表
  708. app.func.req('/api/kwai/barrageList','post',{
  709. 'liveStreamId':this.data.live_stream_id,
  710. 'user_id': this.data.user_id,
  711. 'type': 2,//礼物弹幕
  712. 'page': 1,
  713. 'pagesize': 100
  714. },(res) => {
  715. if(res.auno == 4403 || res.errno == 4003){
  716. this.setData({
  717. giftData:Object.assign(this.data.giftData,{'hasAuno':true})
  718. })
  719. }
  720. if(res&& res.errno == 0){
  721. var arr = res.rst.data;
  722. var obj = {};
  723. arr = arr.reduce(function(item,next){
  724. obj[next.created_at+next.kwai_id]?'':obj[next.created_at+next.kwai_id] = true&&item.push(next);
  725. return item;
  726. },[]);
  727. this.setData({
  728. giftData:Object.assign(this.data.giftData,{
  729. list: arr.reverse(),
  730. total:res.rst.pageInfo.total
  731. })
  732. })
  733. this.barrageAnimation('contentDiv2','contentTrDiv2','animationData2')
  734. this.timeOut('getGiftListTime',this.data.barrageTime,'getGiftList')
  735. }else if(res.errno!=4003){
  736. wx.showToast({
  737. title: res.err,
  738. icon: 'none',
  739. duration: 2000
  740. })
  741. }
  742. },(err)=>{
  743. this.timeOut('getGiftListTime',this.data.barrageTime,'getGiftList')
  744. })
  745. },
  746. getVulgarTycoon() {//土豪送礼列表
  747. app.func.req('/v2/api/show/showtopuserinfo','get',{
  748. 'show_id':this.data.live_stream_id,
  749. 'user_id':this.data.user_id,
  750. },(res) => {
  751. if(res.auno == 4403 || res.errno == 4003){
  752. this.setData({
  753. vulgarTycoonData:Object.assign(this.data.vulgarTycoonData,{'hasAuno':true})
  754. })
  755. return;
  756. }
  757. if(res&&res.errno==0) {
  758. var data=res.rst
  759. this.setData({
  760. vulgarTycoonData:{
  761. list:data
  762. }
  763. })
  764. this.timeOut('getVulgarTycoonTime',this.data.otherTime,'getVulgarTycoon')
  765. }else if(res.errno!=4003){
  766. wx.showToast({
  767. title: res.err,
  768. icon: 'none',
  769. duration: 2000
  770. })
  771. }
  772. },(err)=>{
  773. this.timeOut('getVulgarTycoonTime',this.data.otherTime,'getVulgarTycoon')
  774. })
  775. },
  776. userGoodsStatistics() {//商品统计--趋势
  777. if(this.data.goodsStatisticsData.hasAuno){//防止刷新直播详情接口的时候,趋势接口在无权限的时候跟着更新,浪费资源
  778. return;
  779. }
  780. app.func.req('/v2/api/kwai/goodsStatistics','post',{
  781. 'user_id':this.data.detailInfo.user_id,
  782. 'live_stream_id':this.data.live_stream_id
  783. },(res) => {
  784. wx.hideLoading()
  785. if(res.auno==4403||res.errno==4003) {
  786. this.setData({
  787. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'hasAuno':true})
  788. })
  789. }
  790. this.dataObj = res.rst;
  791. if(res&&res.errno==0) {
  792. this.setData({
  793. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'dataObj':res.rst})
  794. })
  795. if(!res.rst.category||res.rst.category.length == 0){
  796. this.setData({
  797. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'goodsStatisticsFlag':false})
  798. })
  799. }else {
  800. this.setData({
  801. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'goodsStatisticsFlag':true})
  802. })
  803. var categoryName = [],categoryPercent = [];
  804. res.rst.category.forEach((item,index) => {
  805. categoryName.push(item.name)
  806. categoryPercent.push({'value':item.percent,'name':item.name})
  807. });
  808. }
  809. var priceName = [],priceData = [];
  810. if(res.rst.price&&res.rst.price.length){
  811. this.setData({
  812. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'priceEchartsLoding':true})
  813. })
  814. res.rst.price.forEach((item,index) => {
  815. priceName.push(item.price)
  816. priceData.push(item.percent)
  817. });
  818. }else{
  819. this.setData({
  820. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'priceEchartsLoding':false})
  821. })
  822. }
  823. if(!res.rst.channel||res.rst.channel.length == 0){
  824. this.setData({
  825. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'channelEchartsLoding':false})
  826. })
  827. }else {
  828. this.setData({
  829. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{'channelEchartsLoding':true})
  830. })
  831. var channelName = [],channelData = [];
  832. res.rst.channel.forEach((item,index) => {
  833. channelName.push(item.name)
  834. channelData.push({'value':item.percent,'name':item.name})
  835. });
  836. }
  837. if(this.data.goodsStatisticsData.goodsStatisticsFlag){
  838. this.setData({
  839. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  840. 'checkDrawPie':1
  841. })
  842. })
  843. this.drawPie(categoryName,categoryPercent)//类别分析
  844. }
  845. if(this.data.goodsStatisticsData.priceEchartsLoding){
  846. this.setData({
  847. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  848. 'checkPriceTrend':1
  849. })
  850. })
  851. this.drawPrice(priceName,priceData)//价格分布
  852. }
  853. if(this.data.goodsStatisticsData.channelEchartsLoding){
  854. this.setData({
  855. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  856. 'checkChannelTrend':1
  857. })
  858. })
  859. this.drawChannel(channelName,channelData)//商品来源分布
  860. }
  861. }else if(res.errno != 4003){
  862. wx.showToast({
  863. title: res.err,
  864. icon: 'none',
  865. duration: 2000
  866. })
  867. }
  868. },(err)=>{
  869. wx.hideLoading()
  870. })
  871. },
  872. drawPie(name,data) {//分类占比
  873. var colorArr = ['#2296F3','#FF5A7B','#BCA4FC',"#F6564A","#FF936B","#9CCCFF","#FFACB8","#B7EEA8","#FFB89D","#FCE500","#9F9F9F",'#78ADF9'];
  874. for(var i = 0; i<data.length; i++){
  875. if(i>=colorArr.length){
  876. colorArr.push('rgba(' + [
  877. Math.round(Math.random() * 255),
  878. Math.round(Math.random() * 200),
  879. Math.round(Math.random() * 160),
  880. 0.8
  881. ].join(',') + ')')
  882. }
  883. }
  884. data = data.splice(0,12)
  885. var echartsComponnet = this.selectComponent('#typeDis')
  886. echartsComponnet.init((canvas, width, height, dpr) => {
  887. // 初始化图表
  888. const Chart = echarts.init(canvas, null, {
  889. width: width,
  890. height: height,
  891. devicePixelRatio: dpr
  892. });
  893. var option = {
  894. color:colorArr,
  895. tooltip: {
  896. show: true,
  897. formatter: "{b}: {c}%"
  898. },
  899. grid: {
  900. top: '0%',
  901. left:'10%',
  902. right:'10%',
  903. bottom: '30%'
  904. },
  905. series: [{
  906. center: ['50%', '50%'],
  907. radius: ['40%', '60%'],
  908. minShowLabelAngle: 4,
  909. minAngle: 18,//最小的扇区角度(0 ~ 360),用于防止某个值过小导致扇区太小影响交互
  910. avoidLabelOverlap:true,////是否启用防止标签重叠策略
  911. label: {
  912. normal: {
  913. formatter(v) {
  914. let text = v.name + '' + Math.round(v.percent)+'%'
  915. return text
  916. },//文字换行
  917. show: true,
  918. position: 'outside',
  919. }
  920. },
  921. labelLine: {
  922. show: true
  923. },
  924. label: {
  925. normal: {
  926. formatter(v) {
  927. let text = v.name
  928. return text
  929. },//文字换行
  930. show: true,
  931. position: 'outside',
  932. }
  933. },
  934. avoidLabelOverlap: false,
  935. type: 'pie',
  936. data: data
  937. }]
  938. };
  939. Chart.setOption(option);
  940. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  941. return Chart;
  942. });
  943. },
  944. drawPrice(name,data) {//价格分布
  945. var echartsComponnet = this.selectComponent('#priceDis')
  946. echartsComponnet.init((canvas, width, height, dpr) => {
  947. // 初始化图表
  948. const Chart = echarts.init(canvas, null, {
  949. width: width,
  950. height: height,
  951. devicePixelRatio: dpr
  952. });
  953. var option = {
  954. color:["#57C2FF"],
  955. tooltip: {
  956. trigger: 'axis',
  957. formatter: "{b}: {c}%",
  958. },//展示数据
  959. grid: {
  960. left: "6%",
  961. right: "8%",
  962. bottom: "0",
  963. top: "5%",
  964. bottom: "5%",
  965. containLabel: true
  966. },
  967. xAxis:[
  968. {
  969. type:"category",
  970. data:name,
  971. axisLine: {
  972. show: false
  973. },
  974. axisTick: {
  975. show: false
  976. },
  977. axisLabel: {
  978. show: true,
  979. textStyle: {
  980. color: '#fff'
  981. }
  982. },
  983. axisTick: { // X轴线 刻度线
  984. show: false,
  985. length: 10,
  986. lineStyle: {
  987. color: 'red',
  988. type: 'solid',
  989. width: 2
  990. }
  991. },
  992. }
  993. ],
  994. yAxis: [
  995. {
  996. type: "value",
  997. splitLine:{
  998. show: true, // X轴线 颜色类型的修改
  999. lineStyle: {
  1000. type: 'solid',
  1001. color: '#4E588A'
  1002. }
  1003. },
  1004. axisLine: {
  1005. show: false
  1006. },
  1007. axisTick: {
  1008. show: false
  1009. },
  1010. axisLabel: {
  1011. show: true,
  1012. textStyle: {
  1013. color: '#fff'
  1014. }
  1015. },
  1016. }
  1017. ],
  1018. series: [{
  1019. type: 'bar',
  1020. barWidth: '20',
  1021. data:data,
  1022. itemStyle:{
  1023. // color:'#78ADF9',
  1024. color: {
  1025. type: 'linear',
  1026. x: 0,
  1027. y: 0,
  1028. x2: 0,
  1029. y2: 1,
  1030. colorStops: [{
  1031. offset: 0, color: '#53FAF9' // 0% 处的颜色
  1032. }, {
  1033. offset: 1, color: '#1E56FE' // 100% 处的颜色
  1034. }],
  1035. global: false // 缺省为 false
  1036. },
  1037. barBorderRadius: [4,4,4,4],
  1038. borderType:'dotted'
  1039. }
  1040. }]
  1041. };
  1042. Chart.setOption(option);
  1043. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  1044. return Chart;
  1045. });
  1046. },
  1047. drawChannel(name,data) {//商品来源分析
  1048. var colorArr = ['#2296F3','#FF5A7B','#BCA4FC',"#F6564A","#FF936B","#9CCCFF","#FFACB8","#B7EEA8","#FFB89D","#FCE500","#9F9F9F",'#78ADF9'];
  1049. for(var i = 0; i<data.length; i++){
  1050. if(i>=colorArr.length){
  1051. colorArr.push('rgba(' + [
  1052. Math.round(Math.random() * 255),
  1053. Math.round(Math.random() * 200),
  1054. Math.round(Math.random() * 160),
  1055. 0.8
  1056. ].join(',') + ')')
  1057. }
  1058. }
  1059. data = data.splice(0,12)
  1060. var echartsComponnet = this.selectComponent('#channel')
  1061. echartsComponnet.init((canvas, width, height, dpr) => {
  1062. // 初始化图表
  1063. const Chart = echarts.init(canvas, null, {
  1064. width: width,
  1065. height: height,
  1066. devicePixelRatio: dpr
  1067. });
  1068. var option = {
  1069. color:colorArr,
  1070. tooltip: {
  1071. show: true,
  1072. formatter: "{b}: {c}%"
  1073. },
  1074. grid: {
  1075. top: '0%',
  1076. left:'10%',
  1077. right:'10%',
  1078. bottom: '30%'
  1079. },
  1080. series: [{
  1081. center: ['50%', '50%'],
  1082. radius: ['40%', '60%'],
  1083. minShowLabelAngle: 4,
  1084. minAngle: 18,//最小的扇区角度(0 ~ 360),用于防止某个值过小导致扇区太小影响交互
  1085. avoidLabelOverlap:true,////是否启用防止标签重叠策略
  1086. label: {
  1087. normal: {
  1088. formatter(v) {
  1089. let text = v.name + '' + Math.round(v.percent)+'%'
  1090. return text
  1091. },//文字换行
  1092. show: true,
  1093. position: 'outside',
  1094. }
  1095. },
  1096. labelLine: {
  1097. show: true
  1098. },
  1099. label: {
  1100. normal: {
  1101. formatter(v) {
  1102. // let text = v.name + '' + Math.round(v.percent)+'%'
  1103. let text = v.name
  1104. return text
  1105. },//文字换行
  1106. show: true,
  1107. position: 'outside',
  1108. }
  1109. },
  1110. avoidLabelOverlap: false,
  1111. type: 'pie',
  1112. data: data
  1113. }]
  1114. };
  1115. Chart.setOption(option);
  1116. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  1117. return Chart;
  1118. });
  1119. },
  1120. checkDrawPie(e) {//分类占比 type 切换
  1121. var checkType = e.currentTarget.dataset.type;
  1122. this.setData({
  1123. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  1124. 'checkDrawPie':checkType
  1125. })
  1126. })
  1127. if(this.data.goodsStatisticsData.hasAuno){
  1128. return
  1129. }
  1130. if(!this.data.goodsStatisticsData.dataObj.category||this.data.goodsStatisticsData.dataObj.category.length == 0){
  1131. this.setData({
  1132. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  1133. 'goodsStatisticsFlag':false
  1134. })
  1135. })
  1136. }else {
  1137. var categoryName = [],categoryPercent = [];
  1138. var data = checkType==1?this.data.goodsStatisticsData.dataObj.category:checkType==2?this.data.goodsStatisticsData.dataObj.categoryBySellCount:this.data.goodsStatisticsData.dataObj.categoryBySellMoney
  1139. data.forEach((item,index) => {
  1140. categoryName.push(item.name)
  1141. categoryPercent.push({'value':item.percent,'name':item.name})
  1142. });
  1143. }
  1144. if(this.data.goodsStatisticsData.goodsStatisticsFlag){
  1145. this.drawPie(categoryName,categoryPercent)//类别分析
  1146. }
  1147. },
  1148. checkPriceTrend(e) {//价格分布 type 切换
  1149. var priceType = e.currentTarget.dataset.type;
  1150. this.setData({
  1151. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  1152. 'checkPriceTrend':priceType
  1153. })
  1154. })
  1155. if(this.data.goodsStatisticsData.hasAuno){
  1156. return
  1157. }
  1158. var priceName = [],priceData = [];
  1159. if(this.data.goodsStatisticsData.dataObj.price&&this.data.goodsStatisticsData.dataObj.price.length){
  1160. var data = priceType==1?this.data.goodsStatisticsData.dataObj.price:priceType==2?this.data.goodsStatisticsData.dataObj.priceBySellCount:this.data.goodsStatisticsData.dataObj.priceBySellMoney
  1161. data.forEach((item,index) => {
  1162. priceName.push(item.price)
  1163. priceData.push(item.percent)
  1164. });
  1165. }else{
  1166. this.setData({
  1167. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  1168. 'priceEchartsLoding':false
  1169. })
  1170. })
  1171. }
  1172. if(this.data.goodsStatisticsData.priceEchartsLoding){
  1173. this.drawPrice(priceName,priceData)
  1174. }
  1175. },
  1176. checkChannelTrend(e) {//商品来源分布 type 切换
  1177. var sourceType = e.currentTarget.dataset.type;
  1178. this.setData({
  1179. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  1180. 'checkChannelTrend':sourceType
  1181. })
  1182. })
  1183. if(this.data.goodsStatisticsData.hasAuno){
  1184. return
  1185. }
  1186. if(!this.data.goodsStatisticsData.dataObj.channel||this.data.goodsStatisticsData.dataObj.channel.length == 0){
  1187. this.setData({
  1188. goodsStatisticsData:Object.assign(this.data.goodsStatisticsData,{
  1189. 'channelEchartsLoding':false
  1190. })
  1191. })
  1192. }else {
  1193. var data = sourceType==1?this.data.goodsStatisticsData.dataObj.channelBySellCount:sourceType==2?this.data.goodsStatisticsData.dataObj.channelBySellCount:this.data.goodsStatisticsData.dataObj.channelBySellMoney
  1194. var channelName = [],channelData = [];
  1195. data.forEach((item,index) => {
  1196. channelName.push(item.name)
  1197. channelData.push({'value':item.percent,'name':item.name})
  1198. });
  1199. }
  1200. if(this.data.goodsStatisticsData.channelEchartsLoding){
  1201. this.drawChannel(channelName,channelData)
  1202. }
  1203. },
  1204. // 将毫秒转换成几天
  1205. formatDuring(mss) {
  1206. // 分钟*60*1000=毫秒
  1207. mss = mss*60*1000;
  1208. var days = parseInt(mss / (1000 * 60 * 60 * 24))+'天';
  1209. var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))+'小时';
  1210. var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60))+'分钟';
  1211. return (parseInt(days)>0?days:'') + (parseInt(hours)>0?hours:'') + (parseInt(minutes)>0?minutes:'');
  1212. },
  1213. timeOut(timer_name,time,fun){//公共开启定时器方法
  1214. if(this.data.detailInfo.enable == 1){
  1215. clearTimeout(this.data.time_arr[timer_name])
  1216. var time_arr = this.data.time_arr;
  1217. time_arr[timer_name] = setTimeout(()=>{
  1218. this[fun]()
  1219. },time)
  1220. this.setData({
  1221. time_arr:time_arr
  1222. })
  1223. }
  1224. },
  1225. util: function (obj) {//弹幕动画效果
  1226. var continueTime = (parseInt(obj.list / obj.container) + 1) * 1500;
  1227. var setIntervalTime = 50 + continueTime;
  1228. var animation = wx.createAnimation({
  1229. duration: 200, //动画时长
  1230. timingFunction: "linear", //线性
  1231. delay: 0 //0则不延迟
  1232. });
  1233. this.animation = animation;
  1234. animation.translateY(10).step({ duration: 50, timingFunction: 'step-start' }).translateY(-obj.list + obj.container).step({ duration: continueTime });
  1235. this.setData({
  1236. [obj.animation_name]: animation.export()
  1237. })
  1238. setTimeout(() => {
  1239. animation.translateY(0).step({ duration: 50, timingFunction: 'step-start' })
  1240. this.setData({
  1241. [obj.animation_name]: animation.export()
  1242. })
  1243. }, setIntervalTime)
  1244. },
  1245. barrageAnimation(frame,scroll_frame,animation) {
  1246. if(this.data.detailInfo.enable != 1){
  1247. return;
  1248. }
  1249. var obj = new Object();
  1250. //创建节点选择器
  1251. var query = wx.createSelectorQuery();
  1252. query.select('.'+frame).boundingClientRect()
  1253. query.select('.'+scroll_frame).boundingClientRect()
  1254. query.exec((res) => {
  1255. obj.container = res[0].height; // 框的height
  1256. obj.list = res[1].height; // list的height
  1257. obj.animation_name = animation;//动画的名称
  1258. this.util(obj);
  1259. })
  1260. },
  1261. /**
  1262. * 生命周期函数--监听页面隐藏
  1263. */
  1264. onHide: function () {
  1265. console.log('onHide')
  1266. for(var i in this.data.time_arr){
  1267. clearTimeout(this.data.time_arr[i])
  1268. }
  1269. },
  1270. /**
  1271. * 生命周期函数--监听页面卸载
  1272. */
  1273. onUnload: function () {
  1274. console.log('onUnload')
  1275. console.log(this.data.time_arr)
  1276. for(var i in this.data.time_arr){
  1277. clearTimeout(this.data.time_arr[i])
  1278. }
  1279. },
  1280. /**
  1281. * 页面相关事件处理函数--监听用户下拉动作
  1282. */
  1283. onPullDownRefresh: function () {
  1284. },
  1285. /**
  1286. * 页面上拉触底事件的处理函数
  1287. */
  1288. onReachBottom: function () {
  1289. },
  1290. /**
  1291. * 用户点击右上角分享
  1292. */
  1293. onShareAppMessage: function () {
  1294. }
  1295. })