index.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. icon: 'vr_live@2x',
  84. url: '/pages/roomManger/roomManger',
  85. name: '我的房间',
  86. type: 33
  87. }
  88. ],
  89. relatedGoods: [],
  90. isLogin: app.globalData.isLogin
  91. },
  92. getGoodsRelated: function () {
  93. let that = this;
  94. util.request(api.GoodsRelated, {}).then(function (res) {
  95. if (res.errno === 0) {
  96. that.setData({
  97. relatedGoods: res.data.goodsList,
  98. });
  99. }
  100. });
  101. },
  102. tapByIdx:function(e){
  103. let {
  104. type
  105. } = e.currentTarget.dataset;
  106. let {
  107. url
  108. } = e.currentTarget.dataset;
  109. console.log(url+'?type='+type)
  110. // if (this.data.isLogin) {
  111. wx.navigateTo({
  112. url: url+'?type='+type,
  113. success: function (res) { },
  114. fail: function (res) { },
  115. complete: function (res) { },
  116. })
  117. // } else {
  118. // wx.navigateTo({
  119. // url: '/pages/auth/btnAuth/btnAuth',
  120. // })
  121. // // wx.showModal({
  122. // // title: '提示',
  123. // // content: '请登录后查看',
  124. // // showCancel: false,
  125. // // confirmColor: '#0075DC',
  126. // // success: res=>{
  127. // // }
  128. // // });
  129. // }
  130. },
  131. onLoad: function (options) {
  132. getApp().checkNetStatu();
  133. // 页面初始化 options为页面跳转所带来的参数
  134. // this.getGoodsRelated()
  135. // wx.setNavigationBarColor({
  136. // frontColor:'#ffffff',
  137. // backgroundColor:'#fb6400',
  138. // "navigationStyle":"custom"
  139. // animation: {
  140. // duration: 400,
  141. // timingFunc:'easeIn'
  142. // }
  143. // })
  144. },
  145. onReady: function () {
  146. },
  147. async getCounts() {
  148. let { data } = await util.request(api.OrderCount)
  149. let orderList = this.data.orderList.map(item => {
  150. let ci = data.find(({code}) => code === item.id)
  151. if (ci) {
  152. item.count = ci.num > 99 ? '..' : ci.num
  153. }
  154. return { ...item }
  155. })
  156. this.setData({ orderList })
  157. },
  158. async getUserInfo() {
  159. const {data} = await util.request(api.UserInfo)
  160. console.log('UserInfo',data)
  161. wx.setStorageSync('userinfoDetail', data)
  162. this.setData({
  163. userInfo: {
  164. nickName: data.nickname,
  165. avatarUrl: data.avatar,
  166. }
  167. })
  168. },
  169. async getBrandList () {
  170. let res = await util.request(api.GetAdminBrands)
  171. let list = res.data
  172. if (list && list.length>0) {
  173. this.setData({
  174. hasBrand: true
  175. })
  176. } else {
  177. this.setData({
  178. hasBrand: false
  179. })
  180. }
  181. },
  182. onShow: function () {
  183. getApp().updateCardCount()
  184. let userInfo = wx.getStorageSync('userInfo');
  185. let token = wx.getStorageSync('token');
  186. this.getBrandList()
  187. this.getUserInfo()
  188. this.getCounts()
  189. // 页面显示
  190. if (userInfo && token) {
  191. app.globalData.userInfo = userInfo;
  192. app.globalData.token = token;
  193. }
  194. this.setData({
  195. // userInfo: app.globalData.userInfo,
  196. token: app.globalData.token
  197. });
  198. util.request(api.CartList).then((res) => {
  199. let isLogin = false
  200. if (res.errno === 401) {
  201. isLogin = false
  202. app.globalData.userInfo = tempUserInfo;
  203. app.globalData.token = '';
  204. } else {
  205. isLogin = true
  206. app.globalData.userInfo = userInfo;
  207. app.globalData.token = token;
  208. }
  209. if (!isLogin){
  210. this.setData({
  211. token:'',
  212. userInfo: tempUserInfo
  213. });
  214. }
  215. this.setData({
  216. isLogin
  217. });
  218. });
  219. if (typeof this.getTabBar === 'function' && this.getTabBar()) {
  220. this.getTabBar().setData({
  221. selected: 3
  222. })
  223. }
  224. },
  225. onPullDownRefresh() {
  226. getApp().onPullDownRefresh()
  227. },
  228. onHide: function () {
  229. // 页面隐藏
  230. },
  231. onUnload: function () {
  232. // 页面关闭
  233. },
  234. bindGetUserInfo(e) {
  235. let userInfo = wx.getStorageSync('userInfo');
  236. let token = wx.getStorageSync('token');
  237. if (userInfo && token) {
  238. return;
  239. }
  240. if (e.detail.userInfo){
  241. //用户按了允许授权按钮
  242. user.loginByWeixin(e.detail).then(res => {
  243. this.setData({
  244. userInfo: res.data.userInfo,
  245. isLogin: true
  246. });
  247. res.data.userInfo.userId = res.data.userId
  248. res.data.userInfo.isAdmin = res.data.isAdmin
  249. wx.setStorageSync('userInfo', res.data.userInfo);
  250. wx.setStorageSync('token', res.data.token);
  251. wx.setStorageSync('userId', res.data.userId);
  252. app.globalData.userInfo = res.data.userInfo;
  253. app.globalData.token = res.data.token;
  254. }).catch((err) => {
  255. this.setData({
  256. token: '',
  257. userInfo: tempUserInfo
  258. });
  259. app.globalData.userInfo = tempUserInfo;
  260. app.globalData.token = '';
  261. console.log(err)
  262. });
  263. } else {
  264. //用户按了拒绝按钮
  265. // wx.showModal({
  266. // title: '温馨提示',
  267. // content: '您点击了"取消"授权,将无法获取杭州天门科技有限公司完整服务。请“授权”以保证各项功能正常使用。',
  268. // confirmText:'授权',
  269. // success: function (res) {
  270. // if (res.confirm) {
  271. // wx.openSetting({
  272. // success: (res) => {
  273. // if (res.authSetting["scope.userInfo"]) {////如果用户重新同意了授权登录
  274. // user.loginByWeixin(e.detail).then(res => {
  275. // this.setData({
  276. // userInfo: res.data.userInfo
  277. // });
  278. // app.globalData.userInfo = res.data.userInfo;
  279. // app.globalData.token = res.data.token;
  280. // }).catch((err) => {
  281. // console.log(err)
  282. // });
  283. // }
  284. // }
  285. // })
  286. // }
  287. // }
  288. // });
  289. }
  290. },
  291. exitLogin: function () {
  292. wx.showModal({
  293. title: '',
  294. confirmColor: '#b4282d',
  295. content: '退出登录?',
  296. success: function (res) {
  297. if (res.confirm) {
  298. wx.removeStorageSync('token');
  299. wx.removeStorageSync('userInfo');
  300. wx.switchTab({
  301. url: '/pages/index/index'
  302. });
  303. }
  304. }
  305. })
  306. },
  307. toReport () {
  308. wx.navigateTo({
  309. url: '/dataReport/pages/data-report/data-report',
  310. })
  311. }
  312. })