index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. dataTypes: 0, //0-全部数据 1-单独数据
  11. tabsList: ["私域直播", "展会直播", "合作商直播"], //tabs列表
  12. buttonTabs: ["当前直播", "历史直播"], //按钮tabs
  13. tabsIndex: 0, //tabs下标
  14. accountStatus: -1, //直播账号状态 1-账号正常 2-账号审核中 3-没有账号
  15. //liveDataCount: {}, 实时数据统计
  16. liveDataCountForSession: {}, //单场次数据统计
  17. liveSessionList: [], //直播场次列表
  18. liveUserList: [], //直播用户观看记录
  19. crLiveUserList: [], //当前直播用户观看记录
  20. pageNumber: 1, //当前页码
  21. pageTotal: 1, //列表总页数
  22. userPageNumber: 1, //用户当前页码
  23. userPageTotal: 1, //用户总列表
  24. isSy: true, //是否为私域直播
  25. myShowModel: false, //自定义model
  26. myShowModel2: false, // 真正申请中提示
  27. listRowIndex: -1, //列表选中项
  28. CheckTheType: '当前直播', //查看类型
  29. onlineNumber: 0, //实时观看人数
  30. },
  31. /**
  32. * 生命周期函数--监听页面加载
  33. */
  34. onLoad: function (options) {
  35. //获取直播账号
  36. this.getLiveInfo()
  37. },
  38. /* 按钮tab回调 */
  39. tabsSelectedIitem({
  40. detail
  41. }) {
  42. if (detail == this.data.CheckTheType) return;
  43. if (detail == '历史直播') {
  44. if (this.data.liveSessionList.length == 0) return wx.showToast({
  45. title: '当前没有开播记录',
  46. icon: "none"
  47. })
  48. return
  49. }
  50. this.setData({
  51. CheckTheType: detail
  52. })
  53. },
  54. /* 实时 */
  55. realTime() {
  56. const that = this,
  57. token = wx.getStorageSync('userData').token,
  58. channelid = this.data.accountMsg.channelid;
  59. /* 获取当前用户列表 */
  60. this.getRealTimeViewerList();
  61. //获取聊天
  62. /* setInterval(() => {
  63. _Http.basic({
  64. "accesstoken": token,
  65. "classname": "customer.live.live",
  66. "method": "getRealTimeMessageList",
  67. "content": {
  68. "channelid": channelid
  69. }
  70. }, false).then(res => {
  71. console.log("聊天", res)
  72. })
  73. }, 2000); */
  74. //实时观看人数
  75. _Http.basic({
  76. "accesstoken": token,
  77. "classname": "customer.live.live",
  78. "method": "getRealTimeViewers",
  79. "content": {
  80. "channelid": channelid
  81. }
  82. }).then(res => {
  83. if (res.msg != '成功') return;
  84. this.setData({
  85. onlineNumber: res.data.count
  86. })
  87. })
  88. },
  89. /* 获取当前用户列表 */
  90. getRealTimeViewerList() {
  91. _Http.basic({
  92. "accesstoken": wx.getStorageSync('userData').token,
  93. "classname": "customer.live.live",
  94. "method": "getRealTimeViewerList",
  95. "content": {
  96. "pageNumber": this.data.pageNumber,
  97. "pageSize": 20,
  98. "channelid": this.data.accountMsg.channelid
  99. }
  100. }, false).then(res => {
  101. console.log(res)
  102. if (res.msg != '成功') {
  103. if (res.data.liveUserList.length <= 0) return wx.showToast({
  104. title: res.data,
  105. icon: "none"
  106. });
  107. return;
  108. }
  109. this.setData({
  110. crLiveUserList: res.data,
  111. pageTotal: res.pageTotal
  112. })
  113. })
  114. },
  115. /* 自定义model回调 */
  116. showModelCallBack({
  117. detail
  118. }) {
  119. if (detail == 'true') this.copyTheAddress(this.data.accountMsg.fliveurl_web);
  120. },
  121. /* 显示自定义model */
  122. showMyModel() {
  123. this.setData({
  124. myShowModel: true
  125. })
  126. },
  127. /* 申请直播账号 */
  128. applyForLive() {
  129. _Http.basic({
  130. "accesstoken": wx.getStorageSync('userData').token,
  131. "classname": "customer.live.live",
  132. "method": "applySYLive",
  133. "content": {}
  134. }).then(res => {
  135. if (res.code == 1) {
  136. wx.showToast({
  137. title: res.msg,
  138. icon: "none"
  139. })
  140. this.setData({
  141. accountStatus: 2
  142. })
  143. } else {
  144. if (res.data == '私域直播已申请') return this.setData({
  145. myShowModel2: true
  146. })
  147. }
  148. })
  149. },
  150. /* 复制地址 */
  151. copyTheAddress(e) {
  152. const url = (typeof e == "string" || typeof e == String) ? e : e.target.dataset.url;
  153. wx.setClipboardData({
  154. data: url,
  155. success(res) {
  156. wx.getClipboardData({
  157. success(res) {
  158. console.log('内容已复制') // data
  159. }
  160. })
  161. }
  162. })
  163. },
  164. /* 获取直播账号详情 */
  165. getLiveInfo() {
  166. const method = (this.data.tabsIndex == 0) ? 'getSYLiveInfo' : 'getLiveInfo';
  167. _Http.basic({
  168. "accesstoken": wx.getStorageSync('userData').token,
  169. "classname": "customer.live.live",
  170. "method": method,
  171. "content": {}
  172. }).then(res => {
  173. const isSy = (method == "getSYLiveInfo") ? true : false;
  174. this.setData({
  175. accountStatus: res.code,
  176. accountMsg: res.data[0],
  177. isSy
  178. })
  179. //获取实时数据
  180. this.realTime()
  181. //直播场次列表查询
  182. if (res.code == 1) this.getLiveSessionList();
  183. })
  184. },
  185. /* 直播场次列表查询 */
  186. getLiveSessionList() {
  187. const method = (this.data.tabsIndex == 0) ? "getSYLiveSessionList" : "getLiveSessionList"
  188. _Http.basic({
  189. "accesstoken": wx.getStorageSync('userData').token,
  190. "classname": "customer.live.live",
  191. "method": method,
  192. "content": {
  193. "getdatafromdbanyway": true,
  194. "pageNumber": this.data.pageNumber,
  195. "pageSize": 10,
  196. "channelid": this.data.accountMsg.channelid
  197. }
  198. }).then(res => {
  199. if (res.msg != '成功') return wx.showToast({
  200. title: res.data,
  201. icon: "none"
  202. });
  203. let sessionList = [];
  204. for (let i = 0; i < res.data.length; i++) {
  205. let checkdate = res.data[i].starttime,
  206. time = checkdate.slice(0, checkdate.lastIndexOf('.')),
  207. t = time.split(' ');
  208. res.data[i].starttime = t[0];
  209. sessionList.push(t[0])
  210. };
  211. this.setData({
  212. liveSessionList: res.data,
  213. pageTotal: res.pageTotal,
  214. sessionList
  215. });
  216. if (res.data.length > 0) this.viewDetails(0);
  217. })
  218. },
  219. /* 查看场次详情 */
  220. selectorChange(e) {
  221. this.viewDetails(e.detail.value);
  222. },
  223. viewDetails(index) {
  224. console.log(index, this.data.liveSessionList[index])
  225. const sessionid = this.data.liveSessionList[index].sessionid;
  226. this.setData({
  227. showStartTime: this.data.liveSessionList[index].starttime,
  228. sessionid
  229. })
  230. /* 场次详情统计 */
  231. _Http.basic({
  232. "accesstoken": wx.getStorageSync('userData').token,
  233. "classname": "customer.live.live",
  234. "method": "getSYLiveDataCountForSession",
  235. "content": {
  236. "sessionid": sessionid
  237. }
  238. }).then(res => {
  239. if (res.msg != '成功') wx.showToast({
  240. title: '数据统计获取失败,请稍后再试',
  241. icon: "none"
  242. })
  243. this.setData({
  244. liveDataCountForSession: res.data
  245. })
  246. });
  247. this.LiveUserList();
  248. this.setData({
  249. dataTypes: 1
  250. })
  251. },
  252. /* 观看用户列表 */
  253. LiveUserList() {
  254. /* 用户观看列表 */
  255. const method = (this.data.tabsIndex == 0) ? "getSYLiveUserList" : "getLiveUserList";
  256. _Http.basic({
  257. "accesstoken": wx.getStorageSync('userData').token,
  258. "classname": "customer.live.live",
  259. "method": method,
  260. "content": {
  261. "getdatafromdbanyway": true,
  262. "pageNumber": this.data.userPageNumber,
  263. "pageSize": 10,
  264. "sessionid": this.data.sessionid,
  265. "channelid": this.data.accountMsg.channelid
  266. }
  267. }).then(res => {
  268. if (res.msg != '成功') wx.showToast({
  269. title: '观看列表获取失败,请稍后再试',
  270. icon: "none"
  271. })
  272. for (let i = 0; i < res.data.length; i++) {
  273. const index = res.data[i].datetime.lastIndexOf('.');
  274. res.data[i].datetime = res.data[i].datetime.slice(0, index)
  275. }
  276. this.setData({
  277. userPageTotal: res.pageTotal,
  278. liveUserList: res.data
  279. })
  280. });
  281. },
  282. /* 下一页 */
  283. buttonRightClick() {
  284. if (this.data.CheckTheType == '当前直播') {
  285. if (this.data.pageNumber == this.data.pageTotal) return wx.showToast({
  286. title: '已经到达最后一页',
  287. icon: "none"
  288. });
  289. this.setData({
  290. pageNumber: this.data.pageNumber + 1
  291. })
  292. this.getRealTimeViewerList()
  293. } else {
  294. if (this.data.userPageNumber == this.data.userPageTotal) return wx.showToast({
  295. title: '已经到达最后一页',
  296. icon: "none"
  297. });
  298. this.setData({
  299. userPageNumber: this.data.userPageNumber + 1
  300. })
  301. this.LiveUserList()
  302. }
  303. },
  304. /* 上一页 */
  305. buttonLifeClick() {
  306. if (this.data.CheckTheType == '当前直播') {
  307. if (this.data.pageNumber == 1) return wx.showToast({
  308. title: '已经在第一页了',
  309. icon: "none"
  310. });
  311. this.setData({
  312. pageNumber: this.data.pageNumber - 1
  313. })
  314. this.getRealTimeViewerList()
  315. } else {
  316. if (this.data.userPageNumber == 1) return wx.showToast({
  317. title: '已经在第一页了',
  318. icon: "none"
  319. });
  320. this.setData({
  321. userPageNumber: this.data.userPageNumber - 1
  322. })
  323. this.LiveUserList()
  324. }
  325. },
  326. /* 选中行 */
  327. listRowAvtion(e) {
  328. this.setData({
  329. listRowIndex: e.currentTarget.dataset.index
  330. })
  331. },
  332. /* tabs回调 */
  333. setIndex({
  334. detail
  335. }) {
  336. if (this.data.tabsIndex == detail) return;
  337. this.setData({
  338. tabsIndex: detail,
  339. pageNumber: 1,
  340. pageTotal: 1,
  341. userPageNumber: 1,
  342. userPageTotal: 1
  343. });
  344. this.getLiveInfo();
  345. if (detail == 2) this.getCooperationAgentsLiveList();
  346. },
  347. /* 获取合作商直播列表 */
  348. getCooperationAgentsLiveList() {
  349. _Http.basic({
  350. "accesstoken": wx.getStorageSync('userData').token,
  351. "classname": "customer.live.live",
  352. "method": "getCooperationAgentsLiveList",
  353. "content": {}
  354. }).then(res => {
  355. this.setData({
  356. partnerLiveList: res.data
  357. })
  358. })
  359. },
  360. /* 查看合作商直播 */
  361. toLive(e) {
  362. const {
  363. fliveshowurl
  364. } = e.currentTarget.dataset;
  365. wx.navigateTo({
  366. url: '/pages/webView/index?url=' + fliveshowurl,
  367. })
  368. },
  369. /**
  370. * 生命周期函数--监听页面初次渲染完成
  371. */
  372. onReady: function () {},
  373. /**
  374. * 生命周期函数--监听页面显示
  375. */
  376. onShow: function () {},
  377. /**
  378. * 生命周期函数--监听页面隐藏
  379. */
  380. onHide: function () {},
  381. /**
  382. * 生命周期函数--监听页面卸载
  383. */
  384. onUnload: function () {},
  385. /**
  386. * 页面相关事件处理函数--监听用户下拉动作
  387. */
  388. onPullDownRefresh: function () {},
  389. /**
  390. * 页面上拉触底事件的处理函数
  391. */
  392. onReachBottom: function () {},
  393. /**
  394. * 用户点击右上角分享
  395. */
  396. onShareAppMessage: function () {
  397. return {
  398. title: this.data.accountMsg.channelname,
  399. path: "/pages/webView/index?url=" + this.data.accountMsg.fliveshowurl,
  400. imageUrl: this.data.accountMsg.channelcoverimageurl
  401. }
  402. }
  403. })