index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. paging: {
  5. "pageNumber": 1,
  6. "pageSize": 20,
  7. "pageTotal": 1,
  8. },
  9. result: [],
  10. },
  11. onLoad(options) {
  12. let item = JSON.parse(options.data);
  13. console.log(item)
  14. this.setData({
  15. item,
  16. result: item.value ? Array.isArray(item.value) ? item.value : [item.value] : []
  17. })
  18. this.getList();
  19. },
  20. toggle(e) {
  21. const {
  22. item
  23. } = e.currentTarget.dataset;
  24. let result = this.data.result;
  25. if (this.data.item.optionType == 'checkbox') {
  26. let index = result.findIndex(v => v == item.value);
  27. if (index == -1) {
  28. result.push(item.value)
  29. } else {
  30. result.splice(index, 1)
  31. }
  32. this.setData({
  33. result
  34. })
  35. } else {
  36. this.setData({
  37. result: [item.value]
  38. })
  39. this.submit();
  40. }
  41. },
  42. getList(init = false) {
  43. let {
  44. pageNumber,
  45. pageTotal,
  46. pageSize
  47. } = this.data.paging;
  48. if (init) {
  49. pageNumber = 1;
  50. pageTotal = 1;
  51. };
  52. if (pageNumber > pageTotal) return;
  53. _Http.basic({
  54. "classname": "sysmanage.develop.optiontype.optiontype",
  55. "method": "optiontypeselect",
  56. "content": {
  57. pageNumber,
  58. pageSize,
  59. "typename": this.data.item.optionNmae,
  60. "parameter": {
  61. "siteid": wx.getStorageSync('siteP').siteid
  62. }
  63. }
  64. }).then(res => {
  65. if (res.msg != '成功') {
  66. wx.showToast({
  67. title: res.data,
  68. icon: "none"
  69. })
  70. return;
  71. };
  72. this.setData({
  73. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  74. "paging.pageNumber": res.pageNumber + 1,
  75. "paging.pageTotal": res.pageTotal,
  76. "paging.total": res.total,
  77. })
  78. console.log("可选项查询", res)
  79. })
  80. },
  81. submit() {
  82. let item = this.data.item;
  83. if (item.optionType == 'checkbox') {
  84. item.value = this.data.result
  85. } else {
  86. item.value = this.data.result[0]
  87. };
  88. const pages = getCurrentPages();
  89. pages[pages.length - 2].selectComponent(item.model || "#Form").setOption(item);
  90. wx.navigateBack();
  91. },
  92. onReachBottom() {
  93. this.getList();
  94. },
  95. })