channelsignup.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. // mycustomer/pages/channelsignup/channelsignup.js
  2. const app = getApp();
  3. var utils = require("../../../utils/http");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. loginFlag: false,
  10. mobileflag: false,
  11. canIUseGetUserProfile: false,
  12. mobile: true,
  13. companyobj: {},
  14. aid: '',
  15. detail: {
  16. is_poster:2
  17. },
  18. status:'0',//0是授权个人信息,1是授权手机号
  19. codeimg:'',
  20. isign:0
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad(options) {
  26. if (wx.getUserProfile) {
  27. this.setData({
  28. canIUseGetUserProfile: true
  29. })
  30. }
  31. wx.showLoading({
  32. title: '加载中...',
  33. })
  34. if (!!options.scene) {
  35. options = unescape(options.scene);
  36. let arr = options.split('&');
  37. let obj = {};
  38. for (let i = 0; i < arr.length; i++) {
  39. let arr1 = arr[i].split('=');
  40. obj[arr1[0]] = arr1[1];
  41. }
  42. this.setData({
  43. aid: obj.id
  44. })
  45. app.globalData.clientype = obj.ctp;
  46. } else {
  47. this.setData({
  48. aid: options.id
  49. })
  50. app.globalData.clientype = options.ctp;
  51. }
  52. this.channelActivity();
  53. },
  54. /**
  55. * 登录
  56. */
  57. logindata: function (type) {
  58. var that = this;
  59. if(type==1){
  60. that.setData({
  61. loginFlag: false,
  62. status:1
  63. })
  64. }
  65. wx.login({
  66. success: function (data) {
  67. if (data.errMsg == 'login:ok') {
  68. utils.$post({
  69. url: app.globalData.webUrl + 'api/users/code2session',
  70. data: {
  71. client_type: that.data.clientype,
  72. code: data.code,
  73. },
  74. success: function (r) {
  75. if (r.data.code == '0') {
  76. app.globalData.sharepersonobj = r.data.share;
  77. app.globalData.token = r.data.token;
  78. that.sharecompany();
  79. if (r.data.user != null && (!!r.data.user.headimgurl && r.data.user.headimgurl != "" || !!r.data.user.nickname && r.data.user.nickname != "" && r.data.user.nickname != '游客')) {
  80. wx.hideLoading();
  81. app.globalData.use_id = r.data.user.id;
  82. app.globalData.personMsg = r.data.user;
  83. app.globalData.userflag = false; //有个人信息
  84. var nickname = r.data.user.nickname;
  85. var phone = r.data.user.phone;
  86. that.setData({
  87. loginFlag: false,
  88. status:0
  89. })
  90. if(type==1){
  91. that.setData({
  92. isign:1
  93. })
  94. that.signUp();
  95. }else{
  96. that.channelmsg();
  97. }
  98. } else {
  99. wx.hideLoading();
  100. that.setData({
  101. status:0
  102. })
  103. if(that.data.detail.is_poster!=2){
  104. that.setData({
  105. loginFlag: true
  106. })
  107. }else{
  108. that.setData({
  109. loginFlag: false
  110. })
  111. }
  112. }
  113. } else {
  114. wx.hideLoading();
  115. that.setData({
  116. loginFlag: true
  117. })
  118. }
  119. }
  120. })
  121. } else {
  122. wx.hideLoading();
  123. that.setData({
  124. loginFlag: true
  125. })
  126. }
  127. }
  128. })
  129. },
  130. /**
  131. * 获取公司信息
  132. */
  133. sharecompany: function () {
  134. const that = this;
  135. utils.$post({
  136. url: app.globalData.webUrl + 'client/index/content_belong_company',
  137. header: {
  138. 'Authorization': 'bearer ' + app.globalData.token
  139. },
  140. data: {
  141. client_type: app.globalData.clientype,
  142. uid: app.globalData.shareuserid
  143. },
  144. success: function (res) {
  145. if (res.data.code == '0') {
  146. app.globalData.companyobj=res.data.data;
  147. that.setData({
  148. companyobj: res.data.data
  149. })
  150. }
  151. },
  152. complete(res) {
  153. wx.hideLoading()
  154. }
  155. })
  156. },
  157. channelfun(){
  158. const that=this;
  159. that.logindata('1');
  160. },
  161. channelmsg() {
  162. let that = this;
  163. utils.$post({
  164. url: app.globalData.webUrl + 'api/huoma/code_detail',
  165. header: {
  166. 'Authorization': 'bearer ' + app.globalData.token
  167. },
  168. data: {
  169. id: that.data.aid,
  170. uid:app.globalData.personMsg.id
  171. },
  172. success: function (res) {
  173. // res.data.data.is_sing=0;
  174. if (res.data.code == '0') {
  175. that.setData({
  176. isign:res.data.data.is_sing
  177. })
  178. if (res.data.data.is_sing == '1') {
  179. that.setData({
  180. loginFlag: false
  181. })
  182. that.signUp('2');
  183. } else {
  184. if(that.data.detail.is_poster!=2){
  185. that.setData({
  186. loginFlag: true,
  187. mobile:true
  188. })
  189. }else{
  190. that.setData({
  191. loginFlag: false,
  192. mobile:false
  193. })
  194. }
  195. }
  196. }
  197. },
  198. complete(res) {
  199. }
  200. })
  201. },
  202. /**
  203. * 渠道活动信息
  204. */
  205. channelActivity() {
  206. let that = this;
  207. utils.$post({
  208. url: app.globalData.webUrl + 'api/huoma/code_detail',
  209. header: {
  210. 'Authorization': 'bearer ' + app.globalData.token
  211. },
  212. data: {
  213. id: that.data.aid
  214. },
  215. success: function (res) {
  216. if (res.data.code == '0') {
  217. // res.data.data.code_data.is_poster=1;
  218. that.setData({
  219. detail: res.data.data.code_data,
  220. isign:res.data.data.is_sing
  221. })
  222. }
  223. that.logindata();
  224. },
  225. complete(res) {
  226. }
  227. })
  228. },
  229. getUserInfoTap:function(res){
  230. var that=this;
  231. console.log(res)
  232. if(res.detail.errMsg=='getUserInfo:ok'){
  233. utils.$post({
  234. method: "POST",
  235. url: app.globalData.webUrl + 'api/users/setUserInfo',
  236. data: {
  237. encryptedData:res.detail.encryptedData,
  238. iv:res.detail.iv,
  239. rawData:res.detail.rawData,
  240. signature:res.detail.signature,
  241. },
  242. header: {
  243. 'Authorization':'bearer '+app.globalData.token
  244. },
  245. success: function (r) {
  246. if(r.data.code=='0'){
  247. that.setData({
  248. status:1
  249. })
  250. app.globalData.userflag=true;//有个人信息
  251. that.logindata('1');
  252. }else{
  253. if(r.data.code=='403'){
  254. that.logindata();
  255. return false
  256. }
  257. wx.showToast({
  258. title: r.data.msg,
  259. icon: "none",
  260. duration:2000
  261. });
  262. }
  263. }
  264. })
  265. }
  266. },
  267. getUserProfile:function(){
  268. var that=this;
  269. wx.getUserProfile({
  270. lang:'zh_CN',
  271. desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  272. success: (res) => {
  273. console.log(res)
  274. if(res.errMsg=="getUserProfile:ok"){
  275. utils.$post({
  276. method: "POST",//TESTAPIURL APIURL/users/auth
  277. url: app.globalData.webUrl + 'api/users/setUserInfo',
  278. data: {
  279. encryptedData:res.encryptedData,
  280. iv:res.iv,
  281. rawData:res.rawData,
  282. signature:res.signature,
  283. },
  284. header: {
  285. 'Authorization':'bearer '+app.globalData.token
  286. },
  287. success: function (r) {
  288. if(r.data.code=='0'){
  289. that.setData({
  290. status:1
  291. })
  292. app.globalData.userflag=true;//有个人信息
  293. that.logindata('1');
  294. }else{
  295. if(r.data.code=='403'){
  296. that.logindata();
  297. return false
  298. }
  299. wx.showToast({
  300. title: r.data.msg,
  301. icon: "none",
  302. duration:2000
  303. });
  304. }
  305. }
  306. })
  307. }
  308. }
  309. })
  310. },
  311. /**
  312. * 报名
  313. */
  314. getPhoneNumberTap (res) {
  315. let that = this;
  316. console.log(res)
  317. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  318. utils.$post({
  319. url: app.globalData.webUrl + 'api/users/setUserMobile',
  320. data: {
  321. encryptedData: res.detail.encryptedData,
  322. iv: res.detail.iv
  323. },
  324. header: {
  325. 'Authorization': 'bearer ' + app.globalData.token
  326. },
  327. success: function (r) {
  328. if (r.data.code == '0') {
  329. app.globalData.phone = true;
  330. app.globalData.personMsg.phone = r.data.mobile;
  331. that.signUp();
  332. } else {
  333. wx.showToast({
  334. title: r.data.msg,
  335. icon: "none",
  336. duration: 2000
  337. });
  338. }
  339. }
  340. })
  341. }
  342. },
  343. /**
  344. * 报名
  345. */
  346. signUp() {
  347. let that = this;
  348. utils.$post({
  349. url: app.globalData.webUrl + 'api/huoma/send_qrcode',
  350. header: {
  351. 'Authorization': 'bearer ' + app.globalData.token
  352. },
  353. data: {
  354. id: that.data.aid,
  355. uid: app.globalData.use_id,
  356. mobile: app.globalData.personMsg.phone
  357. },
  358. success: function (res) {
  359. if (res.data.code == '0') {
  360. if(that.data.detail.is_poster!=2){
  361. if(that.data.isign==1){
  362. wx.redirectTo({
  363. url: '/mycustomer/pages/success/success?qrlink=' + encodeURIComponent(res.data.data),
  364. })
  365. }else{
  366. that.setData({
  367. codeimg:res.data.data
  368. })
  369. }
  370. }else{
  371. wx.redirectTo({
  372. url: '/mycustomer/pages/success/success?qrlink=' + encodeURIComponent(res.data.data),
  373. })
  374. }
  375. } else {
  376. wx.showToast({
  377. title: res.data.msg,
  378. icon: 'none',
  379. duration: 1500
  380. })
  381. }
  382. },
  383. complete(res) {
  384. wx.hideLoading()
  385. }
  386. })
  387. wx.hideLoading()
  388. },
  389. lookimgtap(){
  390. wx.previewImage({
  391. current: this.data.codeimg, // 当前显示图片的 http 链接
  392. urls: [this.data.codeimg] // 需要预览的图片 http 链接列表
  393. })
  394. },
  395. /**
  396. * 生命周期函数--监听页面初次渲染完成
  397. */
  398. onReady() {
  399. },
  400. /**
  401. * 生命周期函数--监听页面显示
  402. */
  403. onShow() {
  404. },
  405. /**
  406. * 生命周期函数--监听页面隐藏
  407. */
  408. onHide() {
  409. },
  410. /**
  411. * 生命周期函数--监听页面卸载
  412. */
  413. onUnload() {
  414. },
  415. /**
  416. * 页面相关事件处理函数--监听用户下拉动作
  417. */
  418. onPullDownRefresh() {
  419. },
  420. /**
  421. * 页面上拉触底事件的处理函数
  422. */
  423. onReachBottom() {
  424. },
  425. /**
  426. * 用户点击右上角分享
  427. */
  428. onShareappMessage() {
  429. }
  430. })