C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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