index.js 3.8 KB

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