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.

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