register.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. import {
  2. ApiModel
  3. } from "../../utils/api";
  4. const _Http = new ApiModel();
  5. import {
  6. TestVerify
  7. } from "../../utils/verify"
  8. const _Verify = new TestVerify();
  9. const utilMd5 = require('../../utils/md5');
  10. let countDownTime1 = null;
  11. const QR = require('../../miniprogram_npm/qrcode-base64/index.js');
  12. import {
  13. base64src
  14. } from '../../components/My_TwoDimensionalCode/base64src';
  15. Page({
  16. /**
  17. * 页面的初始数据
  18. */
  19. data: {
  20. pageType: 0, //0报名 1查看二维码 2
  21. rulesChecked: true, //同意用户隐私协议
  22. isNoToken: false, //是否存在登录
  23. countDownTime: 30, //倒计时
  24. tactivityid: 2, //展会id
  25. fname: "", //姓名
  26. fidcard: "", //身份证号
  27. fphonenumber: "", //手机号
  28. password: '', //验证码
  29. fcompname: "", //公司
  30. frole: "", //职位
  31. findustry: "", //行业
  32. faddress: "", //地址
  33. fchannel: "", //入会渠道
  34. errTips: {
  35. fname: false, //姓名
  36. fidcard: false, //身份证号
  37. fphonenumber: false, //手机号
  38. password: false, //验证码
  39. fcompname: false, //公司
  40. frole: false, //职位
  41. findustry: false, //行业
  42. faddress: false,
  43. fchannel: false,
  44. },
  45. throttle: false, //截流
  46. msg: null,
  47. myShowModel: false, //角色选择
  48. userIndex: null, //选择账号下标
  49. qrcodeURL: null,
  50. butText: '下一步',
  51. fquestionnaire: [],
  52. surveysList: [{
  53. title: '你所在的公司来自哪里(where does your compangy come from)?',
  54. arr: ['中国大陆公司(Mainland China company)', '海外公司中国大陆分支机构(Overseas company mailand China branch)', '海外公司(含港、澳、台地区)Overseas companies(including Hong Kong,Macao and Taiwan)']
  55. }, {
  56. title: '您的工作性质(what is your function)?',
  57. arr: ['管理(Management)', '采购(Purchasing)', '市场/销售(Marketing/Sales)', '生产/制造(Production/Manufacturing)', '设计师(Designer)', '研发(Research/Development)', '零售(Retailing)', '广告/推广/传媒(Advertising/Promotion)', '政府/管理人员(Government/Administration)', '原料供应商(Material Suppliers)']
  58. }, {
  59. title: '公司主要经营范围(what is your company’sprimary activity)?',
  60. arr: ['面料(Material)', '辅料(Accessory)', '家用纺织品(Famliy textile)', '家具(Furniture)', '纤维/纱线(Fiber/Yarn)', '流行趋势(Fashion trend)', '检测(Tset)', '服务/咨询(Service/Consultant)', '媒体广告(Media advertisement)', '行业协会(Tradeassociation)']
  61. }, {
  62. title: '感兴趣的产品(which products are you in terested in)?',
  63. arr: ['窗帘布面料(Curtain Fabric)', '沙发布面料(Sofa Fabric)', '墙布面料(Wallcloth Fabric)', '功能性纺织品(Functional Textile)', '各类辅料(Accessory)', '趋势(trend)']
  64. }, {
  65. title: '通过以下什么途径知道本展会(How did you learm about the exhibition)?',
  66. arr: ['主办单位邀请函(Directmai/Invitation)', '报纸广告(Newspaper)', '杂志(Magazine Advertisement)', '网络(Internet)', '供应商/参展商邀请(Invitation From Supplier/Exhibitor)', '朋友/同事/同行(Friends/Colleagues Business/Associates)', '行业协会(Trade Association)']
  67. }]
  68. },
  69. /**
  70. * 生命周期函数--监听页面加载
  71. */
  72. onLoad: function (options) {
  73. this.setData({
  74. tactivityid: options.id
  75. })
  76. //判断是否存在登录态
  77. _Http.basic({
  78. "accesstoken": wx.getStorageSync('userData').token,
  79. "classname": "customer.activity.activitysignup",
  80. "method": "getsignupmsg",
  81. "content": {
  82. "tactivityid": options.id
  83. }
  84. }).then(res => {
  85. console.log("获取个人信息", res)
  86. if (res.msg == '失败') {
  87. this.setData({
  88. isNoToken: true
  89. })
  90. } else {
  91. this.setData({
  92. fphonenumber: wx.getStorageSync('userData').fphonenumber
  93. })
  94. if (res.data.length >= 1) {
  95. this.setData({
  96. pageType: 1,
  97. msg: res.data[0]
  98. })
  99. this.qrCode();
  100. this.goTop();
  101. }
  102. }
  103. })
  104. },
  105. qrCode() {
  106. let codeText = this.data.msg.tactivitysignupid + '';
  107. console.log(codeText)
  108. var imgData = QR.drawImg(codeText, {
  109. typeNumber: 4,
  110. errorCorrectLevel: 'M',
  111. size: 500
  112. })
  113. base64src(imgData, res => {
  114. this.setData({
  115. qrcodeURL: res
  116. });
  117. });
  118. },
  119. radioChange(e) {
  120. const {
  121. name,
  122. index
  123. } = e.currentTarget.dataset;
  124. const data = {
  125. "question": name,
  126. "answer": e.detail
  127. }
  128. let fquestionnaire = this.data.fquestionnaire;
  129. fquestionnaire[index] = data;
  130. console.log(fquestionnaire);
  131. },
  132. /* 获取验证码 */
  133. getVerifyCode() {
  134. //验证手机号码
  135. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  136. "errTips.fphonenumber": true
  137. });
  138. /* 倒计时中阻止 */
  139. if (this.data.countDownTime != 30) return wx.showToast({
  140. title: '请勿重复获取验证码',
  141. icon: "none"
  142. });
  143. _Http.getPassword({
  144. "phonenumber": this.data.fphonenumber,
  145. "client": "wechat_customer"
  146. }).then(res => {
  147. this.setData({
  148. countDownTime: this.data.countDownTime - 1
  149. })
  150. countDownTime1 = setInterval(() => {
  151. if (this.data.countDownTime != 0) {
  152. this.setData({
  153. countDownTime: this.data.countDownTime - 1
  154. })
  155. } else {
  156. clearInterval(countDownTime1);
  157. this.setData({
  158. countDownTime: 30
  159. })
  160. }
  161. }, 1000);
  162. wx.showToast({
  163. title: res.msg,
  164. icon: "none",
  165. duration: 3000
  166. })
  167. })
  168. },
  169. //验证必填项
  170. verify() {
  171. let errTips = this.data.errTips,
  172. result = false;
  173. for (let key in this.data.errTips) {
  174. if (this.data.isNoToken) {
  175. if (this.data[key] == '') {
  176. errTips[key] = true;
  177. result = true;
  178. }
  179. } else {
  180. if (this.data[key] == '' && key != 'password') {
  181. errTips[key] = true;
  182. result = true;
  183. }
  184. }
  185. };
  186. if (this.data.fidcard.length != 18) {
  187. errTips.fidcard = true;
  188. result = true;
  189. }
  190. this.setData({
  191. errTips
  192. })
  193. return result;
  194. },
  195. /* 提交表单 */
  196. submitData(e) {
  197. if (this.data.throttle) return;
  198. if (!this.data.rulesChecked) return wx.showToast({
  199. title: '请先勾选《用户隐私协议》',
  200. icon: "none"
  201. })
  202. if (e.target.dataset.text == '下一步') {
  203. if (this.verify()) return wx.showToast({
  204. title: '请完善表格必填项',
  205. icon: "none"
  206. });
  207. if (!this.data.isNoToken) {
  208. //存在登录态,直接提交
  209. // this.signup(wx.getStorageSync('userData').token);
  210. this.setData({
  211. pageType: 2,
  212. butText: '立即报名'
  213. })
  214. this.goTop();
  215. } else {
  216. //未存在登录态,先登录在提交
  217. if (!this.data.password) {
  218. this.setData({
  219. "errTips.password": true
  220. })
  221. return wx.showToast({
  222. title: '还未填写验证码',
  223. icon: "none"
  224. });
  225. };
  226. _Http.login({
  227. "phonenumber": this.data.fphonenumber,
  228. "password": utilMd5.hexMD5(this.data.password),
  229. "client": "wechat_customer"
  230. }).then(res => {
  231. /* 结果验证 */
  232. if (res.msg != '成功') {
  233. this.setData({
  234. "errTips.password": true
  235. });
  236. return wx.showToast({
  237. title: '账号或验证码错误!',
  238. icon: "none"
  239. });
  240. }
  241. console.log("用户登录", res)
  242. if (res.account_list.length == 1) {
  243. // this.signup(res.account_list[0].token);
  244. wx.setStorageSync('userData', res.account_list[0]);
  245. this.setData({
  246. pageType: 2,
  247. butText: '立即报名'
  248. })
  249. this.goTop();
  250. } else {
  251. this.setData({
  252. account_list: res.account_list,
  253. myShowModel: true
  254. })
  255. }
  256. })
  257. }
  258. } else {
  259. let c = 0;
  260. for (let i = 0; i < this.data.fquestionnaire.length; i++) {
  261. if (typeof (this.data.fquestionnaire[i]) == 'object') c += 1;
  262. }
  263. if (c != this.data.surveysList.length) {
  264. wx.showToast({
  265. title: '请完善问卷调查',
  266. icon: "none"
  267. })
  268. } else {
  269. this.signup(wx.getStorageSync('userData').token)
  270. }
  271. }
  272. },
  273. //回到顶部
  274. goTop: function (e) { // 一键回到顶部
  275. if (wx.pageScrollTo) {
  276. wx.pageScrollTo({
  277. scrollTop: 0
  278. })
  279. } else {
  280. wx.showModal({
  281. title: '提示',
  282. content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  283. })
  284. }
  285. },
  286. /* 获取焦点 */
  287. inputFocus(e) {
  288. const {
  289. name
  290. } = e.currentTarget.dataset;
  291. let errTips = this.data.errTips;
  292. errTips[name] = false;
  293. this.setData({
  294. errTips
  295. })
  296. },
  297. /* 失去焦点 */
  298. inputBlur(e) {
  299. const {
  300. name
  301. } = e.currentTarget.dataset;
  302. const {
  303. value
  304. } = e.detail;
  305. if (name == 'fphonenumber') {
  306. if (!_Verify.phoneNumber(this.data.fphonenumber, 1)) return this.setData({
  307. "errTips.fphonenumber": true
  308. })
  309. } else if (name == 'fidcard') {
  310. if (this.data.fidcard.length != 18) {
  311. wx.showToast({
  312. title: '身份证号码格式错误',
  313. icon: "none"
  314. })
  315. return this.setData({
  316. "errTips.fidcard": true
  317. })
  318. }
  319. }
  320. if (value.trim() == "") {
  321. let errTips = this.data.errTips;
  322. errTips[name] = true;
  323. this.setData({
  324. errTips
  325. })
  326. }
  327. },
  328. /* 选择用户 */
  329. userSelect(e) {
  330. const {
  331. index,
  332. item
  333. } = e.currentTarget.dataset;
  334. this.setData({
  335. userIndex: index
  336. })
  337. wx.setStorageSync('userData', item);
  338. this.setData({
  339. pageType: 2,
  340. butText: '立即报名'
  341. })
  342. this.goTop();
  343. },
  344. /* 提交报名表 */
  345. signup(token) {
  346. _Http.basic({
  347. "accesstoken": token,
  348. "classname": "customer.activity.activitysignup",
  349. "method": "getsignupmsg",
  350. "content": {
  351. "tactivityid": this.data.tactivityid
  352. }
  353. }).then(res => {
  354. if (res.msg != '成功') return wx.showToast({
  355. title: res.data,
  356. icon: "none"
  357. })
  358. if (res.data.length >= 1) {
  359. this.setData({
  360. pageType: 1,
  361. msg: res.data[0]
  362. })
  363. this.qrCode();
  364. this.goTop();
  365. } else {
  366. _Http.basic({
  367. "accesstoken": token,
  368. "classname": "customer.activity.activitysignup",
  369. "method": "signup",
  370. "content": {
  371. "fname": this.data.fname,
  372. "fidcard": this.data.fidcard,
  373. "fphonenumber": this.data.fphonenumber,
  374. "fcompname": this.data.fcompname,
  375. "frole": this.data.frole,
  376. "findustry": this.data.findustry,
  377. "faddress": this.data.faddress,
  378. "fchannel": this.data.fchannel,
  379. "tactivityid": this.data.tactivityid,
  380. "fquestionnaire": this.data.fquestionnaire
  381. }
  382. }).then(res => {
  383. console.log("提交报名", res)
  384. if (res.msg != '成功') return wx.showToast({
  385. title: res.data,
  386. icon: "none"
  387. })
  388. this.setData({
  389. throttle: true
  390. });
  391. _Http.basic({
  392. "accesstoken": token,
  393. "classname": "customer.activity.activitysignup",
  394. "method": "getsignupmsg",
  395. "content": {
  396. "tactivityid": this.data.tactivityid
  397. }
  398. }).then(res => {
  399. if (res.msg != '成功') return wx.showToast({
  400. title: res.data,
  401. icon: "none"
  402. })
  403. this.setData({
  404. pageType: 1,
  405. msg: res.data[0]
  406. })
  407. this.qrCode();
  408. this.goTop();
  409. wx.showToast({
  410. title: '报名成功'
  411. })
  412. })
  413. /* setTimeout(() => {
  414. wx.navigateBack({
  415. delta: 1,
  416. })
  417. }, 500); */
  418. })
  419. }
  420. })
  421. },
  422. /* input事件剔除特殊字符 */
  423. eliminate(value) {
  424. const {
  425. name
  426. } = value.target.dataset;
  427. this.setData({
  428. [name]: _Verify.Eliminate(value.detail)
  429. })
  430. },
  431. /* 用户守则 */
  432. rulesOnChange() {
  433. this.setData({
  434. rulesChecked: !this.data.rulesChecked
  435. })
  436. },
  437. viewRules() {
  438. wx.downloadFile({
  439. url: 'https://bwj.obs.cn-east-2.myhuaweicloud.com/resources/PrivacyPolicy.docx',
  440. success: (res) => {
  441. console.log(res)
  442. wx.openDocument({
  443. filePath: res.tempFilePath,
  444. fail: (err) => {
  445. console.log(err)
  446. wx.showToast({
  447. title: '读取失败,请稍后再试',
  448. icon: "none"
  449. })
  450. }
  451. })
  452. },
  453. fail: (err) => {
  454. console.log(err)
  455. wx.showToast({
  456. title: '读取失败,请稍后再试',
  457. icon: "none"
  458. })
  459. }
  460. })
  461. return
  462. },
  463. /**
  464. * 生命周期函数--监听页面初次渲染完成
  465. */
  466. onReady: function () {},
  467. /**
  468. * 生命周期函数--监听页面显示
  469. */
  470. onShow: function () {},
  471. /**
  472. * 生命周期函数--监听页面隐藏
  473. */
  474. onHide: function () {
  475. },
  476. /**
  477. * 生命周期函数--监听页面卸载
  478. */
  479. onUnload: function () {
  480. },
  481. /**
  482. * 页面相关事件处理函数--监听用户下拉动作
  483. */
  484. onPullDownRefresh: function () {
  485. },
  486. /**
  487. * 页面上拉触底事件的处理函数
  488. */
  489. onReachBottom: function () {
  490. },
  491. /**
  492. * 用户点击右上角分享
  493. */
  494. onShareAppMessage: function () {
  495. }
  496. })