C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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