select.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. radio: false, //是否为单选
  5. obj: false, //是否返回数组对象
  6. content: {
  7. ownertable: null,
  8. ownerid: null,
  9. pageSize: 20,
  10. pageNumber: 1,
  11. pageTotal: 1,
  12. "where": {
  13. "condition": ""
  14. }
  15. },
  16. list: [],
  17. result: []
  18. },
  19. async onLoad(options) {
  20. //是否为单选
  21. if (options.radio) this.setData({
  22. radio: true
  23. });
  24. //是否返回数组对象
  25. if (options.obj) this.setData({
  26. obj: true
  27. });
  28. if (options.data) {
  29. let {
  30. ownertable,
  31. ownerid
  32. } = JSON.parse(options.data);
  33. this.setData({
  34. "content.ownertable": ownertable,
  35. "content.ownerid": ownerid,
  36. });
  37. await this.getList();
  38. //是否有默认选项
  39. if (options.result) {
  40. this.setData({
  41. result: [options.result]
  42. });
  43. }
  44. };
  45. },
  46. submit() {
  47. let result = this.data.result;
  48. if (result.length == 0) return;
  49. let pages = getCurrentPages();
  50. let list = this.data.obj ? result.map(id => this.data.list.find(v => v.userid == id)) : result
  51. pages[pages.length - 2].handelSubmit(list);
  52. },
  53. /* 选中 */
  54. onChange(e) {
  55. const userid = e.currentTarget.dataset.item.userid + "";
  56. if (!userid) return;
  57. if (this.data.radio) {
  58. this.setData({
  59. result: [userid]
  60. })
  61. } else {
  62. let result = this.data.result;
  63. if (result.some(v => v == userid)) {
  64. result = result.filter(v => v != userid)
  65. } else {
  66. result.push(userid)
  67. }
  68. this.setData({
  69. result
  70. })
  71. }
  72. },
  73. //获取列表
  74. getList(init = false) {
  75. let content = this.data.content;
  76. if (init) {
  77. content.pageTotal = 1
  78. content.pageNumber = 1
  79. }
  80. if (content.pageNumber > content.pageTotal) return;
  81. _Http.basic({
  82. "id": 20221018122201,
  83. content
  84. }).then(res => {
  85. console.log("数据团队列表", res)
  86. this.setData({
  87. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  88. "content.pageTotal": res.pageTotal,
  89. "content.pageNumber": res.pageNumber + 1,
  90. })
  91. })
  92. },
  93. onReachBottom() {
  94. this.getList();
  95. }
  96. })