| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 |
- /*******************************************************************************
- * Copyright(c) 2022 dongke All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:
- * 2.功能描述:欢迎页面画面
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 姜永辉 2022-11-22 1.00 新建
- *******************************************************************************/
- const app = getApp()
- const api = require('@/utils/api.js');
- const config = require('@/config/config.js');
- const Constants = require('@/utils/Constants.js');
- const util = require('@/utils/util.js');
- const { gradeCode } = require('@/utils/Constants.js');
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- imageUrl: config.image_url + '/static/img/',
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- ("welcome", options);
- // options 中的 scene 需要使用 decodeURIComponent 才能获取到生成二维码时传入的 scene
- if (options.scene) {
- var scene = decodeURIComponent(options.scene)
- this.setData({
- scene: scene,
- })
- }
- // 从员工一览购买授权过来
- if (options.buy) {
- this.setData({
- buy: options.buy,
- })
- }
- // 小程序推送消息传过来的值
- if (options.loginType) {
- this.setData({
- loginType: options.loginType,
- //小程序推送消息传过来的值 pages/welcome/welcome?loginType=loginType&otherParam=值
- })
- }
- // 推送消息的其他参数-字符串处理,需要json到各自模块转换
- if (options.otherParam) {
- let reg = /\\/g
- let otherParam = options.otherParam.replace(reg, '')
- this.setData({
- otherParam
- })
- }
- // 从好有分享过来的数据 好友互利共赢 shareType=1 cpid userid startdate enddate
- if (options.shareType) {
- this.setData({
- shareType: options.shareType,
- })
- }
- // 来源公司id
- if (options.cpIdFrom) {
- this.setData({
- cpIdFrom: options.cpIdFrom,
- })
- }
- // 截止日期
- if (options.shareEndDate) {
- this.setData({
- shareEndDate: options.shareEndDate,
- })
- }
- // 来源公司 -userid
- if (options.userIdFrom) {
- this.setData({
- userIdFrom: options.userIdFrom,
- })
- }
- // 分享链接Id -shareId
- if (options.shareId) {
- this.setData({
- shareId: options.shareId,
- })
- }
- // 来源公司 -员工
- if (options.staffNameFrom) {
- this.setData({
- staffNameFrom: options.staffNameFrom,
- })
- }
- console.log(options,"welcome");
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- // 登录 code
- this.wx_login()
- },
- /**
- * @desc : 登录
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- wx_login() {
- let _this = this
- _this.wxlogin().then(res => {
- _this.getopenid({ code: res.code });
- })
- },
- /**
- * @desc : 获取微信派发的临时登录凭证
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- wxlogin() {
- return new Promise((resolve, reject) => {
- // 登录
- wx.login({
- success: res => {
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- console.log("wx.login", res);
- if (res.code) {
- resolve(res)
- } else {
- reject(res)
- }
- }
- })
- })
- },
- /**
- * @desc : 获取微信派发的 openid
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- getopenid(param) {
- let _this = this
- api.request(Constants.SYS_OPENID_API + 'oauth/wx/login_wechat', 'POST', param).then(res => {
- if (res.data.code == Constants.SUCESS_CODE) {
- app.globalData.openid = res.data.data.openid
- app.globalData.unionId = res.data.data.unionid
- app.globalData.sessionkey = res.data.data.session_key
- _this.gettoken()
- }
- })
- },
- /**
- * @desc : 通过openid获取用户信息
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- gettoken() {
- let _this = this
- // 调用接口
- _this.getTokenPromise().then(res => {
- let data = res.data.data;
- if (res.data.code === Constants.SUCESS_CODE) {
- // 记录登录的缓存
- app.globalData.company = data.company
- app.globalData.user = {
- userId: data.userId,
- userName: data.userName,
- userPhone: data.userPhone
- }
- // 说明注册未支付
- if (data.company && !data.company.license) {
- // 成功后跳转支付
- _this.toPay(res.data.data);
- // 调转选择公司
- if (this.data.shareType) {
- wx.reLaunch({
- url: '../../pages/login/login?shareType='
- + this.data.shareType + '&cpIdFrom=' + this.data.cpIdFrom
- + '&shareEndDate=' + this.data.shareEndDate
- + '&userIdFrom=' + this.data.userIdFrom
- + '&staffNameFrom=' + this.data.staffNameFrom
- + '&shareId=' + this.data.shareId,
- })
- } else {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }
- return
- }
- app.globalData.token = res.data.data.accessToken
- // 读取后台设置的url
- if (data.company && data.company.svcIp && data.company.svcPort) {
- app.globalData.URI = data.company.svcIp + ':' + data.company.svcPort
- }
- if (data.company == undefined && data.joinedCps != undefined && data.joinedCps.length > 0) {
- // // 调转加入企业
- // wx.reLaunch({
- // url: '../../pages/company/company',
- // })
- // 调转选择公司
- if (this.data.shareType) {
- wx.reLaunch({
- url: '../../pages/login/login?shareType='
- + this.data.shareType + '&cpIdFrom=' + this.data.cpIdFrom
- + '&shareEndDate=' + this.data.shareEndDate
- + '&userIdFrom=' + this.data.userIdFrom
- + '&staffNameFrom=' + this.data.staffNameFrom
- + '&shareId=' + this.data.shareId,
- })
- } else {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }
- }
- else
- if (data.company == undefined
- || res.data.data.company.cpId == null
- || res.data.data.company.cpId == ''
- || res.data.data.company.cpId == undefined) {
- // 调转选择公司
- if (this.data.shareType) {
- wx.reLaunch({
- url: '../../pages/login/login?shareType='
- + this.data.shareType + '&cpIdFrom=' + this.data.cpIdFrom
- + '&shareEndDate=' + this.data.shareEndDate
- + '&userIdFrom=' + this.data.userIdFrom
- + '&staffNameFrom=' + this.data.staffNameFrom
- + '&shareId=' + this.data.shareId,
- })
- } else {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }
- }
- else {
- // // 接口登录后获取数据
- _this.getInfoAfterLogin()
- }
- }
- else if (res.data.code === 1015 || res.data.code === 1016) {
- if (res.data.code === 1016) {
- app.globalData.user = {
- userId: data.userId,
- userName: data.userName,
- userPhone: data.userPhone
- }
- app.globalData.openid = data.userWxid
- }
- // 当前用户未注册 // 公司到期
- // 调转选择公司
- setTimeout(() => {
- if (this.data.shareType) {
- wx.reLaunch({
- url: '../../pages/login/login?shareType='
- + this.data.shareType + '&cpIdFrom=' + this.data.cpIdFrom
- + '&shareEndDate=' + this.data.shareEndDate
- + '&userIdFrom=' + this.data.userIdFrom
- + '&staffNameFrom=' + this.data.staffNameFrom
- + '&shareId=' + this.data.shareId,
- })
- } else {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }
- }, 2000)
- } else if (res.data.code == 1000) { // 令牌为空
- // 调转选择公司
- setTimeout(() => {
- if (this.data.shareType) {
- wx.reLaunch({
- url: '../../pages/login/login?shareType='
- + this.data.shareType + '&cpIdFrom=' + this.data.cpIdFrom
- + '&shareEndDate=' + this.data.shareEndDate
- + '&userIdFrom=' + this.data.userIdFrom
- + '&staffNameFrom=' + this.data.staffNameFrom
- + '&shareId=' + this.data.shareId,
- })
- } else {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }
- }, 2000)
- }
- })
- },
- /**
- * @desc : 微信支付
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- toPay(e) {
- let trade = e.company.trade
- let wechatPayService = app.globalData['wechatPayService']
- let params = {
- openId: app.globalData.openid,
- payFee: trade.tradeAmount,
- paymentSn: trade.tradeNo,
- }
- api.request(wechatPayService.prefix + wechatPayService.unifiedOrder, 'POST', params).then(res => {
- if (res.data.code === Constants.SUCESS_CODE) {
- var appid = res.data.data.appId
- var timeStamp = res.data.data.timeStamp
- var nonce_str = res.data.data.nonceStr
- var pk = res.data.data.pack
- var paySign = res.data.data.paySign
- let _this = this
- //调用微信支付
- wx.requestPayment({
- 'appId': appid,
- 'timeStamp': timeStamp,
- 'nonceStr': nonce_str,
- 'package': pk,
- 'signType': 'MD5',
- 'paySign': paySign,
- 'success': function (res) {
- wx.showToast({
- title: '支付成功',
- image: '/static/image/success.png',
- duration: 2000
- })
- _this.setData({
- loading: false
- })
- //刷新当前页面
- _this.onShow()
- },
- 'fail': function (res) {
- _this.setData({
- loading: false
- })
- },
- 'complete': function (res) {
- }
- });
- }
- });
- },
- /**
- * @desc : 登录后获取数据
- * @date : 2022/5/12 13:49
- * @author : 周兴
- */
- getInfoAfterLogin() {
- api.request('mdm-server/mst/staff/get_info_after_login', 'POST',
- {
- 'appCode': Constants.APP_CODE,
- 'cpId': app.globalData.company.cpId,
- 'userId': app.globalData.user.userId
- }).then(res => {
- if (res.data.code === Constants.SUCESS_CODE) {
- // 服务器的日期
- let nowDate = res.data.data.nowDate
- app.globalData.nowDate = nowDate
- // 员工
- let staff = res.data.data.staff
- if (staff && staff.staffId) {
- // 判断当前用户是否到期 标准版
- if (app.globalData.company.gradeCode == Constants.gradeCode.STD && !staff.flgInit) {
- let userEndDate = app.globalData.company.userEndDate
- if (userEndDate) {
- // 必须用服务器的返回时间来判断是否到期
- let diffs = new Date(userEndDate).dayDiff(new Date(nowDate))
- // 说明已经到期,跳转到
- if (diffs < 0) {
- util.showToast('用户已到期,到期日期【' + userEndDate + '】')
- setTimeout(() => {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }, 2000)
- return;
- }
- }
- }
- app.globalData.user.staffId = staff.staffId
- app.globalData.user.staffCode = staff.staffCode
- app.globalData.user.staffName = staff.staffName
- app.globalData.user.staffPhone = staff.staffPhone
- app.globalData.user.roleIds = staff.roleIds
- app.globalData.user.orgId = staff.orgId
- app.globalData.user.orgName = staff.orgName
- app.globalData.user.defaultWhName = staff.defaultWhName
- app.globalData.user.defaultWhId = staff.defaultWhId
- app.globalData.user.flgBusiness = staff.flgBusiness
- app.globalData.user.flgInit = !!staff.flgInit
- // 1:PC端,2:移动端,3:PC+移动端, 4:无)
- if (staff.loginType == null || staff.loginType == 1 || staff.loginType == 4) {
- util.showToast('用户【' + staff.staffName + '】电话【' + staff.staffPhone + '】无权限')
- setTimeout(() => {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }, 2000)
- return;
- }
- // 调转主页--注意有场景值的情况
- if (this.data.scene) {
- wx.reLaunch({
- url: '../../pages/home-page/home-page?scene=' + this.data.scene
- + '&loginType=' + this.data.loginType,
- })
- } else if (this.data.buy) {
- wx.reLaunch({
- url: '../../pages/home-page/home-page?buy=' + this.data.buy
- + '&loginType=' + this.data.loginType,
- })
- } else {
- wx.reLaunch({
- url: '../../pages/home-page/home-page?loginType='
- + this.data.loginType
- + (this.data.otherParam?'&otherParam=' + this.data.otherParam:''),
- })
- }
- }
- // 菜单
- let menuList = res.data.data.menuList
- if (menuList) {
- // 如果标准版把销售出库 修改为订单开单
- // if (app.globalData.company.gradeCode == Constants.gradeCode.STD) {
- // let filters = menuList.filter(it => it.objectCode == 'order-out');
- // if (filters && filters.length > 0) {
- // filters[0].menuName = '订单开单'
- // filters[0].name = '订单开单'
- // }
- // // 出库明细表修改为销售明细表
- // filters = menuList.filter(it => it.objectCode == 'out-detail-report');
- // if (filters && filters.length > 0) {
- // filters[0].menuName = '销售明细表'
- // filters[0].name = '销售明细表'
- // }
- // }
- // 处理操作链接
- let filters = menuList.filter(it => it.menuTags)
- if (filters && filters.length > 0) {
- filters.forEach(t => {
- if (t.menuTags.value) {
- let val = JSON.parse(t.menuTags.value)
- if (val.guideUrl == 'knowledge-view') {
- t.guideUrl = config.knowledge_url + '/' + val.guideUrl + '?appCode=CP-WXP&funId=' + t.funUuid
- }
- }
- })
- }
- // 处理功能包
- app.globalData.menus = util.handleMenu(app.globalData.company.funPackage, menuList);
- // console.log('menus',app.globalData.menus);
- }
- // 常用菜单
- let comMenuList = res.data.data.comMenuList
- if (comMenuList) {
- app.globalData.comMenuList = comMenuList
- }
- // 系统参数
- let setting = res.data.data.settingValue
- if (setting) {
- app.globalData.setting = JSON.parse(setting.setting.value)
- }
- // 系统字典
- let dataKindList = res.data.data.dataKindList
- if (dataKindList) {
- app.globalData.dataKindList = dataKindList
- }
- } else {
- // 报错跳转到登录界面
- setTimeout(() => {
- wx.reLaunch({
- url: '../../pages/login/login',
- })
- }, 3000)
- }
- })
- },
- /**
- * @desc : 获取微信派发的临时登录凭证
- * @date : 2022/5/12 13:49
- * @author : 姜永辉
- */
- getTokenPromise() {
- return new Promise((resolve, reject) => {
- api.request(Constants.SYS_OPENID_API + 'oauth/wx/token', 'POST',
- { 'userWxid': app.globalData.openid, unionId: app.globalData.unionId }).then(res => {
- resolve(res)
- })
- })
- },
- /**
- * @desc : 获取语言的方法
- * @author : 周兴
- * @date : 2024/1/19
- */
- $t(name) {
- if (this.data.$t[name]) {
- return this.data.$t[name];
- } else {
- return name;
- }
- },
- })
|