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.

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