C端小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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