index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company;
  3. const getTabs = require("../../../utils/getTabs")
  4. const login = require("../../../utils/login");
  5. const dateF = require("../../../utils/date")
  6. import Toast from '@vant/weapp/toast/toast';
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. active: 0,
  13. showModel: false,
  14. isSignIn:false
  15. },
  16. /**
  17. * 生命周期函数--监听页面加载
  18. */
  19. onLoad: async function (options) {
  20. login.loginNow()
  21. this.setData({
  22. active: options?.active || 0
  23. })
  24. let list = await getTabs.getDiyTabs()
  25. this.setData({
  26. tabbarList: list
  27. })
  28. let {
  29. q,
  30. invite,
  31. groupId,
  32. path
  33. } = options
  34. let str = decodeURIComponent(q);
  35. let obj = this.getParaName(str)
  36. console.log(obj);
  37. // if ((obj && obj.invite) || invite) {
  38. // wx.setStorageSync("invite", obj && obj.invite || invite);
  39. // let user = Parse.User.current()
  40. // if (user && user.id) {
  41. // invite = wx.getStorageSync("invite")
  42. // console.log('invite=====>', invite);
  43. // let query = new Parse.Query("_User")
  44. // query.include("invite")
  45. // let res = await query.get(user.id)
  46. // let userJSON = res.toJSON()
  47. // //查询邀请人user
  48. // let queryUserInvite = new Parse.Query("_User")
  49. // queryUserInvite.equalTo('objectId',invite)
  50. // let result = await queryUserInvite.first()
  51. // if (result && result.id && result.get('invite')?.id == res.id) {
  52. // console.log('邀请人不能是自己的下级')
  53. // }
  54. // // 用户没有邀请人, 并且邀请人不是自己
  55. // else if (!userJSON.invite && userJSON.objectId != invite && !userJSON.agentLevel) {
  56. // console.log('上下级绑定成功');
  57. // user.set('invite', {
  58. // __type: "Pointer",
  59. // className: "_User",
  60. // objectId: invite
  61. // })
  62. // user.set('agent', {
  63. // __type: "Pointer",
  64. // className: "_User",
  65. // objectId: invite
  66. // })
  67. // }
  68. // await res.save()
  69. // }
  70. // }
  71. if(path){
  72. wx.navigateTo({
  73. url: path,
  74. });
  75. }
  76. },
  77. async onChange(event) {
  78. let currentIndex = event.detail;
  79. let userInfo = wx.getStorageSync("userLogin");
  80. if (currentIndex != 0 && userInfo == '') {
  81. console.log(userInfo);
  82. login.loginNow()
  83. return
  84. }
  85. this.setData({
  86. active: currentIndex
  87. })
  88. let componentPage = this.selectComponent(`#comp${currentIndex}`)
  89. switch (currentIndex) {
  90. case 0:
  91. break;
  92. case 2:
  93. break;
  94. case 3:
  95. // componentPage.getUser()
  96. break;
  97. }
  98. },
  99. toCart() {
  100. this.setData({
  101. active: 2
  102. })
  103. },
  104. //解析二维码
  105. getParaName(url) {
  106. if (!url || url.indexOf('?') == -1) {
  107. return
  108. }
  109. let paraname = url.split('?')[1]
  110. return this.setObject(paraname) //封装成对象
  111. },
  112. setObject(paraArr) {
  113. let obj = {}
  114. let arr1 = paraArr.split('&')
  115. arr1.forEach(item => {
  116. let str = item.split('=')
  117. let key = str[0]
  118. let val = str[1]
  119. obj[key] = val
  120. })
  121. return obj
  122. },
  123. /**
  124. * 生命周期函数--监听页面初次渲染完成
  125. */
  126. onReady: function () {
  127. },
  128. /**
  129. * 生命周期函数--监听页面显示
  130. */
  131. onShow: function () {
  132. this.getRenew()
  133. let {
  134. active
  135. } = this.data
  136. let componentPage = this.selectComponent(`#comp${active}`)
  137. if (!componentPage) {
  138. return
  139. }
  140. switch (active) {
  141. case 0:
  142. // componentPage.refresh()
  143. break;
  144. case 1:
  145. componentPage.setData({
  146. scate: []
  147. })
  148. componentPage.refresh()
  149. break;
  150. case 2:
  151. componentPage.setData({
  152. allCheck: false,
  153. cartList: [],
  154. totalPrice: 0.00,
  155. })
  156. componentPage.getShopcart()
  157. break;
  158. case 3:
  159. componentPage.refresh()
  160. break;
  161. }
  162. },
  163. /* 服务器是否需要续费 */
  164. async getRenew(){
  165. let query = new Parse.Query("Company")
  166. query.select('website','expireMap')
  167. query.equalTo('objectId',company)
  168. let c = await query.first()
  169. if(c?.id && c?.get('expireMap')){
  170. let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath
  171. //website配置且renew(续费)存在
  172. if(c.get('expireMap')?.renew && c.get('website')){
  173. wx.showModal({
  174. title: '警告',
  175. content: '当前平台服务器承载已超出阈值,请与技术人员联系。',
  176. showCancel: false,
  177. cancelText: '取消',
  178. cancelColor: '#000000',
  179. confirmText: '确定',
  180. confirmColor: '#3CC51F',
  181. success: (result) => {
  182. if(result.confirm){
  183. wx.reLaunch({
  184. url: `/common-page/pages/loading/index?url=${url}`,
  185. });
  186. }
  187. },
  188. fail: ()=>{},
  189. complete: ()=>{}
  190. });
  191. }
  192. }
  193. },
  194. /**
  195. * 生命周期函数--监听页面隐藏
  196. */
  197. onHide: function () {
  198. },
  199. /**
  200. * 生命周期函数--监听页面卸载
  201. */
  202. onUnload: function () {
  203. },
  204. /**
  205. * 页面相关事件处理函数--监听用户下拉动作
  206. */
  207. onPullDownRefresh: function () {
  208. wx.reLaunch({
  209. url: '/index',
  210. });
  211. },
  212. /**
  213. * 页面上拉触底事件的处理函数
  214. */
  215. onReachBottom: function () {
  216. },
  217. /**
  218. * 用户点击右上角分享
  219. */
  220. onShareAppMessage: function () {
  221. let uid = Parse.User.current().id
  222. return {
  223. title: '分享',
  224. // path: `index?invite=${uid}`,
  225. path: `index`,
  226. imageUrl: '',
  227. }
  228. }
  229. })