index.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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. tabsIndex: 0, //tabs下标
  13. accountStatus: -1, //直播账号状态 1-账号正常 2-账号审核中 3-没有账号
  14. //liveDataCount: {}, 实时数据统计
  15. liveDataCountForSession: {}, //单场次数据统计
  16. liveSessionList: [], //直播场次列表
  17. liveUserList: [], //直播用户观看记录
  18. pageNumber: 1, //当前页码
  19. pageTotal: 1, //列表总页数
  20. userPageNumber: 1, //用户当前页码
  21. userPageTotal: 1, //用户总列表
  22. optionRow: -1, //列表选中项
  23. isSy: true, //是否为私域直播
  24. myShowModel: false, //自定义model
  25. myShowModel2: false, // 真正申请中提示
  26. },
  27. /**
  28. * 生命周期函数--监听页面加载
  29. */
  30. onLoad: function (options) {
  31. //获取直播账号
  32. this.getLiveInfo()
  33. },
  34. /* 实时 */
  35. realTime() {
  36. const that = this;
  37. _Http.basic({
  38. "accesstoken": wx.getStorageSync('userData').token,
  39. "classname": "customer.live.live",
  40. "method": "getRealTimeViewerList",
  41. "content": {
  42. "pageNumber": 1,
  43. "pageSize": 20,
  44. "channelid": that.data.accountMsg.channelid
  45. }
  46. }, false).then(res => {
  47. console.log(res)
  48. })
  49. },
  50. /* 自定义model回调 */
  51. showModelCallBack({
  52. detail
  53. }) {
  54. if (detail == 'true') this.copyTheAddress(this.data.accountMsg.fliveurl_web);
  55. },
  56. /* 显示自定义model */
  57. showMyModel() {
  58. this.setData({
  59. myShowModel: true
  60. })
  61. },
  62. /* 申请直播账号 */
  63. applyForLive() {
  64. _Http.basic({
  65. "accesstoken": wx.getStorageSync('userData').token,
  66. "classname": "customer.live.live",
  67. "method": "applySYLive",
  68. "content": {}
  69. }).then(res => {
  70. if (res.code == 1) {
  71. wx.showToast({
  72. title: res.msg,
  73. icon: "none"
  74. })
  75. this.setData({
  76. accountStatus: 2
  77. })
  78. } else {
  79. if (res.data == '私域直播已申请') return this.setData({
  80. myShowModel2: true
  81. })
  82. }
  83. })
  84. },
  85. /* 复制地址 */
  86. copyTheAddress(e) {
  87. const url = (typeof e == "string" || typeof e == String) ? e : e.target.dataset.url;
  88. wx.setClipboardData({
  89. data: url,
  90. success(res) {
  91. wx.getClipboardData({
  92. success(res) {
  93. console.log('内容已复制') // data
  94. }
  95. })
  96. }
  97. })
  98. },
  99. /* 获取直播账号详情 */
  100. getLiveInfo() {
  101. const method = (this.data.tabsIndex == 0) ? 'getSYLiveInfo' : 'getLiveInfo';
  102. _Http.basic({
  103. "accesstoken": wx.getStorageSync('userData').token,
  104. "classname": "customer.live.live",
  105. "method": method,
  106. "content": {}
  107. }).then(res => {
  108. console.log("不显示")
  109. const isSy = (method == "getSYLiveInfo") ? true : false;
  110. this.setData({
  111. accountStatus: res.code,
  112. accountMsg: res.data[0],
  113. isSy
  114. })
  115. //获取实时数据
  116. this.realTime()
  117. /* 直播场次列表查询 */
  118. this.getLiveSessionList()
  119. })
  120. },
  121. /* 直播场次列表查询 */
  122. getLiveSessionList() {
  123. const method = (this.data.tabsIndex == 0) ? "getSYLiveSessionList" : "getLiveSessionList"
  124. _Http.basic({
  125. "accesstoken": wx.getStorageSync('userData').token,
  126. "classname": "customer.live.live",
  127. "method": method,
  128. "content": {
  129. "getdatafromdbanyway": true,
  130. "pageNumber": this.data.pageNumber,
  131. "pageSize": 10,
  132. "channelid": this.data.accountMsg.channelid
  133. }
  134. }).then(res => {
  135. if (res.msg != '成功') return wx.showToast({
  136. title: res.data,
  137. icon: "none"
  138. });
  139. for (let i = 0; i < res.data.length; i++) {
  140. let checkdate = res.data[i].starttime;
  141. res.data[i].starttime = checkdate.slice(0, checkdate.lastIndexOf('.'));
  142. }
  143. this.setData({
  144. liveSessionList: res.data,
  145. pageTotal: res.pageTotal
  146. })
  147. })
  148. },
  149. /* 查看场次详情 */
  150. viewDetails(e) {
  151. const {
  152. index
  153. } = e.currentTarget.dataset;
  154. const sessionid = this.data.liveSessionList[index].sessionid;
  155. this.setData({
  156. showStartTime: this.data.liveSessionList[index].starttime,
  157. sessionid
  158. })
  159. /* 场次详情统计 */
  160. _Http.basic({
  161. "accesstoken": wx.getStorageSync('userData').token,
  162. "classname": "customer.live.live",
  163. "method": "getSYLiveDataCountForSession",
  164. "content": {
  165. "sessionid": sessionid
  166. }
  167. }).then(res => {
  168. if (res.msg != '成功') wx.showToast({
  169. title: '数据统计获取失败,请稍后再试',
  170. icon: "none"
  171. })
  172. this.setData({
  173. liveDataCountForSession: res.data
  174. })
  175. });
  176. this.LiveUserList();
  177. this.setData({
  178. dataTypes: 1
  179. })
  180. },
  181. /* 观看用户列表 */
  182. LiveUserList() {
  183. /* 用户观看列表 */
  184. const method = (this.data.tabsIndex == 0) ? "getSYLiveUserList" : "getLiveUserList";
  185. _Http.basic({
  186. "accesstoken": wx.getStorageSync('userData').token,
  187. "classname": "customer.live.live",
  188. "method": method,
  189. "content": {
  190. "getdatafromdbanyway": true,
  191. "pageNumber": this.data.userPageNumber,
  192. "pageSize": 10,
  193. "sessionid": this.data.sessionid,
  194. "channelid": this.data.accountMsg.channelid
  195. }
  196. }).then(res => {
  197. if (res.msg != '成功') wx.showToast({
  198. title: '观看列表获取失败,请稍后再试',
  199. icon: "none"
  200. })
  201. for (let i = 0; i < res.data.length; i++) {
  202. const index = res.data[i].datetime.lastIndexOf('.');
  203. res.data[i].datetime = res.data[i].datetime.slice(0, index)
  204. }
  205. this.setData({
  206. userPageTotal: res.pageTotal,
  207. liveUserList: res.data
  208. })
  209. });
  210. },
  211. /* 场次列表选中 */
  212. optionItemIndex(e) {
  213. const {
  214. index
  215. } = e.currentTarget.dataset;
  216. this.setData({
  217. optionRow: index
  218. })
  219. },
  220. /* 下一页 */
  221. buttonRightClick() {
  222. if (this.data.dataTypes == 0) {
  223. if (this.data.pageNumber == this.data.pageTotal) return wx.showToast({
  224. title: '已经到达最后一页',
  225. icon: "none"
  226. });
  227. this.setData({
  228. pageNumber: this.data.pageNumber + 1
  229. })
  230. this.getSYLiveSessionList()
  231. } else {
  232. if (this.data.userPageNumber == this.data.userPageTotal) return wx.showToast({
  233. title: '已经到达最后一页',
  234. icon: "none"
  235. });
  236. this.setData({
  237. userPageNumber: this.data.userPageNumber + 1
  238. })
  239. this.LiveUserList()
  240. }
  241. },
  242. /* 上一页 */
  243. buttonLifeClick() {
  244. if (this.data.dataTypes == 0) {
  245. if (this.data.pageNumber == 1) return wx.showToast({
  246. title: '已经在第一页了哦',
  247. icon: "none"
  248. });
  249. this.setData({
  250. pageNumber: this.data.pageNumber - 1
  251. })
  252. this.getSYLiveSessionList()
  253. } else {
  254. if (this.data.userPageNumber == 1) return wx.showToast({
  255. title: '已经在第一页了哦',
  256. icon: "none"
  257. });
  258. this.setData({
  259. userPageNumber: this.data.userPageNumber - 1
  260. })
  261. this.LiveUserList()
  262. }
  263. },
  264. /* tabs回调 */
  265. setIndex({
  266. detail
  267. }) {
  268. this.setData({
  269. tabsIndex: detail,
  270. pageNumber: 1,
  271. pageTotal: 1,
  272. userPageNumber: 1,
  273. userPageTotal: 1
  274. })
  275. this.getLiveInfo();
  276. },
  277. /**
  278. * 生命周期函数--监听页面初次渲染完成
  279. */
  280. onReady: function () {
  281. },
  282. /**
  283. * 生命周期函数--监听页面显示
  284. */
  285. onShow: function () {
  286. },
  287. /**
  288. * 生命周期函数--监听页面隐藏
  289. */
  290. onHide: function () {
  291. },
  292. /**
  293. * 生命周期函数--监听页面卸载
  294. */
  295. onUnload: function () {
  296. },
  297. /**
  298. * 页面相关事件处理函数--监听用户下拉动作
  299. */
  300. onPullDownRefresh: function () {
  301. },
  302. /**
  303. * 页面上拉触底事件的处理函数
  304. */
  305. onReachBottom: function () {
  306. },
  307. /**
  308. * 用户点击右上角分享
  309. */
  310. onShareAppMessage: function () {
  311. return {
  312. title: this.data.accountMsg.channelname,
  313. path: "/pages/webView/index?url=" + this.data.accountMsg.fliveshowurl,
  314. imageUrl: this.data.accountMsg.channelcoverimageurl
  315. }
  316. }
  317. })