index.js 13 KB

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