channelsignup.js 13 KB

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