index.js 8.9 KB

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