123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- // index.ts
- // 获取应用实例
- const app_mode = getApp<IAppOption>()
- var mixins = require('../../utils/mixins')
- const computedBehavior = require('miniprogram-computed').behavior
- Page({
- behaviors: [computedBehavior],
- mixins: [mixins],
- data: {
- roomlist: [],
- shareId: '',
- ended: 0,
- myjoin: 0,
- date: 7,
- isShowJoin: false,
- toast_type: 'join',
- hasUserInfo: false,
- currentTapRoom: {
- id: '',
- code: ''
- }
- },
- // 事件处理函数
- onLoad(options) {
- let { shareId } = options
- this.setData({
- shareId
- })
- if (shareId) {
- // @ts-ignore
- app_mode.watch('hasAvatar', (v: any) => {
- if (!v) {
- wx.showModal({
- title: '提示',
- content: '请您授权微信登录',
- confirmText: '登录',
- showCancel: false,
- success: (res) => {
- if (res.confirm) {
- this.getUserProfile((error: any) => {
- if (error) {
- wx.reLaunch({
- url: '/pages/index/index'
- })
- }
- else {
- this.getList()
- }
- })
- }
- }
- })
- } else {
- this.getList()
- }
- })
- }
- else {
- this.getList()
- }
- },
- getUserProfile(cb: any) {
- if (this.data.hasUserInfo) {
- cb()
- }
- else {
- // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: res => {
- let { userInfo } = res
- // @ts-ignore
- this.data.fetchutil.post(`/sys/wxUser/save`, {
- "avatarUrl": userInfo.avatarUrl,
- "gender": userInfo.gender,
- "nickName": userInfo.nickName,
- // @ts-ignore
- id: app_mode.globalData.userInfo.id
- }, {}).then(() => {
- cb()
- })
- },
- fail: () => {
- cb('fail')
- }
- })
- }
- },
- select(e: any) {
- let { select } = e.currentTarget.dataset
- let obj: any = {}
- let r: any = Object.getOwnPropertyDescriptor(this.data, select) as PropertyDecorator
- obj[select] = r.value ? 0 : 1
- this.setData(obj)
- },
- tapnew() {
- this.setData({
- isShowJoin: true,
- toast_type: 'new'
- })
- },
- toDetailPage(data = null) {
- // @ts-ignore
- this.data.fetchutil.get(`cms/room/join/${this.data.currentTapRoom.id}${this.data.currentTapRoom.code ? ('?code=' + data) : ''}`, {}, {}).then((response: any) => {
- console.log();
- this.ontapclose()
- wx.navigateTo({
- // @ts-ignore
- url: `../activity_detail/index?roomId=${response.data.roomId}&id=${response.data.id}&userId=${app_mode.globalData.userInfo.id}`,
- })
- }).catch((error: any) => {
- wx.showModal({
- title: '提示',
- content: error.data.msg,
- showCancel: false
- })
- return
- })
- },
- ontapjoin(e: any) {
- if (this.data.currentTapRoom.code) {
- if (e.detail.inputValue != this.data.currentTapRoom.code) {
- wx.showModal({
- title: '提示',
- content: '口令不正确',
- showCancel: false
- })
- return
- }
- }
- this.toDetailPage(e.detail.inputValue)
- },
- ontaproom(e: any) {
- let { item } = e.detail
- //已结束,直接查看
- if (item.statusVo == 1) {
- // @ts-ignore
- wx.navigateTo({
- // @ts-ignore
- url: `../activity_detail/index?roomId=${item.id}&userId=${app_mode.globalData.userInfo.id}`,
- })
- return
- }
- this.setData({
- currentTapRoom: item,
- toast_type: 'join'
- })
- if (item.code) {
- this.setData({
- isShowJoin: true,
- })
- } else {
- this.toDetailPage()
- }
- },
- ontapclose() {
- this.setData({
- isShowJoin: false
- })
- },
- watch: {
- ended: function () {
- this.getList()
- },
- myjoin: function () {
- this.getList()
- },
- date: function () {
- this.getList()
- }
- },
- onSelectDate(e: any) {
- this.setData({
- date: e.detail.current.key
- })
- },
- createRoom(e: any) {
- let { current, inputValue, ispublic } = e.detail
- if (!inputValue.trim()&&ispublic=='nopublic') {
- wx.showModal({
- title: '提示',
- content: '口令不能为空',
- showCancel: false
- })
- }
- var curTime = new Date();
- var addHour = curTime.setHours(curTime.getHours() + (current.key || 1));
- // @ts-ignore
- let endTime = this.data.formatTime(new Date(addHour))
- console.log('curTime:', endTime)
- // @ts-ignore
- this.data.fetchutil.post(`cms/room/save`, {
- code: ispublic === 'public' ? '' : inputValue,
- endTime
- }, {}).then(() => {
- this.ontapclose()
- this.getList()
- }).catch((error: any) => {
- wx.showModal({
- title: '提示',
- content: error.data.msg,
- showCancel: false
- })
- return
- })
- },
- getList() {
- // @ts-ignore
- this.data.fetchutil.post(`cms/room/list`, {
- date: this.data.date,
- isClose: this.data.ended,
- isJoin: this.data.myjoin
- }, {}).then((response: any) => {
- if (this.data.shareId) {
- let item = response.data.find((ii: any) => ii.id == this.data.shareId)
- this.ontaproom({
- detail: {
- item
- }
- })
- }
- this.setData({
- roomlist: response.data,
- shareId: ''
- })
- })
- }
- })
|