me.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. mixins: [require('../../mixin/globalMixin.js')],
  8. data: {
  9. tablebar: 4,
  10. canIUse: wx.canIUse("getUserProfile"),
  11. theme_type: '',
  12. add_mo: 0,
  13. is_show_on: 0,
  14. level_name: '',
  15. member_level_is_open: 0,
  16. is_yue_open: 0,
  17. needAuth: false,
  18. opencommiss: 0,
  19. inputValue: 0,
  20. getfocus: false,
  21. showguess: true,
  22. items: [],
  23. auditStatus: 5,
  24. isShowCoder: false,
  25. myCoderList: [],
  26. qrcodebase64: "",
  27. setInter: null,
  28. copyright: '',
  29. common_header_backgroundimage: '',
  30. enabled_front_supply: 0,
  31. cartNum: 0,
  32. is_show_about_us: 0,
  33. groupInfo: {
  34. group_name: '社区',
  35. owner_name: '团长'
  36. },
  37. is_show_score: 0,
  38. showGetPhone: false,
  39. user_tool_icons: {},
  40. community: ''
  41. },
  42. isCalling: false,
  43. /**
  44. * 生命周期函数--监听页面加载
  45. */
  46. onLoad: function(options) {
  47. wx.hideTabBar();
  48. let that = this;
  49. status.setNavBgColor();
  50. status.setGroupInfo().then((groupInfo) => {
  51. that.setData({ groupInfo })
  52. });
  53. wx.showLoading();
  54. },
  55. getMemberInfo: function() {
  56. var token = wx.getStorageSync('token');
  57. this.getCommunityInfo();
  58. let that = this;
  59. app.util.request({
  60. url: 'entry/wxapp/user',
  61. data: {
  62. controller: 'user.get_user_info',
  63. token: token
  64. },
  65. dataType: 'json',
  66. success: function(res) {
  67. // wx.hideLoading();
  68. setTimeout(function(){ wx.hideLoading(); },1000);
  69. if (res.data.code == 0) {
  70. let showGetPhone = false;
  71. if (res.data.is_show_auth_mobile == 1 && !res.data.data.telephone) showGetPhone = true;
  72. let member_info = res.data.data || '';
  73. let params = {};
  74. if (member_info){
  75. member_info.member_level_info && (member_info.member_level_info.discount = (member_info.member_level_info.discount/10).toFixed(1));
  76. //开启分销
  77. if (res.data.commiss_level > 0) {
  78. //还差多少人升级
  79. let commiss_share_member_update = res.data.commiss_share_member_update * 1;
  80. let share_member_count = res.data.share_member_count * 1;
  81. let need_num_update = res.data.commiss_share_member_update * 1 - res.data.share_member_count * 1;
  82. //判断表单状态状态
  83. let formStatus = 0; //未填写 1 已填写未审核 2 已审核
  84. if (member_info.is_writecommiss_form == 1) {
  85. formStatus = 1;
  86. //已填写
  87. if (member_info.comsiss_flag == 1) {
  88. member_info.comsiss_state == 0 ? formStatus = 1 : formStatus = 2;
  89. }
  90. }
  91. params = {
  92. formStatus,
  93. commiss_level: res.data.commiss_level,
  94. commiss_sharemember_need: res.data.commiss_sharemember_need,
  95. commiss_share_member_update,
  96. commiss_biaodan_need: res.data.commiss_biaodan_need,
  97. share_member_count,
  98. today_share_member_count: res.data.today_share_member_count,
  99. yestoday_share_member_count: res.data.yestoday_share_member_count,
  100. need_num_update
  101. };
  102. }
  103. } else {
  104. params.needAuth = true;
  105. }
  106. let {
  107. is_supply,
  108. is_open_vipcard_buy,
  109. modify_vipcard_name,
  110. is_vip_card_member,
  111. modify_vipcard_logo,
  112. isopen_signinreward,
  113. show_signinreward_icon,
  114. is_open_supplymobile,
  115. needAuth,
  116. show_user_tuan_mobile,
  117. is_localtown_distributionman,
  118. user_tool_showtype,
  119. isopen_presale,
  120. is_open_invite_invitation,
  121. virtualcard_name_modify,
  122. is_open_virtualcard_show,
  123. isopen_admin_managefront,
  124. isopen_virtualcard
  125. } = res.data;
  126. that.setData({
  127. ...params,
  128. member_info,
  129. is_supply: is_supply || 0,
  130. showGetPhone: showGetPhone,
  131. is_open_vipcard_buy: is_open_vipcard_buy || 0,
  132. modify_vipcard_name: modify_vipcard_name || "会员",
  133. is_vip_card_member: is_vip_card_member || 0,
  134. modify_vipcard_logo,
  135. show_signinreward_icon,
  136. isopen_signinreward,
  137. is_open_supplymobile,
  138. needAuth,
  139. show_user_tuan_mobile,
  140. is_localtown_distributionman,
  141. user_tool_showtype: user_tool_showtype || 0,
  142. isopen_presale,
  143. is_open_invite_invitation,
  144. virtualcard_name_modify,
  145. is_open_virtualcard_show,
  146. isopen_admin_managefront,
  147. isopen_virtualcard
  148. });
  149. } else {
  150. //needAuth
  151. that.setData({
  152. needAuth: true
  153. })
  154. wx.setStorage({
  155. key: "member_id",
  156. data: null
  157. })
  158. }
  159. }
  160. })
  161. },
  162. getCommunityInfo: function(){
  163. let that = this;
  164. let community = wx.getStorageSync('community');
  165. if (community&&community.headDoorphoto) {
  166. if(!community.head_mobile) {
  167. util.getCommunityById(community.communityId).then(res=>{
  168. let head_mobile = res.data.disUserMobile || res.data.head_mobile;
  169. head_mobile && (res.data.hideTel = util.filterTel(head_mobile));
  170. that.setData({ community: res.data })
  171. })
  172. } else {
  173. let head_mobile = community.disUserMobile || community.head_mobile;
  174. head_mobile && (community.hideTel = util.filterTel(head_mobile));
  175. that.setData({ community })
  176. }
  177. } else {
  178. var token = wx.getStorageSync('token');
  179. token && util.getCommunityInfo().then(res => {
  180. let head_mobile = res.disUserMobile || res.head_mobile;
  181. head_mobile && (res.hideTel = util.filterTel(head_mobile));
  182. that.setData({ community: res })
  183. })
  184. }
  185. },
  186. getCopyright: function() {
  187. let that = this;
  188. app.util.request({
  189. 'url': 'entry/wxapp/user',
  190. 'data': {
  191. controller: 'user.get_copyright'
  192. },
  193. dataType: 'json',
  194. success: function(res) {
  195. if (res.data.code == 0) {
  196. let rdata = res.data;
  197. let {
  198. enabled_front_supply,
  199. is_open_yue_pay,
  200. is_show_score,
  201. user_order_menu_icons,
  202. close_community_apply_enter,
  203. user_tool_icons,
  204. ishow_user_loginout_btn,
  205. commiss_diy_name,
  206. supply_diy_name,
  207. user_service_switch,
  208. fetch_coder_type,
  209. show_user_pin,
  210. common_header_backgroundimage,
  211. is_show_about_us,
  212. show_user_change_comunity,
  213. show_user_change_comunity_map,
  214. open_danhead_model,
  215. default_head_info,
  216. is_open_solitaire,
  217. user_top_font_color,
  218. excharge_nav_name,
  219. hide_community_change_btn,
  220. hide_community_change_word,
  221. close_community_index
  222. } = rdata;
  223. let h = {};
  224. if (open_danhead_model==1) {
  225. let hideTel = (default_head_info.head_mobile && util.filterTel(default_head_info.head_mobile)) || '';
  226. default_head_info.hideTel = hideTel;
  227. h.community = default_head_info;
  228. wx.setStorageSync('community', default_head_info);
  229. }
  230. commiss_diy_name = commiss_diy_name || '分销';
  231. supply_diy_name = supply_diy_name || '供应商';
  232. wcache.put('commiss_diy_name', commiss_diy_name);
  233. wcache.put('supply_diy_name', supply_diy_name);
  234. that.setData({
  235. copyright: rdata.data || '',
  236. common_header_backgroundimage: common_header_backgroundimage || '',
  237. is_show_about_us: is_show_about_us || 0,
  238. enabled_front_supply,
  239. is_open_yue_pay,
  240. is_show_score,
  241. user_order_menu_icons: user_order_menu_icons || {},
  242. commiss_diy_name,
  243. close_community_apply_enter: close_community_apply_enter || 0,
  244. user_tool_icons: user_tool_icons || {},
  245. ishow_user_loginout_btn: ishow_user_loginout_btn || 0,
  246. supply_diy_name,
  247. user_service_switch,
  248. fetch_coder_type: fetch_coder_type || 0,
  249. show_user_pin,
  250. show_user_change_comunity,
  251. show_user_change_comunity_map,
  252. open_danhead_model,
  253. is_open_solitaire,
  254. user_top_font_color,
  255. excharge_nav_name: excharge_nav_name || '查看',
  256. hide_community_change_btn: hide_community_change_btn || 0,
  257. hide_community_change_word: hide_community_change_word || 0,
  258. close_community_index,
  259. ...h
  260. })
  261. }
  262. }
  263. })
  264. },
  265. /**
  266. * 授权成功回调
  267. */
  268. authSuccess: function() {
  269. let that = this;
  270. wx.showLoading();
  271. that.setData({ needAuth: false, showAuthModal: false, tabbarRefresh: true });
  272. (0, status.cartNum)('', true).then((res) => {
  273. res.code == 0 && that.setData({
  274. cartNum: res.data
  275. })
  276. });
  277. that.getMemberInfo();
  278. },
  279. authModal: function(){
  280. if(this.data.needAuth) {
  281. this.setData({ showAuthModal: !this.data.showAuthModal });
  282. return false;
  283. }
  284. return true;
  285. },
  286. /**
  287. * 跳转团长中心
  288. */
  289. goToGroup: function() {
  290. 5 === this.data.auditStatus ? wx.navigateTo({
  291. url: "/lionfish_comshop/moduleA/groupCenter/index"
  292. }) : wx.navigateTo({
  293. url: "/lionfish_comshop/moduleA/groupCenter/apply"
  294. });
  295. },
  296. /**
  297. * 更新资料
  298. */
  299. bindGetUserInfo: function(e) {
  300. this.authModal()
  301. },
  302. /**
  303. * 预览图片
  304. */
  305. previewImage: function(e) {
  306. var current = e.currentTarget.dataset.src;
  307. current && wx.previewImage({
  308. current: current,
  309. urls: [current]
  310. })
  311. },
  312. goLink2: function(event) {
  313. if(!this.authModal()) return;
  314. let link = event.currentTarget.dataset.link;
  315. var pages_all = getCurrentPages();
  316. if (pages_all.length > 3) {
  317. wx.redirectTo({
  318. url: link
  319. })
  320. } else {
  321. wx.navigateTo({
  322. url: link
  323. })
  324. }
  325. },
  326. /**
  327. * 生命周期函数--监听页面显示
  328. */
  329. onShow: function() {
  330. let that = this;
  331. util.check_login_new().then((res)=>{
  332. console.log(res)
  333. if (res) {
  334. that.setData({ tabbarRefresh: true });
  335. (0, status.cartNum)('', true).then((res) => {
  336. res.code == 0 && that.setData({
  337. cartNum: res.data
  338. })
  339. });
  340. } else {
  341. that.setData({ needAuth: true });
  342. wx.hideLoading();
  343. }
  344. })
  345. that.getCopyright();
  346. that.getMemberInfo();
  347. },
  348. /**
  349. * 生命周期函数--监听页面隐藏
  350. */
  351. onHide: function() {
  352. this.setData({
  353. tabbarRefresh: false
  354. })
  355. },
  356. /**
  357. * 设置手机号
  358. */
  359. getReceiveMobile: function(e) {
  360. wx.showToast({
  361. icon: 'none',
  362. title: '授权成功',
  363. })
  364. this.setData({
  365. showGetPhone: false
  366. });
  367. },
  368. /**
  369. * 关闭手机授权
  370. */
  371. close: function() {
  372. this.setData({
  373. showGetPhone: false
  374. });
  375. },
  376. /**
  377. * 关闭分销
  378. */
  379. closeDistribution: function() {
  380. this.setData({
  381. showDistribution: false
  382. })
  383. },
  384. /**
  385. * 分销下一步
  386. */
  387. goDistribution: function() {
  388. let member_info = this.data.member_info;
  389. //判断是不是分销商
  390. if (member_info.comsiss_flag == 0) {
  391. this.distributionNext();
  392. } else {
  393. if (member_info.comsiss_state == 0) {
  394. //分销商未审核
  395. this.distributionNext();
  396. } else {
  397. //分销商已审核
  398. wx.navigateTo({
  399. url: '/lionfish_comshop/distributionCenter/pages/me',
  400. })
  401. }
  402. }
  403. },
  404. distributionNext: function() {
  405. if (this.data.commiss_sharemember_need == 1) {
  406. console.log('需要分享');
  407. let url = '/lionfish_comshop/distributionCenter/pages/recruit';
  408. wx.navigateTo({
  409. url
  410. })
  411. } else if (this.data.commiss_biaodan_need == 1) {
  412. console.log('需要表单');
  413. // let url = '/lionfish_comshop/pages/distribution/apply';
  414. wx.navigateTo({
  415. url: '/lionfish_comshop/distributionCenter/pages/recruit',
  416. })
  417. } else {
  418. // 跳转表单自动审核
  419. let status = 0;
  420. let member_info = this.data.member_info;
  421. if (member_info.comsiss_flag == 1) {
  422. member_info.comsiss_state == 0 ? status = 1 : status = 2;
  423. }
  424. let url = '/lionfish_comshop/distributionCenter/pages/recruit';
  425. if (status == 2) {
  426. url = '/lionfish_comshop/distributionCenter/pages/me';
  427. }
  428. wx.navigateTo({
  429. url
  430. })
  431. }
  432. },
  433. goNext: function(e) {
  434. console.log(e)
  435. let status = 0;
  436. let member_info = this.data.member_info;
  437. if (member_info.comsiss_flag == 1) {
  438. member_info.comsiss_state == 0 ? status = 1 : status = 2;
  439. }
  440. let type = e.currentTarget.dataset.type;
  441. if (type == 'share') {
  442. wx.navigateTo({
  443. url: '/lionfish_comshop/distributionCenter/pages/share',
  444. })
  445. } else if (type == 'commiss') {
  446. if (status == 2) {
  447. wx.navigateTo({
  448. url: '/lionfish_comshop/distributionCenter/pages/me',
  449. })
  450. } else {
  451. wx.navigateTo({
  452. url: '/lionfish_comshop/distributionCenter/pages/recruit',
  453. })
  454. }
  455. } else if (type == 'form') {
  456. if (status == 2) {
  457. wx.navigateTo({
  458. url: '/lionfish_comshop/distributionCenter/pages/me',
  459. })
  460. } else {
  461. // let url = '/lionfish_comshop/pages/distribution/apply';
  462. wx.navigateTo({
  463. url: '/lionfish_comshop/distributionCenter/pages/recruit',
  464. })
  465. }
  466. }
  467. },
  468. loginOut: function() {
  469. wx.removeStorageSync('community');
  470. wx.removeStorage({
  471. key: 'token',
  472. success(res) {
  473. wx.reLaunch({
  474. url: '/lionfish_comshop/pages/user/me',
  475. })
  476. }
  477. })
  478. },
  479. toggleFetchCoder: function() {
  480. if (!this.authModal()) return;
  481. this.setData({
  482. isShowCoder: !this.data.isShowCoder
  483. })
  484. },
  485. /**
  486. * 拨打电话
  487. */
  488. callTelphone: function (e) {
  489. var that = this;
  490. var phoneNumber = e.currentTarget.dataset.phone;
  491. if (phoneNumber) {
  492. this.isCalling || (this.isCalling = true, wx.makePhoneCall({
  493. phoneNumber: phoneNumber,
  494. complete: function () {
  495. that.isCalling = false;
  496. }
  497. }));
  498. }
  499. },
  500. /**
  501. * 查看地图
  502. */
  503. gotoMap: function () {
  504. let community = this.data.community;
  505. let postion = {lat: community.lat, lon: community.lon};
  506. let longitude = parseFloat(postion.lon),
  507. latitude = parseFloat(postion.lat),
  508. name = community.disUserName,
  509. address = `${community.fullAddress}(${community.communityName})`;
  510. wx.openLocation({
  511. latitude: latitude,
  512. longitude: longitude,
  513. name: name,
  514. address: address,
  515. scale: 28
  516. })
  517. },
  518. })