index.js 3.6 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. "classname": this.data.butText == '账号' ? "sale.team.team" : "sale.role.role",
  44. "method": this.data.butText == '账号' ? "query_teamList" : "query_roleList",
  45. "content": this.data.content
  46. }).then(res => {
  47. this.selectComponent('#ListBox').RefreshToComplete();
  48. if (res.msg != '成功') return wx.showToast({
  49. title: res.msg,
  50. icon: "none"
  51. })
  52. if (this.data.butText == '账号') {
  53. for (let i = 0; i < res.data.length; i++) {
  54. res.data[i].attinfos = res.data[i].attinfos.filter(v => v.usetype == 'headportrait');
  55. }
  56. }
  57. this.setData({
  58. list: (res.pageNumber == 1) ? res.data : this.data.list.concat(res.data),
  59. ['content.pageNumber']: res.pageNumber + 1,
  60. ['content.pageTotal']: res.pageTotal
  61. })
  62. })
  63. },
  64. /* 新建账号/角色 */
  65. newItem() {
  66. if (this.data.butText == '账号') {
  67. wx.navigateTo({
  68. url: '/pages/teams/addUsers'
  69. })
  70. } else {
  71. wx.navigateTo({
  72. url: '/pages/teams/addRole'
  73. })
  74. }
  75. },
  76. /* tab切换 */
  77. tabChange(e) {
  78. this.setData({
  79. butText: e.detail.title.slice(0, 2),
  80. list: [],
  81. })
  82. this.getList(true);
  83. },
  84. /* 修改角色 */
  85. changeRole(e) {
  86. let {
  87. item
  88. } = e.currentTarget.dataset;
  89. wx.navigateTo({
  90. url: `./addRole?item=${JSON.stringify(item)}&update=${this.data.authList.includes("角色修改")}&userDelete=${this.data.authList.includes("角色删除")}`
  91. })
  92. },
  93. /* 修改账号 */
  94. changeUser(e) {
  95. let {
  96. item
  97. } = e.currentTarget.dataset;
  98. delete(item.attinfos);
  99. wx.navigateTo({
  100. url: `./addUsers?item=${JSON.stringify(item)}&update=${this.data.authList.includes("账号修改")}`
  101. })
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady() {
  107. getHeight.getHeight('.tabs', this).then(res => {
  108. this.setData({
  109. listHeight: res
  110. })
  111. });
  112. },
  113. })