index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. // 定义插件变量 引入方法
  6. const tempUserInfo = {
  7. nickName: 'Hi,游客',
  8. userName: '点击去登录',
  9. avatarUrl: 'https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180727/150547696d798c.png'
  10. }
  11. Page({
  12. data: {
  13. userInfo: {},
  14. hasMobile: '',
  15. imgServer: util.imgServer,
  16. all: {
  17. icon: 'ct1',
  18. name: '全部订单',
  19. id: -1
  20. },
  21. orderList:[
  22. {
  23. icon: 'ct2',
  24. name: '待付款',
  25. id: 0
  26. },
  27. {
  28. icon: 'ct3',
  29. name: '待发货',
  30. id: 201
  31. },
  32. {
  33. icon: 'ct4',
  34. name: '待收货',
  35. id: 300
  36. },
  37. {
  38. icon: 'ct5',
  39. name: '已完成',
  40. id: 301
  41. }
  42. ],
  43. barList:[
  44. {
  45. icon: 'cb1',
  46. url: '/pages/ucenter/collect/collect',
  47. name: '我的收藏',
  48. id: 0
  49. },
  50. {
  51. icon: 'cb5',
  52. url: '/pages/coupon/coupon',
  53. name: '优惠券',
  54. id: 5
  55. },
  56. // {
  57. // icon: 'cb6',
  58. // url: '/pages/ucenter/footprint/footprint',
  59. // name: '我的积分',
  60. // id: 1
  61. // },
  62. {
  63. icon: 'cb2',
  64. url: '/pages/ucenter/address/address',
  65. name: '地址管理',
  66. id: 1
  67. }
  68. ],
  69. senceList:[
  70. {
  71. icon: 'vr@2x',
  72. url: '/pages/sence/sence',
  73. name: 'VR场景',
  74. type: 31
  75. },
  76. {
  77. icon: 'vr_live@2x',
  78. url: '/pages/sence/sence',
  79. name: 'VR场景直播间',
  80. type: 32
  81. }
  82. ],
  83. relatedGoods: [],
  84. isLogin: app.globalData.isLogin
  85. },
  86. getGoodsRelated: function () {
  87. let that = this;
  88. util.request(api.GoodsRelated, {}).then(function (res) {
  89. if (res.errno === 0) {
  90. that.setData({
  91. relatedGoods: res.data.goodsList,
  92. });
  93. }
  94. });
  95. },
  96. tapByIdx:function(e){
  97. let {
  98. type
  99. } = e.currentTarget.dataset;
  100. let {
  101. url
  102. } = e.currentTarget.dataset;
  103. console.log(url+'?type='+type)
  104. // if (this.data.isLogin) {
  105. wx.navigateTo({
  106. url: url+'?type='+type,
  107. success: function (res) { },
  108. fail: function (res) { },
  109. complete: function (res) { },
  110. })
  111. // } else {
  112. // wx.navigateTo({
  113. // url: '/pages/auth/btnAuth/btnAuth',
  114. // })
  115. // // wx.showModal({
  116. // // title: '提示',
  117. // // content: '请登录后查看',
  118. // // showCancel: false,
  119. // // confirmColor: '#0075DC',
  120. // // success: res=>{
  121. // // }
  122. // // });
  123. // }
  124. },
  125. onLoad: function (options) {
  126. getApp().checkNetStatu();
  127. // 页面初始化 options为页面跳转所带来的参数
  128. // this.getGoodsRelated()
  129. // wx.setNavigationBarColor({
  130. // frontColor:'#ffffff',
  131. // backgroundColor:'#fb6400',
  132. // "navigationStyle":"custom"
  133. // animation: {
  134. // duration: 400,
  135. // timingFunc:'easeIn'
  136. // }
  137. // })
  138. },
  139. onReady: function () {
  140. },
  141. async getCounts() {
  142. let { data } = await util.request(api.OrderCount)
  143. let orderList = this.data.orderList.map(item => {
  144. let ci = data.find(({code}) => code === item.id)
  145. if (ci) {
  146. item.count = ci.num > 99 ? '..' : ci.num
  147. }
  148. return { ...item }
  149. })
  150. this.setData({ orderList })
  151. },
  152. async getUserInfo() {
  153. const {data} = await util.request(api.UserInfo)
  154. wx.setStorageSync('userinfoDetail', data)
  155. this.setData({
  156. userInfo: {
  157. nickName: data.nickname,
  158. avatarUrl: data.avatar,
  159. }
  160. })
  161. },
  162. async getBrandList () {
  163. let res = await util.request(api.GetAdminBrands)
  164. let list = res.data
  165. if (list && list.length>0) {
  166. this.setData({
  167. hasBrand: true
  168. })
  169. } else {
  170. this.setData({
  171. hasBrand: false
  172. })
  173. }
  174. },
  175. onShow: function () {
  176. getApp().updateCardCount()
  177. let userInfo = wx.getStorageSync('userInfo');
  178. let token = wx.getStorageSync('token');
  179. this.getBrandList()
  180. this.getUserInfo()
  181. this.getCounts()
  182. // 页面显示
  183. if (userInfo && token) {
  184. app.globalData.userInfo = userInfo;
  185. app.globalData.token = token;
  186. }
  187. this.setData({
  188. // userInfo: app.globalData.userInfo,
  189. token: app.globalData.token
  190. });
  191. util.request(api.CartList).then((res) => {
  192. let isLogin = false
  193. if (res.errno === 401) {
  194. isLogin = false
  195. app.globalData.userInfo = tempUserInfo;
  196. app.globalData.token = '';
  197. } else {
  198. isLogin = true
  199. app.globalData.userInfo = userInfo;
  200. app.globalData.token = token;
  201. }
  202. if (!isLogin){
  203. this.setData({
  204. token:'',
  205. userInfo: tempUserInfo
  206. });
  207. }
  208. this.setData({
  209. isLogin
  210. });
  211. });
  212. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  213. this.getTabBar().setData({
  214. selected: 3
  215. })
  216. }
  217. },
  218. onPullDownRefresh() {
  219. getApp().onPullDownRefresh()
  220. },
  221. onHide: function () {
  222. // 页面隐藏
  223. },
  224. onUnload: function () {
  225. // 页面关闭
  226. },
  227. bindGetUserInfo(e) {
  228. let userInfo = wx.getStorageSync('userInfo');
  229. let token = wx.getStorageSync('token');
  230. if (userInfo && token) {
  231. return;
  232. }
  233. if (e.detail.userInfo){
  234. //用户按了允许授权按钮
  235. user.loginByWeixin(e.detail).then(res => {
  236. this.setData({
  237. userInfo: res.data.userInfo,
  238. isLogin: true
  239. });
  240. res.data.userInfo.userId = res.data.userId
  241. res.data.userInfo.isAdmin = res.data.isAdmin
  242. wx.setStorageSync('userInfo', res.data.userInfo);
  243. wx.setStorageSync('token', res.data.token);
  244. wx.setStorageSync('userId', res.data.userId);
  245. app.globalData.userInfo = res.data.userInfo;
  246. app.globalData.token = res.data.token;
  247. }).catch((err) => {
  248. this.setData({
  249. token: '',
  250. userInfo: tempUserInfo
  251. });
  252. app.globalData.userInfo = tempUserInfo;
  253. app.globalData.token = '';
  254. console.log(err)
  255. });
  256. } else {
  257. //用户按了拒绝按钮
  258. // wx.showModal({
  259. // title: '温馨提示',
  260. // content: '您点击了"取消"授权,将无法获取杭州天门科技有限公司完整服务。请“授权”以保证各项功能正常使用。',
  261. // confirmText:'授权',
  262. // success: function (res) {
  263. // if (res.confirm) {
  264. // wx.openSetting({
  265. // success: (res) => {
  266. // if (res.authSetting["scope.userInfo"]) {////如果用户重新同意了授权登录
  267. // user.loginByWeixin(e.detail).then(res => {
  268. // this.setData({
  269. // userInfo: res.data.userInfo
  270. // });
  271. // app.globalData.userInfo = res.data.userInfo;
  272. // app.globalData.token = res.data.token;
  273. // }).catch((err) => {
  274. // console.log(err)
  275. // });
  276. // }
  277. // }
  278. // })
  279. // }
  280. // }
  281. // });
  282. }
  283. },
  284. exitLogin: function () {
  285. wx.showModal({
  286. title: '',
  287. confirmColor: '#b4282d',
  288. content: '退出登录?',
  289. success: function (res) {
  290. if (res.confirm) {
  291. wx.removeStorageSync('token');
  292. wx.removeStorageSync('userInfo');
  293. wx.switchTab({
  294. url: '/pages/index/index'
  295. });
  296. }
  297. }
  298. })
  299. },
  300. toReport () {
  301. wx.navigateTo({
  302. url: '/dataReport/pages/data-report/data-report',
  303. })
  304. }
  305. })