index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. var util = require('../../../../utils/util.js');
  2. var api = require('../../../../config/api.js');
  3. var user = require('../../../../utils/user.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. userInfo: {
  8. nickName: '点击登录',
  9. avatarUrl: '/static/images/new/icon-user.png',
  10. isDis: false
  11. },
  12. order: {
  13. unpaid: 0,
  14. unship: 0,
  15. unrecv: 0,
  16. uncomment: 0
  17. },
  18. hasLogin: false,
  19. isdis: false, //是否分销员
  20. issign: true, //是否注册完成了信息,
  21. isMember: false, //是否是会员
  22. },
  23. onLoad: function (options) {
  24. // 页面初始化 options为页面跳转所带来的参数
  25. console.info("pages/tabBar/ucenter/index/index onload")
  26. },
  27. onReady: function () {},
  28. goReferee() {
  29. if (this.data.hasLogin) {
  30. wx.navigateTo({
  31. url: "/pages/referee/index"
  32. });
  33. } else {
  34. wx.navigateTo({
  35. url: "/pages/auth/login/login"
  36. });
  37. }
  38. },
  39. onShow: function () {
  40. console.info(app.globalData.hasLogin);
  41. //获取用户的登录信息
  42. if (app.globalData.hasLogin) {
  43. let userInfo = wx.getStorageSync('userInfo');
  44. //console.info(userInfo);
  45. this.setData({
  46. userInfo: userInfo,
  47. hasLogin: true
  48. });
  49. app.globalData.userInfo = userInfo;
  50. //console.log(app.globalData.hasLogin);
  51. //console.log(userInfo);
  52. let that = this;
  53. util.request(api.UserIndex).then(function (res) {
  54. if (res.errno === 0) {
  55. console.log(res);
  56. that.setData({
  57. collectCount: res.data.collectCount,
  58. couponCount: res.data.couponCount,
  59. order: res.data.order,
  60. isdis: res.data.isdis,
  61. issign: res.data.issign,
  62. isMember: res.data.level == '1' ? true : false,
  63. });
  64. app.globalData.isMember = (res.data.level == '1' ? true : false);
  65. }
  66. });
  67. }
  68. },
  69. onHide: function () {
  70. // 页面隐藏
  71. },
  72. onUnload: function () {
  73. // 页面关闭
  74. },
  75. goAftersaleList() {
  76. console.log('来了');
  77. if (this.data.hasLogin) {
  78. wx.navigateTo({
  79. url: "/pages/ucenter/aftersaleList/aftersaleList"
  80. });
  81. } else {
  82. wx.navigateTo({
  83. url: "/pages/auth/login/login"
  84. });
  85. }
  86. },
  87. goLogin() {
  88. if (!this.data.hasLogin) {
  89. wx.navigateTo({
  90. url: "/pages/auth/login/login"
  91. });
  92. }
  93. },
  94. goOrder() {
  95. if (this.data.hasLogin) {
  96. try {
  97. wx.setStorageSync('tab', 0);
  98. } catch (e) {
  99. }
  100. wx.navigateTo({
  101. url: "/pages/ucenter/order/order",
  102. });
  103. } else {
  104. wx.navigateTo({
  105. url: "/pages/auth/login/login"
  106. });
  107. }
  108. },
  109. goOrderIndex(e) {
  110. if (this.data.hasLogin) {
  111. let tab = e.currentTarget.dataset.index
  112. let route = e.currentTarget.dataset.route
  113. try {
  114. wx.setStorageSync('tab', tab);
  115. } catch (e) {
  116. }
  117. wx.navigateTo({
  118. url: route,
  119. success: function (res) {},
  120. fail: function (res) {},
  121. complete: function (res) {},
  122. })
  123. } else {
  124. wx.navigateTo({
  125. url: "/pages/auth/login/login"
  126. });
  127. };
  128. },
  129. goSign() {
  130. wx.navigateTo({
  131. url: "/pages/ucenter/parter/sign/index"
  132. });
  133. },
  134. goStar() {
  135. if (this.data.hasLogin) {
  136. if (this.data.isdis) {
  137. let url = "/pages/ucenter/parter/index";
  138. // if(!this.data.isnid)//是否实名过
  139. // url="/pages/auth/register/register";
  140. //跳转
  141. wx.navigateTo({
  142. url: url
  143. });
  144. } else {
  145. wx.navigateTo({
  146. url: "/pages/ucenter/parter/join/joinapply"
  147. });
  148. }
  149. } else {
  150. wx.navigateTo({
  151. url: "/pages/auth/login/login"
  152. });
  153. };
  154. },
  155. goCoupon() {
  156. if (this.data.hasLogin) {
  157. wx.navigateTo({
  158. url: "/pages/ucenter/couponList/couponList"
  159. });
  160. } else {
  161. wx.navigateTo({
  162. url: "/pages/auth/login/login"
  163. });
  164. };
  165. },
  166. goGroupon() {
  167. if (this.data.hasLogin) {
  168. wx.navigateTo({
  169. url: "/pages/groupon/myGroupon/myGroupon"
  170. });
  171. } else {
  172. wx.navigateTo({
  173. url: "/pages/auth/login/login"
  174. });
  175. };
  176. },
  177. goCollect() {
  178. if (this.data.hasLogin) {
  179. wx.navigateTo({
  180. url: "/pages/ucenter/collect/collect"
  181. });
  182. } else {
  183. wx.navigateTo({
  184. url: "/pages/auth/login/login"
  185. });
  186. };
  187. },
  188. goFeedback(e) {
  189. if (this.data.hasLogin) {
  190. wx.navigateTo({
  191. url: "/pages/ucenter/feedback/feedback"
  192. });
  193. } else {
  194. wx.navigateTo({
  195. url: "/pages/auth/login/login"
  196. });
  197. };
  198. },
  199. goRegistr() {
  200. if (this.data.hasLogin) {
  201. wx.navigateTo({
  202. url: "/pages/auth/register/register"
  203. });
  204. } else {
  205. wx.navigateTo({
  206. url: "/pages/auth/login/login"
  207. });
  208. };
  209. },
  210. goFootprint() {
  211. if (this.data.hasLogin) {
  212. wx.navigateTo({
  213. url: "/pages/ucenter/footprint/footprint"
  214. });
  215. } else {
  216. wx.navigateTo({
  217. url: "/pages/auth/login/login"
  218. });
  219. };
  220. },
  221. goAddress() {
  222. if (this.data.hasLogin) {
  223. wx.navigateTo({
  224. url: "/pages/ucenter/address/address"
  225. });
  226. } else {
  227. wx.navigateTo({
  228. url: "/pages/auth/login/login"
  229. });
  230. };
  231. },
  232. wxLogin: function () {
  233. let that = this;
  234. console.log();
  235. wx.getUserProfile({
  236. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  237. success: (res) => {
  238. console.log(res);
  239. let e = res;
  240. if (e.userInfo == null) {
  241. wx.showToast({
  242. title: '未授权,无法完善信息',
  243. icon: 'success',
  244. duration: 3000
  245. });
  246. return;
  247. }
  248. e.userInfo.encryptedData = e.encryptedData;
  249. user.loginByWeixin(e.userInfo).then(function (res) {
  250. app.globalData.userInfo=res.data.userInfo;
  251. wx.setStorageSync('userInfo', res.data.userInfo);
  252. that.setData({
  253. issign: true,
  254. userInfo:res.data.userInfo
  255. })
  256. wx.showToast({
  257. title: '信息完善成功',
  258. icon: 'success',
  259. duration: 3000
  260. });
  261. }).catch((err) => {
  262. console.info(err);
  263. wx.showToast({
  264. title: '请求失败,稍后再试',
  265. icon: 'success',
  266. duration: 3000
  267. });
  268. });
  269. }
  270. })
  271. },
  272. goAfterSale: function () {
  273. if (this.data.hasLogin) {
  274. wx.navigateTo({
  275. url: "/pages/ucenter/aftersaleList/aftersaleList"
  276. });
  277. } else {
  278. wx.navigateTo({
  279. url: "/pages/auth/login/login"
  280. });
  281. };
  282. },
  283. aboutUs: function () {
  284. wx.navigateTo({
  285. url: '/pages/ucenter/about/about'
  286. });
  287. },
  288. goHelp: function () {
  289. wx.navigateTo({
  290. url: '/pages/ucenter/help/help'
  291. });
  292. },
  293. createQrcode: function () { //二维码生成
  294. util.request(api.QrCodeCreate, {
  295. path: '/pages/index/index'
  296. }, 'POST').then(function (res) {
  297. console.log(res);
  298. wx.previewImage({
  299. current: res.data.imgUrl, // 当前显示图片的http链接
  300. urls: [res.data.imgUrl] // 需要预览的图片http链接列表
  301. })
  302. });
  303. },
  304. exitLogin: function () {
  305. wx.showModal({
  306. title: '',
  307. confirmColor: '#b4282d',
  308. content: '退出登录?',
  309. success: function (res) {
  310. if (!res.confirm) {
  311. return;
  312. }
  313. util.request(api.AuthLogout, {}, 'POST');
  314. app.globalData={};
  315. wx.removeStorageSync('token');
  316. wx.removeStorageSync('userInfo');
  317. wx.reLaunch({
  318. url: '/pages/tabBar/ucenter/index/index'
  319. });
  320. // wx.reLaunch({
  321. // url: '/pages/index/index'
  322. // });
  323. }
  324. })
  325. },
  326. goMemberCenter() {
  327. wx.navigateTo({
  328. url: "/pages/member/memberCenter/memberCenter"
  329. });
  330. },
  331. goBuyMember() {
  332. wx.navigateTo({
  333. url: "/pages/member/buyMember/buyMember"
  334. });
  335. },
  336. })