index.js 3.9 KB

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