me.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. //index.js
  2. var util = require('../../utils/util.js');
  3. var status = require('../../utils/index.js');
  4. var wcache = require('../../utils/wcache.js');
  5. var app = getApp()
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. tablebar: 4,
  12. canIUse: wx.canIUse("button.open-type.getUserInfo"),
  13. theme_type: '',
  14. add_mo: 0,
  15. is_show_on: 0,
  16. level_name: '',
  17. member_level_is_open: 0,
  18. is_yue_open: 0,
  19. is_login: true,
  20. opencommiss: 0,
  21. inputValue: 0,
  22. getfocus: false,
  23. showguess: true,
  24. items: [],
  25. auditStatus: 5,
  26. isShowCoder: false,
  27. myCoderList: [],
  28. qrcodebase64: "",
  29. setInter: null,
  30. copyright: '',
  31. common_header_backgroundimage: '',
  32. enabled_front_supply: 0,
  33. cartNum: 0,
  34. is_show_about_us: 0,
  35. groupInfo: {
  36. group_name: '社区',
  37. owner_name: '团长'
  38. },
  39. is_show_score: 0,
  40. showGetPhone: false
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function(options) {
  46. wx.hideTabBar();
  47. let that = this;
  48. status.setNavBgColor();
  49. status.setGroupInfo().then((groupInfo) => { that.setData({ groupInfo }) });
  50. wx.showLoading();
  51. this.getCopyright();
  52. },
  53. getMemberInfo: function(){
  54. var token = wx.getStorageSync('token');
  55. let that = this;
  56. app.util.request({
  57. 'url': 'entry/wxapp/user',
  58. 'data': {
  59. controller: 'user.get_user_info',
  60. token: token
  61. },
  62. dataType: 'json',
  63. success: function (res) {
  64. wx.hideLoading();
  65. if (res.data.code == 0) {
  66. let showGetPhone = false;
  67. if (res.data.is_show_auth_mobile == 1 && !res.data.data.telephone) showGetPhone = true;
  68. let member_info = res.data.data;
  69. let params = {};
  70. //开启分销
  71. if (res.data.commiss_level > 0) {
  72. //还差多少人升级
  73. let commiss_share_member_update = res.data.commiss_share_member_update * 1;
  74. let share_member_count = res.data.share_member_count * 1;
  75. let need_num_update = res.data.commiss_share_member_update*1 - res.data.share_member_count*1;
  76. //判断表单状态状态
  77. let formStatus = 0; //未填写 1 已填写未审核 2 已审核
  78. if (member_info.is_writecommiss_form == 1) {
  79. formStatus = 1;
  80. //已填写
  81. if (member_info.comsiss_flag == 1) {
  82. member_info.comsiss_state == 0 ? formStatus = 1 : formStatus = 2;
  83. }
  84. }
  85. params = {
  86. formStatus,
  87. commiss_level: res.data.commiss_level,
  88. commiss_sharemember_need: res.data.commiss_sharemember_need,
  89. commiss_share_member_update,
  90. commiss_biaodan_need: res.data.commiss_biaodan_need,
  91. share_member_count,
  92. today_share_member_count: res.data.today_share_member_count,
  93. yestoday_share_member_count: res.data.yestoday_share_member_count,
  94. need_num_update
  95. };
  96. }
  97. that.setData({
  98. ...params,
  99. member_info,
  100. enabled_front_supply: res.data.enabled_front_supply,
  101. is_supply: res.data.is_supply,
  102. is_open_yue_pay: res.data.is_open_yue_pay,
  103. is_show_score: res.data.is_show_score,
  104. showGetPhone: showGetPhone,
  105. index_top_font_color: res.data.index_top_font_color || '#fff',
  106. user_order_menu_icons: res.data.user_order_menu_icons || {},
  107. commiss_diy_name: res.data.commiss_diy_name || '分销',
  108. close_community_apply_enter: res.data.close_community_apply_enter || 0
  109. });
  110. } else {
  111. //is_login
  112. that.setData({
  113. is_login: false
  114. })
  115. wx.hideTabBar();
  116. wx.setStorage({
  117. key: "member_id",
  118. data: null
  119. })
  120. }
  121. }
  122. })
  123. },
  124. getCopyright: function (){
  125. let that = this;
  126. app.util.request({
  127. 'url': 'entry/wxapp/user',
  128. 'data': {
  129. controller: 'user.get_copyright'
  130. },
  131. dataType: 'json',
  132. success: function (res) {
  133. if (res.data.code == 0) {
  134. that.setData({
  135. copyright: res.data.data || '',
  136. common_header_backgroundimage: res.data.common_header_backgroundimage || '',
  137. is_show_about_us: res.data.is_show_about_us || 0
  138. })
  139. }
  140. }
  141. })
  142. },
  143. /**
  144. * 授权成功回调
  145. */
  146. authSuccess: function() {
  147. wx.reLaunch({
  148. url: '/lionfish_comshop/pages/user/me',
  149. })
  150. },
  151. /**
  152. * 跳转团长中心
  153. */
  154. goToGroup: function() {
  155. 5 === this.data.auditStatus ? wx.navigateTo({
  156. url: "/lionfish_comshop/pages/groupCenter/index"
  157. }) : wx.navigateTo({
  158. url: "/lionfish_comshop/pages/groupCenter/apply"
  159. });
  160. },
  161. /**
  162. * 更新资料
  163. */
  164. bindGetUserInfo: function (e) {
  165. let that = this;
  166. if ("getUserInfo:ok" === e.detail.errMsg) {
  167. var userInfo = Object.assign({}, wx.getStorageSync("userInfo"), {
  168. avatarUrl: e.detail.userInfo.avatarUrl,
  169. nickName: e.detail.userInfo.nickName
  170. });
  171. app.globalData.userInfo = userInfo, wx.setStorage({
  172. key: "userInfo",
  173. data: userInfo
  174. }), this.setData({
  175. userInfo: userInfo
  176. }), wx.showToast({
  177. title: "资料已更新",
  178. icon: "none",
  179. duration: 2000
  180. }),app.util.request({
  181. 'url': 'entry/wxapp/user',
  182. 'data': {
  183. controller: 'user.update_user_info',
  184. memberId: wx.getStorageSync("member_id"),
  185. nickName: e.detail.userInfo.nickName,
  186. avatarUrl: e.detail.userInfo.avatarUrl
  187. },
  188. dataType: 'json',
  189. success: function (res) {
  190. let member_info = that.data.member_info;
  191. let user_info = Object.assign({}, member_info, {
  192. avatar: e.detail.userInfo.avatarUrl,
  193. username: e.detail.userInfo.nickName
  194. });
  195. that.setData({
  196. member_info: user_info
  197. })
  198. }
  199. })
  200. } else {
  201. wx.showToast({
  202. title: "资料更新失败。",
  203. icon: "none"
  204. });
  205. }
  206. },
  207. /**
  208. * 预览图片
  209. */
  210. previewImage: function (e) {
  211. var current = e.target.dataset.src;
  212. current && wx.previewImage({
  213. current: current,
  214. urls: [current]
  215. })
  216. },
  217. goLink2: function(event) {
  218. let link = event.currentTarget.dataset.link;
  219. var pages_all = getCurrentPages();
  220. if (pages_all.length > 3) {
  221. wx.redirectTo({
  222. url: link
  223. })
  224. } else {
  225. wx.navigateTo({
  226. url: link
  227. })
  228. }
  229. },
  230. /**
  231. * 生命周期函数--监听页面显示
  232. */
  233. onShow: function() {
  234. this.setData({
  235. tabbarRefresh: true
  236. })
  237. var that = this;
  238. (0, status.cartNum)('', true).then((res) => {
  239. res.code == 0 && that.setData({ cartNum: res.data })
  240. });
  241. util.check_login() ? this.setData({ is_login: true }) : this.setData({ is_login: false });
  242. this.getMemberInfo()
  243. },
  244. /**
  245. * 生命周期函数--监听页面隐藏
  246. */
  247. onHide: function() {
  248. this.setData({ tabbarRefresh: false })
  249. },
  250. /**
  251. * 设置手机号
  252. */
  253. getReceiveMobile: function (e) {
  254. var num = e.detail;
  255. wx.showToast({
  256. icon: 'none',
  257. title: '授权成功',
  258. })
  259. this.setData({
  260. showGetPhone: false
  261. });
  262. },
  263. /**
  264. * 关闭手机授权
  265. */
  266. close: function () {
  267. this.setData({
  268. showGetPhone: false
  269. });
  270. },
  271. /**
  272. * 关闭分销
  273. */
  274. closeDistribution: function(){
  275. this.setData({ showDistribution: false })
  276. },
  277. /**
  278. * 分销下一步
  279. */
  280. goDistribution: function(){
  281. let member_info = this.data.member_info;
  282. //判断是不是分销商
  283. if (member_info.comsiss_flag==0) {
  284. this.distributionNext();
  285. } else {
  286. if (member_info.comsiss_state==0) {
  287. //分销商未审核
  288. this.distributionNext();
  289. } else {
  290. //分销商已审核
  291. wx.navigateTo({
  292. url: '/lionfish_comshop/pages/distribution/me',
  293. })
  294. }
  295. }
  296. },
  297. distributionNext: function(){
  298. if (this.data.commiss_sharemember_need==1) {
  299. console.log('需要分享');
  300. let url = '/lionfish_comshop/pages/distribution/recruit';
  301. wx.navigateTo({ url })
  302. } else if (this.data.commiss_biaodan_need==1){
  303. console.log('需要表单');
  304. // let url = '/lionfish_comshop/pages/distribution/apply';
  305. wx.navigateTo({
  306. url: '/lionfish_comshop/pages/distribution/recruit',
  307. })
  308. } else {
  309. // 跳转表单自动审核
  310. let status = 0;
  311. let member_info = this.data.member_info;
  312. if (member_info.comsiss_flag == 1) {
  313. member_info.comsiss_state == 0 ? status = 1 : status = 2;
  314. }
  315. let url = '/lionfish_comshop/pages/distribution/recruit';
  316. if(status==2){
  317. url = '/lionfish_comshop/pages/distribution/me';
  318. }
  319. wx.navigateTo({ url })
  320. }
  321. },
  322. goNext: function(e){
  323. console.log(e)
  324. let status = 0;
  325. let member_info = this.data.member_info;
  326. if (member_info.comsiss_flag == 1) {
  327. member_info.comsiss_state == 0 ? status = 1 : status = 2;
  328. }
  329. let type = e.currentTarget.dataset.type;
  330. if (type=='share'){
  331. wx.navigateTo({
  332. url: '/lionfish_comshop/pages/distribution/share',
  333. })
  334. } else if (type=='commiss'){
  335. if(status == 2){
  336. wx.navigateTo({
  337. url: '/lionfish_comshop/pages/distribution/me',
  338. })
  339. } else {
  340. wx.navigateTo({
  341. url: '/lionfish_comshop/pages/distribution/recruit',
  342. })
  343. }
  344. } else if (type =='form'){
  345. if (status == 2) {
  346. wx.navigateTo({
  347. url: '/lionfish_comshop/pages/distribution/me',
  348. })
  349. } else {
  350. // let url = '/lionfish_comshop/pages/distribution/apply';
  351. wx.navigateTo({
  352. url: '/lionfish_comshop/pages/distribution/recruit',
  353. })
  354. }
  355. }
  356. },
  357. /**
  358. * 用户点击右上角分享
  359. */
  360. onShareAppMessage: function() {
  361. }
  362. })