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.

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