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.

244 regels
5.8 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. console.log("onShow")
  28. console.log()
  29. var todayDate=new Date().getTime();
  30. that.setData({
  31. todayDate:todayDate
  32. })
  33. that.getList(1, "bargaingoods");
  34. that.setData({
  35. flag: "bargaingoods",
  36. bargaingoods:true,
  37. mybargain:false
  38. })
  39. },
  40. /**
  41. * banner
  42. */
  43. getBannerlist: function () {
  44. let that = this;
  45. Http.get({
  46. url: config.api.bannerlist,
  47. data: {
  48. pageNum: 1,
  49. pageSize: 7
  50. }
  51. }).then(res => {
  52. that.setData({
  53. list: res.data.list
  54. });
  55. });
  56. },
  57. getList(pageNum, flag) {
  58. var that = this;
  59. console.log(pageNum)
  60. if (that.data.allow_load) {
  61. /**
  62. * mybargain: 我的砍价
  63. * bargaingoods: 砍价商品
  64. */
  65. that.setData({
  66. loading: true,
  67. content: '小主,我在玩命加载中...'
  68. })
  69. var param = {};
  70. if (flag == 'mybargain') {
  71. that.setData({
  72. flag: "mybargain"
  73. })
  74. var param = {
  75. pageNum: pageNum,
  76. pageSize: 10
  77. };
  78. var url = config.api.pressOrderList;
  79. } else if (flag == 'bargaingoods') {
  80. that.setData({
  81. flag: "bargaingoods"
  82. })
  83. var param = {
  84. pageNum: pageNum,
  85. pageSize: 10,
  86. targetAd: 6
  87. };
  88. var url = config.api.couponChannelList;
  89. }
  90. // 请求接口
  91. Http.get({
  92. url: url,
  93. data: param
  94. }).then(res => {
  95. console.log(res)
  96. /**
  97. * 加载完成
  98. */
  99. if (pageNum >= res.data.pages) {
  100. if (res.data.pages == 0 || res.data.pages == 1) {
  101. that.setData({
  102. allow_load: true,
  103. loading: false,
  104. content: ""
  105. });
  106. } else {
  107. that.setData({
  108. allow_load: false,
  109. loading: true,
  110. content: "——— 再拉裤子就掉了啦 ———",
  111. });
  112. }
  113. }
  114. if (pageNum == 1) {
  115. that.setData({
  116. lists: [],
  117. })
  118. }
  119. var tmpArr = that.data.lists;
  120. tmpArr.push.apply(tmpArr, res.data.list);
  121. that.setData({
  122. lists: tmpArr
  123. })
  124. })
  125. .catch(err => {
  126. wx.showToast({
  127. title: err.message,
  128. icon: 'none',
  129. duration: 2000,
  130. mask: false
  131. });
  132. })
  133. setTimeout(function () {
  134. that.setData({
  135. loading: false,
  136. })
  137. }, 1400);
  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. /**
  151. * 如果是重新砍价,需要重新下单
  152. */
  153. orderSave: function (couponId,couponChannelId) {
  154. Http.post({
  155. url: config.api.orderSave,
  156. data: {
  157. couponId: "" + couponId,
  158. couponChannelId:""+couponChannelId,
  159. press: true
  160. }
  161. })
  162. .then(res => {
  163. console.log(res)
  164. wx.navigateTo({
  165. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  166. })
  167. })
  168. .catch(err => {
  169. wx.showToast({
  170. title: err.message,
  171. icon: "none"
  172. })
  173. })
  174. },
  175. inviteFriend: function (e) {
  176. /**
  177. * 添加标识
  178. */
  179. wx.navigateTo({
  180. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  181. })
  182. },
  183. barginAgain: function (e) {
  184. let that = this;
  185. console.log(e)
  186. let couponId = e.currentTarget.dataset.couponid;
  187. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  188. // let orderId = e.currentTarget.dataset.id;
  189. that.orderSave(couponId,couponChannelId)
  190. },
  191. mybargain: function () {
  192. let that = this;
  193. that.setData({
  194. bargaingoods: false,
  195. mybargain: true,
  196. flag: "mybargain",
  197. allow_load: true,
  198. loading: false,
  199. content: ""
  200. })
  201. that.getList(1, 'mybargain');
  202. wx.setNavigationBarTitle({
  203. title: '我的砍价'
  204. })
  205. },
  206. bargaingoods: function () {
  207. let that = this;
  208. that.setData({
  209. bargaingoods: true,
  210. mybargain: false,
  211. flag: "bargaingoods",
  212. allow_load: true,
  213. loading: false,
  214. content: ""
  215. })
  216. that.getList(1, 'bargaingoods');
  217. wx.setNavigationBarTitle({
  218. title: '砍价专场'
  219. })
  220. },
  221. /**
  222. *
  223. * @param {砍价} 邀请好友砍价
  224. */
  225. invite: function (e) {
  226. let couponChannelId = e.currentTarget.dataset.id;
  227. let couponId = e.currentTarget.dataset.couponid;
  228. if (couponChannelId && couponId) {
  229. wx.navigateTo({
  230. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  231. })
  232. }
  233. },
  234. //加载更多
  235. onReachBottom: function () {
  236. let that = this;
  237. that.data.page++;
  238. that.setData({
  239. page: that.data.page
  240. });
  241. that.getList(that.data.page, that.data.flag);
  242. },
  243. })