大数据平台的小程序版本

index.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. // pages/liveDetail/index.js
  2. import * as echarts from '../../components/ec-canvas/echarts';
  3. var app = getApp();
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. ec: {
  10. lazyLoad: true // 延迟加载
  11. },
  12. hasAuno: false,
  13. hasAunoTotal: false,
  14. is_big_fan: true,
  15. checkType: 1,
  16. live_stream_id: '',
  17. user_id: '',
  18. infoObj: {},
  19. noneReward: false,
  20. nonePro: false,
  21. tab: 1,
  22. rewardList: [],
  23. productList: [],
  24. giftObj: {},
  25. targetTop: '',
  26. isFix: false,
  27. page: 1,
  28. pages: 1
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad(options) {
  34. var that = this;
  35. wx.showLoading({
  36. title: '加载中',
  37. })
  38. that.setData({
  39. 'live_stream_id':options.id,
  40. 'user_id':options.userid
  41. })
  42. wx.getSystemInfo({
  43. success(res) {
  44. that.setData({
  45. scrollHeight: res.windowHeight - 10
  46. });
  47. }
  48. });
  49. that.getInfo();
  50. var query = wx.createSelectorQuery();
  51. //选择id
  52. query.select('#tabItem').boundingClientRect()
  53. query.exec((res) => {
  54. //res就是 所有标签为mjltest的元素的信息 的数组
  55. that.setData({
  56. targetTop: res[0].top
  57. })
  58. })
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. console.log("卸载")
  80. // const ctx = wx.createCanvasContext('gift')
  81. // ctx.draw()
  82. // this.data.oCanvas.clear();
  83. },
  84. //在线人数
  85. onlineCanvas: function (data) {
  86. this.echartsComponnet = this.selectComponent('#online')
  87. this.echartsComponnet.init((canvas, width, height,dpr) => {
  88. // 初始化图表
  89. const Chart = echarts.init(canvas, null, {
  90. width: width,
  91. height: height,
  92. devicePixelRatio: dpr
  93. });
  94. // 指定图表的配置项和数据
  95. var option = {
  96. tooltip: {
  97. trigger: "axis",
  98. formatter: (params) => {
  99. var result = params[0].name + "\n";
  100. params.forEach((item,index)=>{
  101. result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
  102. })
  103. return result;
  104. }
  105. },
  106. grid: {
  107. left: "8%",
  108. right: "8%",
  109. top: "8%",
  110. bottom: '8%',
  111. containLabel: true
  112. },
  113. xAxis: {
  114. type: 'category',
  115. data: data.keyes,
  116. axisLine: {
  117. show: false
  118. },
  119. axisTick: {
  120. show: false
  121. },
  122. axisLabel: {
  123. show: true,
  124. color:'#434140',
  125. fontSize:10,
  126. // interval:0,
  127. // rotate:30,
  128. textStyle: {
  129. color: '#929292'
  130. }
  131. },
  132. splitLine: {
  133. show: false
  134. }
  135. },
  136. yAxis: {
  137. type: "value",
  138. axisLine: {
  139. show: false
  140. },
  141. axisTick: {
  142. show: false
  143. },
  144. splitLine: {
  145. lineStyle: {
  146. color: "#eee",
  147. type: "dashed"
  148. }
  149. },
  150. nameTextStyle: {
  151. padding: [0, 35, 0, 0]
  152. },
  153. axisLabel: {
  154. show: true,
  155. formatter: function(params) {
  156. var result = params;
  157. return app.func.NumberHandle(result);
  158. }
  159. },
  160. },
  161. series: [{
  162. name: "在线人数",
  163. itemStyle: {
  164. normal: {
  165. color: "#FF5A7B",
  166. borderColor: "#FF5A7B" //拐点边框颜色
  167. }
  168. },
  169. areaStyle: {
  170. color: "#E5F2FE"
  171. },
  172. data: data.value,
  173. type: 'line'
  174. }]
  175. }
  176. Chart.setOption(option);
  177. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  178. return Chart;
  179. });
  180. },
  181. //商品销量
  182. saleCanvas: function (data) {
  183. this.echartsComponnet = this.selectComponent('#sale')
  184. this.echartsComponnet.init((canvas, width, height,dpr) => {
  185. // 初始化图表
  186. const Chart = echarts.init(canvas, null, {
  187. width: width,
  188. height: height,
  189. devicePixelRatio: dpr
  190. });
  191. // 指定图表的配置项和数据
  192. var option = {
  193. tooltip: {
  194. trigger: "axis",
  195. formatter: (params) => {
  196. var result = params[0].name + "\n";
  197. params.forEach((item,index)=>{
  198. result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
  199. })
  200. return result;
  201. }
  202. },
  203. grid: {
  204. left: "8%",
  205. right: "8%",
  206. top: "8%",
  207. bottom: '8%',
  208. containLabel: true
  209. },
  210. xAxis: {
  211. type: 'category',
  212. data: data.keyes,
  213. axisLine: {
  214. show: false
  215. },
  216. axisTick: {
  217. show: false
  218. },
  219. axisLabel: {
  220. show: true,
  221. color:'#434140',
  222. fontSize:10,
  223. // interval:0,
  224. // rotate:30,
  225. textStyle: {
  226. color: '#929292'
  227. }
  228. },
  229. splitLine: {
  230. show: false
  231. }
  232. },
  233. yAxis: {
  234. type: "value",
  235. axisLine: {
  236. show: false
  237. },
  238. axisTick: {
  239. show: false
  240. },
  241. splitLine: {
  242. lineStyle: {
  243. color: "#eee",
  244. type: "dashed"
  245. }
  246. },
  247. nameTextStyle: {
  248. padding: [0, 35, 0, 0]
  249. },
  250. axisLabel: {
  251. show: true,
  252. formatter: function(params) {
  253. var result = params;
  254. return app.func.NumberHandle(result);
  255. }
  256. },
  257. },
  258. series: [{
  259. name: "商品销量",
  260. itemStyle: {
  261. normal: {
  262. color: "#FF5A7B",
  263. borderColor: "#FF5A7B" //拐点边框颜色
  264. }
  265. },
  266. areaStyle: {
  267. color: "#E5F2FE"
  268. },
  269. data: data.value,
  270. type: 'line'
  271. }]
  272. }
  273. Chart.setOption(option);
  274. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  275. return Chart;
  276. });
  277. },
  278. //点赞数
  279. likeCanvas: function (data) {
  280. this.echartsComponnet = this.selectComponent('#like')
  281. this.echartsComponnet.init((canvas, width, height,dpr) => {
  282. // 初始化图表
  283. const Chart = echarts.init(canvas, null, {
  284. width: width,
  285. height: height,
  286. devicePixelRatio: dpr
  287. });
  288. // 指定图表的配置项和数据
  289. var option = {
  290. tooltip: {
  291. trigger: "axis",
  292. formatter: (params) => {
  293. var result = params[0].name + "\n";
  294. params.forEach((item,index)=>{
  295. result += item.seriesName + ':' + app.func.NumberHandle(item.value,2)
  296. })
  297. return result;
  298. }
  299. },
  300. grid: {
  301. left: "8%",
  302. right: "8%",
  303. top: "8%",
  304. bottom: '8%',
  305. containLabel: true
  306. },
  307. xAxis: {
  308. type: 'category',
  309. data: data.keyes,
  310. axisLine: {
  311. show: false
  312. },
  313. axisTick: {
  314. show: false
  315. },
  316. axisLabel: {
  317. show: true,
  318. color:'#434140',
  319. fontSize:10,
  320. // interval:0,
  321. // rotate:30,
  322. textStyle: {
  323. color: '#929292'
  324. }
  325. },
  326. splitLine: {
  327. show: false
  328. }
  329. },
  330. yAxis: {
  331. type: "value",
  332. axisLine: {
  333. show: false
  334. },
  335. axisTick: {
  336. show: false
  337. },
  338. splitLine: {
  339. lineStyle: {
  340. color: "#eee",
  341. type: "dashed"
  342. }
  343. },
  344. nameTextStyle: {
  345. padding: [0, 35, 0, 0]
  346. },
  347. axisLabel: {
  348. show: true,
  349. formatter: function(params) {
  350. var result = params;
  351. return app.func.NumberHandle(result);
  352. }
  353. },
  354. },
  355. series: [{
  356. name: "点赞数",
  357. itemStyle: {
  358. normal: {
  359. color: "#FF5A7B",
  360. borderColor: "#FF5A7B" //拐点边框颜色
  361. }
  362. },
  363. areaStyle: {
  364. color: "#E5F2FE"
  365. },
  366. data: data.value,
  367. type: 'line'
  368. }]
  369. }
  370. Chart.setOption(option);
  371. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  372. return Chart;
  373. });
  374. },
  375. //礼物收入趋势
  376. giftCanvas: function (data) {
  377. this.echartsComponnet = this.selectComponent('#gift')
  378. this.echartsComponnet.init((canvas, width, height,dpr) => {
  379. // 初始化图表
  380. const Chart = echarts.init(canvas, null, {
  381. width: width,
  382. height: height,
  383. devicePixelRatio: dpr
  384. });
  385. // 指定图表的配置项和数据
  386. var option = {
  387. legend: {
  388. data: ['打赏人数', '打赏金额'],
  389. bottom: 0
  390. },
  391. tooltip: {
  392. trigger: "axis",
  393. formatter: (params) => {
  394. var result = params[0].name + "\n";
  395. params.forEach((item,index)=>{
  396. result += item.seriesName + ':' + app.func.NumberHandle(item.value,1)+(index==0?"\n":"")
  397. })
  398. return result;
  399. }
  400. },
  401. grid: {
  402. left: "8%",
  403. right: "8%",
  404. top: "8%",
  405. bottom: '10%',
  406. containLabel: true
  407. },
  408. xAxis: {
  409. type: 'category',
  410. data: this.data.giftObj.timeArr,
  411. axisLine: {
  412. show: false
  413. },
  414. axisTick: {
  415. show: false
  416. },
  417. axisLabel: {
  418. show: true,
  419. color:'#434140',
  420. fontSize:10,
  421. // interval:0,
  422. // rotate:30,
  423. textStyle: {
  424. color: '#929292'
  425. }
  426. },
  427. splitLine: {
  428. show: false
  429. }
  430. },
  431. yAxis: {
  432. type: "value",
  433. axisLine: {
  434. show: false
  435. },
  436. axisTick: {
  437. show: false
  438. },
  439. splitLine: {
  440. lineStyle: {
  441. color: "#eee",
  442. type: "dashed"
  443. }
  444. },
  445. nameTextStyle: {
  446. padding: [0, 35, 0, 0]
  447. },
  448. axisLabel: {
  449. show: true,
  450. formatter: function(params) {
  451. var result = params;
  452. return app.func.NumberHandle(result,1);
  453. }
  454. },
  455. },
  456. series: [
  457. {
  458. name: "打赏人数",
  459. type: "line",
  460. itemStyle: {
  461. normal: {
  462. color: "#FF5A7B",
  463. borderColor: "#FF5A7B" //拐点边框颜色
  464. }
  465. },
  466. areaStyle: {
  467. color: "#E5F2FE"
  468. },
  469. data: this.data.checkType==1?this.data.giftObj.incrCount:this.data.giftObj.countArr
  470. },
  471. {
  472. // name: this.data.giftObj==1?"打赏金额增量":"打赏金额总量",
  473. name: "打赏金额",
  474. type: "line",
  475. itemStyle: {
  476. normal: {
  477. color: "#6BD7D8",
  478. borderColor: "#6BD7D8" //拐点边框颜色
  479. }
  480. },
  481. areaStyle: {
  482. color: "#E5F2FE"
  483. },
  484. data: this.data.checkType==1?this.data.giftObj.incrSum:this.data.giftObj.sumArr
  485. }
  486. ]
  487. }
  488. Chart.setOption(option);
  489. // 注意这里一定要返回 chart 实例,否则会影响事件处理等
  490. return Chart;
  491. });
  492. },
  493. checkBtn:function(e) {
  494. this.setData({
  495. checkType: e.currentTarget.dataset.id
  496. })
  497. this.giftCanvas();
  498. },
  499. // 直播趋势
  500. getTrend:function() {
  501. var that = this;
  502. app.func.req('/api/kwai/todayShowDetail','post',{
  503. 'liveStreamId':that.data.live_stream_id,
  504. 'user_id':that.data.user_id
  505. },
  506. function(res) {
  507. wx.hideLoading({
  508. title: '加载中',
  509. })
  510. that.setData({
  511. hasAuno: res.auno==4403||res.errno==4003
  512. })
  513. if(res && res.errno == 0){
  514. //成功
  515. var data = res.rst;
  516. var watching_count_record = data?data.watching_count_record : {}; //在线人数曲线
  517. var watching_count_record_arr = { keyes: [], value: [] };
  518. for (let item in watching_count_record) {
  519. watching_count_record_arr.keyes.push(item.split(" ")[1]);
  520. watching_count_record_arr.value.push(watching_count_record[item]);
  521. }
  522. var live_commodity_sum_record = data?data.live_commodity_sum_record : {}; //商品销量
  523. var saleArr_arr = { keyes: [], value: [] };
  524. for (let item in live_commodity_sum_record) {
  525. saleArr_arr.keyes.push(item.split(" ")[1]);
  526. saleArr_arr.value.push(
  527. live_commodity_sum_record[item]
  528. );
  529. }
  530. var like_count_record = data?data.like_count_record : {}; //点赞数
  531. var like_count_record_arr = { keyes: [], value: [] };
  532. for (let item in like_count_record) {
  533. like_count_record_arr.keyes.push(item.split(" ")[1]);
  534. like_count_record_arr.value.push(like_count_record[item]);
  535. }
  536. if(that.data.tab==1) {
  537. that.onlineCanvas(watching_count_record_arr);//在线人数
  538. that.saleCanvas(saleArr_arr)//商品销量
  539. that.likeCanvas(like_count_record_arr)//点赞数
  540. }
  541. }
  542. },function(err){
  543. console.log(err)
  544. })
  545. },
  546. // 礼物趋势
  547. getGift:function() {
  548. wx.showLoading({
  549. title: '加载中',
  550. })
  551. var that = this;
  552. app.func.req('/v2/api/show/showtopinfo','get',{
  553. 'show_id':that.data.live_stream_id,
  554. 'user_id':that.data.user_id
  555. },
  556. function(res) {
  557. wx.hideLoading({
  558. title: '加载中',
  559. })
  560. if(res && res.errno == 0){
  561. //成功
  562. var data = res.rst;
  563. var timeArr = [], incrCount = [], incrSum = [], countArr = [], sumArr = [];
  564. data.forEach((item) => {
  565. timeArr.push(item.count_at.split(" ")[1]);
  566. incrCount.push(item.new_reward_count);
  567. incrSum.push(item.new_reward_sum);
  568. countArr.push(item.reward_count);
  569. sumArr.push(item.reward_sum);
  570. })
  571. // timeArr = timeArr.slice(timeArr.length-10)
  572. // incrCount = incrCount.slice(incrCount.length-10)
  573. // incrSum = incrSum.slice(incrSum.length-10)
  574. // countArr = countArr.slice(countArr.length-10)
  575. // sumArr = sumArr.slice(sumArr.length-10)
  576. that.setData({
  577. giftObj: {
  578. 'timeArr': timeArr,
  579. 'incrCount': incrCount,
  580. 'incrSum': incrSum,
  581. 'countArr': countArr,
  582. 'sumArr': sumArr
  583. }
  584. })
  585. if(that.data.tab==1) {
  586. that.giftCanvas()
  587. }
  588. }
  589. },function(err){
  590. console.log(err)
  591. })
  592. },
  593. // 直播详情
  594. getInfo:function() {
  595. var that = this;
  596. app.func.req('/v2/api/show/showDetailInfo','get',{
  597. 'live_stream_id':that.data.live_stream_id,
  598. 'user_id': that.data.user_id
  599. },
  600. function(res) {
  601. that.setData({
  602. hasAunoTotal: res.auno==4403||res.errno==4003
  603. })
  604. if(res && res.errno == 0){
  605. //成功
  606. var data = res.rst;
  607. // 粉丝在100w以上显示趋势
  608. that.setData({
  609. infoObj: data,
  610. is_big_fan: data.is_big_fan==1
  611. })
  612. if(data.is_big_fan==1) {
  613. that.getTrend();
  614. that.getGift();
  615. }else {
  616. that.setData({
  617. hasAunoTotal: res.auno==4403||res.errno==4003
  618. })
  619. wx.hideLoading({
  620. title: '加载中',
  621. })
  622. }
  623. }
  624. },function(err){
  625. console.log(err)
  626. })
  627. },
  628. // 礼物收入
  629. getReward:function() {
  630. wx.showLoading({
  631. title: '加载中',
  632. })
  633. var that = this;
  634. app.func.req('/v2/api/show/showtopuserinfo','get',{
  635. 'show_id':that.data.live_stream_id,
  636. 'user_id':that.data.user_id
  637. },
  638. function(res) {
  639. wx.hideLoading({
  640. title: '加载中',
  641. })
  642. that.setData({
  643. hasAuno: res.auno==4403||res.errno==4003
  644. })
  645. if(res && res.errno == 0){
  646. //成功
  647. var data = res.rst;
  648. that.setData({
  649. rewardList: data
  650. })
  651. if(that.data.rewardList.length==0) {
  652. that.setData({
  653. noneReward: true
  654. })
  655. }
  656. }
  657. },function(err){
  658. if(that.data.rewardList.length==0) {
  659. that.setData({
  660. noneReward: true
  661. })
  662. }
  663. })
  664. },
  665. // 滚动
  666. scroll(e) {
  667. let page = this,
  668. scrollTop = e.detail.scrollTop;
  669. if(scrollTop>=this.data.targetTop) {
  670. this.setData({
  671. isFix: true
  672. })
  673. }else {
  674. this.setData({
  675. isFix: false
  676. })
  677. }
  678. },
  679. // 带货商品
  680. getProduct:function() {
  681. wx.showLoading({
  682. title: '加载中',
  683. })
  684. var that = this;
  685. app.func.req('/api/kwai/showGoods','post',{
  686. 'live_stream_id':that.data.live_stream_id,
  687. 'user_id':that.data.user_id,
  688. 'sort':0,
  689. 'page':that.data.page
  690. },
  691. function(res) {
  692. wx.hideLoading({
  693. title: '加载中',
  694. })
  695. that.setData({
  696. hasAuno: res.auno==4403||res.errno==4003
  697. })
  698. if(res && res.errno == 0){
  699. //成功
  700. var data = res.rst;
  701. that.setData({
  702. productList: that.data.productList.concat(data.data),
  703. pages: data.pageInfo.pages
  704. })
  705. if(that.data.productList.length==0) {
  706. that.setData({
  707. nonePro: true
  708. })
  709. }
  710. }
  711. },function(err){
  712. if(that.data.productList.length==0) {
  713. that.setData({
  714. nonePro: true
  715. })
  716. }
  717. })
  718. },
  719. check(e) {
  720. this.setData({
  721. tab: e.target.dataset.id,
  722. hasAuno: false
  723. })
  724. if(this.data.tab==1){
  725. this.getTrend()
  726. this.getGift()
  727. }else if(this.data.tab==2) {
  728. this.setData({
  729. rewardList: []
  730. })
  731. this.getReward()
  732. }else if(this.data.tab==3) {
  733. this.setData({
  734. productList: []
  735. })
  736. this.getProduct()
  737. }
  738. },
  739. goHrDetail(e){
  740. wx.navigateTo({
  741. url: '/pages/hrDetail/hrDetail?user_id=' + e.currentTarget.dataset.userid ,
  742. })
  743. },
  744. bindDownLoad() {
  745. if(this.data.page<this.data.pages&&!this.data.hasAuno&&this.data.tab==3) {
  746. this.setData({
  747. page: ++this.data.page
  748. })
  749. this.getProduct();
  750. }
  751. },
  752. /**
  753. * 页面相关事件处理函数--监听用户下拉动作
  754. */
  755. onPullDownRefresh: function () {
  756. },
  757. /**
  758. * 页面上拉触底事件的处理函数
  759. */
  760. onReachBottom: function () {
  761. },
  762. /**
  763. * 用户点击右上角分享
  764. */
  765. onShareAppMessage: function () {
  766. }
  767. })