index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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: '场景列表',
  74. type: 31
  75. },
  76. {
  77. icon: 'vr_live@2x',
  78. url: '/pages/sence/sence',
  79. name: '带看',
  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. console.log('UserInfo',data)
  155. wx.setStorageSync('userinfoDetail', data)
  156. this.setData({
  157. userInfo: {
  158. nickName: data.nickname,
  159. avatarUrl: data.avatar,
  160. }
  161. })
  162. },
  163. async getBrandList () {
  164. let res = await util.request(api.GetAdminBrands)
  165. let list = res.data
  166. if (list && list.length>0) {
  167. this.setData({
  168. hasBrand: true
  169. })
  170. } else {
  171. this.setData({
  172. hasBrand: false
  173. })
  174. }
  175. },
  176. onShow: function () {
  177. getApp().updateCardCount()
  178. let userInfo = wx.getStorageSync('userInfo');
  179. let token = wx.getStorageSync('token');
  180. this.getBrandList()
  181. this.getUserInfo()
  182. this.getCounts()
  183. // 页面显示
  184. if (userInfo && token) {
  185. app.globalData.userInfo = userInfo;
  186. app.globalData.token = token;
  187. }
  188. this.setData({
  189. // userInfo: app.globalData.userInfo,
  190. token: app.globalData.token
  191. });
  192. util.request(api.CartList).then((res) => {
  193. let isLogin = false
  194. if (res.errno === 401) {
  195. isLogin = false
  196. app.globalData.userInfo = tempUserInfo;
  197. app.globalData.token = '';
  198. } else {
  199. isLogin = true
  200. app.globalData.userInfo = userInfo;
  201. app.globalData.token = token;
  202. }
  203. if (!isLogin){
  204. this.setData({
  205. token:'',
  206. userInfo: tempUserInfo
  207. });
  208. }
  209. this.setData({
  210. isLogin
  211. });
  212. });
  213. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  214. this.getTabBar().setData({
  215. selected: 3
  216. })
  217. }
  218. },
  219. onPullDownRefresh() {
  220. getApp().onPullDownRefresh()
  221. },
  222. onHide: function () {
  223. // 页面隐藏
  224. },
  225. onUnload: function () {
  226. // 页面关闭
  227. },
  228. bindGetUserInfo(e) {
  229. let userInfo = wx.getStorageSync('userInfo');
  230. let token = wx.getStorageSync('token');
  231. if (userInfo && token) {
  232. return;
  233. }
  234. if (e.detail.userInfo){
  235. //用户按了允许授权按钮
  236. user.loginByWeixin(e.detail).then(res => {
  237. this.setData({
  238. userInfo: res.data.userInfo,
  239. isLogin: true
  240. });
  241. res.data.userInfo.userId = res.data.userId
  242. res.data.userInfo.isAdmin = res.data.isAdmin
  243. wx.setStorageSync('userInfo', res.data.userInfo);
  244. wx.setStorageSync('token', res.data.token);
  245. wx.setStorageSync('userId', res.data.userId);
  246. app.globalData.userInfo = res.data.userInfo;
  247. app.globalData.token = res.data.token;
  248. }).catch((err) => {
  249. this.setData({
  250. token: '',
  251. userInfo: tempUserInfo
  252. });
  253. app.globalData.userInfo = tempUserInfo;
  254. app.globalData.token = '';
  255. console.log(err)
  256. });
  257. } else {
  258. //用户按了拒绝按钮
  259. // wx.showModal({
  260. // title: '温馨提示',
  261. // content: '您点击了"取消"授权,将无法获取杭州天门科技有限公司完整服务。请“授权”以保证各项功能正常使用。',
  262. // confirmText:'授权',
  263. // success: function (res) {
  264. // if (res.confirm) {
  265. // wx.openSetting({
  266. // success: (res) => {
  267. // if (res.authSetting["scope.userInfo"]) {////如果用户重新同意了授权登录
  268. // user.loginByWeixin(e.detail).then(res => {
  269. // this.setData({
  270. // userInfo: res.data.userInfo
  271. // });
  272. // app.globalData.userInfo = res.data.userInfo;
  273. // app.globalData.token = res.data.token;
  274. // }).catch((err) => {
  275. // console.log(err)
  276. // });
  277. // }
  278. // }
  279. // })
  280. // }
  281. // }
  282. // });
  283. }
  284. },
  285. exitLogin: function () {
  286. wx.showModal({
  287. title: '',
  288. confirmColor: '#b4282d',
  289. content: '退出登录?',
  290. success: function (res) {
  291. if (res.confirm) {
  292. wx.removeStorageSync('token');
  293. wx.removeStorageSync('userInfo');
  294. wx.switchTab({
  295. url: '/pages/index/index'
  296. });
  297. }
  298. }
  299. })
  300. },
  301. toReport () {
  302. wx.navigateTo({
  303. url: '/dataReport/pages/data-report/data-report',
  304. })
  305. }
  306. })