C端小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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