index.js 3.9 KB

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