index.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // index.ts
  2. // 获取应用实例
  3. const app_mode = getApp<IAppOption>()
  4. var mixins = require('../../utils/mixins')
  5. const computedBehavior = require('miniprogram-computed').behavior
  6. Page({
  7. behaviors: [computedBehavior],
  8. mixins: [mixins],
  9. data: {
  10. roomlist: [],
  11. shareId: '',
  12. ended: 0,
  13. myjoin: 0,
  14. date: 7,
  15. isShowJoin: false,
  16. toast_type: 'join',
  17. hasUserInfo: false,
  18. currentTapRoom: {
  19. id: '',
  20. code: ''
  21. }
  22. },
  23. // 事件处理函数
  24. onLoad(options) {
  25. let { shareId } = options
  26. this.setData({
  27. shareId
  28. })
  29. if (shareId) {
  30. // @ts-ignore
  31. app_mode.watch('hasAvatar', (v: any) => {
  32. if (!v) {
  33. wx.showModal({
  34. title: '提示',
  35. content: '请您授权微信登录',
  36. confirmText: '登录',
  37. showCancel: false,
  38. success: (res) => {
  39. if (res.confirm) {
  40. this.getUserProfile((error: any) => {
  41. if (error) {
  42. wx.reLaunch({
  43. url: '/pages/index/index'
  44. })
  45. }
  46. else {
  47. this.getList()
  48. }
  49. })
  50. }
  51. }
  52. })
  53. } else {
  54. this.getList()
  55. }
  56. })
  57. }
  58. else {
  59. this.getList()
  60. }
  61. },
  62. getUserProfile(cb: any) {
  63. if (this.data.hasUserInfo) {
  64. cb()
  65. }
  66. else {
  67. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  68. wx.getUserProfile({
  69. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  70. success: res => {
  71. let { userInfo } = res
  72. // @ts-ignore
  73. this.data.fetchutil.post(`/sys/wxUser/save`, {
  74. "avatarUrl": userInfo.avatarUrl,
  75. "gender": userInfo.gender,
  76. "nickName": userInfo.nickName,
  77. // @ts-ignore
  78. id: app_mode.globalData.userInfo.id
  79. }, {}).then(() => {
  80. cb()
  81. })
  82. },
  83. fail: () => {
  84. cb('fail')
  85. }
  86. })
  87. }
  88. },
  89. select(e: any) {
  90. let { select } = e.currentTarget.dataset
  91. let obj: any = {}
  92. let r: any = Object.getOwnPropertyDescriptor(this.data, select) as PropertyDecorator
  93. obj[select] = r.value ? 0 : 1
  94. this.setData(obj)
  95. },
  96. tapnew() {
  97. this.setData({
  98. isShowJoin: true,
  99. toast_type: 'new'
  100. })
  101. },
  102. toDetailPage(data = null) {
  103. // @ts-ignore
  104. this.data.fetchutil.get(`cms/room/join/${this.data.currentTapRoom.id}${this.data.currentTapRoom.code ? ('?code=' + data) : ''}`, {}, {}).then((response: any) => {
  105. console.log();
  106. this.ontapclose()
  107. wx.navigateTo({
  108. // @ts-ignore
  109. url: `../activity_detail/index?roomId=${response.data.roomId}&id=${response.data.id}&userId=${app_mode.globalData.userInfo.id}`,
  110. })
  111. }).catch((error: any) => {
  112. wx.showModal({
  113. title: '提示',
  114. content: error.data.msg,
  115. showCancel: false
  116. })
  117. return
  118. })
  119. },
  120. ontapjoin(e: any) {
  121. if (this.data.currentTapRoom.code) {
  122. if (e.detail.inputValue != this.data.currentTapRoom.code) {
  123. wx.showModal({
  124. title: '提示',
  125. content: '口令不正确',
  126. showCancel: false
  127. })
  128. return
  129. }
  130. }
  131. this.toDetailPage(e.detail.inputValue)
  132. },
  133. ontaproom(e: any) {
  134. let { item } = e.detail
  135. //已结束,直接查看
  136. if (item.statusVo == 1) {
  137. // @ts-ignore
  138. wx.navigateTo({
  139. // @ts-ignore
  140. url: `../activity_detail/index?roomId=${item.id}&userId=${app_mode.globalData.userInfo.id}`,
  141. })
  142. return
  143. }
  144. this.setData({
  145. currentTapRoom: item,
  146. toast_type: 'join'
  147. })
  148. if (item.code) {
  149. this.setData({
  150. isShowJoin: true,
  151. })
  152. } else {
  153. this.toDetailPage()
  154. }
  155. },
  156. ontapclose() {
  157. this.setData({
  158. isShowJoin: false
  159. })
  160. },
  161. watch: {
  162. ended: function () {
  163. this.getList()
  164. },
  165. myjoin: function () {
  166. this.getList()
  167. },
  168. date: function () {
  169. this.getList()
  170. }
  171. },
  172. onSelectDate(e: any) {
  173. this.setData({
  174. date: e.detail.current.key
  175. })
  176. },
  177. createRoom(e: any) {
  178. let { current, inputValue, ispublic } = e.detail
  179. if (!inputValue.trim()&&ispublic=='nopublic') {
  180. wx.showModal({
  181. title: '提示',
  182. content: '口令不能为空',
  183. showCancel: false
  184. })
  185. }
  186. var curTime = new Date();
  187. var addHour = curTime.setHours(curTime.getHours() + (current.key || 1));
  188. // @ts-ignore
  189. let endTime = this.data.formatTime(new Date(addHour))
  190. console.log('curTime:', endTime)
  191. // @ts-ignore
  192. this.data.fetchutil.post(`cms/room/save`, {
  193. code: ispublic === 'public' ? '' : inputValue,
  194. endTime
  195. }, {}).then(() => {
  196. this.ontapclose()
  197. this.getList()
  198. }).catch((error: any) => {
  199. wx.showModal({
  200. title: '提示',
  201. content: error.data.msg,
  202. showCancel: false
  203. })
  204. return
  205. })
  206. },
  207. getList() {
  208. // @ts-ignore
  209. this.data.fetchutil.post(`cms/room/list`, {
  210. date: this.data.date,
  211. isClose: this.data.ended,
  212. isJoin: this.data.myjoin
  213. }, {}).then((response: any) => {
  214. if (this.data.shareId) {
  215. let item = response.data.find((ii: any) => ii.id == this.data.shareId)
  216. this.ontaproom({
  217. detail: {
  218. item
  219. }
  220. })
  221. }
  222. this.setData({
  223. roomlist: response.data,
  224. shareId: ''
  225. })
  226. })
  227. }
  228. })