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

247 lines
6.6 KiB

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