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.

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