switchAccount.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // pages/switchAccount/switchAccount.js
  2. const utils = require('../../utils/util.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. entTaxId: '',
  9. userInfo: '',
  10. list: [],
  11. pageNum: 1,
  12. pageSize: 20,
  13. pages: '',
  14. finish: false,
  15. tabIndex: 0,
  16. deviceList: [],
  17. deviceNumber: '',
  18. deviceFinish: false,
  19. },
  20. /**
  21. * 生命周期函数--监听页面加载
  22. */
  23. onLoad: function (options) {
  24. this.setData({
  25. entTaxId: wx.getStorageSync('entTaxId'),
  26. userInfo: utils.getInfo()
  27. })
  28. this.getList()
  29. },
  30. //切换
  31. switchTab(e) {
  32. let tabIndex = e.currentTarget.dataset.index
  33. this.setData({
  34. tabIndex
  35. })
  36. },
  37. //列表
  38. getList(type) {
  39. let params = {
  40. userMobile: this.data.userInfo.mobile,
  41. pageNum: this.data.pageNum,
  42. pageSize: this.data.pageSize
  43. }
  44. utils.axios({
  45. method: 'get',
  46. url: '/sys/entInfo/findPageByMobile',
  47. data: params,
  48. sendBefore() {
  49. wx.showNavigationBarLoading()
  50. },
  51. complete() {
  52. wx.hideNavigationBarLoading()
  53. wx.stopPullDownRefresh()
  54. },
  55. success: res => {
  56. let result = res.data
  57. for (let i = 0; i < result.records.length; i++) {
  58. result.records[i].selected = false
  59. if (result.records[i].entTaxId === this.data.entTaxId.toString()) {
  60. result.records[i].selected = true
  61. }
  62. }
  63. if (type === 'toFresh') {
  64. this.setData({
  65. list: result.records,
  66. pages: result.pages
  67. })
  68. this.getDeviceList('toFresh')
  69. } else {
  70. let list = this.data.list
  71. list = list.concat(result.records)
  72. this.setData({
  73. list,
  74. pages: result.pages
  75. })
  76. this.getDeviceList()
  77. }
  78. if (result.total <= this.data.pageSize) {
  79. this.setData({
  80. finish: true
  81. })
  82. }
  83. }
  84. })
  85. },
  86. //列表
  87. getDeviceList(type) {
  88. let defaultCompany = utils.getCurrEntInfo()
  89. let company = {}
  90. this.data.list.forEach((item) => {
  91. if (item.selected === true) {
  92. company = item
  93. }
  94. })
  95. let params = {
  96. entTaxId: company.entTaxId
  97. }
  98. utils.axios({
  99. method: 'get',
  100. url: '/sys/entDevice/findDevices',
  101. data: params,
  102. sendBefore() {
  103. wx.showNavigationBarLoading()
  104. },
  105. complete() {
  106. wx.hideNavigationBarLoading()
  107. wx.stopPullDownRefresh()
  108. },
  109. success: res => {
  110. for (let i = 0; i < res.data.length; i++) {
  111. res.data[i].selected = false
  112. if (res.data[i].deviceKey === defaultCompany.defaultDeviceInfo.deviceKey) {
  113. res.data[i].selected = true
  114. }
  115. }
  116. if (type === 'toFresh') {
  117. this.setData({
  118. deviceList: res.data,
  119. deviceNumber: res.data.length,
  120. deviceFinish: true
  121. })
  122. } else {
  123. let list = this.data.deviceList
  124. list = list.concat(res.data)
  125. this.setData({
  126. deviceList: list,
  127. deviceNumber: res.data.length,
  128. deviceFinish: true
  129. })
  130. }
  131. }
  132. })
  133. },
  134. toFresh() {
  135. this.setData({
  136. pageNum: 1,
  137. pages: '',
  138. finish: false
  139. })
  140. wx.pageScrollTo({
  141. scrollTop: 0,
  142. duration: 300
  143. })
  144. this.getList('toFresh')
  145. },
  146. //切换企业
  147. switchCompany(e) {
  148. let list = this.data.list
  149. let entTaxId = e.currentTarget.dataset.id
  150. let params = {
  151. mobile: this.data.userInfo.mobile,
  152. defaultChoose: entTaxId,
  153. reqChannel: 5
  154. }
  155. utils.axios({
  156. method: 'post',
  157. url: '/auth/comm/user/setDefaultChoose',
  158. data: params,
  159. sendBefore() {
  160. wx.showLoading({
  161. title: '企业切换中...',
  162. mask: true
  163. })
  164. },
  165. complete() {
  166. wx.hideLoading()
  167. },
  168. success: (res) => {
  169. utils.toast('企业切换成功')
  170. this.setData({
  171. entTaxId
  172. })
  173. for (let i = 0; i < list.length; i++) {
  174. list[i].selected = false
  175. if (list[i].entTaxId === this.data.entTaxId.toString()) {
  176. list[i].selected = true
  177. }
  178. }
  179. this.setData({
  180. list
  181. })
  182. let userInfo = wx.getStorageSync('userInfo')
  183. wx.setStorageSync('userInfo', userInfo)
  184. wx.setStorageSync('token', res.data.token)
  185. wx.setStorageSync('expirationTime', res.data.expirationTime)
  186. wx.setStorageSync('entTaxId', entTaxId)
  187. wx.setStorageSync('company', res.data.chooseEntity)
  188. // utils.getCompany().then(res => {
  189. // wx.setStorageSync('company', res.data)
  190. // })
  191. }
  192. })
  193. },
  194. //切换企业
  195. switchDevice(e) {
  196. let defaultCompany = utils.getCurrEntInfo()
  197. let device = e.currentTarget.dataset
  198. defaultCompany.deviceKey = device.deviceKey;
  199. defaultCompany.deviceLabel = device.deviceLabel;
  200. defaultCompany.devicePos = device.devicePos;
  201. defaultCompany.deviceType = device.deviceType;
  202. defaultCompany.entTaxId = device.entTaxId;
  203. defaultCompany.initStatus = device.initStatus;
  204. defaultCompany.isvPlatform = device.isvPlatform;
  205. defaultCompany.statusChangeTime = device.statusChangeTime;
  206. defaultCompany.taxDiscId = device.taxDiscId;
  207. defaultCompany.taxMachineNo = device.taxMachineNo;
  208. wx.setStorageSync('company', defaultCompany)
  209. utils.toast('设备切换成功')
  210. },
  211. /**
  212. * 生命周期函数--监听页面初次渲染完成
  213. */
  214. onReady: function () {
  215. },
  216. /**
  217. * 生命周期函数--监听页面显示
  218. */
  219. onShow: function () {
  220. },
  221. /**
  222. * 生命周期函数--监听页面隐藏
  223. */
  224. onHide: function () {
  225. },
  226. /**
  227. * 生命周期函数--监听页面卸载
  228. */
  229. onUnload: function () {
  230. },
  231. /**
  232. * 页面相关事件处理函数--监听用户下拉动作
  233. */
  234. onPullDownRefresh: function () {
  235. this.toFresh()
  236. },
  237. /**
  238. * 页面上拉触底事件的处理函数
  239. */
  240. onReachBottom: function () {
  241. let pageNum = this.data.pageNum
  242. let pages = this.data.pages
  243. pageNum++
  244. if (pageNum <= pages) {
  245. this.setData({
  246. pageNum
  247. })
  248. this.getList()
  249. } else {
  250. this.setData({
  251. finish: true
  252. })
  253. return
  254. }
  255. },
  256. /**
  257. * 用户点击右上角分享
  258. */
  259. onShareAppMessage: function () {
  260. return {
  261. title: '诺信云',
  262. path: '/pages/index/index'
  263. }
  264. }
  265. })