index.js 3.2 KB

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