C端小程序
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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