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.

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