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.

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