index.js 8.0 KB

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