index.js 3.9 KB

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