C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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