C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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