index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const _Http = getApp().globalData.http;
  2. const getHeight = require("../../utils/GetRheRemainingHeight");
  3. Page({
  4. data: {
  5. tabShow: true,
  6. auth: {}, //权限
  7. listHeight: 0,
  8. butText: "", //按钮类型
  9. content: {
  10. "pageNumber": 1,
  11. "pageSize": 20,
  12. "pageTotal": 1,
  13. "where": {
  14. "condition": ""
  15. }
  16. }
  17. },
  18. onLoad(options) {
  19. let auth = options.auth ? JSON.parse(options.auth) : getApp().globalData.queryPer.query(wx.getStorageSync('userauth'), ['通用'], ['个人中心'])[0].apps[0].meta.auth,
  20. authList = auth.map(v => v.optionname);
  21. let tabShow = false,
  22. butText = '账号';
  23. if (authList.includes('查看账号') && authList.includes('查看角色')) {
  24. tabShow = true;
  25. } else {
  26. butText = authList.includes('查看角色') ? '角色' : '账号';
  27. }
  28. this.setData({
  29. tabShow,
  30. butText,
  31. authList
  32. })
  33. this.getList();
  34. },
  35. /* 获取列表 */
  36. getList(init = false) {
  37. if (init.detail != undefined) init = init.detail;
  38. if (init) this.setData({
  39. ['content.pageNumber']: 1
  40. })
  41. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  42. _Http.basic({
  43. "id": this.data.butText == '账号' ? "20221107094704" : "20221109091404",
  44. "content": this.data.content
  45. }).then(res => {
  46. this.selectComponent('#ListBox').RefreshToComplete();
  47. if (res.msg != '成功') return wx.showToast({
  48. title: res.msg,
  49. icon: "none"
  50. })
  51. if (this.data.butText == '账号') {
  52. for (let i = 0; i < res.data.length; i++) {
  53. res.data[i].attinfos = res.data[i].attinfos.filter(v => v.usetype == 'headportrait');
  54. }
  55. }
  56. this.setData({
  57. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  58. ['content.pageNumber']: res.pageNumber + 1,
  59. ['content.pageTotal']: res.pageTotal
  60. })
  61. })
  62. },
  63. /* 新建账号/角色 */
  64. newItem() {
  65. if (this.data.butText == '账号') {
  66. wx.navigateTo({
  67. url: '/pages/teams/addUsers'
  68. })
  69. } else {
  70. wx.navigateTo({
  71. url: '/pages/teams/addRole'
  72. })
  73. }
  74. },
  75. /* tab切换 */
  76. tabChange(e) {
  77. this.setData({
  78. butText: e.detail.title.slice(0, 2),
  79. list: [],
  80. })
  81. this.getList(true);
  82. },
  83. /* 修改角色 */
  84. changeRole(e) {
  85. let {
  86. item
  87. } = e.currentTarget.dataset;
  88. wx.navigateTo({
  89. url: `./addRole?item=${JSON.stringify(item)}&update=${this.data.authList.includes("角色修改")}&userDelete=${this.data.authList.includes("角色删除")}`
  90. })
  91. },
  92. /* 修改账号 */
  93. changeUser(e) {
  94. let {
  95. item
  96. } = e.currentTarget.dataset;
  97. delete(item.attinfos);
  98. wx.navigateTo({
  99. url: `./addUsers?item=${JSON.stringify(item)}&update=${this.data.authList.includes("账号修改")}`
  100. })
  101. },
  102. /**
  103. * 生命周期函数--监听页面初次渲染完成
  104. */
  105. onReady() {
  106. getHeight.getHeight('.tabs', this).then(res => {
  107. this.setData({
  108. listHeight: res
  109. })
  110. });
  111. },
  112. onShareAppMessage(res) {}
  113. })