select.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. _Http.basic({
  102. "id": 20221018122201,
  103. content
  104. }).then(res => {
  105. console.log("数据团队列表", res)
  106. this.setData({
  107. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  108. "content.pageTotal": res.pageTotal,
  109. "content.pageNumber": res.pageNumber + 1,
  110. })
  111. })
  112. },
  113. /* 开始搜索 */
  114. startSearch({
  115. detail
  116. }) {
  117. let condition = this.data.content ? this.data.content.where.condition : this.data.params.content.where.condition;
  118. if (detail == condition) return;
  119. this.setData({
  120. 'content.where.condition': detail,
  121. 'params.content.where.condition': detail
  122. });
  123. this.getList(true);
  124. },
  125. /* 取消搜索 */
  126. onClear() {
  127. this.setData({
  128. 'content.where.condition': "",
  129. 'params.content.where.condition': ""
  130. });
  131. this.getList(true);
  132. },
  133. onReachBottom() {
  134. this.getList();
  135. }
  136. })