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.

316 line
7.8 KiB

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