index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. const _Http = getApp().globalData.http;
  2. Page({
  3. data: {
  4. id: 2026052510105006,
  5. active: 0,
  6. content: {
  7. nocache: true,
  8. pageNumber: 1,
  9. pageSize: 20,
  10. where: {
  11. status: '',
  12. showShipping: false,
  13. begindate: '',
  14. enddate: '',
  15. auditbegindate: '',
  16. auditenddate: '',
  17. condition: ''
  18. }
  19. },
  20. list: [],
  21. totalCount: 0,
  22. totalPoints: 0,
  23. isback: false,
  24. },
  25. onShow() {
  26. if (this.data.isback) {
  27. this.getList(true);
  28. }
  29. },
  30. onSearch({ detail }) {
  31. this.setData({
  32. 'content.where.condition': detail
  33. });
  34. this.getList(true);
  35. },
  36. startSearch({ detail }) {
  37. const condition = detail.value !== undefined ? detail.value : detail;
  38. if (condition == this.data.content.where.condition) return;
  39. this.setData({
  40. 'content.where.condition': condition
  41. });
  42. this.getList(true);
  43. },
  44. onClear() {
  45. this.setData({
  46. 'content.where.condition': ''
  47. });
  48. this.getList(true);
  49. },
  50. onChangeTab({ detail }) {
  51. this.setData({
  52. 'content.where.status': detail.title === '全部' ? '' : detail.title
  53. });
  54. this.getList(true);
  55. },
  56. getList(init = false) {
  57. if (init) this.selectComponent('#ListBox').goTop();
  58. _Http.init(this.data.content, init).then(content => {
  59. _Http.basic({
  60. id: this.data.id,
  61. content
  62. }).then(res => {
  63. this.selectComponent('#ListBox').RefreshToComplete();
  64. if (res.code != '1') return wx.showToast({
  65. title: res.msg,
  66. icon: "none"
  67. });
  68. // 处理商品图片
  69. let list = res.data || [];
  70. list.forEach(order => {
  71. if (order.items && order.items.length) {
  72. order.items.forEach(item => {
  73. item.imgUrl = item.attinfos && item.attinfos.length ? _Http.getSpecifiedImage(item.attinfos[0]) : '';
  74. });
  75. }
  76. });
  77. const isFirstPage = res.pageNumber == 1;
  78. const newList = isFirstPage ? list : this.data.list.concat(list);
  79. const totalPoints = newList.reduce((sum, order) => sum + (order.totalpoints || 0), 0);
  80. this.setData({
  81. content: _Http.paging(content, res),
  82. list: newList,
  83. totalCount: res.total || 0,
  84. totalPoints
  85. });
  86. });
  87. });
  88. },
  89. onLoad(options) {
  90. getApp().globalData.Language.getLanguagePackage(this, '积分订单');
  91. // 处理从"我的"页面传入的状态参数
  92. const tabs = ['', '新建', '提交', '完成'];
  93. let active = 0;
  94. if (options.status) {
  95. const idx = tabs.indexOf(options.status);
  96. if (idx > -1) active = idx;
  97. this.setData({
  98. 'content.where.status': options.status,
  99. active
  100. });
  101. }
  102. this.getList();
  103. }
  104. });