index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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": 7
  13. }
  14. }
  15. },
  16. onLoad(options) {
  17. this.getList();
  18. },
  19. tabChange(e) {
  20. this.data.content.where.type = e.detail.title == '客户' ? 7 : 5;
  21. this.getList(true)
  22. },
  23. changeResult(e) {
  24. const {
  25. item
  26. } = e.currentTarget.dataset;
  27. wx.showModal({
  28. title: '提示',
  29. content: `是否确认选择${item.enterprisename}?`,
  30. complete: ({
  31. confirm
  32. }) => {
  33. if (confirm) getApp().globalData.handleSelect(item);
  34. }
  35. })
  36. },
  37. /* 获取列表 */
  38. getList(init = false) {
  39. //init 用于初始化分页
  40. if (init.detail != undefined) init = init.detail;
  41. let content = this.data.content;
  42. if (init) content.pageNumber = 1;
  43. if (content.pageNumber > content.pageTotal) return;
  44. _Http.basic({
  45. "id": 20220920083901,
  46. content
  47. }).then(res => {
  48. console.log("关联客户列表", res)
  49. this.selectComponent('#ListBox').RefreshToComplete();
  50. if (res.msg != '成功') return wx.showToast({
  51. title: res.data,
  52. icon: "none"
  53. })
  54. this.setData({
  55. 'content.pageNumber': res.pageNumber + 1,
  56. 'content.pageTotal': res.pageTotal,
  57. 'content.total': res.total,
  58. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data)
  59. })
  60. this.getTags();
  61. })
  62. },
  63. /* 开始搜索 */
  64. startSearch({
  65. detail
  66. }) {
  67. if (detail == this.data.content.where.condition) return;
  68. this.setData({
  69. 'content.where.condition': detail
  70. });
  71. this.getList(true);
  72. },
  73. /* 取消搜索 */
  74. onClear() {
  75. this.setData({
  76. 'content.where.condition': ""
  77. });
  78. this.getList(true);
  79. },
  80. /* 获取标签 */
  81. getTags() {
  82. let list = this.data.list,
  83. ownerids = list.map(v => v.sa_customersid);
  84. _Http.basic({
  85. "id": 20221018102001,
  86. "content": {
  87. "ownertable": "sa_customers",
  88. ownerids
  89. }
  90. }).then(res => {
  91. console.log("标签", res)
  92. if (res.msg != '成功') return;
  93. for (let key in res.data) {
  94. let index = list.findIndex(v => v.sa_customersid == key);
  95. if (index != -1) list[index].tags = res.data[key]
  96. };
  97. this.setData({
  98. list
  99. })
  100. })
  101. },
  102. onReady() {
  103. this.selectComponent("#ListBox").setHeight(".search", this);
  104. },
  105. onUnload() {
  106. getApp().globalData.handleSelect = null;
  107. }
  108. })