index.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. content: {
  5. nocache: true,
  6. pageNumber: 1,
  7. pageSize: 20,
  8. pageTotal: 1,
  9. total: 0,
  10. where: {
  11. "condition": "",
  12. }
  13. },
  14. list: [],
  15. sa_customersid: 0,
  16. loading: false
  17. },
  18. getList(init = false) {
  19. const content = this.data.content;
  20. if (init) content.pageNumber = 1;
  21. if (content.pageNumber > content.pageTotal) return;
  22. _Http.basic({
  23. id: 20240531152004,
  24. content
  25. }).then(res => {
  26. console.log("通讯录列表", res)
  27. if (res.msg != '成功') return wx.showToast({
  28. title: res.data,
  29. icon: "none"
  30. });
  31. content.pageNumber = res.pageNumber + 1;
  32. content.pageTotal = res.pageTotal;
  33. content.total = res.total;
  34. this.setData({
  35. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  36. content
  37. })
  38. })
  39. },
  40. onLoad(options) {
  41. if (options.sys_enterpriseid) this.setData({
  42. 'content.ownertable': 'sys_enterprise',
  43. 'content.ownerid': options.sys_enterpriseid,
  44. enterprisename: options.enterprisename,
  45. sa_customersid: options.sa_customersid
  46. });
  47. this.getList();
  48. },
  49. /* 默认添加 */
  50. created() {
  51. wx.redirectTo({
  52. url: '/packageA/setclient/modules/contacts/add/index?sys_enterpriseid=' + this.data.content.ownerid + "&enterprisename=" + this.data.enterprisename + "&sa_customersid=" + this.data.sa_customersid,
  53. })
  54. },
  55. onClick(e) {
  56. if (this.data.loading) return;
  57. const {
  58. item
  59. } = e.currentTarget.dataset;
  60. delete(item.tag1)
  61. item.sys_enterpriseid = this.data.content.ownerid;
  62. this.data.loading = true;
  63. _Http.basic({
  64. "id": "20240531151704",
  65. content: item
  66. }).then(res => {
  67. console.log("编辑联系人", res)
  68. this.data.loading = false;
  69. wx.showToast({
  70. title: res.msg != '成功' ? res.msg : '添加成功',
  71. icon: "none",
  72. mask: true
  73. });
  74. if (res.msg == '成功') setTimeout(() => {
  75. wx.navigateBack()
  76. getCurrentPages().forEach(v => {
  77. if (v.__route__ == 'packageA/setclient/modules/contacts/detail/index' || v.__route__ == 'packageA/contacts/detail') {
  78. v.getDetail();
  79. } else if (v.selectComponent("#Contacts")) {
  80. let page = v.selectComponent("#Contacts");
  81. page.getList(page.data.content.sys_enterpriseid, true)
  82. } else if (v.__route__ == 'packageA/project/modules/contacts/search/index') {
  83. let index = v.data.list.findIndex(value => value.sys_phonebookid == res.data.sys_phonebookid);
  84. if (index != -1) v.setData({
  85. [`list[${index}]`]: res.data
  86. })
  87. }
  88. });
  89. }, 500)
  90. });
  91. return;
  92. wx.redirectTo({
  93. url: `/packageA/setclient/modules/contacts/add/index?sys_enterpriseid=${this.data.content.ownerid}&enterprisename=${this.data.enterprisename}&sa_customersid=${this.data.sa_customersid}&data=${JSON.stringify(item)}`,
  94. })
  95. },
  96. onSearch({
  97. detail
  98. }) {
  99. this.setData({
  100. 'content.where.condition': detail ? detail : ""
  101. });
  102. this.getList(true);
  103. },
  104. onClear() {
  105. this.setData({
  106. 'content.where.condition': ""
  107. });
  108. this.getList(true);
  109. },
  110. onReachBottom() {
  111. this.getList();
  112. },
  113. })