123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- // pages/switchAccount/switchAccount.js
- const utils = require('../../utils/util.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- entTaxId: '',
- userInfo: '',
- list: [],
- pageNum: 1,
- pageSize: 20,
- pages: '',
- finish: false,
- tabIndex: 0,
- deviceList: [],
- deviceNumber: '',
- deviceFinish: false,
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- this.setData({
- entTaxId: wx.getStorageSync('entTaxId'),
- userInfo: utils.getInfo()
- })
- this.getList()
- },
- //切换
- switchTab(e) {
- let tabIndex = e.currentTarget.dataset.index
- this.setData({
- tabIndex
- })
- },
- //列表
- getList(type) {
- let params = {
- userMobile: this.data.userInfo.mobile,
- pageNum: this.data.pageNum,
- pageSize: this.data.pageSize
- }
- utils.axios({
- method: 'get',
- url: '/sys/entInfo/findPageByMobile',
- data: params,
- sendBefore() {
- wx.showNavigationBarLoading()
- },
- complete() {
- wx.hideNavigationBarLoading()
- wx.stopPullDownRefresh()
- },
- success: res => {
- let result = res.data
- for (let i = 0; i < result.records.length; i++) {
- result.records[i].selected = false
- if (result.records[i].entTaxId === this.data.entTaxId.toString()) {
- result.records[i].selected = true
- }
- }
- if (type === 'toFresh') {
- this.setData({
- list: result.records,
- pages: result.pages
- })
- this.getDeviceList('toFresh')
- } else {
- let list = this.data.list
- list = list.concat(result.records)
- this.setData({
- list,
- pages: result.pages
- })
- this.getDeviceList()
- }
- if (result.total <= this.data.pageSize) {
- this.setData({
- finish: true
- })
- }
- }
- })
- },
- //列表
- getDeviceList(type) {
- let defaultCompany = utils.getCurrEntInfo()
- let company = {}
- this.data.list.forEach((item) => {
- if (item.selected === true) {
- company = item
- }
- })
- let params = {
- entTaxId: company.entTaxId
- }
- utils.axios({
- method: 'get',
- url: '/sys/entDevice/findDevices',
- data: params,
- sendBefore() {
- wx.showNavigationBarLoading()
- },
- complete() {
- wx.hideNavigationBarLoading()
- wx.stopPullDownRefresh()
- },
- success: res => {
- for (let i = 0; i < res.data.length; i++) {
- res.data[i].selected = false
- if (res.data[i].deviceKey === defaultCompany.defaultDeviceInfo.deviceKey) {
- res.data[i].selected = true
- }
- }
- if (type === 'toFresh') {
- this.setData({
- deviceList: res.data,
- deviceNumber: res.data.length,
- deviceFinish: true
- })
- } else {
- let list = this.data.deviceList
- list = list.concat(res.data)
- this.setData({
- deviceList: list,
- deviceNumber: res.data.length,
- deviceFinish: true
- })
- }
- }
- })
- },
- toFresh() {
- this.setData({
- pageNum: 1,
- pages: '',
- finish: false
- })
- wx.pageScrollTo({
- scrollTop: 0,
- duration: 300
- })
- this.getList('toFresh')
- },
- //切换企业
- switchCompany(e) {
- let list = this.data.list
- let entTaxId = e.currentTarget.dataset.id
- let params = {
- mobile: this.data.userInfo.mobile,
- defaultChoose: entTaxId,
- reqChannel: 5
- }
- utils.axios({
- method: 'post',
- url: '/auth/comm/user/setDefaultChoose',
- data: params,
- sendBefore() {
- wx.showLoading({
- title: '企业切换中...',
- mask: true
- })
- },
- complete() {
- wx.hideLoading()
- },
- success: (res) => {
- utils.toast('企业切换成功')
- this.setData({
- entTaxId
- })
- for (let i = 0; i < list.length; i++) {
- list[i].selected = false
- if (list[i].entTaxId === this.data.entTaxId.toString()) {
- list[i].selected = true
- }
- }
- this.setData({
- list
- })
- let userInfo = wx.getStorageSync('userInfo')
- wx.setStorageSync('userInfo', userInfo)
- wx.setStorageSync('token', res.data.token)
- wx.setStorageSync('expirationTime', res.data.expirationTime)
- wx.setStorageSync('entTaxId', entTaxId)
- wx.setStorageSync('company', res.data.chooseEntity)
-
- // utils.getCompany().then(res => {
- // wx.setStorageSync('company', res.data)
- // })
- }
- })
- },
- //切换企业
- switchDevice(e) {
- let defaultCompany = utils.getCurrEntInfo()
- let device = e.currentTarget.dataset
- defaultCompany.deviceKey = device.deviceKey;
- defaultCompany.deviceLabel = device.deviceLabel;
- defaultCompany.devicePos = device.devicePos;
- defaultCompany.deviceType = device.deviceType;
- defaultCompany.entTaxId = device.entTaxId;
- defaultCompany.initStatus = device.initStatus;
- defaultCompany.isvPlatform = device.isvPlatform;
- defaultCompany.statusChangeTime = device.statusChangeTime;
- defaultCompany.taxDiscId = device.taxDiscId;
- defaultCompany.taxMachineNo = device.taxMachineNo;
- wx.setStorageSync('company', defaultCompany)
- utils.toast('设备切换成功')
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- this.toFresh()
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- let pageNum = this.data.pageNum
- let pages = this.data.pages
- pageNum++
- if (pageNum <= pages) {
- this.setData({
- pageNum
- })
- this.getList()
- } else {
- this.setData({
- finish: true
- })
- return
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- title: '诺信云',
- path: '/pages/index/index'
- }
- }
- })
|