select.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. list: [],
  5. result: [],
  6. radio: false,
  7. },
  8. onLoad(options) {
  9. if (options.item) {
  10. let item = JSON.parse(options.item);
  11. this.setData({
  12. item,
  13. params: item.params,
  14. result: item.value.length ? item.value[1] : []
  15. })
  16. };
  17. if (options.params) this.setData({
  18. params: JSON.parse(params)
  19. })
  20. this.setData({
  21. radio: options.radio ? true : false
  22. })
  23. this.getList();
  24. },
  25. /* 提交 */
  26. submit() {
  27. let pages = getCurrentPages(),
  28. item = this.data.item,
  29. result = this.data.result,
  30. list = this.data.result.map(value => this.data.list.find(v => v.contactsid == value));
  31. try {
  32. let page = pages[pages.length - 2].selectComponent(item.model || "#Form");
  33. if (page) {
  34. item.value = this.data.radio ? [list[0].name, result] : [list.map(v => v.name), result];
  35. page.handleRoute(item);
  36. } else {
  37. pages[pages.length - 2].handleSelectContacts(this.data.result, list)
  38. }
  39. } catch (e) {
  40. wx.showToast({
  41. title: '操作失败',
  42. icon: "none"
  43. })
  44. }
  45. },
  46. /* 开始搜索 */
  47. onSearch({
  48. detail
  49. }) {
  50. if (this.data.params.content.where.condition == detail) return;
  51. this.setData({
  52. 'params.content.where.condition': detail
  53. });
  54. this.getList(true)
  55. },
  56. onClear() {
  57. this.setData({
  58. 'params.content.where.condition': ""
  59. });
  60. this.getList(true)
  61. },
  62. /* 选中 */
  63. onChange(e) {
  64. const contactsid = e.currentTarget.dataset.item.contactsid + "";
  65. if (!contactsid) return;
  66. let result = this.data.result;
  67. if (this.data.radio) {
  68. result = [contactsid]
  69. } else {
  70. if (result.some(v => v == contactsid)) {
  71. result = result.filter(v => v != contactsid)
  72. } else {
  73. result.push(contactsid)
  74. }
  75. }
  76. this.setData({
  77. result
  78. })
  79. },
  80. //获取列表
  81. getList(init = false) {
  82. let params = this.data.params;
  83. if (init) params.content.pageNumber = 1;
  84. if (params.content.pageNumber > params.content.pageTotal) return;
  85. _Http.basic(params).then(res => {
  86. console.log("联系人", res)
  87. if (res.msg != '成功') return wx.showToast({
  88. title: res.data,
  89. icon: "none"
  90. });
  91. this.setData({
  92. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  93. "params.content.pageNumber": res.pageNumber + 1,
  94. "params.content.pageTotal": res.pageTotal,
  95. })
  96. })
  97. },
  98. onReachBottom() {
  99. this.getList();
  100. }
  101. })