C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

288 lines
7.0 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. if (flag == 'bargaingoods'){
  118. var tmpArr = that.data.lists;
  119. tmpArr.push.apply(tmpArr, res.data.list);
  120. that.setData({
  121. lists: tmpArr
  122. })
  123. } else if (flag == 'mybargain'){
  124. console.log(res.data.list)
  125. var tmpArr = that.data.lists;
  126. tmpArr.push.apply(tmpArr, res.data.list);
  127. console.log(tmpArr)
  128. let lists = [];
  129. tmpArr.map(file => {
  130. if (file.orderStatus != 1) {
  131. lists.push(file);
  132. }
  133. })
  134. that.setData({
  135. lists: lists
  136. })
  137. }
  138. wx.stopPullDownRefresh();
  139. })
  140. .catch(err => {
  141. wx.stopPullDownRefresh();
  142. wx.showToast({
  143. title: err.message,
  144. icon: 'none',
  145. duration: 2000,
  146. mask: false
  147. });
  148. })
  149. setTimeout(function () {
  150. that.setData({
  151. loading: false,
  152. })
  153. }, 1400);
  154. } else {
  155. that.setData({
  156. loading: true,
  157. content: "——— 再拉裤子就掉了啦 ———"
  158. })
  159. setTimeout(function () {
  160. that.setData({
  161. loading: false,
  162. })
  163. }, 1400)
  164. }
  165. },
  166. /**
  167. * 如果是重新砍价,需要重新下单
  168. */
  169. orderSave: function (couponId,couponChannelId) {
  170. Http.post({
  171. url: config.api.orderSave,
  172. data: {
  173. couponId: "" + couponId,
  174. couponChannelId:""+couponChannelId,
  175. press: true
  176. }
  177. })
  178. .then(res => {
  179. console.log(res)
  180. wx.navigateTo({
  181. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  182. })
  183. })
  184. .catch(err => {
  185. wx.showToast({
  186. title: err.message,
  187. icon: "none"
  188. })
  189. })
  190. },
  191. inviteFriend: function (e) {
  192. /**
  193. * 添加标识
  194. */
  195. wx.navigateTo({
  196. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  197. })
  198. },
  199. barginAgain: function (e) {
  200. let that = this;
  201. console.log(e)
  202. let couponId = e.currentTarget.dataset.couponid;
  203. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  204. // let orderId = e.currentTarget.dataset.id;
  205. that.orderSave(couponId,couponChannelId)
  206. },
  207. mybargain: function () {
  208. let that = this;
  209. that.setData({
  210. bargaingoods: false,
  211. mybargain: true,
  212. flag: "mybargain",
  213. allow_load: true,
  214. loading: false,
  215. content: "",
  216. page:1
  217. })
  218. that.getList(1, 'mybargain');
  219. wx.setNavigationBarTitle({
  220. title: '我的砍价'
  221. })
  222. },
  223. bargaingoods: function () {
  224. let that = this;
  225. that.setData({
  226. bargaingoods: true,
  227. mybargain: false,
  228. flag: "bargaingoods",
  229. allow_load: true,
  230. loading: false,
  231. page:1,
  232. content: ""
  233. })
  234. that.getList(1, 'bargaingoods');
  235. wx.setNavigationBarTitle({
  236. title: '砍价专场'
  237. })
  238. },
  239. /**
  240. *
  241. * @param {砍价} 邀请好友砍价
  242. */
  243. invite: function (e) {
  244. let couponChannelId = e.currentTarget.dataset.id;
  245. let couponId = e.currentTarget.dataset.couponid;
  246. if (couponChannelId && couponId) {
  247. wx.navigateTo({
  248. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  249. })
  250. }
  251. },
  252. //加载更多
  253. onReachBottom: function () {
  254. let that = this;
  255. that.data.page++;
  256. that.setData({
  257. page: that.data.page
  258. });
  259. that.getList(that.data.page, that.data.flag);
  260. },
  261. /**
  262. * 刷新
  263. */
  264. onPullDownRefresh: function (e) {
  265. let that = this;
  266. if (that.data.flag == 'bargaingoods'){
  267. that.getBannerlist();
  268. var todayDate = new Date().getTime();
  269. that.setData({
  270. todayDate: todayDate
  271. })
  272. that.getList(1, "bargaingoods");
  273. that.setData({
  274. flag: "bargaingoods",
  275. bargaingoods: true,
  276. mybargain: false
  277. })
  278. } else if (that.data.flag == 'mybargain'){
  279. that.getList(1, "mybargain");
  280. that.setData({
  281. flag: "mybargain",
  282. bargaingoods: false,
  283. mybargain: true
  284. })
  285. }
  286. },
  287. })