index.js 4.0 KB

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