index.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var user = require('../../../services/user.js');
  4. var app = getApp();
  5. Page({
  6. data: {
  7. unPayNum:0,
  8. unTakeNum:0,
  9. unEvalNum:0,
  10. userInfo: {},
  11. curUser:{},
  12. isQueryCrossQuotal: null
  13. },
  14. onLoad: function (options) {
  15. // 页面初始化 options为页面跳转所带来的参数
  16. let that = this;
  17. },
  18. onReady: function () {
  19. },
  20. onShow: function () {
  21. let that = this;
  22. let userInfo = wx.getStorageSync('userInfo');
  23. let token = wx.getStorageSync('token');
  24. if (wx.getStorageSync('storeId')) {
  25. util.request(api.ChooseStoreId, {
  26. storeId: wx.getStorageSync('storeId'),
  27. merchSn: wx.getStorageSync('merchSn'),
  28. isRefusedLogin: wx.getStorageSync('isRefusedLogin')
  29. }, 'POST').then(function (res) {
  30. if (res.errno === 0) {
  31. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  32. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  33. }
  34. });
  35. }
  36. if(userInfo){
  37. app.globalData.userInfo = userInfo;
  38. this.setData({
  39. userInfo: app.globalData.userInfo,
  40. });
  41. }else{
  42. app.globalData.userInfo = {
  43. nickName: '点击头像登录',
  44. avatarUrl: 'http://120.76.26.84:80/group1/M00/00/02/rBJEdVvr3_eAJe0WAAAB_us54MA728.png'
  45. };
  46. this.setData({
  47. userInfo: app.globalData.userInfo,
  48. });
  49. }
  50. if (token) {
  51. app.globalData.token = token;
  52. }
  53. // 页面显示
  54. if (userInfo && token) {
  55. util.request(api.getCurUser, {
  56. userInfo: app.globalData.userInfo
  57. }, 'POST').then(function (res) {
  58. if (res.errno === 0) {
  59. that.setData({
  60. curUser: res.data
  61. });
  62. }
  63. });
  64. // 根据用户信息查询订单信息
  65. util.request(api.UcenterIndex, {}).then(function (res) {
  66. if (res.errno === 0) {
  67. if (res.data.countMap.orders > 0) {
  68. that.setData({
  69. unPayNum: res.data.countMap.unPayNum,
  70. unPaymentNum: res.data.countMap.unPaymentNum,
  71. unTakeNum: res.data.countMap.unTakeNum,
  72. unEvalNum: res.data.countMap.unEvalNum,
  73. isQueryCrossQuotal: res.data.countMap.isQueryCrossQuotal
  74. });
  75. console.log(res.data.countMap.isQueryCrossQuotal)
  76. }
  77. }
  78. });
  79. if (wx.getStorageSync('storeId') && wx.getStorageSync('merchSn')){
  80. that.reLoad();
  81. }
  82. } else {
  83. // console.log('拒绝授权:' + wx.getStorageSync('isRefusedLogin'))
  84. // if (wx.getStorageSync('isRefusedLogin') != 'true') {
  85. // wx.navigateTo({
  86. // url: '/pages/auth/btnAuth/btnAuth',
  87. // })
  88. // }
  89. }
  90. },
  91. onHide: function () {
  92. // 页面隐藏
  93. },
  94. onUnload: function () {
  95. // 页面关闭
  96. },
  97. reLoad: function () {
  98. let that = this;
  99. if (wx.getStorageSync('storeId')) {
  100. if (wx.getStorageSync('userId')) {
  101. wx.request({
  102. url: api.updateLoginUser,
  103. data: {
  104. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  105. },
  106. method: 'POST',
  107. header: {
  108. 'Content-Type': 'application/json'
  109. },
  110. success: function (wxRes) {
  111. if (wxRes.data.errno === 0) {
  112. // console.log("用户信息更新成功");
  113. }
  114. },
  115. fail: function (err) {
  116. console.log("failed");
  117. }
  118. });
  119. }
  120. }
  121. },
  122. bindMobile:function(){
  123. wx.navigateTo({
  124. url: '../../auth/newuser/newuser'
  125. })
  126. },
  127. // goLogin(){
  128. // user.loginByWeixin().then(res => {
  129. // this.setData({
  130. // userInfo: res.data.data.userInfo
  131. // });
  132. // app.globalData.userInfo = res.data.data.userInfo;
  133. // app.globalData.token = res.data.token;
  134. // }).catch((err) => {
  135. // console.log(err)
  136. // });
  137. // },
  138. allOrder() {
  139. let userInfo = wx.getStorageSync('userInfo');
  140. let token = wx.getStorageSync('token');
  141. if (userInfo && token) {
  142. wx.navigateTo({
  143. url: '/pages/ucenter/order/order'
  144. })
  145. }else{
  146. util.showErrorToast('请先登录');
  147. return false;
  148. }
  149. },
  150. checkUnNum(e){
  151. console.log(e.currentTarget.dataset.index)
  152. let userInfo = wx.getStorageSync('userInfo');
  153. let token = wx.getStorageSync('token');
  154. if (userInfo && token) {
  155. wx.navigateTo({
  156. url: '/pages/ucenter/order/order?tabIndex=' + e.currentTarget.dataset.index
  157. })
  158. } else {
  159. util.showErrorToast('请先登录');
  160. return false;
  161. }
  162. },
  163. exitLogin: function () {
  164. var that = this;
  165. wx.showModal({
  166. title: '',
  167. confirmColor: '#b4282d',
  168. content: '退出登录?',
  169. success: function (res) {
  170. if (res.confirm) {
  171. wx.removeStorageSync('token');
  172. wx.removeStorageSync('userInfo');
  173. wx.removeStorageSync('isRefusedLogin');
  174. that.setData({
  175. unPayNum: 0,
  176. unPaymentNum: 0,
  177. unTakeNum: 0,
  178. unEvalNum: 0
  179. });
  180. app.globalData.userInfo = {
  181. nickName: '点击头像登录',
  182. avatarUrl: 'http://120.76.26.84:80/group1/M00/00/02/rBJEdVvr3_eAJe0WAAAB_us54MA728.png'
  183. };
  184. wx.switchTab({
  185. url: '/pages/index/index'
  186. });
  187. }
  188. }
  189. })
  190. },
  191. loginUser() {
  192. wx.navigateTo({
  193. url: '/pages/ucenter/userLogin/userLogin'
  194. })
  195. },
  196. checkCouponLogin() {
  197. let userInfo = wx.getStorageSync('userInfo');
  198. let token = wx.getStorageSync('token');
  199. if (userInfo && token) {
  200. wx.navigateTo({
  201. url: '/pages/ucenter/coupon/coupon'
  202. })
  203. } else {
  204. util.showErrorToast('请先登录');
  205. return false;
  206. }
  207. },
  208. checkCollectLogin() {
  209. let userInfo = wx.getStorageSync('userInfo');
  210. let token = wx.getStorageSync('token');
  211. if (userInfo && token) {
  212. wx.navigateTo({
  213. url: '/pages/ucenter/collect/collect'
  214. })
  215. } else {
  216. util.showErrorToast('请先登录');
  217. return false;
  218. }
  219. },
  220. checkFootLogin() {
  221. let userInfo = wx.getStorageSync('userInfo');
  222. let token = wx.getStorageSync('token');
  223. if (userInfo && token) {
  224. wx.navigateTo({
  225. url: '/pages/ucenter/footprint/footprint'
  226. })
  227. } else {
  228. util.showErrorToast('请先登录');
  229. return false;
  230. }
  231. },
  232. checkAddressLogin() {
  233. let userInfo = wx.getStorageSync('userInfo');
  234. let token = wx.getStorageSync('token');
  235. if (userInfo && token) {
  236. wx.navigateTo({
  237. url: '/pages/ucenter/address/address'
  238. })
  239. } else {
  240. util.showErrorToast('请先登录');
  241. return false;
  242. }
  243. },
  244. checkCardLogin() {
  245. let userInfo = wx.getStorageSync('userInfo');
  246. let token = wx.getStorageSync('token');
  247. if (userInfo && token) {
  248. wx.navigateTo({
  249. url: '/pages/ucenter/idCard/idCard'
  250. })
  251. } else {
  252. util.showErrorToast('请先登录');
  253. return false;
  254. }
  255. },
  256. checkFeedLogin() {
  257. let userInfo = wx.getStorageSync('userInfo');
  258. let token = wx.getStorageSync('token');
  259. if (userInfo && token) {
  260. wx.navigateTo({
  261. url: '/pages/ucenter/feedback/feedback'
  262. })
  263. } else {
  264. util.showErrorToast('请先登录');
  265. return false;
  266. }
  267. },
  268. crossBoundaryQuotaQuery() {
  269. let userInfo = wx.getStorageSync('userInfo');
  270. let token = wx.getStorageSync('token');
  271. if (userInfo && token) {
  272. console.log('点击')
  273. wx.navigateTo({
  274. url: '/pages/ucenter/crossBoundaryQuotaQuery/crossBoundaryQuotaQuery'
  275. })
  276. } else {
  277. util.showErrorToast('请先登录');
  278. return false;
  279. }
  280. },
  281. })