C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

253 rader
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: null,
  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. if (that.data.allow_load) {
  67. /**
  68. * mybargain: 我的砍价
  69. * bargaingoods: 砍价商品
  70. */
  71. that.setData({
  72. loading: true,
  73. content: '小主,我在玩命加载中...'
  74. })
  75. var param = {};
  76. if (flag == 'mybargain') {
  77. that.setData({
  78. flag: "mybargain"
  79. })
  80. var param = {
  81. pageNum: pageNum,
  82. pageSize: 6
  83. };
  84. var url = config.api.pressOrderList;
  85. } else if (flag == 'bargaingoods') {
  86. that.setData({
  87. flag: "bargaingoods"
  88. })
  89. var param = {
  90. pageNum: pageNum,
  91. pageSize: 6,
  92. targetAd: 6
  93. };
  94. var url = config.api.couponChannelList;
  95. }
  96. // 请求接口
  97. Http.get({
  98. url: url,
  99. data: param
  100. }).then(res => {
  101. console.log(res)
  102. /**
  103. * 加载完成
  104. */
  105. if (pageNum >= res.data.pages) {
  106. if (res.data.pages == 0 || res.data.pages == 1) {
  107. that.setData({
  108. allow_load: true,
  109. loading: false,
  110. content: ""
  111. });
  112. } else {
  113. that.setData({
  114. allow_load: false,
  115. loading: true,
  116. content: "——— 再拉裤子就掉了啦 ———",
  117. });
  118. }
  119. }
  120. if (pageNum == 1) {
  121. that.setData({
  122. lists: [],
  123. })
  124. }
  125. var tmpArr = that.data.lists;
  126. tmpArr.push.apply(tmpArr, res.data.list);
  127. that.setData({
  128. lists: tmpArr
  129. })
  130. })
  131. .catch(err => {
  132. wx.showToast({
  133. title: err.errMsg,
  134. icon: 'none',
  135. duration: 2000,
  136. mask: false
  137. });
  138. })
  139. setTimeout(function () {
  140. that.setData({
  141. loading: false,
  142. })
  143. }, 1400);
  144. } else {
  145. that.setData({
  146. loading: true,
  147. content: "——— 再拉裤子就掉了啦 ———"
  148. })
  149. setTimeout(function () {
  150. that.setData({
  151. loading: false,
  152. })
  153. }, 1400)
  154. }
  155. },
  156. /**
  157. * 如果是重新砍价,需要重新下单
  158. */
  159. orderSave: function (couponId,orderId,couponChannelId) {
  160. Http.post({
  161. url: config.api.orderSave,
  162. data: {
  163. couponId: "" + couponId,
  164. couponChannelId:""+couponChannelId,
  165. press: true
  166. }
  167. })
  168. .then(res => {
  169. console.log(res)
  170. wx.navigateTo({
  171. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${orderId}`
  172. })
  173. })
  174. .catch(err => {
  175. wx.showToast({
  176. title: err.message,
  177. icon: "none"
  178. })
  179. })
  180. },
  181. inviteFriend: function (e) {
  182. /**
  183. * 添加标识
  184. */
  185. wx.navigateTo({
  186. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  187. })
  188. },
  189. barginAgain: function (e) {
  190. let that = this;
  191. console.log(e)
  192. let couponId = e.currentTarget.dataset.couponid;
  193. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  194. let orderId = e.currentTarget.dataset.id;
  195. that.orderSave(couponId,orderId,couponChannelId)
  196. },
  197. mybargain: function () {
  198. let that = this;
  199. that.setData({
  200. bargaingoods: false,
  201. mybargain: true,
  202. flag: "mybargain",
  203. allow_load: true,
  204. loading: false,
  205. content: ""
  206. })
  207. that.getList(1, 'mybargain');
  208. wx.setNavigationBarTitle({
  209. title: '我的砍价'
  210. })
  211. },
  212. bargaingoods: function () {
  213. let that = this;
  214. that.setData({
  215. bargaingoods: true,
  216. mybargain: false,
  217. flag: "bargaingoods",
  218. allow_load: true,
  219. loading: false,
  220. content: ""
  221. })
  222. that.getList(1, 'bargaingoods');
  223. wx.setNavigationBarTitle({
  224. title: '砍价专场'
  225. })
  226. },
  227. /**
  228. *
  229. * @param {砍价} 邀请好友砍价
  230. */
  231. invite: function (e) {
  232. console.log(e.currentTarget.dataset.id);
  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. })