select.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. radio: false, //是否为单选
  5. obj: false, //是否返回数组对象
  6. model: "", //提交上一级组件中的事件
  7. principal: false, //是否为更换负责人
  8. content: {
  9. nocache: true,
  10. ownertable: null,
  11. ownerid: null,
  12. pageSize: 20,
  13. pageNumber: 1,
  14. pageTotal: 1,
  15. "where": {
  16. "condition": ""
  17. }
  18. },
  19. list: [],
  20. result: []
  21. },
  22. async onLoad(options) {
  23. //是否为单选
  24. if (options.radio) this.setData({
  25. radio: true
  26. });
  27. //是否返回数组对象
  28. if (options.obj) this.setData({
  29. obj: true
  30. });
  31. //调用上一级组件中的提交事件
  32. if (options.model) this.setData({
  33. model: options.model
  34. });
  35. //是否为更换负责人
  36. if (options.principal) {
  37. this.setData({
  38. principal: true
  39. })
  40. wx.setNavigationBarTitle({
  41. title: '更换负责人'
  42. })
  43. }
  44. if (options.data) {
  45. let {
  46. ownertable,
  47. ownerid
  48. } = JSON.parse(options.data);
  49. this.setData({
  50. "content.ownertable": ownertable,
  51. "content.ownerid": ownerid,
  52. });
  53. await this.getList();
  54. //是否有默认选项
  55. if (options.result) {
  56. this.setData({
  57. result: [options.result]
  58. });
  59. }
  60. };
  61. },
  62. submit() {
  63. let result = this.data.result;
  64. if (result.length == 0) return;
  65. let pages = getCurrentPages();
  66. let list = this.data.obj ? result.map(id => this.data.list.find(v => v.userid == id)) : result;
  67. if (this.data.model) {
  68. pages[pages.length - 2].selectComponent("#" + this.data.model).handelSubmit(list);
  69. } else {
  70. pages[pages.length - 2].handelSubmit(list);
  71. }
  72. },
  73. /* 选中 */
  74. onChange(e) {
  75. const userid = e.currentTarget.dataset.item.userid + "";
  76. if (!userid) return;
  77. if (this.data.radio) {
  78. this.setData({
  79. result: [userid]
  80. })
  81. } else {
  82. let result = this.data.result;
  83. if (result.some(v => v == userid)) {
  84. result = result.filter(v => v != userid)
  85. } else {
  86. result.push(userid)
  87. }
  88. this.setData({
  89. result
  90. })
  91. }
  92. },
  93. //获取列表
  94. getList(init = false) {
  95. let content = this.data.content;
  96. if (init) {
  97. content.pageTotal = 1
  98. content.pageNumber = 1
  99. }
  100. if (content.pageNumber > content.pageTotal) return;
  101. if (this.data.principal) {
  102. _Http.basic({
  103. "id": 20220930103501,
  104. content
  105. }).then(res => {
  106. console.log("团队成员列表", res)
  107. if (res.msg != '成功') return wx.showToast({
  108. title: res.data,
  109. icon: "none"
  110. })
  111. let data = res.data.find(v => v.ismyteam == 1);
  112. this.setData({
  113. list: data.team.filter(v => v.userid != data.teamleader[0].userid)
  114. })
  115. })
  116. } else {
  117. _Http.basic({
  118. "id": 20221018122201,
  119. content
  120. }).then(res => {
  121. console.log("数据团队列表", res)
  122. this.setData({
  123. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  124. "content.pageTotal": res.pageTotal,
  125. "content.pageNumber": res.pageNumber + 1,
  126. })
  127. })
  128. }
  129. },
  130. onReachBottom() {
  131. this.getList();
  132. }
  133. })