index.js 3.9 KB

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