me.js 15 KB

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