C端小程序
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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