index.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. wx.navigateTo({
  114. url: "/pages/ucenter/order/order?tab=" + tab,
  115. });
  116. } else {
  117. wx.navigateTo({
  118. url: "/pages/auth/login/login"
  119. });
  120. };
  121. },
  122. goSign() {
  123. wx.navigateTo({
  124. url: "/pages/ucenter/parter/sign/index"
  125. });
  126. },
  127. goStar() {
  128. if (this.data.hasLogin) {
  129. if (this.data.isdis) {
  130. let url = "/pages/ucenter/parter/index";
  131. // if(!this.data.isnid)//是否实名过
  132. // url="/pages/auth/register/register";
  133. //跳转
  134. wx.navigateTo({
  135. url: url
  136. });
  137. } else {
  138. wx.navigateTo({
  139. url: "/pages/ucenter/parter/join/joinapply"
  140. });
  141. }
  142. } else {
  143. wx.navigateTo({
  144. url: "/pages/auth/login/login"
  145. });
  146. };
  147. },
  148. goCoupon() {
  149. if (this.data.hasLogin) {
  150. wx.navigateTo({
  151. url: "/pages/ucenter/couponList/couponList"
  152. });
  153. } else {
  154. wx.navigateTo({
  155. url: "/pages/auth/login/login"
  156. });
  157. };
  158. },
  159. goGroupon() {
  160. if (this.data.hasLogin) {
  161. wx.navigateTo({
  162. url: "/pages/groupon/myGroupon/myGroupon"
  163. });
  164. } else {
  165. wx.navigateTo({
  166. url: "/pages/auth/login/login"
  167. });
  168. };
  169. },
  170. goCollect() {
  171. if (this.data.hasLogin) {
  172. wx.navigateTo({
  173. url: "/pages/ucenter/collect/collect"
  174. });
  175. } else {
  176. wx.navigateTo({
  177. url: "/pages/auth/login/login"
  178. });
  179. };
  180. },
  181. goFeedback(e) {
  182. if (this.data.hasLogin) {
  183. wx.navigateTo({
  184. url: "/pages/ucenter/feedback/feedback"
  185. });
  186. } else {
  187. wx.navigateTo({
  188. url: "/pages/auth/login/login"
  189. });
  190. };
  191. },
  192. goRegistr() {
  193. if (this.data.hasLogin) {
  194. wx.navigateTo({
  195. url: "/pages/auth/register/register"
  196. });
  197. } else {
  198. wx.navigateTo({
  199. url: "/pages/auth/login/login"
  200. });
  201. };
  202. },
  203. goFootprint() {
  204. if (this.data.hasLogin) {
  205. wx.navigateTo({
  206. url: "/pages/ucenter/footprint/footprint"
  207. });
  208. } else {
  209. wx.navigateTo({
  210. url: "/pages/auth/login/login"
  211. });
  212. };
  213. },
  214. goAddress() {
  215. if (this.data.hasLogin) {
  216. wx.navigateTo({
  217. url: "/pages/ucenter/address/address"
  218. });
  219. } else {
  220. wx.navigateTo({
  221. url: "/pages/auth/login/login"
  222. });
  223. };
  224. },
  225. wxLogin: function () {
  226. let that = this;
  227. console.log();
  228. wx.getUserProfile({
  229. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  230. success: (res) => {
  231. console.log(res);
  232. let e = res;
  233. if (e.userInfo == null) {
  234. wx.showToast({
  235. title: '未授权,无法完善信息',
  236. icon: 'success',
  237. duration: 3000
  238. });
  239. return;
  240. }
  241. e.userInfo.encryptedData = e.encryptedData;
  242. user.loginByWeixin(e.userInfo).then(function (res) {
  243. app.globalData.userInfo=res.data.userInfo;
  244. wx.setStorageSync('userInfo', res.data.userInfo);
  245. that.setData({
  246. issign: true,
  247. userInfo:res.data.userInfo
  248. })
  249. wx.showToast({
  250. title: '信息完善成功',
  251. icon: 'success',
  252. duration: 3000
  253. });
  254. }).catch((err) => {
  255. console.info(err);
  256. wx.showToast({
  257. title: '请求失败,稍后再试',
  258. icon: 'success',
  259. duration: 3000
  260. });
  261. });
  262. }
  263. })
  264. },
  265. goAfterSale: function () {
  266. if (this.data.hasLogin) {
  267. wx.navigateTo({
  268. url: "/pages/ucenter/aftersaleList/aftersaleList"
  269. });
  270. } else {
  271. wx.navigateTo({
  272. url: "/pages/auth/login/login"
  273. });
  274. };
  275. },
  276. aboutUs: function () {
  277. wx.navigateTo({
  278. url: '/pages/ucenter/about/about'
  279. });
  280. },
  281. goHelp: function () {
  282. wx.navigateTo({
  283. url: '/pages/ucenter/help/help'
  284. });
  285. },
  286. createQrcode: function () { //二维码生成
  287. util.request(api.QrCodeCreate, {
  288. path: '/pages/index/index'
  289. }, 'POST').then(function (res) {
  290. console.log(res);
  291. wx.previewImage({
  292. current: res.data.imgUrl, // 当前显示图片的http链接
  293. urls: [res.data.imgUrl] // 需要预览的图片http链接列表
  294. })
  295. });
  296. },
  297. exitLogin: function (e) {
  298. let type=e.target.dataset.type;
  299. let msg=type==1?"是否切换账号?":"退出登录?";
  300. wx.showModal({
  301. title: '',
  302. confirmColor: '#b4282d',
  303. content:msg,
  304. success: function (res) {
  305. if (!res.confirm) {
  306. return;
  307. }
  308. util.request(api.AuthLogout, {}, 'POST');
  309. app.globalData={};
  310. wx.removeStorageSync('token');
  311. wx.removeStorageSync('userInfo');
  312. console.log(type);
  313. if(type==1){//切换账号
  314. wx.navigateTo({
  315. url: '/pages/auth/login/login?type='+type
  316. });
  317. }else{
  318. wx.reLaunch({
  319. url: '/pages/tabBar/ucenter/index/index'
  320. });
  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. goIm(){
  336. wx.navigateTo({
  337. url: '/pages/im/im'
  338. });
  339. },
  340. })