index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. content: {
  5. nocache: true,
  6. sa_projectid: 1,
  7. pageSize: 20,
  8. pageNumber: 1,
  9. pageTotal: 1,
  10. "where": {
  11. "condition": ""
  12. }
  13. },
  14. list: [],
  15. result: []
  16. },
  17. onLoad(options) {
  18. this.setData({
  19. "content.sa_projectid": options.sa_projectid
  20. });
  21. this.getList();
  22. },
  23. /* 提交 */
  24. submit() {
  25. _Http.basic({
  26. "id": 20221111131104,
  27. "content": {
  28. "sa_project_contactsid": 0,
  29. "contactsid": this.data.result,
  30. "sa_projectid": this.data.content.sa_projectid,
  31. "remarks": ""
  32. }
  33. }).then(res => {
  34. console.log("项目添加联系人", res)
  35. if (res.msg != '成功') return wx.showToast({
  36. title: res.data,
  37. icon: "none"
  38. });
  39. wx.showToast({
  40. title: '添加成功',
  41. icon: "none"
  42. });
  43. setTimeout(() => {
  44. wx.navigateBack();
  45. }, 300)
  46. })
  47. },
  48. /* 开始搜索 */
  49. onSearch({
  50. detail
  51. }) {
  52. if (this.data.content.where.condition == detail) return;
  53. this.setData({
  54. 'content.where.condition': detail
  55. });
  56. this.getList(true)
  57. },
  58. onClear() {
  59. this.setData({
  60. 'content.where.condition': ""
  61. });
  62. this.getList(true)
  63. },
  64. /* 选中 */
  65. onChange(e) {
  66. const contactsid = e.currentTarget.dataset.item.contactsid + "";
  67. if (!contactsid) return;
  68. let result = this.data.result;
  69. if (result.some(v => v == contactsid)) {
  70. result = result.filter(v => v != contactsid)
  71. } else {
  72. result.push(contactsid)
  73. }
  74. this.setData({
  75. result
  76. })
  77. },
  78. //获取列表
  79. getList(init = false) {
  80. let content = this.data.content;
  81. if (init) content.pageNumber = 1;
  82. if (content.pageNumber > content.pageTotal) return;
  83. _Http.basic({
  84. "id": 20221111130704,
  85. content
  86. }).then(res => {
  87. console.log("可添加联系人", res)
  88. if (res.msg != '成功') return wx.showToast({
  89. title: res.data,
  90. icon: "none"
  91. });
  92. this.setData({
  93. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  94. "content.pageNumber": res.pageNumber + 1,
  95. "content.pageTotal": res.pageTotal,
  96. })
  97. })
  98. },
  99. onReachBottom() {
  100. this.getList();
  101. }
  102. })