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

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