index.js 7.9 KB

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