index.js 10 KB

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