123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- // pages/roomManger/roomManger
- var util = require('./../../utils/util.js');
- var api = require('./../../config/api.js');
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- roomList: [],
- hasData: true,
- loading: false,
- listNmb: {
- NotStart: 0,
- Start: 0,
- },
- isSearch: false,
- state: true,
- canShow: false,
- maxPage: false,
- fetcherData: {
- type: 32,
- address: '',
- page: 1,
- size: 20,
- name: '',
- state: 102
- }
- },
- async getUserInfo() {
- const {
- data
- } = await util.request(api.UserInfo)
- console.log('UserInfo', data)
- let {
- canShow
- } = data
- wx.setStorageSync('userinfoDetail', data)
- this.setData({
- canShow: canShow !== 1 ? false : true,
- userInfo: {
- nickName: data.nickname,
- avatarUrl: data.avatar,
- }
- })
- },
- async handleDelete(e) {
- wx.showModal({
- title: '温馨提示',
- content: this.data.fetcherData.state !== 102 ? '关闭房间后,房间内的所有人都会退出房间,是否继续关闭?' : '删除房间后,房间信息将进行销毁,是否继续删除?',
- success: (res) => {
- console.log('requestDelete', res)
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- this.requestDelete(e);
- }
- }
- })
- },
- async requestDelete(e) {
- const businessId = e.target.dataset && e.target.dataset.id;
- const apiUrl = this.data.fetcherData.state == 102 ? api.deleteRoom : api.exitRoom;
- const res = await util.request(apiUrl, {
- businessId
- }, 'POST', 'application/json')
- const {
- data,
- code
- } = res
- if (code !== 200) return
- let roomList = this.data.roomList.filter(ele => ele.businessId !== businessId)
- this.setData({
- roomList: roomList,
- })
- },
- setActive(ev) {
- const that = this
- const {
- type
- } = ev.currentTarget.dataset
- this.setData({
- 'fetcherData.state': type == 'true' ? 102 : 101,
- }, () => {
- that.searchRoomList()
- });
- },
- inputChange(e) {
- this.setData({
- 'fetcherData.name': e.detail.value,
- });
- },
- search() {
- if (this.data.fetcherData.name != '') {
- wx.showLoading({
- title: '加载中...',
- });
- this.setData({
- isSearch: true
- })
- this.searchRoomList()
- } else {
- if (this.data.isSearch) {
- this.setData({
- isSearch: false
- })
- this.searchRoomList()
- } else {
- // wx.showToast({
- // title: '请输入VR场景名称',
- // icon: 'none'
- // })
- wx.showLoading({
- title: '加载中...',
- });
- this.setData({
- isSearch: true
- })
- this.searchRoomList()
- }
- }
- },
- addRoom() {
- wx.navigateTo({
- url: `/pages/room/add`,
- })
- },
- async getStartNum() {
- const res = await util.request(api.roomChatList, {
- ...this.data.fetcherData,
- state: 101,
- }, 'POST', 'application/json')
- // debugger
- if (res.code === 200) {
- let listNmb = this.data.listNmb
- listNmb.Start = res.data.count
- if (res.data.data.length != 0) {
- this.setData({
- listNmb
- })
- }
- }
- this.setData({
- loading: false
- })
- },
- async getRoomList() {
- if (this.data.hasData) {
- if (!this.data.loading) {
- this.setData({
- loading: true
- })
- wx.showLoading({
- title: '加载中...',
- })
- try {
- const res = await util.request(api.roomChatList, this.data.fetcherData, 'POST', 'application/json')
- // debugger
- if (res.code === 200) {
- if (res.data.data.length != 0) {
- let listNmb = this.data.listNmb
- let objlistNmb = {
- 101: 'Start',
- 102: 'NotStart',
- }
- listNmb[objlistNmb[this.data.fetcherData.state]] = res.data.count
- let {
- totalPages
- } = res.data
- this.setData({
- roomList: this.data.roomList.concat(res.data.data),
- 'fetcherData.page': this.data.fetcherData.page + 1,
- maxPage: totalPages == this.data.fetcherData.page,
- listNmb,
- })
- } else {
- this.setData({
- hasData: false
- })
- }
- }
- this.setData({
- loading: false
- })
- console.log('roomList', this.data.roomList, this.data.fetcherData.page);
- } catch (error) {
- this.setData({
- hasData: false
- })
- }
- }
- } else {
- console.log('没有更多数据')
- }
- },
- reloadData() {
- this.setData({
- hasData: true
- }, () => {
- this.getRoomList()
- })
- },
- searchRoomList() {
- if (!this.data.loading) {
- this.setData({
- loading: false
- })
- this.setData({
- 'fetcherData.page': 1,
- 'fetcherData.size': 100,
- })
- util.request(api.roomChatList, this.data.fetcherData, 'POST', 'application/json').then((res) => {
- this.setData({
- loading: false
- })
- wx.hideLoading()
- if (res.errno === 0) {
- let listNmb = this.data.listNmb
- let objlistNmb = {
- 101: 'Start',
- 102: 'NotStart',
- }
- listNmb[objlistNmb[this.data.fetcherData.state]] = res.data.count
- this.setData({
- roomList: res.data.data,
- listNmb,
- })
- }
- }).catch(err => {
- this.setData({
- loading: false
- })
- });
- }
- },
- gotoWV: function (event) {
- let {
- id,
- roomId
- } = event.detail
- const type = this.data.fetcherData.type || 33
- wx.navigateTo({
- url: `/pages/webview/index?id=${id}&type=${type}&roomId=${roomId}`,
- })
- util.request(api.increaseViewCount, {
- brandId: id,
- type: type
- }, 'GET').then((res) => {
- });
- },
- // storeGotoWv(event) {
- // let {
- // id,
- // roomId,
- // index
- // } = event.detail
- // debugger;
- // wx.navigateTo({
- // url: `/pages/webview/index?id=${id}&type=${this.data.fetcherData.type}&roomId=${roomId}`,
- // })
- // util.request(api.increaseViewCount, {
- // brandId: id,
- // type: this.data.fetcherData.type
- // }, 'GET').then((res) => {
- // var num = 'roomList[' + index + '].pvTotalNum'
- // this.setData({
- // [num]: res.data
- // })
- // });
- // },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- getApp().checkNetStatu();
- console.log(options)
- this.setData({
- 'fetcherData.type': options.type
- })
- // this.getRoomList()
- this.getUserInfo()
- this.getStartNum()
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // debugger
- this.setData({
- roomList: [],
- 'fetcherData.page': 1
- }, () => {
- this.getRoomList()
- })
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- const that = this
- this.setData({
- hasData: true,
- 'fetcherData': {
- ...that.data.fetcherData,
- page: 1,
- },
- "roomList": [],
- }, () => {
- that.getRoomList()
- wx.stopPullDownRefresh()
- })
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- if (!this.data.isSearch && !this.data.maxPage) {
- this.getRoomList()
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|