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.

269 lines
6.6 KiB

  1. const util = require("../../utils/util.js");
  2. const config = require("../../config/config.js");
  3. const Http = require("../../utils/HttpBasics");
  4. const imgurl = require("../../utils/imgurl");
  5. let app = getApp();
  6. Page({
  7. data: {
  8. tabData:[
  9. {
  10. title: '全部',
  11. id: ''
  12. },
  13. {
  14. title:'可转赠',
  15. id:1
  16. },
  17. {
  18. title: '不可转赠',
  19. id: 0
  20. }
  21. ],
  22. couponUrl: imgurl.coupon.url,
  23. loadingUrl: imgurl.loading.url,
  24. wmhome: imgurl.wmhome.url,
  25. canTransferred: imgurl.canTransferred.url,
  26. tabs: [],
  27. list: [],
  28. current: "0",
  29. current_scroll: "",
  30. page: 1,
  31. allow_load: true,
  32. loading: true, //"上拉加载"的变量,默认false,隐藏
  33. content: "",
  34. mystatus: '',
  35. showPage: false,
  36. paramData:null
  37. },
  38. goback: function () {
  39. wx.switchTab({
  40. url: '/pages/main/index',
  41. })
  42. },
  43. onLoad(options) {
  44. this.getList(0, 1);
  45. if(options.fromId){
  46. this.setData({
  47. paramData:options
  48. },function(){
  49. // this.userLogin()
  50. })
  51. }
  52. },
  53. //点击跳转到卡详情页面
  54. gotouse: function (e) {
  55. console.log(e.currentTarget.dataset.couponid)
  56. wx.navigateTo({
  57. url: `/pages/coupon/detail/index?couponChannelId=${e.currentTarget.dataset.quancode}&couponId=${e.currentTarget.dataset.couponid}&cardType=${e.currentTarget.dataset.type}`
  58. });
  59. },
  60. getList(key, pageNum) {
  61. var that = this;
  62. // 根据 key == 0 区分全部或其它tab,决定是否传参数 business
  63. if (!key) {
  64. var param = {
  65. pageNum: pageNum,
  66. pageSize: 8,
  67. targetAd: 5,
  68. };
  69. } else {
  70. var param = {
  71. pageNum: pageNum,
  72. pageSize: 8,
  73. supportTransfer:key,
  74. targetAd: 5,
  75. };
  76. }
  77. if (that.data.allow_load) {
  78. that.setData({
  79. loading: true,
  80. content: "小主,我在玩命加载中...",
  81. });
  82. Http.get({
  83. url: config.api.couponChannelList,
  84. data: param
  85. })
  86. .then(res => {
  87. if (res.code == 200) {
  88. that.setData({
  89. showPage: true
  90. })
  91. }
  92. res.data.list.map(file => {
  93. file.expiredTime = util.fmtDate(file.expiredTime);
  94. });
  95. setTimeout(function () {
  96. that.setData({
  97. loading: false
  98. });
  99. }, 1400);
  100. if (pageNum >= res.data.pages) {
  101. that.setData({
  102. allow_load: false
  103. });
  104. }
  105. if (pageNum == 1) {
  106. that.setData({
  107. list: []
  108. })
  109. }
  110. var tmpArr = that.data.list;
  111. tmpArr.push.apply(tmpArr, res.data.list);
  112. that.setData({
  113. list: tmpArr
  114. })
  115. })
  116. .catch(err => {
  117. wx.showModal({
  118. title: '提示',
  119. content: err.errMsg,
  120. showCancel: false
  121. })
  122. })
  123. } else {
  124. that.setData({
  125. loading: true,
  126. content: "——— 再拉裤子就掉了啦 ———"
  127. });
  128. setTimeout(function () {
  129. that.setData({
  130. loading: false
  131. });
  132. }, 1400);
  133. }
  134. },
  135. handleChangeScroll({
  136. detail
  137. }) {
  138. console.log(detail)
  139. this.setData({
  140. list: [],
  141. allow_load: true,
  142. current_scroll: detail.key,
  143. page: 1,
  144. });
  145. this.getList(detail.key, 1);
  146. },
  147. onReachBottom: function () {
  148. var that = this;
  149. that.data.page++;
  150. that.setData({
  151. page: that.data.page
  152. });
  153. that.getList(that.data.current_scroll, that.data.page);
  154. },
  155. /**
  156. * 用户登录
  157. */
  158. // userLogin: function () {
  159. // var that = this;
  160. // // 登录
  161. // wx.login({
  162. // success: ({
  163. // code
  164. // }) => {
  165. // wx.getSystemInfo({
  166. // success: function (res) {
  167. // that.setData({
  168. // systemInfo: JSON.stringify(res)
  169. // })
  170. // }
  171. // })
  172. // var usrdata = {
  173. // appId: config.weapp.AppId,
  174. // code: code,
  175. // sceneAddress: app.globalData.sceneAddress,
  176. // scene: that.data.scene,
  177. // systemInfo: that.data.systemInfo
  178. // };
  179. // if (app.globalData.locationInfo) {
  180. // usrdata = {
  181. // appId: config.weapp.AppId,
  182. // code: code,
  183. // sceneAddress: app.globalData.sceneAddress,
  184. // latitude: "" + app.globalData.locationInfo.latitude,
  185. // longitude: "" + app.globalData.locationInfo.longitude,
  186. // scene: that.data.scene,
  187. // systemInfo: that.data.systemInfo
  188. // };
  189. // }
  190. // Http.post({
  191. // url: config.api.login,
  192. // data: usrdata
  193. // })
  194. // .then(res => {
  195. // that.setData({
  196. // showPages: true
  197. // })
  198. // app.globalData.token = res.data.token;
  199. // Http.setToken(res.data.token);
  200. // that.checkuerstatus();
  201. // })
  202. // .catch(err => {
  203. // wx.showModal({
  204. // title: '提示',
  205. // showCancel: false,
  206. // content: '登录失败,请重新尝试',
  207. // success: function (res) {
  208. // if (res.cancel) {
  209. // //点击取消,默认隐藏弹框
  210. // } else {
  211. // //点击确定
  212. // wx.reLaunch({
  213. // url: '/pages/index/index',
  214. // })
  215. // }
  216. // }
  217. // })
  218. // });
  219. // }
  220. // });
  221. // },
  222. checkuerstatus(){
  223. Http.get({
  224. url: config.api.checkPhoneStatus,
  225. data: {}
  226. })
  227. .then(res => {
  228. })
  229. .catch(err => {
  230. if (err.code == 11005) {
  231. // 用户手机未授权
  232. /**
  233. * 将值传到用户手机号授权的页面
  234. *
  235. */
  236. wx.redirectTo({
  237. url: "/pages/getphoneInfo/index?path=index&fromId=" + that.data.paramData.fromId
  238. });
  239. } else if (err.code == 11006) {
  240. // 用户手机已加密
  241. wx.redirectTo({
  242. url: "/pages/phoneinput/phoneinput?path=index&fromId=" + that.data.paramData.fromId
  243. });
  244. } else {
  245. wx.showToast({
  246. title: err.message,
  247. icon: 'none',
  248. duration: 2000,
  249. mask: false
  250. });
  251. }
  252. })
  253. }
  254. })
  255. function compare(pro) {
  256. return function (obj2, obj1) {
  257. var val1 = obj1[pro];
  258. var val2 = obj2[pro];
  259. if (val1 < val2) {
  260. return 1;
  261. } else if (val1 > val2) {
  262. return -1;
  263. } else {
  264. return 0;
  265. }
  266. }
  267. }