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