index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. item: null,
  5. radio: true,
  6. content: {
  7. sys_phonebookid: 0,
  8. "nocache": true,
  9. "pageNumber": 1,
  10. "pageTotal": 1,
  11. "pageSize": 20,
  12. "where": {
  13. "condition": ""
  14. }
  15. }
  16. },
  17. onLoad(options) {
  18. console.log(options)
  19. if (options.sys_phonebookid) this.data.content.sys_phonebookid = options.sys_phonebookid;
  20. this.data.content.sa_projectid = getCurrentPages().find(v => v.__route__ == 'packageA/project/detail').data.sa_projectid
  21. /* 从表单组件进入进入 */
  22. this.getList()
  23. },
  24. getList(init = false) {
  25. //init 用于初始化分页
  26. if (init.detail != undefined) init = init.detail;
  27. let content = this.data.content;
  28. if (init) content.pageNumber = 1;
  29. if (content.pageNumber > content.pageTotal) return;
  30. _Http.basic({
  31. "id": "20231215134204",
  32. content
  33. }).then(res => {
  34. console.log("选择客户列表", res)
  35. this.selectComponent('#ListBox').RefreshToComplete();
  36. if (res.code != '1') return getApp().globalData.Language.showToast(res.msg)
  37. })
  38. },
  39. /* 获取列表标签 */
  40. getTags() {
  41. let list = this.data.list,
  42. ownerids = list.map(v => v.sys_enterpriseid)
  43. _Http.basic({
  44. "id": 20221018102001,
  45. "content": {
  46. "ownertable": "sa_customers",
  47. ownerids
  48. }
  49. }).then(res => {
  50. for (let key in res.data) {
  51. let index = list.findIndex(v => v.sys_enterpriseid == key);
  52. list[index].tags = res.data[key]
  53. };
  54. this.setData({
  55. list
  56. })
  57. })
  58. },
  59. /* 选中 */
  60. changeResult(e) {
  61. let {
  62. id
  63. } = e.currentTarget.dataset, result = this.data.result;
  64. if (this.data.radio) {
  65. result = [id];
  66. } else {
  67. result.some(v => v == id) ? result = result.filter(v => v != id) : result.push(id)
  68. }
  69. this.setData({
  70. result
  71. });
  72. this.submit();
  73. },
  74. /* 提交 */
  75. submit() {
  76. let result = this.data.result,
  77. obj = this.data.radio ? {
  78. id: result,
  79. item: this.data.list.find(value => value.contactsid == result),
  80. value: [this.data.list.find(value => value.contactsid == result).enterprisename, result]
  81. } : {
  82. result,
  83. list: result.map(v => this.data.list.find(value => value.contactsid == v)),
  84. value: [result.map(v => {
  85. let data = this.data.list.find(value => value.contactsid == v);
  86. return data ? data.enterprisename : ""
  87. }), result]
  88. }
  89. getApp().globalData.handleSelect && getApp().globalData.handleSelect(obj)
  90. },
  91. /* 开始搜索 */
  92. startSearch({
  93. detail
  94. }) {
  95. let condition = this.data.content ? this.data.content.where.condition : this.data.content.where.condition;
  96. if (detail == condition) return;
  97. this.setData({
  98. 'content.where.condition': detail
  99. });
  100. this.getList(true);
  101. },
  102. /* 取消搜索 */
  103. onClear() {
  104. this.setData({
  105. 'content.where.condition': ""
  106. });
  107. this.getList(true);
  108. }
  109. })