C端小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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