select.js 2.2 KB

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