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.

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