123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555 |
- // pages/regular_register/regular_register.js
- import international from '../../international/appointment_scence/index'
- const {
- getBuildingList,
- userWhiteCheck,
- getCompanyList,
- getAdminConfig,
- } = require('../../utils/api/api')
- const {
- throttle
- } = require("../../utils/throttle/throttle");
- import {
- getContextByAdminId, selectContextByCardId
- } from '../../utils/api/customField'
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- //国际化语言包
- international: international,
- //中英文配置
- language: null,
- // 功能列表
- component_list: [{
- id: 1,
- name_ch: '重新下发',
- name_en: 'Again issued',
- icon: '../../static/mine/deliver_again.png',
- url: ''
- },
- {
- id: 2,
- name_ch: '认证信息',
- name_en: 'Authentication information',
- icon: '../../static/mine/certification_msg.png',
- url: ''
- },
- {
- id: 3,
- name_ch: '邀请人员',
- name_en: 'Invite people',
- icon: '../../static/mine/my_appointment.png',
- url: ''
- }],
- //楼宇列表
- buildingList: [],
- buildingAdminId: null,
- buildingName: null,
- buildingIndex: null,
- //企业列表
- companyList: [],
- companyAdminId: null,
- companyName: null, //是否显示企业名称&存储企业名称
- companyIndex: null,
- //允许被显示的企业列表
- newCompanyList: [],
- //用户基础信息
- userInfo: null,
- //可供使用的账号信息
- usedAdminInfo: null,
- //是否禁用选择楼宇企业
- disableSelectAdminInfo: false,
- //是否禁用人员认证按钮
- isDisabled: false,
- //楼宇账号是否开启自定义字段
- isShowApplet: false,
- //自定义字段内容
- customField: [],
- //是否禁用提交按钮
- isSubmit: false,
- //是否能显示功能区
- showMyFun: false,
- //登录参数列表
- needLoginList: [],
- //是否输入手机号 0-否 1-需要
- needPhone: null,
- //是否需要照片 0-否 1-需要
- needPhoto: null,
- //是否需要实名 0-否 1-需要
- needRealname: null,
- //申报下发倒计时
- timeCount: null,
- },
- //获取楼宇列表: tip1-仅一个楼宇则自动填充 tip2-多个楼宇则判断是否扫码或者缓存进入
- getBuildingList() {
- getBuildingList().then(res => {
- let buildingIndex = null;
- //无楼宇,异常
- if (res.data.length < 1) {
- wx.showToast({
- title: '未查询到可用楼宇,请联系管理员',
- icon: "none"
- })
- return;
- }
- //多个楼宇,判断是否有可使用的账号信息
- if (res.data.length > 1 && this.data.usedAdminInfo) {
- let index = res.data.findIndex(item => {
- return item.adminId == this.data.usedAdminInfo.buildingAdminId
- })
- //可使用的信息无效
- if (index <= -1) {
- wx.removeStorageSync('adminInfo');
- app.data.adminInfo = null;
- app.data.temporaryAdminInfo = null;
- return;
- }
- //可使用的信息有效,自动选中
- if (index > -1) {
- buildingIndex = index
- this.setData({
- buildingAdminId: res.data[index].adminId,
- buildingName: res.data[index].name
- })
- }
- }
- //仅一个楼宇,自动填充
- if (res.data.length == 1) {
- buildingIndex = 0;
- this.setData({
- buildingAdminId: res.data[0].adminId,
- buildingName: res.data[0].name
- })
- }
- //有选中的楼宇id
- if (buildingIndex != null) {
- //获取企业列表
- this.getCompanyList();
- //获取是否开启自定义字段
- this.getContextStatusByAdminId(this.data.buildingAdminId)
- //获取楼宇账号配置
- this.getAdminConfig()
- }
- this.setData({
- buildingList: res.data,
- buildingIndex: buildingIndex
- });
- })
- },
- // 根据选择的楼宇查找企业列表: tip1-仅一个企业则自动填充 tip2-多个企业则判断是否扫码或者缓存进入
- getCompanyList() {
- wx.showLoading({
- title: '获取企业列表...',
- });
- //清空原有的选择
- this.setData({
- companyAdminId: null,
- companyName: null,
- companyIndex: null
- })
- let data = {
- adminId: this.data.buildingAdminId,
- }
- getCompanyList(data).then(res => {
- wx.hideLoading()
- //接口异常
- if (!res.code === 200) {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- });
- return;
- }
- //楼宇下无企业,异常
- if (res.data.length <= 0) {
- wx.showToast({
- title: '该楼宇下暂无企业',
- icon: 'none'
- });
- return;
- }
- //楼宇下有企业
- let companyIndex = null
- let newCompanyList = []
- if (res.data.length > 0) {
- //列表只显示可被搜索的企业
- res.data.forEach(item => {
- if (item.isCanSearch) {
- newCompanyList.push(item)
- }
- });
- }
- //没有可被搜索的企业
- if (newCompanyList.length <= 0) {
- wx.showToast({
- title: '该楼宇下暂无企业',
- icon: 'none'
- });
- return;
- }
- //可被搜索的企业数量大于 0 && 有可被使用的账号信息
- if (newCompanyList.length > 1 && this.data.usedAdminInfo && this.data.usedAdminInfo.companyAdminId) {
- let index = res.data.findIndex(item => {
- return item.adminId == this.data.usedAdminInfo.companyAdminId
- })
- //可使用的信息无效
- if (index <= -1) {
- wx.removeStorageSync('adminInfo');
- app.data.adminInfo = null;
- app.data.temporaryAdminInfo = null;
- return;
- }
- //可使用的信息有效
- if (index > -1) {
- companyIndex = index
- this.setData({
- companyAdminId: res.data[index].adminId,
- companyName: res.data[index].name,
- })
- }
- }
- //可被搜索的企业数量为 1 自动填充
- if (newCompanyList.length === 1) {
- companyIndex = 0;
- this.setData({
- companyAdminId: newCompanyList[0].adminId,
- companyName: newCompanyList[0].name
- })
- }
- this.setData({
- companyList: res.data,
- companyIndex: companyIndex,
- newCompanyList,
- })
- this.getContextByAdminId()
- });
- },
- // 获取账号的配置信息
- getAdminConfig() {
- getAdminConfig({
- adminId: this.data.buildingAdminId
- }).then(res => {
- this.setData({
- needPhone: res.data.whitelistAppPhone,
- needPhoto: res.data.whitelistAppPhoto,
- needRealname: res.data.whitelistAppRealname,
- needLoginList: res.data.whitelistAppLoginList,
- })
- })
- },
- //获取是否有自定义字段
- getContextStatusByAdminId(orgId) {
- getContextByAdminId(orgId).then(res => {
- if (res.code == 200) {
- this.setData({
- isShowApplet: res.data,
- isFillFields: !res.data,
- })
- this.canOperation()
- } else {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- }
- })
- },
- //选择楼宇或企业
- getValue(e) {
- switch (e.currentTarget.dataset.type) {
- case 'buildingAdminId':
- this.setData({
- buildingAdminId: e.detail.adminId,
- buildingName: e.detail.name,
- })
- this.getCompanyList()
- this.getContextStatusByAdminId(e.detail.adminId)
- this.getAdminConfig()
- break;
- case 'companyAdminId':
- this.setData({
- companyAdminId: e.detail.adminId,
- companyName: e.detail.name
- });
- this.getContextByAdminId()
- break;
- default:
- break;
- };
- this.canOperation()
- },
- // 获取组件抛出的认证状态-实名认证
- getCertificationState(e) {
- if (!e.detail) {
- wx.showToast({
- title: '认证失败了,再试一次吧~',
- icon: 'none'
- });
- return;
- }
- wx.showToast({
- title: '认证成功~',
- icon: 'none'
- })
- this.setData({
- isDisabled: true,
- });
- this.updateSetting()
- this.getContextByAdminId()
- },
- // 获取组件抛出的认证状态-ocr
- getUpdateState(e) {
- if (e.detail) {
- this.updateSetting()
- this.getContextByAdminId()
- }
- },
- // 获取用户填写的自定义字段内容
- getContextByAdminId() {
- if (!this.data.companyAdminId || !this.data.userInfo) {
- return;
- }
- selectContextByCardId(this.data.buildingAdminId, this.data.userInfo.userId).then(res => {
- this.setData({
- customField: res.data
- })
- })
- },
- // 判断提交按钮是否禁用
- canOperation() {
- let {
- buildingAdminId,
- companyAdminId,
- isSubmit,
- isFillFields,
- } = this.data;
- isSubmit = (buildingAdminId != null && companyAdminId != null && isFillFields) ? true : false;
- this.setData({
- isSubmit
- })
- },
- // 更新个人信息
- updateSetting() {
- //是否禁用选择楼宇企业选择栏
- let disableSelectAdminInfo = app.data.adminInfo || (app.data.temporaryAdminInfo && app.data.temporaryAdminInfo.companyAdminId);
- this.setData({
- showMyFun: app.data.adminInfo ? true : false,
- isDisabled: app.data.userInfo ? true : false,
- disableSelectAdminInfo: disableSelectAdminInfo
- });
- this.data.userInfo = app.data.userInfo
- },
- // 判断是否填写完成
- isFillFields(e) {
- this.data.isFillFields = e.detail
- this.canOperation()
- },
- // 提交
- sure() {
- let {
- buildingAdminId,
- buildingName,
- companyAdminId,
- companyName,
- userInfo,
- isFillFields,
- } = this.data
- if (!buildingAdminId || !companyAdminId || !userInfo.userId) {
- wx.showToast({
- title: '请先将信息填写完整',
- icon: 'none'
- })
- return;
- }
- let data = {
- adminId: buildingAdminId,
- userId: this.data.userInfo.userId,
- companyAdminId: companyAdminId,
- type: app.data.qrcodeInfo.type ? 1 : 0,
- addCustomList: isFillFields == true ? null : isFillFields,
- }
- userWhiteCheck(data).then(res => {
- if (res.code !== 200) {
- wx.showToast({
- title: res.msg,
- icon: 'none'
- })
- return;
- }
- let adminInfo = {
- buildingAdminId: buildingAdminId,
- buildingName: buildingName,
- companyAdminId: companyAdminId,
- companyName: companyName,
- userWhitelistId: res.data[0].userWhitelistId,
- official: true
- }
- wx.setStorageSync('adminInfo', adminInfo);
- app.data.adminInfo = adminInfo;
- this.updateSetting();
- wx.showModal({
- title: '提示',
- content: '恭喜绑定企业成功~',
- showCancel: false,
- success() {}
- });
- });
- },
- // 更改信息
- goToChange() {
- wx.navigateTo({
- url: '/pages/changeUserInfo/index?userType=常客&adminId=' + this.data.usedAdminInfo.buildingAdminId
- })
- },
- //其他功能跳转
- goto(e) {
- let id = e.currentTarget.dataset.id
- let url = ''
- if (id == 1) {
- this.doPass()
- return
- } else if (id == 2) {
- url = '/pages/regular_msg/regular_msg'
- } else if (id == 3) {
- wx.requestSubscribeMessage({
- tmplIds: ['261lS0M-ugfPHTOFeTFS6IN8WQshNOCbrPEC51OONy8'],
- success(res) { }
- })
- url = '/pages/regular_invite/regular_invite'
- }
- wx.navigateTo({
- url
- })
- },
- //人脸下发
- doPass: throttle(function () {
- let data = {
- adminId: this.data.usedAdminInfo.buildingAdminId,
- companyAdminId: this.data.usedAdminInfo.companyAdminId,
- userId: this.data.userInfo.userId,
- }
- wx.showLoading({
- title: '申报中..',
- });
- userWhiteCheck(data).then((res) => {
- if (res.code == 200) {
- this.data.timeCount = 30
- this.countDown()
- // this.data.userInfo.createTime = res.data.date;
- wx.showModal({
- content: '恭喜申报成功,您已获得闸机快速通行权限,如有疑问,请就近联系管理人员',
- showCancel: false,
- })
- } else {
- wx.showModal({
- content: res.msg,
- showCancel: false,
- })
- };
- // wx.setStorageSync('userInfo', this.data.userInfo);
- })
- .catch(err => { })
- .finally(() => {
- wx.hideLoading()
- })
- }, 30000),
- //申报倒计时
- countDown() {
- let {
- timeCount
- } = this.data;
- if (timeCount > 0) {
- setTimeout(() => {
- timeCount--
- this.setData({
- timeCount
- })
- this.countDown();
- }, 1000)
- }
- },
- //扫码账号信息和缓存的账号信息的处理
- doCheckAdmin() {
- //临时账号信息&&常客账号信息不一致
- if ((app.data.temporaryAdminInfo && app.data.adminInfo) && app.data.temporaryAdminInfo.companyAdminId && (app.data.temporaryAdminInfo.companyAdminId !== app.data.adminInfo.companyAdminId)) {
- wx.showModal({
- content: `检测到您本次扫码为"${app.data.temporaryAdminInfo.companyName || "未知"}",与上次注册的"${app.data.adminInfo.companyName || "未知"}"不一致,是否按照本次的信息进行认证?`,
- cancelText: "使用上次",
- confirmText: "使用本次",
- complete: (res) => {
- if (res.cancel) {
- app.data.temporaryAdminInfo = null
- }
- if (res.confirm) {
- app.data.adminInfo = null;
- wx.removeStorageSync('adminInfo');
- };
- this.setData({
- usedAdminInfo: app.data.adminInfo || app.data.temporaryAdminInfo
- })
- this.getBuildingList();
- this.updateSetting();
- }
- })
- return;
- //临时账号信息&&常客账号信息其中一个有,或两个没有,或两个都有,但是信息一致
- } else {
- this.setData({
- usedAdminInfo: app.data.adminInfo || app.data.temporaryAdminInfo
- })
- this.getBuildingList();
- this.updateSetting();
- }
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- userInfo: app.data.userInfo,
- language: app.data.language
- })
- this.doCheckAdmin();
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {},
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {},
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {},
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {},
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {},
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {},
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {}
- })
|