select.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. idName: "sa_contractid"
  10. },
  11. onLoad(options) {
  12. console.log(options)
  13. if (options.item) {
  14. let item = JSON.parse(options.item);
  15. this.setData({
  16. item,
  17. params: item.params
  18. });
  19. }
  20. if (options.params) this.setData({
  21. params: JSON.parse(options.params)
  22. })
  23. this.setData({
  24. radio: options.radio ? true : false
  25. })
  26. this.getList()
  27. },
  28. submit() {
  29. let pages = getCurrentPages(),
  30. item = this.data.item,
  31. result = this.data.result,
  32. list = this.data.result.map(v => this.data.list.find(value => value[this.data.idName] == v));
  33. try {
  34. if (item) {
  35. let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
  36. item.value = this.data.radio ? [list[0].title, result] : [list.map(v => v.title), result];
  37. page.handleRoute(item, list);
  38. } else {
  39. pages[pages.length - 2].handleSelectProject(this.data.result, list)
  40. }
  41. } catch (e) {
  42. console.log(e)
  43. wx.showToast({
  44. title: '操作失败',
  45. icon: "none"
  46. })
  47. }
  48. },
  49. getList(init = false) {
  50. //init 用于初始化分页
  51. if (init.detail != undefined) init = init.detail;
  52. let params = this.data.params;
  53. if (init) params.content.pageNumber = 1
  54. if (params.content.pageNumber > params.content.pageTotal) return;
  55. _Http.basic(params).then(res => {
  56. console.log("选择合同列表", res)
  57. this.selectComponent('#ListBox').RefreshToComplete();
  58. if (res.msg != '成功') return wx.showToast({
  59. title: res.data,
  60. icon: "none"
  61. })
  62. this.setData({
  63. 'params.content.pageNumber': res.pageNumber + 1,
  64. 'params.content.pageTotal': res.pageTotal,
  65. 'params.content.total': res.total,
  66. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  67. })
  68. this.getTags();
  69. })
  70. },
  71. /* 获取列表标签 */
  72. getTags() {
  73. let list = this.data.list,
  74. ownerids = list.map(v => v.sa_contractid);
  75. _Http.basic({
  76. "id": 20221018102001,
  77. "content": {
  78. nocache: true,
  79. "ownertable": "sa_contract",
  80. ownerids
  81. }
  82. }).then(res => {
  83. console.log("标签", res)
  84. for (let key in res.data) {
  85. let index = list.findIndex(v => v.sa_contractid == key);
  86. list[index].tags = res.data[key]
  87. };
  88. this.setData({
  89. list
  90. })
  91. })
  92. },
  93. /* 选中 */
  94. changeResult(e) {
  95. const {
  96. id
  97. } = e.currentTarget.dataset;
  98. let result = this.data.result;
  99. if (this.data.radio) {
  100. result = [id];
  101. } else {
  102. if (result.some(v => v == id)) {
  103. result = result.filter(v => v != id);
  104. } else {
  105. result.push(id)
  106. };
  107. }
  108. this.setData({
  109. result
  110. });
  111. if (this.data.radio) this.submit();
  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. /* 删除项 */
  134. deteleItem(id, idName = 'sa_contractid') {
  135. this.setData({
  136. list: this.data.list.filter(v => v[idName] != id)
  137. })
  138. },
  139. onReady() {
  140. getHeight.getHeight('.total', this).then(res => this.setData({
  141. listHeight: res
  142. }));
  143. }
  144. })