index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. // pages/regular_register/regular_register.js
  2. import international from '../../international/appointment_scence/index'
  3. const {
  4. getBuildingList,
  5. userWhiteCheck,
  6. getCompanyList,
  7. getAdminConfig,
  8. } = require('../../utils/api/api')
  9. const {
  10. throttle
  11. } = require("../../utils/throttle/throttle");
  12. import {
  13. getContextByAdminId, selectContextByCardId
  14. } from '../../utils/api/customField'
  15. const app = getApp()
  16. Page({
  17. /**
  18. * 页面的初始数据
  19. */
  20. data: {
  21. //国际化语言包
  22. international: international,
  23. //中英文配置
  24. language: null,
  25. // 功能列表
  26. component_list: [{
  27. id: 1,
  28. name_ch: '重新下发',
  29. name_en: 'Again issued',
  30. icon: '../../static/mine/deliver_again.png',
  31. url: ''
  32. },
  33. {
  34. id: 2,
  35. name_ch: '认证信息',
  36. name_en: 'Authentication information',
  37. icon: '../../static/mine/certification_msg.png',
  38. url: ''
  39. },
  40. {
  41. id: 3,
  42. name_ch: '邀请人员',
  43. name_en: 'Invite people',
  44. icon: '../../static/mine/my_appointment.png',
  45. url: ''
  46. }],
  47. //楼宇列表
  48. buildingList: [],
  49. buildingAdminId: null,
  50. buildingName: null,
  51. buildingIndex: null,
  52. //企业列表
  53. companyList: [],
  54. companyAdminId: null,
  55. companyName: null, //是否显示企业名称&存储企业名称
  56. companyIndex: null,
  57. //允许被显示的企业列表
  58. newCompanyList: [],
  59. //用户基础信息
  60. userInfo: null,
  61. //可供使用的账号信息
  62. usedAdminInfo: null,
  63. //是否禁用选择楼宇企业
  64. disableSelectAdminInfo: false,
  65. //是否禁用人员认证按钮
  66. isDisabled: false,
  67. //楼宇账号是否开启自定义字段
  68. isShowApplet: false,
  69. //自定义字段内容
  70. customField: [],
  71. //是否禁用提交按钮
  72. isSubmit: false,
  73. //是否能显示功能区
  74. showMyFun: false,
  75. //登录参数列表
  76. needLoginList: [],
  77. //是否输入手机号 0-否 1-需要
  78. needPhone: null,
  79. //是否需要照片 0-否 1-需要
  80. needPhoto: null,
  81. //是否需要实名 0-否 1-需要
  82. needRealname: null,
  83. //申报下发倒计时
  84. timeCount: null,
  85. },
  86. //获取楼宇列表: tip1-仅一个楼宇则自动填充 tip2-多个楼宇则判断是否扫码或者缓存进入
  87. getBuildingList() {
  88. getBuildingList().then(res => {
  89. let buildingIndex = null;
  90. //无楼宇,异常
  91. if (res.data.length < 1) {
  92. wx.showToast({
  93. title: '未查询到可用楼宇,请联系管理员',
  94. icon: "none"
  95. })
  96. return;
  97. }
  98. //多个楼宇,判断是否有可使用的账号信息
  99. if (res.data.length > 1 && this.data.usedAdminInfo) {
  100. let index = res.data.findIndex(item => {
  101. return item.adminId == this.data.usedAdminInfo.buildingAdminId
  102. })
  103. //可使用的信息无效
  104. if (index <= -1) {
  105. wx.removeStorageSync('adminInfo');
  106. app.data.adminInfo = null;
  107. app.data.temporaryAdminInfo = null;
  108. return;
  109. }
  110. //可使用的信息有效,自动选中
  111. if (index > -1) {
  112. buildingIndex = index
  113. this.setData({
  114. buildingAdminId: res.data[index].adminId,
  115. buildingName: res.data[index].name
  116. })
  117. }
  118. }
  119. //仅一个楼宇,自动填充
  120. if (res.data.length == 1) {
  121. buildingIndex = 0;
  122. this.setData({
  123. buildingAdminId: res.data[0].adminId,
  124. buildingName: res.data[0].name
  125. })
  126. }
  127. //有选中的楼宇id
  128. if (buildingIndex != null) {
  129. console.log(buildingIndex);
  130. //获取企业列表
  131. this.getCompanyList();
  132. //获取是否开启自定义字段
  133. this.getContextStatusByAdminId(this.data.buildingAdminId)
  134. //获取楼宇账号配置
  135. this.getAdminConfig()
  136. }
  137. this.setData({
  138. buildingList: res.data,
  139. buildingIndex: buildingIndex
  140. });
  141. })
  142. },
  143. // 根据选择的楼宇查找企业列表: tip1-仅一个企业则自动填充 tip2-多个企业则判断是否扫码或者缓存进入
  144. getCompanyList() {
  145. wx.showLoading({
  146. title: '获取企业列表...',
  147. });
  148. //清空原有的选择
  149. this.setData({
  150. companyAdminId: null,
  151. companyName: null,
  152. companyIndex: null
  153. })
  154. let data = {
  155. adminId: this.data.buildingAdminId,
  156. }
  157. getCompanyList(data).then(res => {
  158. wx.hideLoading()
  159. //接口异常
  160. if (!res.code === 200) {
  161. wx.showToast({
  162. title: res.msg,
  163. icon: 'none'
  164. });
  165. return;
  166. }
  167. //楼宇下无企业,异常
  168. if (res.data.length <= 0) {
  169. wx.showToast({
  170. title: '该楼宇下暂无企业',
  171. icon: 'none'
  172. });
  173. return;
  174. }
  175. //楼宇下有企业
  176. let companyIndex = null
  177. let newCompanyList = []
  178. if (res.data.length > 0) {
  179. //列表只显示可被搜索的企业
  180. res.data.forEach(item => {
  181. if (item.isCanSearch) {
  182. newCompanyList.push(item)
  183. }
  184. });
  185. }
  186. //没有可被搜索的企业
  187. if (newCompanyList.length <= 0) {
  188. wx.showToast({
  189. title: '该楼宇下暂无企业',
  190. icon: 'none'
  191. });
  192. return;
  193. }
  194. //可被搜索的企业数量大于 0 && 有可被使用的账号信息
  195. if (newCompanyList.length > 1 && this.data.usedAdminInfo && this.data.usedAdminInfo.companyAdminId) {
  196. let index = res.data.findIndex(item => {
  197. return item.adminId == this.data.usedAdminInfo.companyAdminId
  198. })
  199. //可使用的信息无效
  200. if (index <= -1) {
  201. wx.removeStorageSync('adminInfo');
  202. app.data.adminInfo = null;
  203. app.data.temporaryAdminInfo = null;
  204. return;
  205. }
  206. //可使用的信息有效
  207. if (index > -1) {
  208. companyIndex = index
  209. this.setData({
  210. companyAdminId: res.data[index].adminId,
  211. companyName: res.data[index].name,
  212. })
  213. }
  214. }
  215. //可被搜索的企业数量为 1 自动填充
  216. if (newCompanyList.length === 1) {
  217. companyIndex = 0;
  218. this.setData({
  219. companyAdminId: newCompanyList[0].adminId,
  220. companyName: newCompanyList[0].name
  221. })
  222. }
  223. this.setData({
  224. companyList: res.data,
  225. companyIndex: companyIndex,
  226. newCompanyList,
  227. })
  228. this.getContextByAdminId()
  229. });
  230. },
  231. // 获取账号的配置信息
  232. getAdminConfig() {
  233. getAdminConfig({
  234. adminId: this.data.buildingAdminId
  235. }).then(res => {
  236. this.setData({
  237. needPhone: res.data.whitelistAppPhone,
  238. needPhoto: res.data.whitelistAppPhoto,
  239. needRealname: res.data.whitelistAppRealname,
  240. needLoginList: res.data.whitelistAppLoginList,
  241. })
  242. })
  243. },
  244. //获取是否有自定义字段
  245. getContextStatusByAdminId(orgId) {
  246. getContextByAdminId(orgId).then(res => {
  247. if (res.code == 200) {
  248. console.log(res);
  249. this.setData({
  250. isShowApplet: res.data,
  251. isFillFields: !res.data,
  252. })
  253. this.canOperation()
  254. } else {
  255. wx.showToast({
  256. title: res.msg,
  257. icon: 'none'
  258. })
  259. }
  260. })
  261. },
  262. //选择楼宇或企业
  263. getValue(e) {
  264. switch (e.currentTarget.dataset.type) {
  265. case 'buildingAdminId':
  266. this.setData({
  267. buildingAdminId: e.detail.adminId,
  268. buildingName: e.detail.name,
  269. })
  270. this.getCompanyList()
  271. this.getContextStatusByAdminId(e.detail.adminId)
  272. this.getAdminConfig()
  273. break;
  274. case 'companyAdminId':
  275. this.setData({
  276. companyAdminId: e.detail.adminId,
  277. companyName: e.detail.name
  278. });
  279. this.getContextByAdminId()
  280. break;
  281. default:
  282. break;
  283. };
  284. this.canOperation()
  285. },
  286. // 获取组件抛出的认证状态-实名认证
  287. getCertificationState(e) {
  288. if (!e.detail) {
  289. wx.showToast({
  290. title: '认证失败了,再试一次吧~',
  291. icon: 'none'
  292. });
  293. return;
  294. }
  295. wx.showToast({
  296. title: '认证成功~',
  297. icon: 'none'
  298. })
  299. this.setData({
  300. isDisabled: true,
  301. });
  302. this.updateSetting()
  303. this.getContextByAdminId()
  304. },
  305. // 获取组件抛出的认证状态-ocr
  306. getUpdateState(e) {
  307. if (e.detail) {
  308. this.updateSetting()
  309. this.getContextByAdminId()
  310. }
  311. },
  312. // 获取用户填写的自定义字段内容
  313. getContextByAdminId() {
  314. if (!this.data.companyAdminId || !this.data.userInfo) {
  315. return;
  316. }
  317. selectContextByCardId(this.data.buildingAdminId, this.data.userInfo.userId).then(res => {
  318. console.log(res.data);
  319. this.setData({
  320. customField: res.data
  321. })
  322. })
  323. },
  324. // 判断提交按钮是否禁用
  325. canOperation() {
  326. let {
  327. buildingAdminId,
  328. companyAdminId,
  329. isSubmit,
  330. isFillFields,
  331. } = this.data;
  332. isSubmit = (buildingAdminId != null && companyAdminId != null && isFillFields) ? true : false;
  333. this.setData({
  334. isSubmit
  335. })
  336. },
  337. // 更新个人信息
  338. updateSetting() {
  339. //是否禁用选择楼宇企业选择栏
  340. let disableSelectAdminInfo = app.data.adminInfo || (app.data.temporaryAdminInfo && app.data.temporaryAdminInfo.companyAdminId);
  341. this.setData({
  342. showMyFun: app.data.adminInfo ? true : false,
  343. isDisabled: app.data.userInfo ? true : false,
  344. disableSelectAdminInfo: disableSelectAdminInfo
  345. });
  346. this.data.userInfo = app.data.userInfo
  347. },
  348. // 判断是否填写完成
  349. isFillFields(e) {
  350. this.data.isFillFields = e.detail
  351. this.canOperation()
  352. },
  353. // 提交
  354. sure() {
  355. let {
  356. buildingAdminId,
  357. buildingName,
  358. companyAdminId,
  359. companyName,
  360. userInfo,
  361. isFillFields,
  362. } = this.data
  363. if (!buildingAdminId || !companyAdminId || !userInfo.userId) {
  364. wx.showToast({
  365. title: '请先将信息填写完整',
  366. icon: 'none'
  367. })
  368. return;
  369. }
  370. let data = {
  371. adminId: buildingAdminId,
  372. userId: this.data.userInfo.userId,
  373. companyAdminId: companyAdminId,
  374. type: app.data.qrcodeInfo.type ? 1 : 0,
  375. addCustomList: isFillFields == true ? null : isFillFields,
  376. }
  377. userWhiteCheck(data).then(res => {
  378. if (res.code !== 200) {
  379. wx.showToast({
  380. title: res.msg,
  381. icon: 'none'
  382. })
  383. return;
  384. }
  385. let adminInfo = {
  386. buildingAdminId: buildingAdminId,
  387. buildingName: buildingName,
  388. companyAdminId: companyAdminId,
  389. companyName: companyName,
  390. userWhitelistId: res.data[0].userWhitelistId,
  391. official: true
  392. }
  393. wx.setStorageSync('adminInfo', adminInfo);
  394. app.data.adminInfo = adminInfo;
  395. this.updateSetting();
  396. wx.showModal({
  397. title: '提示',
  398. content: '恭喜绑定企业成功~',
  399. showCancel: false,
  400. success() {}
  401. });
  402. });
  403. },
  404. // 更改信息
  405. goToChange() {
  406. wx.navigateTo({
  407. url: '/pages/changeUserInfo/index?userType=常客&adminId=' + this.data.usedAdminInfo.buildingAdminId
  408. })
  409. },
  410. //其他功能跳转
  411. goto(e) {
  412. let id = e.currentTarget.dataset.id
  413. let url = ''
  414. if (id == 1) {
  415. this.doPass()
  416. return
  417. } else if (id == 2) {
  418. url = '/pages/regular_msg/regular_msg'
  419. } else if (id == 3) {
  420. wx.requestSubscribeMessage({
  421. tmplIds: ['261lS0M-ugfPHTOFeTFS6IN8WQshNOCbrPEC51OONy8'],
  422. success(res) { }
  423. })
  424. url = '/pages/regular_invite/regular_invite'
  425. }
  426. wx.navigateTo({
  427. url
  428. })
  429. },
  430. //人脸下发
  431. doPass: throttle(function () {
  432. let data = {
  433. adminId: this.data.usedAdminInfo.buildingAdminId,
  434. companyAdminId: this.data.usedAdminInfo.companyAdminId,
  435. userId: this.data.userInfo.userId,
  436. }
  437. wx.showLoading({
  438. title: '申报中..',
  439. });
  440. userWhiteCheck(data).then((res) => {
  441. console.log(res);
  442. if (res.code == 200) {
  443. this.data.timeCount = 30
  444. this.countDown()
  445. // this.data.userInfo.createTime = res.data.date;
  446. wx.showModal({
  447. content: '恭喜申报成功,您已获得闸机快速通行权限,如有疑问,请就近联系管理人员',
  448. showCancel: false,
  449. })
  450. } else {
  451. wx.showModal({
  452. content: res.msg,
  453. showCancel: false,
  454. })
  455. };
  456. // wx.setStorageSync('userInfo', this.data.userInfo);
  457. })
  458. .catch(err => { })
  459. .finally(() => {
  460. wx.hideLoading()
  461. })
  462. }, 30000),
  463. //申报倒计时
  464. countDown() {
  465. let {
  466. timeCount
  467. } = this.data;
  468. if (timeCount > 0) {
  469. setTimeout(() => {
  470. timeCount--
  471. this.setData({
  472. timeCount
  473. })
  474. this.countDown();
  475. }, 1000)
  476. }
  477. },
  478. //扫码账号信息和缓存的账号信息的处理
  479. doCheckAdmin() {
  480. //临时账号信息&&常客账号信息不一致
  481. if ((app.data.temporaryAdminInfo && app.data.adminInfo) && app.data.temporaryAdminInfo.companyAdminId && (app.data.temporaryAdminInfo.companyAdminId !== app.data.adminInfo.companyAdminId)) {
  482. wx.showModal({
  483. content: `检测到您本次扫码为"${app.data.temporaryAdminInfo.companyName || "未知"}",与上次注册的"${app.data.adminInfo.companyName || "未知"}"不一致,是否按照本次的信息进行认证?`,
  484. cancelText: "使用上次",
  485. confirmText: "使用本次",
  486. complete: (res) => {
  487. console.log(res);
  488. if (res.cancel) {
  489. app.data.temporaryAdminInfo = null
  490. }
  491. if (res.confirm) {
  492. app.data.adminInfo = null;
  493. wx.removeStorageSync('adminInfo');
  494. };
  495. this.setData({
  496. usedAdminInfo: app.data.adminInfo || app.data.temporaryAdminInfo
  497. })
  498. this.getBuildingList();
  499. this.updateSetting();
  500. }
  501. })
  502. return;
  503. //临时账号信息&&常客账号信息其中一个有,或两个没有,或两个都有,但是信息一致
  504. } else {
  505. this.setData({
  506. usedAdminInfo: app.data.adminInfo || app.data.temporaryAdminInfo
  507. })
  508. this.getBuildingList();
  509. this.updateSetting();
  510. }
  511. },
  512. /**
  513. * 生命周期函数--监听页面加载
  514. */
  515. onLoad: function (options) {
  516. this.setData({
  517. userInfo: app.data.userInfo,
  518. language: app.data.language
  519. })
  520. this.doCheckAdmin();
  521. },
  522. /**
  523. * 生命周期函数--监听页面初次渲染完成
  524. */
  525. onReady: function () {},
  526. /**
  527. * 生命周期函数--监听页面显示
  528. */
  529. onShow: function () {},
  530. /**
  531. * 生命周期函数--监听页面隐藏
  532. */
  533. onHide: function () {},
  534. /**
  535. * 生命周期函数--监听页面卸载
  536. */
  537. onUnload: function () {},
  538. /**
  539. * 页面相关事件处理函数--监听用户下拉动作
  540. */
  541. onPullDownRefresh: function () {},
  542. /**
  543. * 页面上拉触底事件的处理函数
  544. */
  545. onReachBottom: function () {},
  546. /**
  547. * 用户点击右上角分享
  548. */
  549. onShareAppMessage: function () {}
  550. })