C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
5.9 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. console.log("onShow")
  33. console.log(that.data.current_scroll)
  34. if (that.data.current_scroll == "4") {
  35. that.getList(4, 1);
  36. } else {
  37. that.getList('5,6,7', 1);
  38. }
  39. wx.setStorage({
  40. key: 'couponNum2',
  41. data: "couponNum3",
  42. })
  43. wx.hideTabBarRedDot({
  44. index: 2
  45. })
  46. },
  47. userule: function() {
  48. wx.navigateTo({
  49. url: '/pages/cardorder/userule/userule',
  50. })
  51. },
  52. // 扫一扫去支付
  53. gotoPay: function(e) {
  54. let that = this;
  55. wx.scanCode({
  56. success: (res) => {
  57. let value = JSON.parse(res.result);
  58. if (value.END == 'B' && value.TYPE == 'merchant' && value.ID){
  59. Http.get({
  60. url: config.api.findByCode,
  61. data: {
  62. merchantCode:value.ID,
  63. }
  64. })
  65. .then(res => {
  66. if (res.code == 200) {
  67. let merChantDetail = JSON.stringify(res.data);
  68. if (merChantDetail && e.currentTarget.dataset.cardid && e.currentTarget.dataset.remainingamount) {
  69. wx.navigateTo({
  70. url: `/pages/scanPay/scanPay?merChant=${merChantDetail}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
  71. })
  72. }
  73. }
  74. })
  75. .catch(err => {
  76. console.log(err)
  77. })
  78. }else{
  79. wx.showToast({
  80. title: "未识别到商户二维码",
  81. icon: "none",
  82. mask: false
  83. })
  84. }
  85. },
  86. fail: (res) => {
  87. console.log(res);
  88. }
  89. })
  90. },
  91. // 跳转到详情
  92. gotoConsumeDetail: function(e) {
  93. wx.navigateTo({
  94. url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
  95. })
  96. },
  97. //点击跳转到券详情页面
  98. gotouse: function(e) {
  99. if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
  100. var mystatus = e.currentTarget.dataset.couponorderstatus;
  101. } else {
  102. var mystatus = this.data.mystatus;
  103. }
  104. wx.navigateTo({
  105. url: `/pages/couponorder/detail/index?quancode=${
  106. e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
  107. });
  108. },
  109. gotoBuy: function() {
  110. wx.navigateTo({
  111. url: '/pages/discountCardList/discountCardList',
  112. })
  113. },
  114. getList(key, pageNum) {
  115. var that = this;
  116. // if (that.data.allow_load) {
  117. that.setData({
  118. loading: true,
  119. content: "小主,我在玩命加载中...",
  120. });
  121. if (key == "4") {
  122. var data = {
  123. pageNum: pageNum,
  124. pageSize: 6,
  125. couponType: "100",
  126. couponOrderStatus: 4
  127. }
  128. } else if (key == '5,6,7') {
  129. var data = {
  130. pageNum: pageNum,
  131. pageSize: 6,
  132. couponType: "100",
  133. statusStr: "5,6,7"
  134. }
  135. }
  136. Http.get({
  137. url: config.api.cardorderList,
  138. data: data
  139. })
  140. .then(res => {
  141. console.log(res)
  142. if (res.code == 200) {
  143. that.setData({
  144. showPage: true
  145. })
  146. }
  147. res.data.list.map(file => {
  148. file.expiredTime = util.formatTime(file.expiredTime, "yyyy.MM.dd")
  149. if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7) {
  150. file.background = 'rgba(179,180,181,1)';
  151. file.showImg = true;
  152. } else if (file.couponOrderStatus == 4) {
  153. if (file.remainingAmount > 0 && 29900 >= file.remainingAmount) {
  154. file.background = '#7184E2'
  155. } else if (file.remainingAmount >= 30000 && 49900 >= file.remainingAmount) {
  156. file.background = '#63AAE6'
  157. } else if (file.remainingAmount >= 50000 && 99900 >= file.remainingAmount) {
  158. file.background = '#E2A471'
  159. } else if (file.remainingAmount >= 100000) {
  160. file.background = '#E67663'
  161. }
  162. }
  163. });
  164. setTimeout(function() {
  165. that.setData({
  166. loading: false
  167. });
  168. }, 1400);
  169. if (pageNum >= res.data.pages && pageNum != 1) {
  170. that.setData({
  171. allow_load: false
  172. });
  173. }
  174. if (pageNum == 1) {
  175. that.setData({
  176. list: []
  177. })
  178. }
  179. var tmpArr = that.data.list;
  180. tmpArr.push.apply(tmpArr, res.data.list);
  181. that.setData({
  182. list: tmpArr
  183. })
  184. })
  185. .catch(err => {
  186. wx.showModal({
  187. title: '提示',
  188. content: err.errMsg,
  189. showCancel: false
  190. })
  191. })
  192. // } else {
  193. // that.setData({
  194. // loading: true,
  195. // content: "——— 再拉裤子就掉了啦 ———"
  196. // });
  197. // setTimeout(function() {
  198. // that.setData({
  199. // loading: false
  200. // });
  201. // }, 1400);
  202. // }
  203. },
  204. handleChangeScroll({
  205. detail
  206. }) {
  207. this.setData({
  208. list: [],
  209. allow_load: true,
  210. current_scroll: detail.key,
  211. page: 1,
  212. });
  213. this.getList(detail.key, 1);
  214. },
  215. onReachBottom: function() {
  216. var that = this;
  217. that.data.page++;
  218. that.setData({
  219. page: that.data.page
  220. });
  221. that.getList(that.data.current_scroll, that.data.page);
  222. }
  223. });