index.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. "id": 2026030916100201,
  5. list: [],
  6. content: {
  7. nocache: true,
  8. pageNumber: 1,
  9. pageSize: 20,
  10. pageTotal: 1,
  11. where: {
  12. condition: "",
  13. tablefilter: {
  14. status: null,
  15. name: null,
  16. siteid: null,
  17. storename: null,
  18. sex: null
  19. }
  20. },
  21. tableid: 2096
  22. }
  23. },
  24. onLoad(options) {
  25. // 检查是否是选择模式
  26. this.setData({
  27. selectMode: options.selectMode === 'true'
  28. });
  29. this.getList();
  30. },
  31. /* 获取客户列表 */
  32. getList(init = false) {
  33. if (init.detail != undefined) init = init.detail;
  34. if (init) {
  35. this.setData({
  36. 'content.pageNumber': 1
  37. });
  38. }
  39. if (this.data.content.pageNumber > this.data.content.pageTotal) return;
  40. this.setListHeight();
  41. _Http.basic({
  42. id: this.data.id,
  43. content: this.data.content
  44. }).then(res => {
  45. console.log("客户列表数据", res);
  46. this.selectComponent('#ListBox').RefreshToComplete();
  47. this.setData({
  48. 'content.pageNumber': res.pageNumber + 1,
  49. 'content.pageTotal': res.pageTotal,
  50. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  51. total: res.total
  52. });
  53. }).catch(err => {
  54. console.error("获取客户列表失败", err);
  55. this.selectComponent('#ListBox').RefreshToComplete();
  56. });
  57. },
  58. /* 设置页面高度 */
  59. setListHeight() {
  60. this.selectComponent("#ListBox").setHeight(".header", this);
  61. },
  62. /* 搜索 */
  63. onSearch({
  64. detail
  65. }) {
  66. this.setData({
  67. 'content.where.condition': detail
  68. });
  69. this.getList(true);
  70. },
  71. /* 新增客户 */
  72. addCustomer() {
  73. if (this.data.selectMode) {
  74. wx.navigateTo({
  75. url: '/CRM/customer/create?selectMode=true'
  76. });
  77. } else {
  78. wx.navigateTo({
  79. url: '/CRM/customer/create'
  80. });
  81. }
  82. },
  83. /* 选择客户 */
  84. selectCustomer(e) {
  85. if (this.data.selectMode) {
  86. const customerItem = e.currentTarget.dataset.item;
  87. // 调用全局回调函数,设置客户信息
  88. if (getApp().globalData.setCustomer) {
  89. getApp().globalData.setCustomer(customerItem);
  90. }
  91. // 返回上一页
  92. wx.navigateBack();
  93. }
  94. }
  95. });