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.

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