index.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. getApp().globalData.Language.getLanguagePackage(this, 'E-订单');
  20. },
  21. toggle(e) {
  22. const {
  23. item
  24. } = e.currentTarget.dataset;
  25. let result = this.data.result;
  26. if (this.data.item.optionType == 'checkbox') {
  27. let index = result.findIndex(v => v == item.value);
  28. if (index == -1) {
  29. result.push(item.value)
  30. } else {
  31. result.splice(index, 1)
  32. }
  33. this.setData({
  34. result
  35. })
  36. } else {
  37. this.setData({
  38. result: [item.value]
  39. })
  40. this.submit();
  41. }
  42. },
  43. getList(init = false) {
  44. let {
  45. pageNumber,
  46. pageTotal,
  47. pageSize
  48. } = this.data.paging;
  49. if (init) {
  50. pageNumber = 1;
  51. pageTotal = 1;
  52. };
  53. if (pageNumber > pageTotal) return;
  54. _Http.basic({
  55. "classname": "sysmanage.develop.optiontype.optiontype",
  56. "method": "optiontypeselect",
  57. "content": {
  58. pageNumber,
  59. pageSize,
  60. "typename": this.data.item.optionNmae,
  61. "parameter": {
  62. "siteid": wx.getStorageSync('siteP').siteid
  63. }
  64. }
  65. }).then(res => {
  66. if (res.code != '1') {
  67. wx.showToast({
  68. title: res.data,
  69. icon: "none"
  70. })
  71. return;
  72. };
  73. this.setData({
  74. list: res.pageNumber == 1 ? res.data : this.data.list.concat(res.data),
  75. "paging.pageNumber": res.pageNumber + 1,
  76. "paging.pageTotal": res.pageTotal,
  77. "paging.total": res.total,
  78. })
  79. console.log("可选项查询", res)
  80. })
  81. },
  82. submit() {
  83. let item = this.data.item;
  84. if (item.optionType == 'checkbox') {
  85. item.value = this.data.result
  86. } else {
  87. item.value = this.data.result[0]
  88. };
  89. const pages = getCurrentPages();
  90. pages[pages.length - 2].selectComponent(item.model || "#Form").setOption(item);
  91. wx.navigateBack();
  92. item.setFun && getApp().globalData.optionFun && getApp().globalData.optionFun({
  93. item,
  94. list: this.data.result.map(v => this.data.list.find(s => s.value == v))
  95. });
  96. },
  97. onReachBottom() {
  98. this.getList();
  99. },
  100. })