C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

313 Zeilen
7.7 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.orderNumber}`
  205. })
  206. })
  207. .catch(err => {
  208. wx.showToast({
  209. title: err.message,
  210. icon: "none"
  211. })
  212. })
  213. },
  214. inviteFriend: function (e) {
  215. /**
  216. * 添加标识
  217. */
  218. wx.navigateTo({
  219. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${e.currentTarget.dataset.id}`
  220. })
  221. },
  222. barginAgain: function (e) {
  223. let that = this;
  224. console.log(e)
  225. let formId = e.detail.formId;
  226. let couponId = e.currentTarget.dataset.couponid;
  227. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  228. // let orderId = e.currentTarget.dataset.id;
  229. that.orderSave(couponId,couponChannelId,formId)
  230. },
  231. mybargain: function () {
  232. let that = this;
  233. that.setData({
  234. bargaingoods: false,
  235. mybargain: true,
  236. flag: "mybargain",
  237. allow_load: true,
  238. loading: false,
  239. content: "",
  240. page:1
  241. })
  242. that.getList(1, 'mybargain');
  243. wx.setNavigationBarTitle({
  244. title: '我的砍价'
  245. })
  246. },
  247. bargaingoods: function () {
  248. let that = this;
  249. that.setData({
  250. bargaingoods: true,
  251. mybargain: false,
  252. flag: "bargaingoods",
  253. allow_load: true,
  254. loading: false,
  255. page:1,
  256. content: ""
  257. })
  258. that.getList(1, 'bargaingoods');
  259. wx.setNavigationBarTitle({
  260. title: '砍价专场'
  261. })
  262. },
  263. /**
  264. *
  265. * @param {砍价} 发起砍价
  266. */
  267. invite: function (e) {
  268. let couponChannelId = e.currentTarget.dataset.id;
  269. let couponId = e.currentTarget.dataset.couponid;
  270. if (couponChannelId && couponId) {
  271. wx.navigateTo({
  272. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`
  273. })
  274. }
  275. },
  276. //加载更多
  277. onReachBottom: function () {
  278. let that = this;
  279. that.data.page++;
  280. that.setData({
  281. page: that.data.page
  282. });
  283. that.getList(that.data.page, that.data.flag);
  284. },
  285. /**
  286. * 刷新
  287. */
  288. onPullDownRefresh: function (e) {
  289. let that = this;
  290. if (that.data.flag == 'bargaingoods'){
  291. that.getBannerlist();
  292. var todayDate = new Date().getTime();
  293. that.setData({
  294. todayDate: todayDate
  295. })
  296. that.getList(1, "bargaingoods");
  297. that.setData({
  298. flag: "bargaingoods",
  299. bargaingoods: true,
  300. mybargain: false
  301. })
  302. } else if (that.data.flag == 'mybargain'){
  303. that.getList(1, "mybargain");
  304. that.setData({
  305. flag: "mybargain",
  306. bargaingoods: false,
  307. mybargain: true
  308. })
  309. }
  310. },
  311. })