C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

251 行
6.1 KiB

  1. var config = require("../../config/config.js");
  2. const Http = require("../../utils/HttpBasics");
  3. const imgurl = require("../../utils/imgurl");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. bannerUrl: imgurl.banner.url,
  10. loadingUrl: imgurl.loading.url,
  11. bargaingoods: true,
  12. mybargain: false,
  13. list: [],
  14. lists: [],
  15. page: 1, // 设置加载的第几次,默认是第一次
  16. pageSize: 10, //返回数据的个数
  17. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  18. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  19. myorder: false,
  20. actUrl: imgurl.act.url,
  21. loadingUrl: imgurl.loading.url,
  22. flag: 'bargaingoods',
  23. },
  24. onShow: function () {
  25. let that = this;
  26. that.getBannerlist();
  27. var todayDate=new Date().getTime();
  28. that.setData({
  29. todayDate:todayDate
  30. })
  31. let myDiscount = wx.getStorageSync('myDiscount');
  32. console.log(myDiscount)
  33. if (myDiscount == 'myDiscount') {
  34. wx.setStorageSync('myDiscount', "dismyDiscount")
  35. that.getList(1, "mybargain");
  36. that.setData({
  37. flag: "mybargain"
  38. })
  39. } else {
  40. wx.setStorageSync('myDiscount', "dismyDiscount")
  41. that.getList(1, "bargaingoods");
  42. that.setData({
  43. flag: "bargaingoods"
  44. })
  45. }
  46. },
  47. /**
  48. * banner
  49. */
  50. getBannerlist: function () {
  51. let that = this;
  52. Http.get({
  53. url: config.api.bannerlist,
  54. data: {
  55. pageNum: 1,
  56. pageSize: 7
  57. }
  58. }).then(res => {
  59. that.setData({
  60. list: res.data.list
  61. });
  62. });
  63. },
  64. getList(pageNum, flag) {
  65. var that = this;
  66. console.log(pageNum)
  67. if (that.data.allow_load) {
  68. /**
  69. * mybargain: 我的砍价
  70. * bargaingoods: 砍价商品
  71. */
  72. that.setData({
  73. loading: true,
  74. content: '小主,我在玩命加载中...'
  75. })
  76. var param = {};
  77. if (flag == 'mybargain') {
  78. that.setData({
  79. flag: "mybargain"
  80. })
  81. var param = {
  82. pageNum: pageNum,
  83. pageSize: 10
  84. };
  85. var url = config.api.pressOrderList;
  86. } else if (flag == 'bargaingoods') {
  87. that.setData({
  88. flag: "bargaingoods"
  89. })
  90. var param = {
  91. pageNum: pageNum,
  92. pageSize: 10,
  93. targetAd: 6
  94. };
  95. var url = config.api.couponChannelList;
  96. }
  97. // 请求接口
  98. Http.get({
  99. url: url,
  100. data: param
  101. }).then(res => {
  102. console.log(res)
  103. /**
  104. * 加载完成
  105. */
  106. if (pageNum >= res.data.pages) {
  107. if (res.data.pages == 0 || res.data.pages == 1) {
  108. that.setData({
  109. allow_load: true,
  110. loading: false,
  111. content: ""
  112. });
  113. } else {
  114. that.setData({
  115. allow_load: false,
  116. loading: true,
  117. content: "——— 再拉裤子就掉了啦 ———",
  118. });
  119. }
  120. }
  121. if (pageNum == 1) {
  122. that.setData({
  123. lists: [],
  124. })
  125. }
  126. var tmpArr = that.data.lists;
  127. tmpArr.push.apply(tmpArr, res.data.list);
  128. that.setData({
  129. lists: tmpArr
  130. })
  131. })
  132. .catch(err => {
  133. wx.showToast({
  134. title: err.message,
  135. icon: 'none',
  136. duration: 2000,
  137. mask: false
  138. });
  139. })
  140. setTimeout(function () {
  141. that.setData({
  142. loading: false,
  143. })
  144. }, 1400);
  145. } else {
  146. that.setData({
  147. loading: true,
  148. content: "——— 再拉裤子就掉了啦 ———"
  149. })
  150. setTimeout(function () {
  151. that.setData({
  152. loading: false,
  153. })
  154. }, 1400)
  155. }
  156. },
  157. /**
  158. * 如果是重新砍价,需要重新下单
  159. */
  160. orderSave: function (couponId,couponChannelId) {
  161. Http.post({
  162. url: config.api.orderSave,
  163. data: {
  164. couponId: "" + couponId,
  165. couponChannelId:""+couponChannelId,
  166. press: true
  167. }
  168. })
  169. .then(res => {
  170. console.log(res)
  171. wx.navigateTo({
  172. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  173. })
  174. })
  175. .catch(err => {
  176. wx.showToast({
  177. title: err.message,
  178. icon: "none"
  179. })
  180. })
  181. },
  182. inviteFriend: function (e) {
  183. /**
  184. * 添加标识
  185. */
  186. wx.navigateTo({
  187. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  188. })
  189. },
  190. barginAgain: function (e) {
  191. let that = this;
  192. console.log(e)
  193. let couponId = e.currentTarget.dataset.couponid;
  194. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  195. // let orderId = e.currentTarget.dataset.id;
  196. that.orderSave(couponId,couponChannelId)
  197. },
  198. mybargain: function () {
  199. let that = this;
  200. that.setData({
  201. bargaingoods: false,
  202. mybargain: true,
  203. flag: "mybargain",
  204. allow_load: true,
  205. loading: false,
  206. content: ""
  207. })
  208. that.getList(1, 'mybargain');
  209. wx.setNavigationBarTitle({
  210. title: '我的砍价'
  211. })
  212. },
  213. bargaingoods: function () {
  214. let that = this;
  215. that.setData({
  216. bargaingoods: true,
  217. mybargain: false,
  218. flag: "bargaingoods",
  219. allow_load: true,
  220. loading: false,
  221. content: ""
  222. })
  223. that.getList(1, 'bargaingoods');
  224. wx.setNavigationBarTitle({
  225. title: '砍价专场'
  226. })
  227. },
  228. /**
  229. *
  230. * @param {砍价} 邀请好友砍价
  231. */
  232. invite: function (e) {
  233. let couponChannelId = e.currentTarget.dataset.id;
  234. let couponId = e.currentTarget.dataset.couponid;
  235. if (couponChannelId && couponId) {
  236. wx.navigateTo({
  237. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  238. })
  239. }
  240. },
  241. //加载更多
  242. onReachBottom: function () {
  243. let that = this;
  244. that.data.page++;
  245. that.setData({
  246. page: that.data.page
  247. });
  248. that.getList(that.data.page, that.data.flag);
  249. },
  250. })