select.js 3.7 KB

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