index.js 4.1 KB

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