index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. let that = this;
  26. wx.showModal({
  27. title: '提示',
  28. content: '是否确认添加联系人',
  29. complete: ({
  30. confirm
  31. }) => {
  32. if (confirm) {
  33. _Http.basic({
  34. "id": 20221111131104,
  35. "content": {
  36. "sa_project_contactsid": 0,
  37. "contactsids": that.data.result,
  38. "sa_projectid": that.data.content.sa_projectid,
  39. "remarks": ""
  40. }
  41. }).then(res => {
  42. console.log("项目添加联系人", res)
  43. if (res.msg != '成功') return wx.showToast({
  44. title: res.data,
  45. icon: "none"
  46. });
  47. wx.showToast({
  48. title: '添加成功',
  49. icon: "none"
  50. });
  51. setTimeout(() => {
  52. wx.navigateBack();
  53. let pages = getCurrentPages();
  54. pages[pages.length - 2].partialRenewal(true);
  55. }, 300)
  56. })
  57. }
  58. }
  59. })
  60. },
  61. /* 开始搜索 */
  62. onSearch({
  63. detail
  64. }) {
  65. if (this.data.content.where.condition == detail) return;
  66. this.setData({
  67. 'content.where.condition': detail
  68. });
  69. this.getList(true)
  70. },
  71. onClear() {
  72. this.setData({
  73. 'content.where.condition': ""
  74. });
  75. this.getList(true)
  76. },
  77. /* 选中 */
  78. onChange(e) {
  79. const contactsid = e.currentTarget.dataset.item.contactsid + "";
  80. if (!contactsid) return;
  81. let result = this.data.result;
  82. if (result.some(v => v == contactsid)) {
  83. result = result.filter(v => v != contactsid)
  84. } else {
  85. result.push(contactsid)
  86. }
  87. this.setData({
  88. result
  89. })
  90. },
  91. //获取列表
  92. getList(init = false) {
  93. let content = this.data.content;
  94. if (init) content.pageNumber = 1;
  95. if (content.pageNumber > content.pageTotal) return;
  96. _Http.basic({
  97. "id": 20221111130704,
  98. content
  99. }).then(res => {
  100. console.log("可添加联系人", res)
  101. if (res.msg != '成功') return wx.showToast({
  102. title: res.data,
  103. icon: "none"
  104. });
  105. this.setData({
  106. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  107. "content.pageNumber": res.pageNumber + 1,
  108. "content.pageTotal": res.pageTotal,
  109. })
  110. })
  111. },
  112. onReachBottom() {
  113. this.getList();
  114. }
  115. })