user.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. const app = getApp()
  2. const api = require('../../../request/api');
  3. const http = require('../../../request/http');
  4. const utils = require('../../../utils/util.js');
  5. const storeKeys = require('../../../utils/storageKeys.js');
  6. Page({
  7. data: {
  8. showModal:false, //是否显示奖励金说明弹窗
  9. showWithdrawalModal:false, //是否显示提现提示
  10. isLoading: true, //是否处于加载
  11. sHome: false,
  12. isLogOn: false, //是否已登录
  13. info:{},
  14. todoCounts:{}, //待处理订单数
  15. },
  16. onLoad: function (options) {
  17. },
  18. onShow() {
  19. if(!utils.getStorageSync(storeKeys.TOKEN)){
  20. this.setData({
  21. isLogOn: false,
  22. isLoading:false
  23. })
  24. }else{
  25. this.setData({
  26. isLogOn: true,
  27. })
  28. this.getUserInfo();
  29. this.getTodoCounts();
  30. }
  31. this.changePageHaed();
  32. app.changeTabBarBadge(utils.getStorageSync(storeKeys.CARETOTAl));
  33. },
  34. changePageHaed(){
  35. let token = utils.getStorageSync(storeKeys.TOKEN);
  36. if(token){
  37. if(this.data.info.chara){
  38. wx.setNavigationBarColor({
  39. frontColor: '#ffffff',
  40. backgroundColor: '#DF3120',
  41. })
  42. }else{
  43. wx.setNavigationBarColor({
  44. frontColor: '#000000',
  45. backgroundColor: '#F7F7F7',
  46. })
  47. }
  48. }else{
  49. wx.setNavigationBarColor({
  50. frontColor: '#000000',
  51. backgroundColor: '#F7F7F7',
  52. })
  53. }
  54. },
  55. //获取用户信息
  56. getUserInfo() {
  57. http.request({
  58. url: api.URL + '/api/user/info',
  59. method: 'GET',
  60. token: utils.getStorageSync(storeKeys.TOKEN),
  61. success: (res) => {
  62. let info = res.data.data.userInfo;
  63. // 开发专用
  64. if(info.mobile == "17573207179"){
  65. // info.show_cash_box = true;
  66. // info.role = 1;
  67. // info.seller_grade = 3;
  68. info.grade_id = 10001;
  69. info.is_pickup = 1
  70. }
  71. //是否为特殊身份
  72. let chara = false;
  73. if((info.role && info.role !=1)|| info.show_cash_box){
  74. chara = true;
  75. }
  76. info.chara = chara;
  77. utils.setStorageSync(storeKeys.USERINFO, info);
  78. this.setData({
  79. info
  80. })
  81. this.changePageHaed();
  82. setTimeout(() => {
  83. this.setData({
  84. isLoading: false
  85. });
  86. }, 300)
  87. },
  88. error: (res) => {
  89. utils.toast(res.data.message)
  90. },
  91. })
  92. },
  93. //获取用户待处理订单数
  94. getTodoCounts() {
  95. http.request({
  96. url: api.URL + '/api/order/todoCounts',
  97. method: 'GET',
  98. token: utils.getStorageSync(storeKeys.TOKEN),
  99. success: (res) => {
  100. this.setData({
  101. todoCounts: res.data.data.counts || {}
  102. })
  103. },
  104. error: (res) => {
  105. utils.toast(res.data.message)
  106. },
  107. })
  108. },
  109. navigateTo(e) {
  110. app.navigateTo(e);
  111. },
  112. //需要登陆进入的页面
  113. navigateToToken: utils.throttle(function (e) {
  114. if (utils.getStorageSync(storeKeys.TOKEN)) {
  115. app.navigateTo(e);
  116. } else {
  117. wx.navigateTo({
  118. url: "/pages/tabBar/login/login"
  119. })
  120. }
  121. }),
  122. //提现
  123. withdrawal: utils.throttle(function (e) {
  124. if (utils.getStorageSync(storeKeys.TOKEN)) {
  125. let ktxyj_amount = parseFloat(this.data.info.ktxyj_amount)
  126. if(!ktxyj_amount || ktxyj_amount <= 0){
  127. utils.toast("暂无可提现金额")
  128. return;
  129. }
  130. wx.navigateTo({
  131. url: "/pages/user/pages/withdrawal/withdrawal"
  132. })
  133. } else {
  134. wx.navigateTo({
  135. url: "/pages/tabBar/login/login"
  136. })
  137. }
  138. }),
  139. //前往分销中心
  140. goTopPomotionCenter: utils.throttle(function (e) {
  141. let role = this.data.info.role
  142. //1 :普通用户
  143. let url = "/pages/user/pages/store/promotionCenter/promotionCenter?role="+role;
  144. if(role == 1){
  145. url = "/pages/user/pages/store/applyRetail/applyRetail";
  146. }
  147. wx.navigateTo({
  148. url: url
  149. })
  150. }),
  151. //显示奖励金说明弹窗
  152. showModal(){
  153. this.setData({
  154. showModal:true
  155. })
  156. },
  157. //隐藏奖励金说明弹窗
  158. hideModal(){
  159. this.setData({
  160. showModal:false
  161. })
  162. },
  163. //显示提现提示
  164. showWithdrawalModal(){
  165. this.setData({
  166. showWithdrawalModal:true
  167. })
  168. },
  169. //隐藏提现提示
  170. hideWithdrawalModal(){
  171. this.setData({
  172. showWithdrawalModal:false
  173. })
  174. },
  175. //前往我的分享码
  176. goToPoster: utils.throttle(function (e) {
  177. let url = "/pages/user/pages/appletIncomePoster/appletIncomePoster";
  178. wx.navigateTo({
  179. url: url
  180. })
  181. }),
  182. //授权获取微信信息
  183. getUserProfile: utils.throttle(function (e) {
  184. wx.getUserProfile({
  185. desc: '用于头像展示',
  186. success: (res) => {
  187. this.updateUserInfo(res.userInfo.avatarUrl, res.userInfo.nickName)
  188. }
  189. })
  190. }),
  191. updateUserInfo(avatarUrl, nickName) {
  192. let data = {
  193. avatarUrl,
  194. nickName
  195. }
  196. wx.showLoading({
  197. title: "加载中",
  198. mask: true
  199. });
  200. http.request({
  201. url: api.URL + '/api/user/upd',
  202. method: 'POST',
  203. token: utils.getStorageSync(storeKeys.TOKEN),
  204. data,
  205. success: (res) => {
  206. wx.hideLoading()
  207. this.getUserInfo()
  208. },
  209. error: (res) => {
  210. wx.hideLoading()
  211. utils.toast(res.data.message)
  212. },
  213. })
  214. },
  215. //开通会员、前往会员中心
  216. memberClick: utils.throttle(function (e) {
  217. //is_member 是否为会员 1是 0否
  218. if(this.data.info.is_member == 1){
  219. wx.navigateTo({
  220. url: "/pages/member/pages/memberCenter/memberCenter"
  221. })
  222. }else{
  223. wx.navigateTo({
  224. url: "/pages/member/pages/buyMember/buyMember"
  225. })
  226. }
  227. }),
  228. // 福利核销
  229. clickScanCode: utils.throttle(function (e) {
  230. console.log("福利核销")
  231. let _this = this;
  232. wx.scanCode({
  233. success(res) {
  234. console.log(res)
  235. let result = res.result
  236. try {
  237. wx.navigateTo({
  238. url: "/pages/member/pages/writeOff/writeOff?hxCode=" + result
  239. })
  240. } catch (e) {
  241. utils.toast("二维码错误");
  242. }
  243. },
  244. fail() {}
  245. })
  246. }),
  247. })