select.js 3.6 KB

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