select.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. const _Http = getApp().globalData.http,
  2. getHeight = require("../../../utils/getRheRemainingHeight");
  3. Page({
  4. data: {
  5. item: null,
  6. result: [],
  7. params: {},
  8. radio: false,
  9. },
  10. onLoad(options) {
  11. console.log(options)
  12. if (options.item) {
  13. let item = JSON.parse(options.item);
  14. this.setData({
  15. item,
  16. params: item.params
  17. });
  18. }
  19. if (options.params) this.setData({
  20. params: JSON.parse(options.params)
  21. })
  22. this.setData({
  23. radio: options.radio ? true : false
  24. })
  25. this.getList()
  26. },
  27. submit() {
  28. let pages = getCurrentPages(),
  29. item = this.data.item,
  30. result = this.data.result,
  31. list = this.data.result.map(v => this.data.list.find(value => value.sa_projectid == v));
  32. try {
  33. if (item) {
  34. let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
  35. item.value = this.data.radio ? [list[0].projectname, result] : [list.map(v => v.projectname), result];
  36. page.handleRoute(item);
  37. } else {
  38. pages[pages.length - 2].handleSelectProject(this.data.result, list)
  39. }
  40. } catch (e) {
  41. wx.showToast({
  42. title: '操作失败',
  43. icon: "none"
  44. })
  45. }
  46. },
  47. getList(init = false) {
  48. //init 用于初始化分页
  49. if (init.detail != undefined) init = init.detail;
  50. let params = this.data.params;
  51. if (init) params.content.pageNumber = 1
  52. if (params.content.pageNumber > params.content.pageTotal) return;
  53. _Http.basic(params).then(res => {
  54. console.log("选择项目列表", res)
  55. this.selectComponent('#ListBox').RefreshToComplete();
  56. if (res.msg != '成功') return wx.showToast({
  57. title: res.data,
  58. icon: "none"
  59. })
  60. this.setData({
  61. 'params.content.pageNumber': res.pageNumber + 1,
  62. 'params.content.pageTotal': res.pageTotal,
  63. 'params.content.total': res.total,
  64. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  65. })
  66. this.getTags();
  67. })
  68. },
  69. /* 获取列表标签 */
  70. getTags() {
  71. let list = this.data.list,
  72. ownerids = list.map(v => v.sa_projectid);
  73. _Http.basic({
  74. "id": 20221018102001,
  75. "content": {
  76. nocache: true,
  77. "ownertable": "sa_project",
  78. ownerids
  79. }
  80. }).then(res => {
  81. console.log("标签", res)
  82. for (let key in res.data) {
  83. let index = list.findIndex(v => v.sa_projectid == key);
  84. list[index].tags = res.data[key]
  85. };
  86. console.log(list)
  87. this.setData({
  88. list
  89. })
  90. })
  91. },
  92. /* 选中 */
  93. changeResult(e) {
  94. const {
  95. id
  96. } = e.currentTarget.dataset;
  97. let result = this.data.result;
  98. if (this.data.radio) {
  99. result = [id];
  100. } else {
  101. if (result.some(v => v == id)) {
  102. result = result.filter(v => v != id);
  103. } else {
  104. result.push(id)
  105. };
  106. }
  107. this.setData({
  108. result
  109. })
  110. },
  111. /* 开始搜索 */
  112. startSearch({
  113. detail
  114. }) {
  115. let condition = this.data.content?this.data.content.where.condition:this.data.params.content.where.condition;
  116. if (detail == condition) return;
  117. this.setData({
  118. 'content.where.condition': detail,
  119. 'params.content.where.condition': detail
  120. });
  121. this.getList(true);
  122. },
  123. /* 取消搜索 */
  124. onClear() {
  125. this.setData({
  126. 'content.where.condition': "",
  127. 'params.content.where.condition': ""
  128. });
  129. this.getList(true);
  130. },
  131. onReady() {
  132. getHeight.getHeight('.total', this).then(res => this.setData({
  133. listHeight: res
  134. }));
  135. }
  136. })