1
0

index.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. that.setData({
  68. isQueryCrossQuotal: res.data.countMap.isQueryCrossQuotal
  69. });
  70. if (res.data.countMap.orders > 0) {
  71. that.setData({
  72. unPayNum: res.data.countMap.unPayNum,
  73. unPaymentNum: res.data.countMap.unPaymentNum,
  74. unTakeNum: res.data.countMap.unTakeNum,
  75. unEvalNum: res.data.countMap.unEvalNum,
  76. isQueryCrossQuotal: res.data.countMap.isQueryCrossQuotal
  77. });
  78. console.log(res.data.countMap.isQueryCrossQuotal)
  79. }
  80. }
  81. });
  82. if (wx.getStorageSync('storeId') && wx.getStorageSync('merchSn')){
  83. that.reLoad();
  84. }
  85. } else {
  86. // console.log('拒绝授权:' + wx.getStorageSync('isRefusedLogin'))
  87. // if (wx.getStorageSync('isRefusedLogin') != 'true') {
  88. // wx.navigateTo({
  89. // url: '/pages/auth/btnAuth/btnAuth',
  90. // })
  91. // }
  92. }
  93. },
  94. onHide: function () {
  95. // 页面隐藏
  96. },
  97. onUnload: function () {
  98. // 页面关闭
  99. },
  100. reLoad: function () {
  101. let that = this;
  102. if (wx.getStorageSync('storeId')) {
  103. if (wx.getStorageSync('userId')) {
  104. wx.request({
  105. url: api.updateLoginUser,
  106. data: {
  107. userId: wx.getStorageSync('userId'), storeId: wx.getStorageSync('storeId'), merchSn: wx.getStorageSync('merchSn')
  108. },
  109. method: 'POST',
  110. header: {
  111. 'Content-Type': 'application/json'
  112. },
  113. success: function (wxRes) {
  114. if (wxRes.data.errno === 0) {
  115. // console.log("用户信息更新成功");
  116. }
  117. },
  118. fail: function (err) {
  119. console.log("failed");
  120. }
  121. });
  122. }
  123. }
  124. },
  125. bindMobile:function(){
  126. wx.navigateTo({
  127. url: '../../auth/newuser/newuser'
  128. })
  129. },
  130. // goLogin(){
  131. // user.loginByWeixin().then(res => {
  132. // this.setData({
  133. // userInfo: res.data.data.userInfo
  134. // });
  135. // app.globalData.userInfo = res.data.data.userInfo;
  136. // app.globalData.token = res.data.token;
  137. // }).catch((err) => {
  138. // console.log(err)
  139. // });
  140. // },
  141. allOrder() {
  142. let userInfo = wx.getStorageSync('userInfo');
  143. let token = wx.getStorageSync('token');
  144. if (userInfo && token) {
  145. wx.navigateTo({
  146. url: '/pages/ucenter/order/order'
  147. })
  148. }else{
  149. util.showErrorToast('请先登录');
  150. return false;
  151. }
  152. },
  153. checkUnNum(e){
  154. console.log(e.currentTarget.dataset.index)
  155. let userInfo = wx.getStorageSync('userInfo');
  156. let token = wx.getStorageSync('token');
  157. if (userInfo && token) {
  158. wx.navigateTo({
  159. url: '/pages/ucenter/order/order?tabIndex=' + e.currentTarget.dataset.index
  160. })
  161. } else {
  162. util.showErrorToast('请先登录');
  163. return false;
  164. }
  165. },
  166. exitLogin: function () {
  167. var that = this;
  168. wx.showModal({
  169. title: '',
  170. confirmColor: '#b4282d',
  171. content: '退出登录?',
  172. success: function (res) {
  173. if (res.confirm) {
  174. wx.removeStorageSync('token');
  175. wx.removeStorageSync('userInfo');
  176. wx.removeStorageSync('isRefusedLogin');
  177. that.setData({
  178. unPayNum: 0,
  179. unPaymentNum: 0,
  180. unTakeNum: 0,
  181. unEvalNum: 0
  182. });
  183. app.globalData.userInfo = {
  184. nickName: '点击头像登录',
  185. avatarUrl: 'http://120.76.26.84:80/group1/M00/00/02/rBJEdVvr3_eAJe0WAAAB_us54MA728.png'
  186. };
  187. wx.switchTab({
  188. url: '/pages/index/index'
  189. });
  190. }
  191. }
  192. })
  193. },
  194. loginUser() {
  195. wx.navigateTo({
  196. url: '/pages/ucenter/userLogin/userLogin'
  197. })
  198. },
  199. checkCouponLogin() {
  200. let userInfo = wx.getStorageSync('userInfo');
  201. let token = wx.getStorageSync('token');
  202. if (userInfo && token) {
  203. wx.navigateTo({
  204. url: '/pages/ucenter/coupon/coupon'
  205. })
  206. } else {
  207. util.showErrorToast('请先登录');
  208. return false;
  209. }
  210. },
  211. checkCollectLogin() {
  212. let userInfo = wx.getStorageSync('userInfo');
  213. let token = wx.getStorageSync('token');
  214. if (userInfo && token) {
  215. wx.navigateTo({
  216. url: '/pages/ucenter/collect/collect'
  217. })
  218. } else {
  219. util.showErrorToast('请先登录');
  220. return false;
  221. }
  222. },
  223. checkFootLogin() {
  224. let userInfo = wx.getStorageSync('userInfo');
  225. let token = wx.getStorageSync('token');
  226. if (userInfo && token) {
  227. wx.navigateTo({
  228. url: '/pages/ucenter/footprint/footprint'
  229. })
  230. } else {
  231. util.showErrorToast('请先登录');
  232. return false;
  233. }
  234. },
  235. checkAddressLogin() {
  236. let userInfo = wx.getStorageSync('userInfo');
  237. let token = wx.getStorageSync('token');
  238. if (userInfo && token) {
  239. wx.navigateTo({
  240. url: '/pages/ucenter/address/address'
  241. })
  242. } else {
  243. util.showErrorToast('请先登录');
  244. return false;
  245. }
  246. },
  247. checkCardLogin() {
  248. let userInfo = wx.getStorageSync('userInfo');
  249. let token = wx.getStorageSync('token');
  250. if (userInfo && token) {
  251. wx.navigateTo({
  252. url: '/pages/ucenter/idCard/idCard'
  253. })
  254. } else {
  255. util.showErrorToast('请先登录');
  256. return false;
  257. }
  258. },
  259. checkFeedLogin() {
  260. let userInfo = wx.getStorageSync('userInfo');
  261. let token = wx.getStorageSync('token');
  262. if (userInfo && token) {
  263. wx.navigateTo({
  264. url: '/pages/ucenter/feedback/feedback'
  265. })
  266. } else {
  267. util.showErrorToast('请先登录');
  268. return false;
  269. }
  270. },
  271. crossBoundaryQuotaQuery() {
  272. let that = this;
  273. let userInfo = wx.getStorageSync('userInfo');
  274. let token = wx.getStorageSync('token');
  275. if (userInfo && token) {
  276. if(that.data.curUser.idNo){
  277. wx.navigateTo({
  278. url: '/pages/ucenter/crossBoundaryQuotaQuery/crossBoundaryQuotaQuery'
  279. })
  280. }else{
  281. util.showErrorToast('请先实名认证');
  282. return false;
  283. }
  284. } else {
  285. util.showErrorToast('请先登录');
  286. return false;
  287. }
  288. },
  289. })