C端小程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

291 行
7.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. bargaincancel: imgurl.bargaincancel.url,
  12. bargainfail: imgurl.bargainfail.url,
  13. bargainsuccess: imgurl.bargainsuccess.url,
  14. bargaingoods: true,
  15. mybargain: false,
  16. list: [],
  17. lists: [],
  18. page: 1, // 设置加载的第几次,默认是第一次
  19. pageSize: 10, //返回数据的个数
  20. searchLoadingComplete: false, //“没有数据”的变量,默认false,隐藏
  21. allow_load: true, // 是否允许继续加载标识 默认 true 允许,false 加载完成
  22. myorder: false,
  23. actUrl: imgurl.act.url,
  24. loadingUrl: imgurl.loading.url,
  25. flag: 'bargaingoods',
  26. },
  27. onLoad: function () {
  28. let that = this;
  29. that.getBannerlist();
  30. var todayDate=new Date().getTime();
  31. that.setData({
  32. todayDate:todayDate
  33. })
  34. that.getList(1, "bargaingoods");
  35. that.setData({
  36. flag: "bargaingoods",
  37. bargaingoods:true,
  38. mybargain:false
  39. })
  40. },
  41. /**
  42. * banner
  43. */
  44. getBannerlist: function () {
  45. let that = this;
  46. Http.get({
  47. url: config.api.bannerlist,
  48. data: {
  49. pageNum: 1,
  50. pageSize: 7
  51. }
  52. }).then(res => {
  53. that.setData({
  54. list: res.data.list
  55. });
  56. });
  57. },
  58. getList(pageNum, flag) {
  59. var that = this;
  60. console.log(pageNum)
  61. if (that.data.allow_load) {
  62. /**
  63. * mybargain: 我的砍价
  64. * bargaingoods: 砍价商品
  65. */
  66. that.setData({
  67. loading: true,
  68. content: '小主,我在玩命加载中...'
  69. })
  70. var param = {};
  71. if (flag == 'mybargain') {
  72. that.setData({
  73. flag: "mybargain"
  74. })
  75. var param = {
  76. pageNum: pageNum,
  77. pageSize: 10
  78. };
  79. var url = config.api.pressOrderList;
  80. } else if (flag == 'bargaingoods') {
  81. that.setData({
  82. flag: "bargaingoods"
  83. })
  84. var param = {
  85. pageNum: pageNum,
  86. pageSize: 10,
  87. targetAd: 6
  88. };
  89. var url = config.api.couponChannelList;
  90. }
  91. // 请求接口
  92. Http.get({
  93. url: url,
  94. data: param
  95. }).then(res => {
  96. console.log(res)
  97. /**
  98. * 加载完成
  99. */
  100. if (pageNum >= res.data.pages) {
  101. if (res.data.pages == 0 || res.data.pages == 1) {
  102. that.setData({
  103. allow_load: true,
  104. loading: false,
  105. content: ""
  106. });
  107. } else {
  108. that.setData({
  109. allow_load: false,
  110. loading: true,
  111. content: "——— 再拉裤子就掉了啦 ———",
  112. });
  113. }
  114. }
  115. if (pageNum == 1) {
  116. that.setData({
  117. lists: [],
  118. })
  119. }
  120. if (flag == 'bargaingoods'){
  121. var tmpArr = that.data.lists;
  122. tmpArr.push.apply(tmpArr, res.data.list);
  123. that.setData({
  124. lists: tmpArr
  125. })
  126. } else if (flag == 'mybargain'){
  127. console.log(res.data.list)
  128. var tmpArr = that.data.lists;
  129. tmpArr.push.apply(tmpArr, res.data.list);
  130. console.log(tmpArr)
  131. let lists = [];
  132. tmpArr.map(file => {
  133. if (file.orderStatus != 1) {
  134. lists.push(file);
  135. }
  136. })
  137. that.setData({
  138. lists: lists
  139. })
  140. }
  141. wx.stopPullDownRefresh();
  142. })
  143. .catch(err => {
  144. wx.stopPullDownRefresh();
  145. wx.showToast({
  146. title: err.message,
  147. icon: 'none',
  148. duration: 2000,
  149. mask: false
  150. });
  151. })
  152. setTimeout(function () {
  153. that.setData({
  154. loading: false,
  155. })
  156. }, 1400);
  157. } else {
  158. that.setData({
  159. loading: true,
  160. content: "——— 再拉裤子就掉了啦 ———"
  161. })
  162. setTimeout(function () {
  163. that.setData({
  164. loading: false,
  165. })
  166. }, 1400)
  167. }
  168. },
  169. /**
  170. * 如果是重新砍价,需要重新下单
  171. */
  172. orderSave: function (couponId,couponChannelId) {
  173. Http.post({
  174. url: config.api.orderSave,
  175. data: {
  176. couponId: "" + couponId,
  177. couponChannelId:""+couponChannelId,
  178. press: true
  179. }
  180. })
  181. .then(res => {
  182. console.log(res)
  183. wx.navigateTo({
  184. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.orderNumber}`
  185. })
  186. })
  187. .catch(err => {
  188. wx.showToast({
  189. title: err.message,
  190. icon: "none"
  191. })
  192. })
  193. },
  194. inviteFriend: function (e) {
  195. /**
  196. * 添加标识
  197. */
  198. wx.navigateTo({
  199. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  200. })
  201. },
  202. barginAgain: function (e) {
  203. let that = this;
  204. console.log(e)
  205. let couponId = e.currentTarget.dataset.couponid;
  206. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  207. // let orderId = e.currentTarget.dataset.id;
  208. that.orderSave(couponId,couponChannelId)
  209. },
  210. mybargain: function () {
  211. let that = this;
  212. that.setData({
  213. bargaingoods: false,
  214. mybargain: true,
  215. flag: "mybargain",
  216. allow_load: true,
  217. loading: false,
  218. content: "",
  219. page:1
  220. })
  221. that.getList(1, 'mybargain');
  222. wx.setNavigationBarTitle({
  223. title: '我的砍价'
  224. })
  225. },
  226. bargaingoods: function () {
  227. let that = this;
  228. that.setData({
  229. bargaingoods: true,
  230. mybargain: false,
  231. flag: "bargaingoods",
  232. allow_load: true,
  233. loading: false,
  234. page:1,
  235. content: ""
  236. })
  237. that.getList(1, 'bargaingoods');
  238. wx.setNavigationBarTitle({
  239. title: '砍价专场'
  240. })
  241. },
  242. /**
  243. *
  244. * @param {砍价} 邀请好友砍价
  245. */
  246. invite: function (e) {
  247. let couponChannelId = e.currentTarget.dataset.id;
  248. let couponId = e.currentTarget.dataset.couponid;
  249. if (couponChannelId && couponId) {
  250. wx.navigateTo({
  251. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  252. })
  253. }
  254. },
  255. //加载更多
  256. onReachBottom: function () {
  257. let that = this;
  258. that.data.page++;
  259. that.setData({
  260. page: that.data.page
  261. });
  262. that.getList(that.data.page, that.data.flag);
  263. },
  264. /**
  265. * 刷新
  266. */
  267. onPullDownRefresh: function (e) {
  268. let that = this;
  269. if (that.data.flag == 'bargaingoods'){
  270. that.getBannerlist();
  271. var todayDate = new Date().getTime();
  272. that.setData({
  273. todayDate: todayDate
  274. })
  275. that.getList(1, "bargaingoods");
  276. that.setData({
  277. flag: "bargaingoods",
  278. bargaingoods: true,
  279. mybargain: false
  280. })
  281. } else if (that.data.flag == 'mybargain'){
  282. that.getList(1, "mybargain");
  283. that.setData({
  284. flag: "mybargain",
  285. bargaingoods: false,
  286. mybargain: true
  287. })
  288. }
  289. },
  290. })