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.

272 line
6.7 KiB

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