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.

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