vouche.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Component({
  4. properties:{
  5. show: {
  6. type: Boolean,
  7. observer: function (val) {
  8. this.setData({ show: val });
  9. }
  10. },
  11. info:{
  12. type:Object,
  13. observer:function(options){
  14. if (util.isObjEmpty(options)) {
  15. return false;
  16. }
  17. if (options.packIds && options.aid && options.sid) {
  18. let data = {};
  19. data.meals = options.packIds;
  20. data.aid = options.aid;
  21. data.sid = options.sid;
  22. data.cid = options.cid;
  23. data.vid = options.vid != -1 ? options.vid : "";
  24. this.setData({ data: data });
  25. }
  26. this.getlist(false);
  27. }
  28. },
  29. status:{
  30. type: Number,
  31. observer: function (val) {
  32. this.setData({ presellstatus : val });
  33. }
  34. },
  35. type:{
  36. type: Number,
  37. observer: function (val) {
  38. this.setData({ type: val });
  39. }
  40. }
  41. },
  42. data: {
  43. show:false,
  44. list: [],
  45. data: Object,
  46. selectId: 0,
  47. isLoadMore: true,
  48. pageIndex: 1,
  49. pageSize: 10,
  50. tabStatus:1,
  51. presellstatus:0,
  52. type:0,
  53. },
  54. methods:{
  55. getlist: function (load) {
  56. var self = this,
  57. url = "v2/order/pay_vouchers",
  58. data = { "pageIndex": self.data.pageIndex, "pageSize": self.data.pageSize };
  59. if (self.data.data.meals) {
  60. url = "v2/order/pay_vouchers";
  61. data = self.data.data;
  62. data.pageIndex = self.data.pageIndex;
  63. data.pageSize = self.data.pageSize;
  64. data.status = self.data.tabStatus;
  65. if (self.data.presellstatus != 0) {
  66. data.otype = self.data.type == 1 ? 2 : 1;
  67. }else{
  68. data.otype = 0
  69. }
  70. }
  71. util.ajax({
  72. func: url,
  73. data: data,
  74. load: load
  75. }, function (res) {
  76. if (res.code == 0) {
  77. let isLoadMore = true;
  78. let newData = self.data.data.meals ? res.data.list : res.data.collects;
  79. let oldData = !load ? newData : [...self.data.list, ...newData];
  80. if (newData.length < self.data.pageSize && oldData.length > self.data.pageSize) {
  81. isLoadMore = false;
  82. }
  83. for (let i = 0; i < oldData.length; i++) {
  84. oldData[i].description = oldData[i].description.replace("<b>", "<b class='b'>");
  85. }
  86. self.setData({ list: oldData, isLoadMore: isLoadMore, selectId: data.vid || '' });
  87. } else
  88. util.showTips(res.reason);
  89. });
  90. },
  91. onbottom() {
  92. var self = this;
  93. if (self.data.isLoadMore == false) return false;
  94. setTimeout(function () {
  95. self.setData({ pageIndex: self.data.pageIndex + 1 });
  96. self.getlist(true);
  97. }, 1000);
  98. },
  99. radioChange: function (e) {
  100. if (!this.data.data.meals) return false;
  101. this.setData({ show:false})
  102. this.triggerEvent("change", e.detail.value)
  103. },
  104. notUse(){
  105. this.setData({ show: false });
  106. this.triggerEvent("close", this.data.show);
  107. this.triggerEvent("change", -1);
  108. },
  109. tabsChange(e) {
  110. let tabStatus = e.currentTarget.dataset.status;
  111. if (tabStatus == this.data.tabStatus) return false;
  112. this.setData({ tabStatus, list: [], pageIndex:1});
  113. this.getlist(false)
  114. },
  115. close() {
  116. this.setData({ show: false });
  117. this.triggerEvent("close", this.data.show);
  118. }
  119. },
  120. })