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.

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