C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
5.4 KiB

  1. const util = require("../../../utils/util.js");
  2. const config = require("../../../config/config.js");
  3. const Http = require("../../../utils/HttpBasics");
  4. let app = getApp();
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. data: {
  8. couponUrl: imgurl.coupon.url,
  9. linessUrl: imgurl.liness.url,
  10. loadingUrl: imgurl.loading.url,
  11. tabs: [{
  12. key: 4,
  13. name: "使用中"
  14. },
  15. {
  16. key: "5,6,7",
  17. name: "已失效"
  18. }
  19. ],
  20. list: [],
  21. current: "4",
  22. current_scroll: "4",
  23. page: 1,
  24. allow_load: true,
  25. loading: true, //"上拉加载"的变量,默认false,隐藏
  26. content: "",
  27. mystatus: '',
  28. showPage: false
  29. },
  30. onShow: function() {
  31. let that = this;
  32. if (that.data.current_scroll==4){
  33. that.getList(4, 1);
  34. }else{
  35. that.getList('5,6,7', 1);
  36. }
  37. wx.setStorage({
  38. key: 'couponNum2',
  39. data: "couponNum3",
  40. })
  41. wx.hideTabBarRedDot({
  42. index: 2
  43. })
  44. },
  45. userule:function(){
  46. wx.navigateTo({
  47. url: '/pages/cardorder/userule/userule',
  48. })
  49. },
  50. // 扫一扫去支付
  51. gotoPay: function(e) {
  52. let that = this;
  53. wx.scanCode({
  54. success: (res) => {
  55. console.log(JSON.parse(res.result).merchant_id)
  56. if(JSON.parse(res.result).merchant_id&&e.currentTarget.dataset.cardid&&e.currentTarget.dataset.remainingamount){
  57. wx.navigateTo({
  58. url: `/pages/scanPay/scanPay?merChant=${res.result}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
  59. })
  60. }else{
  61. wx.showToast({
  62. title:"未识别到商户二维码",
  63. icon:"none",
  64. mask: false
  65. })
  66. }
  67. },
  68. fail: (res) => {
  69. console.log(res);
  70. }
  71. })
  72. },
  73. // 跳转到详情
  74. gotoConsumeDetail: function(e) {
  75. console.log(e.currentTarget.dataset.id)
  76. wx.navigateTo({
  77. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
  78. })
  79. },
  80. //点击跳转到券详情页面
  81. gotouse: function(e) {
  82. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  83. var mystatus = e.currentTarget.dataset.couponorderstatus;
  84. } else {
  85. var mystatus = this.data.mystatus;
  86. }
  87. wx.navigateTo({
  88. url: `/pages/couponorder/detail/index?quancode=${
  89. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  90. });
  91. },
  92. gotoBuy:function(){
  93. wx.navigateTo({
  94. url: '/pages/discountCardList/discountCardList',
  95. })
  96. },
  97. getList(key, pageNum) {
  98. var that = this;
  99. console.log(key)
  100. if (that.data.allow_load) {
  101. that.setData({
  102. loading: true,
  103. content: "小主,我在玩命加载中...",
  104. });
  105. if (key == 4) {
  106. var data = {
  107. pageNum: pageNum,
  108. pageSize: 6,
  109. couponType: "7",
  110. couponOrderStatus: 4
  111. }
  112. } else if (key == '5,6,7') {
  113. var data = {
  114. pageNum: pageNum,
  115. pageSize: 6,
  116. couponType: "7",
  117. statusStr: "5,6,7"
  118. }
  119. }
  120. Http.get({
  121. url: config.api.cardorderList,
  122. data: data
  123. })
  124. .then(res => {
  125. if (res.code == 200) {
  126. that.setData({
  127. showPage: true
  128. })
  129. }
  130. res.data.list.map(file => {
  131. file.expiredTime = util.fmtDate(file.expiredTime);
  132. if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7) {
  133. file.background = 'rgba(179,180,181,1)';
  134. file.showImg = true;
  135. } else if (file.couponOrderStatus == 4) {
  136. if (file.remainingAmount > 0 && 29900 >= file.remainingAmount) {
  137. file.background = '#7184E2'
  138. } else if (file.remainingAmount >= 30000 && 49900 >= file.remainingAmount) {
  139. file.background = '#63AAE6'
  140. } else if (file.remainingAmount >= 50000 && 99900 >= file.remainingAmount) {
  141. file.background = '#E2A471'
  142. } else if (file.remainingAmount >= 100000){
  143. file.background = '#E67663'
  144. }
  145. }
  146. });
  147. setTimeout(function() {
  148. that.setData({
  149. loading: false
  150. });
  151. }, 1400);
  152. if (pageNum >= res.data.pages) {
  153. that.setData({
  154. allow_load: false
  155. });
  156. }
  157. if (pageNum == 1) {
  158. that.setData({
  159. list: []
  160. })
  161. }
  162. var tmpArr = that.data.list;
  163. tmpArr.push.apply(tmpArr, res.data.list);
  164. that.setData({
  165. list: tmpArr
  166. })
  167. })
  168. .catch(err => {
  169. wx.showModal({
  170. title: '提示',
  171. content: err.errMsg,
  172. showCancel: false
  173. })
  174. })
  175. } else {
  176. that.setData({
  177. loading: true,
  178. content: "——— 再拉裤子就掉了啦 ———"
  179. });
  180. setTimeout(function() {
  181. that.setData({
  182. loading: false
  183. });
  184. }, 1400);
  185. }
  186. },
  187. handleChangeScroll({
  188. detail
  189. }) {
  190. this.setData({
  191. list: [],
  192. allow_load: true,
  193. current_scroll: detail.key,
  194. page: 1,
  195. });
  196. this.getList(detail.key, 1);
  197. },
  198. onReachBottom: function() {
  199. var that = this;
  200. that.data.page++;
  201. that.setData({
  202. page: that.data.page
  203. });
  204. that.getList(that.data.current_scroll, that.data.page);
  205. }
  206. });